A font switching method and device, electronic equipment and storage medium

By storing and downloading font configuration files and switching font files on a cloud server, converting them into objects recognizable by the Android system, and rewriting them during the application's page lifecycle, the problem of increased installation package size and compatibility and security risks caused by font switching in existing technologies is solved, achieving stable and efficient font switching.

CN116339858BActive Publication Date: 2026-05-12CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
Filing Date
2023-03-30
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing font switching methods require packaging custom font files into the installation package of third-party applications, which increases the size of the installation package and reduces user download and usage rates; or decompiling third-party applications by hooking system APIs, which poses compatibility and security risks and has poor stability.

Method used

By storing font configuration files and switching font files on a cloud server, pulling and downloading them from the cloud to the local directory of the terminal device, converting them into font objects that the Android system can recognize, and rewriting them in the lifecycle methods of the application's display page, font switching can be achieved without packaging and decompiling.

Benefits of technology

This avoids increasing the installation package size, increases user download and usage rates, reduces system compatibility and security risks, improves stability, and supports flexible font switching configurations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116339858B_ABST
    Figure CN116339858B_ABST
Patent Text Reader

Abstract

The application relates to the computer technical field and provides a font switching method and device, electronic equipment and a storage medium. The method comprises the following steps: receiving a font switching instruction; pulling a target font configuration file from a cloud server and downloading a target switching font file into a local directory of an application program; reading the target switching font file and converting the target switching font file into a font object that can be recognized and rendered by an Android system; analyzing the target font configuration file to obtain switching configuration information; rewriting a life cycle method of an interface display control of a display page of a target application program according to the switching configuration information to obtain a rewritten life cycle method; triggering the rewritten life cycle method to take effect and inputting the font object when entering the display page of the target application program, and switching a current application font of the display page of the target application program into a target switching font. The application can improve the download and use rate of the application program, reduce the compatibility and security risk of the system, and has good stability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a font switching method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the continuous development of computer technology, the application of terminal devices (such as mobile phones and computers) is becoming increasingly widespread. Users also have increasingly personalized needs for the application functions provided by these terminal devices; for example, users want to be able to easily switch the font of the text displayed on the terminal device.

[0003] In existing technologies, a common approach is to package a custom font file into the installation package of a third-party application, install the package on the terminal device, and overwrite the original system font file with the custom font file so that the terminal device can display text using the font from the custom font file. Alternatively, after the user downloads the installation package of the third-party application, the system API (programming interface) needs to be hooked to intercept the installation package. The package then needs to be decompressed and decompiled to obtain the source code. The original font file referenced by the third-party application's font in the source code is then replaced with the custom font file, resulting in a modified application. This modified application is then repackaged to obtain a new application package, which is finally installed on the terminal device, enabling the terminal device to display text using the font from the custom font file.

[0004] It is evident that existing font switching methods require packaging custom font files into the installation package of third-party applications, which significantly increases the size of the application installation package. The more custom font files packaged, the larger the installation package becomes, which may lead to a decrease in user download and usage rates. Alternatively, it may require hooking system APIs, decompiling third-party applications, and repackaging them. This process is prone to compatibility and security risks and has poor stability. Summary of the Invention

[0005] In view of this, embodiments of this application provide a font switching method, apparatus, electronic device, and storage medium to solve the problems of existing technologies that require packaging custom font files into the installation package of third-party applications, which significantly increases the size of the installation package and reduces the user's download and usage rate of the application; or require hooking the system API, decompiling the third-party application, and repackaging it, which is prone to compatibility and security risks and has poor stability.

[0006] A first aspect of this application provides a font switching method, including:

[0007] Receive font switching instructions, which include the target application and the target font to switch to;

[0008] Retrieve the target font configuration file corresponding to the font switching command from the cloud server, and download the target switching font file corresponding to the target font configuration file from the cloud server to the application's local directory;

[0009] Read the target font switching file from the application's local directory and convert it into a font object that the Android system can recognize and render.

[0010] The target font configuration file is parsed to obtain the switching configuration information, which includes the target font to switch, the switching mode, the switching method, and the current font used by the target application.

[0011] Based on the switching configuration information, the lifecycle methods of the display controls of the target application's display page are overridden to obtain the overridden lifecycle methods of the display controls of the display page.

[0012] When entering the target application's display page, the overridden lifecycle method is triggered and a font object is passed in, switching the current application font of the target application's display page to the target font.

[0013] A second aspect of this application provides a font switching device, including:

[0014] The receiving module is configured to receive font switching instructions, which include the target application and the target font to be switched.

[0015] The download module is configured to retrieve the target font configuration file corresponding to the font switching command from the cloud server, and download the target switching font file corresponding to the target font configuration file from the cloud server to the application's local directory;

[0016] The conversion module is configured to read the target switching font file from the application's local directory and convert the target switching font file into a font object that the Android system can recognize and render;

[0017] The parsing module is configured to parse the target font configuration file to obtain the switching configuration information, which includes the target font to switch, the switching mode, the switching method, and the current font of the target application.

[0018] The rewrite module is configured to override the lifecycle methods of the UI display controls of the target application's display page based on the switching configuration information, thereby obtaining the overridden lifecycle methods of the UI display controls of the display page.

[0019] The switching module is configured to trigger the overridden lifecycle method and pass in a font object when entering the target application's display page, switching the current application font of the target application's display page to the target switching font.

[0020] A third aspect of this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method.

[0021] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method.

[0022] Compared with the prior art, the beneficial effects of this application embodiment include at least the following: On the one hand, this application embodiment stores the target font configuration file and the target switching font file corresponding to the font switching command in a cloud server. When needed, the target font configuration file corresponding to the font switching command is retrieved from the cloud server, and the target switching font file corresponding to the target font configuration file is downloaded from the cloud server to the local directory of the application on the terminal device (such as a mobile phone, computer, etc.). This eliminates the need to package the custom font file into the application's installation package, avoiding increasing the size of the installation package and improving the user's download and usage rate of the application. On the other hand, in this embodiment, the terminal device first reads the target font switching file from the application's local directory and converts it into a font object that the Android system can recognize and render. Then, the target font configuration file is parsed to obtain switching configuration information. Based on the switching configuration information, the lifecycle methods of the interface display controls on the target application's display page are overridden to obtain the overridden lifecycle methods of the interface display controls on the display page. Subsequently, when entering the target application's display page, the overridden lifecycle methods are triggered and a font object is passed in to switch the current application font on the target application's display page to the target font switching font. The entire font switching process does not require hooking system APIs, decompiling third-party applications, or repackaging, reducing system compatibility and security risks, and exhibiting good stability. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 This is a schematic diagram illustrating one application scenario of this application.

[0025] Figure 2 This is a flowchart illustrating a font switching method provided in an embodiment of this application;

[0026] Figure 3 This is a schematic diagram of the overall process of a font switching method provided in an embodiment of this application;

[0027] Figure 4 This is a schematic diagram of the display control distribution on a display page in a font switching method provided in this application embodiment;

[0028] Figure 5 This is a schematic diagram of the structure of a font switching device provided in an embodiment of this application;

[0029] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0030] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.

[0031] A font switching method and apparatus according to an embodiment of this application will now be described in detail with reference to the accompanying drawings.

[0032] Figure 1 This is a schematic diagram illustrating an application scenario according to an embodiment of this application. The application scenario may include a terminal device 101, a cloud server 102, and a network 103.

[0033] Terminal device 101 can be hardware or software. When terminal device 101 is hardware, it can be various electronic devices with a display screen that support communication with cloud server 102, including but not limited to smartphones, tablets, laptops, and desktop computers; when terminal device 101 is software, it can be installed in the aforementioned electronic devices. Terminal device 101 can be implemented as multiple software programs or software modules, or as a single software program or software module; this application embodiment does not limit this. Furthermore, various applications can be installed on terminal device 101, such as data processing applications, instant messaging tools, social platform software, search applications, shopping applications, etc.

[0034] The cloud server 102 can be a single server, a server cluster consisting of several servers, or a cloud computing service center. This application embodiment does not limit this.

[0035] Network 103 can be a wired network using coaxial cable, twisted pair, and fiber optic connection, or it can be a wireless network that enables interconnection of various communication devices without wiring, such as Bluetooth, Near Field Communication (NFC), and Infrared. This application embodiment does not limit this.

[0036] Terminal device 101 can establish a communication connection with cloud server 102 via network 103 to receive or send information. Specifically, when terminal device 101 receives a font switching command triggered by the user or issued by cloud server 102, it can retrieve the target font configuration file corresponding to the font switching command from cloud server 102 and download the target switching font file corresponding to the target font configuration file to its application's local directory. Then, it reads the target switching font file from the application's local directory and converts it into a font object that the Android system can recognize and render. Next, it parses the target font configuration file to obtain switching configuration information. Then, based on the switching configuration information, it overrides the lifecycle methods of the interface display controls of the target application's display page to obtain the overridden lifecycle methods of the interface display controls of the display page. When entering the display page of the target application, the overridden lifecycle methods are triggered and the font object is passed in, switching the current application font of the target application's display page to the target switching font. The entire font switching process does not require hooking system APIs, decompiling third-party applications, or repackaging, reducing system compatibility and security risks, and has good stability.

[0037] It should be noted that the specific types, quantities, and combinations of terminal device 101, cloud server 102, and network 103 can be adjusted according to the actual needs of the application scenario, and this application embodiment does not impose any restrictions on this.

[0038] Figure 2 This is a flowchart illustrating a font switching method provided in an embodiment of this application. Figure 2 The font switching method can be provided by Figure 1 The terminal device 101 executes. For example... Figure 2 As shown, the font switching method includes:

[0039] Step S201: Receive a font switching instruction, which includes the target application and the target font to switch to.

[0040] Combination Figure 3 In one implementation, when a user is browsing a third-party application installed on terminal device 101 and wants to change the font of the current application, the terminal device 101 can establish a communication connection with the cloud server 102 via network 103. The terminal device 101 then retrieves font list data from the cloud server 102. This font list data includes at least the names of the fonts that can be switched, and the font list data is displayed on the current interface of the terminal device 101 so that the user can select the font they want to switch to. For example, when the user selects a font from the font list data through clicking or other operations, it is considered that the user has initiated a font switching command (which can be called a local switching command) to the terminal device 101. At this time, the terminal device 101 receives the font switching command, which includes the third-party application currently being browsed by the user (i.e., the target application) and the target font to switch to (for example, if the user clicks on "SimSun" in the font list data, then the target font to switch to is "SimSun").

[0041] In another implementation, when the cloud server 102 pushes application services to the terminal device 101, it can issue a font switching command (which may be called a cloud switching command) to the terminal device 101.

[0042] Terminal device 101 can listen to notifications from the cloud server 102 regarding push application services, which carry font switching instructions. Upon receiving this notification, terminal device 101 determines whether the target application is in the foreground. If the target application is in the foreground, it continues with steps S202 to S206. If the target application is in the background or has been killed, the font switching instructions are saved locally, and then steps S202 to S206 are executed again to perform the font switching operation when the target application starts.

[0043] Third-party applications, including but not limited to WeChat, QQ, Sogou Input Method and other applications (APPs).

[0044] Step S202: Retrieve the target font configuration file corresponding to the font switching instruction from the cloud server, and download the target switching font file corresponding to the target font configuration file from the cloud server to the application's local directory.

[0045] The font configuration file related to the font switching function can be configured through the terminal device 101 and uploaded to the cloud server 102 for storage. The font configuration file mainly stores information such as font name (e.g., SimSun, Heiti, Kaiti, etc.), font style (e.g., bold, italic, bold italic, normal font, etc.), font weight (font thickness, such as how many points), the page to be switched, and the currently applied font (e.g., SimSun, Heiti, etc.), and can be stored in key-value pairs using JSON.

[0046] In addition, font files for various fonts can be stored on cloud server 102. Font files are typically in OTF or TTF format and are relatively large. Storing font files on cloud server 102, rather than packaging them into the application's installation package, does not increase the installation package size, which helps improve user download and usage rates of the application.

[0047] In one embodiment, a FontSwitchManager management class can be created on the terminal device 101 to manage font configuration files and establish a connection with the cloud server 102 to obtain font switching instructions.

[0048] The FontSwitchManager class is a global singleton, ensuring that there is only one instance of the FontSwitchManager class in the application, thus avoiding resource conflicts and waste. That is, if there are N third-party applications, then N FontSwitchManager classes will be set up accordingly, with one FontSwitchManager class corresponding to each third-party application, where N is a positive integer ≥ 1.

[0049] In another embodiment, a communication middleware can be provided, through which terminal device 101 and cloud server 102 can transmit information. This middleware can be used to configure font configuration files related to the font switching function and uploaded to cloud server 102 for storage, increasing the flexibility of configuration operations.

[0050] For ease of management and maintenance, typically one font configuration sub-file corresponds to one third-party application. These sub-files are then merged into a single font configuration file and uploaded to a cloud server (102 storage). A typical font configuration sub-file includes multiple switchable fonts (such as SimSun, Heiti, Kaiti, etc.) and the corresponding switching configuration information for each font.

[0051] When terminal device 101 receives a font switching command, it can retrieve the font configuration sub-file corresponding to the target application from the cloud server 102, then further extract the target font configuration file corresponding to the target font to be switched from the font configuration sub-file, and simultaneously download the target font file corresponding to the target font to be switched from the cloud server 102 to its application's local directory. The target font file is usually in OTF or TTF format.

[0052] Step S203: Read the target switching font file from the application's local directory and convert the target switching font file into a font object that the Android system can recognize and render.

[0053] Terminal device 101 reads the downloaded target font file from the application's local directory, and then calls the system method `Typeface.createFromFile(path:String)`, passing in the font file path of the downloaded target font file, to convert the target font file, which is in OTF or TTF format, into a Typeface font object that the Android system can recognize and render. Typeface is responsible for loading fonts in the Android system and calling related font APIs provided by the upper layer.

[0054] Step S204: Parse the target font configuration file to obtain the switching configuration information, which includes the target switching font, switching mode, switching method, and the current application font of the target application.

[0055] Switch mode and switch type can be stored as key-value pairs.

[0056] Based on the granularity of switching, switching methods can be divided into two types: switching based on category and switching based on unique identifier.

[0057] The current application font refers to the font currently used by the target application.

[0058] In one embodiment, the target font configuration file can be parsed using the FontSwitchManager management class to obtain the switching configuration information.

[0059] Step S205: Based on the switching configuration information, the lifecycle methods of the interface display controls of the target application's display page are overridden to obtain the overridden lifecycle methods of the interface display controls of the display page.

[0060] Display pages typically refer to the pages that can be shown to users within a target application.

[0061] Interface display controls include display controls (or view controls) for displaying text information and display controls (or view controls) for displaying image information.

[0062] In one embodiment, a base class DynamicFontActivity, which inherits from Activity, can be created on the terminal device 101. Activity is a class in the Android system responsible for interface display. The interface display control is implemented based on Activity. According to the parsed switching configuration information, the lifecycle methods (onResume() method) of the interface display control of the target application's display page are overridden to obtain the overridden lifecycle methods of the interface display control of the display page.

[0063] The font switching logic can be implemented by calling the switching method in the FontSwitchManager management class in the overridden lifecycle methods.

[0064] Step S206: When entering the display page of the target application, the overridden lifecycle method is triggered and a font object is passed in to switch the current application font of the display page of the target application to the target switching font.

[0065] The technical solution provided in this application has several advantages. First, by storing the target font configuration file and target font file corresponding to the font switching command in a cloud server, the size of the application's installation package is not increased, which helps improve the download and usage rate of the APP (application). Second, the entire font switching process does not require hooking system APIs, decompiling third-party applications, or repackaging, reducing system compatibility and security risks and improving stability. Third, the technical solution provided in this application supports flexible configuration of font switching and supports both local and cloud-based methods. It supports switching the font of the target application by issuing font switching commands from the cloud, improving the flexibility of font switching and expanding the applicable scenarios for font switching.

[0066] In some embodiments, the switching mode is a global switching mode. The global switching mode can be defined as FULL mode.

[0067] The above step S205 specifically includes: determining each display page in the target application as a target switching page; and rewriting the lifecycle methods of the interface display controls of each target switching page according to the switching configuration information to obtain the corresponding rewritten lifecycle methods.

[0068] Android applications typically consist of multiple display pages, each of which is hosted by a separate Activity. Each Activity has an onResume() lifecycle method, which is called by the system when the application resumes from an activity. During this lifecycle, UI elements are generally visible to the user, and the method is also called when switching display pages. Therefore, the font switching operation (i.e., the switching logic that implements font switching) should be placed within the onResume() lifecycle method to ensure that all pages complete the font switching operation.

[0069] As an example, suppose the target application has 10 display pages, numbered A, B, C...J, and these 10 display pages are all designated as target switching pages. Based on the switching configuration information, the lifecycle methods of the UI controls for these 10 display pages (i.e., the target switching pages) are overridden. Specifically, the switching logic (including switching methods, switching modes, etc.) used to implement font switching from the switching configuration information is written into the `onResume()` lifecycle method of each target switching page's UI control, resulting in the corresponding overridden lifecycle methods.

[0070] The above step S206 specifically includes:

[0071] When entering any target switching page in the target application, obtain the root view of the interface display control of the target switching page; traverse the root view to find the target display control that is a text control or its subclass. The interface display control includes multiple display controls, and the target display control is one or more of the multiple display controls; trigger the overridden lifecycle method of the target switching page and pass in the font object to switch the current application font of the page area corresponding to the target display control in the target switching page to the target switching font.

[0072] Specifically, a `switchFont(decorView:View)` method can be created in the `FontSwitchManager` management class. Its parameter is the root view obtained by calling the system method `window.devorView`. Since the Android view system is implemented using a view tree, and `View` is the base class of each control, there may be multiple child views under each parent view. Therefore, this method is implemented by obtaining the root view (i.e., the parent view) and then traversing the current page view tree. When the view control is a `TextView` or its subclass, the `setTypeface()` method is called, passing in the `Typeface` font object obtained in step S203 above to complete the font switching.

[0073] TextView is a view control in the Android system that displays font text.

[0074] View is the base class for all View controls in the Android system, responsible for the width, height, layout, and rendering of the controls.

[0075] As an example, combined with Figure 4 Suppose that when a user enters the display page A of a target application A, the `switchFont(decorView:View)` method calls the system method `window.devorView` to obtain the root view (parent view) of the UI display controls of display page A. Then, the view tree of display page A is traversed to find the target display control that is a text control (TextView) or its subclass. For example, after traversal, it is determined that... Figure 4 If the display controls ①, ②, ③, and ④ are all TextView or their subclasses, then the display controls ①, ②, ③, and ④ are determined as the target display controls. Afterwards, the overridden lifecycle method of display page A is triggered. Within the overridden lifecycle method, the setTypeface() method is called, passing in the Typeface font object obtained in step S203 above. This switches the currently applied font (e.g., SimSun) of the page areas corresponding to display controls ①, ②, ③, and ④ in display page A to the target switching font (e.g., Heiti).

[0076] In some embodiments, the overridden lifecycle method of the target switching page is triggered, and a font object is passed in to switch the current application font of the page area corresponding to the target display control in the target switching page to the target switching font, specifically including:

[0077] If the current application font in the page area corresponding to the target display control in the target switching page has a font style, then load the target font file corresponding to the font style from the target switching font file, and convert the target font file into a target font object that the Android system can recognize and render; trigger the overridden lifecycle method of the target switching page to take effect, and pass in the target font object to switch the current application font in the page area corresponding to the target display control in the target switching page to the target switching font.

[0078] refer to Figure 4Referring to the example above, assuming that the current application font in the page area corresponding to the target display control in display page A has a font style (e.g., italic), in order to ensure that the display style is consistent before and after the font switch, it is necessary to load the target font file corresponding to the font style from the target switching font file, and convert the target font file into a target font object that the Android system can recognize and render, referring to the method in step S203 above. Then, the overridden lifecycle method of display page A is triggered to take effect. In the overridden lifecycle method, the setTypeface() method is called, passing in the Typeface font object obtained in step S203 above, which will switch the current application font (e.g., SimSun, italic style) in the page area corresponding to display controls ①, ②, ③ and ④ in display page A to the target switching font (e.g., bold, italic style).

[0079] In other embodiments, the switching mode is a partial switching mode, and the switching configuration information also includes text control labels. The partial switching mode can be defined as a PART mode. The text control label refers to the label information of the text control corresponding to the page area (such as an advertisement space) that requires font switching on the display page. This label information can be numbers, letters, or other strings.

[0080] When the target application starts, the terminal device can upload the text control label to the cloud server via an HTTP request, which facilitates subsequent configuration.

[0081] The above step S205 specifically includes:

[0082] Each display page in the target application is identified as a target switching page; based on the switching configuration information, the lifecycle methods of the interface display controls of each target switching page are overridden to obtain the corresponding overridden lifecycle methods.

[0083] As an example, suppose the target application has 10 display pages, numbered A, B, C...J, and these 10 display pages are all designated as target switching pages. Based on the switching configuration information, the lifecycle methods of the UI controls for these 10 display pages (i.e., the target switching pages) are overridden. Specifically, the switching logic (including switching methods, switching modes, etc.) used to implement font switching from the switching configuration information is written into the `onResume()` lifecycle method of each target switching page's UI control, resulting in the corresponding overridden lifecycle methods.

[0084] The above step S206 specifically includes:

[0085] Upon entering any target switching page in the target application, obtain the label information of the text display control in the interface display controls of the target switching page. The interface display controls include multiple display controls, and the text display control is one or more of the multiple display controls. Filter out the target text display control from the text display controls whose label information matches the text control's label. Trigger the overridden lifecycle method of the target switching page and pass in a font object to switch the current application font of the page area corresponding to the target text display control in the target switching page to the target switching font.

[0086] In one embodiment, the text display controls in each display page of the target application A can be categorized first. For example, titles can be categorized as H1, H2, H3, etc., and paragraphs can be categorized as P1, P2, P3, etc. Then, different category labels can be set for each different text display control according to the category. Specifically, the setTag() method can be called to set different category labels (i.e., label information) for each text display control.

[0087] Taking page A as an example, there are a total of 4 text display controls on page A (display controls ①, ②, ③ and ④ respectively). Display control ① corresponds to the title display area, so the setTag() method can be called to set the category label of display control ① to "H1". Display controls ②, ③ and ④ are all paragraph display areas, so the setTag() method can be called to set the category labels of display controls ②, ③ and ④ to "P1", "P2" and "P3" respectively.

[0088] As an example, combined with Figure 4 When a user enters display page A of a target application A, the method provided in the example above can be used to first identify the text display controls that belong to TextView or its subclasses on display page A. For example, the text display controls that belong to TextView or its subclasses are... Figure 4 If we select the display controls ①, ②, ③, and ④, we can further obtain the label information of the display controls ①, ②, ③, and ④.

[0089] Assuming the text control's label is "H1", the `getTag()` method can be used to retrieve the label information of display controls ①, ②, ③, and ④. Then, the retrieved label information is compared with the text control's label. If the comparison confirms that the label information "H1" of display control ① matches the text control's label "H1", then display control ① is selected as the target text display control. Next, the overridden lifecycle method of page display A is triggered, and a font object is passed in to switch the current applied font (e.g., SimSun) of the page area corresponding to display control ① in the target switching page to the target switching font (e.g., Heiti).

[0090] In another embodiment, a unique identifier can be set for the text display controls on each display page of the target application A. Specifically, the setId method can be called to set a custom unique identifier. This unique identifier is the label information of the text display control.

[0091] Based on the above example, taking page A as an example, there are a total of 4 text display controls on page A (namely display controls ①, ②, ③ and ④). You can set a custom unique identifier "①", "②", "③" and "④" for each text display control by calling the setId method.

[0092] Assuming the text control's label is "①", the label information of display controls ①, ②, ③, and ④ can be obtained by calling the `getId()` method. Then, the obtained label information is compared with the text control's label. If the comparison confirms that the label information "①" of display control ① matches the text control's label "①", then display control ① is selected as the target text display control. Next, the overridden lifecycle method of page display A is triggered, and a font object is passed in to switch the current applied font (e.g., SimSun) of the page area corresponding to display control ① in the target switching page to the target switching font (e.g., Heiti).

[0093] The technical solution provided in this application embodiment can partially switch font effects on page elements. If an advertisement space exists on a display page, the font effect of the advertisement space in that area can be switched to highlight the advertisement space and reflect its advertising value.

[0094] In some other embodiments, the switching mode is a multi-page switching mode, and the switching method includes a global font switching method or a local font switching method. The switching configuration information also includes multiple unique page identifiers.

[0095] The global font switching method can be defined as the switchFontPartly() method, and the local font switching method can be defined as the switchFontFully() method.

[0096] The page unique identifier is a unique identifier used to indicate which page needs to be switched to. Page unique identifiers can be distinguished using the full path of the class name, such as the string com.seres.sone.TestActivity.

[0097] When the target application starts, the terminal device can upload the page's unique identifier information to the cloud server via an HTTP request, facilitating subsequent configuration.

[0098] The above step S206 specifically includes:

[0099] When entering the currently displayed page of the target application, obtain the page tag information of the currently displayed page; if the page tag information is included in multiple page unique identifiers, then determine the target control on the currently displayed page that needs to be font switched based on the switching method; trigger the overridden lifecycle method of the currently displayed page to take effect, and pass in the font object to switch the current application font of the page area corresponding to the target control in the current display page of the target application to the target switching font.

[0100] Page tag information is a unique identifier used to indicate the currently displayed page. Page tag information can also be distinguished using the full path of the class name, such as the string com.seres.sone.TestActivity.

[0101] You can add switchFontPartly() / switchFontFully() methods to the FontSwitchManager management class.

[0102] As an example, upon entering the current display page (e.g., display page B) of a target application A, the page label information of display page B is obtained. Then, multiple page unique identifiers are traversed to check if a page unique identifier matching the page label information exists. If it exists, the corresponding switching method (e.g., a global font switching method) is found using that page unique identifier, and the target control requiring font switching is further determined based on the `switchFontFully()` method. For example, if the switching method corresponding to display page B is a global font switching method, then all text display controls belonging to `TextView` or its subclasses on display page B are identified as target controls. Afterwards, the overridden lifecycle method of display page B is triggered, passing in a font object, and the current application font of all page areas in display page B of the target application A corresponding to the target control is switched to the target font.

[0103] If the switching method corresponding to the display page B is a partial font switching method, then the target control whose font needs to be switched can be obtained by calling the system findViewWithTag() method in the switchFontPartly() method, and the obtained target control can be cached in a collection. This triggers the overridden lifecycle method of the display page B to take effect, and the font object is passed in to switch the current application font of the page area corresponding to the target control in the collection to the target switching font.

[0104] When navigating from display page B to display page C, the above steps can be used to switch the global or partial font on display page C.

[0105] The technical solution provided in this application embodiment adds switchFontPartly() / switchFontFully() methods to the FontSwitchManager management class. When the FontSwitchManager management class is called to parse the target font configuration file and obtain the switching configuration information, the switching method of the current display page that needs to switch fonts can be determined according to the unique page identifier information, thereby calling different switching methods to realize multi-mode font switching for multiple display pages.

[0106] In some embodiments, step S206 above includes:

[0107] When entering display page A of the target application, the overridden lifecycle method of display page A is triggered and a font object is passed in. The current application font of display page A is switched to the target font, and the font switching time is recorded. When jumping from display page A to display page B and then back to display page A, the jump time when jumping back to display page A is obtained. The time difference between the jump time and the font switching time is calculated. If the time difference exceeds a preset time threshold, the overridden lifecycle method of display page A is triggered again and a font object is passed in. The current application font of display page A is switched to the target font, and the font switching time is updated.

[0108] Specifically, in the FontSwitchManager management class, you can define a field called switchTimeMap, which is declared as a hash dictionary type, with the key being the page class and the value being the last font switching time; and define a field called keepDuration, such as 60 seconds.

[0109] As an example, upon entering display page A of the target application K, the overwrite lifecycle method of display page A is triggered and a font object is passed in. The current application font of display page A is switched to the target font, and the font switching time T1 is recorded. When navigating from display page A to display page B and then back to display page A, the navigation time T2 (i.e., the current time) is obtained, and the font switching time T1 is retrieved from the switchTimeMap. Next, the time difference between the navigation time T2 and the font switching time T1 is calculated. This time difference is then compared to the defined retention time (keepDuration) (i.e., a preset time threshold). If the time difference exceeds the preset time threshold, the overwrite lifecycle method of display page A is triggered again, passing in a font object to switch the current application font of display page A to the target font, and the font switching time is updated. If the time difference does not exceed the preset time threshold, the overwrite lifecycle method of display page A is not triggered again.

[0110] Considering the scenario of navigating from the current display page to the next display page and then back to the current display page, the aforementioned preset time threshold method cannot fully cover this usage scenario. There is a possibility that the overridden lifecycle method of the current display page might be repeatedly called after the preset time threshold is exceeded. This application proposes another solution. Specifically, step S206 includes:

[0111] The font switching field value of the target application's display page A is set to the first field value. When entering the target application's display page A, the overridden lifecycle method of display page A is triggered and a font object is passed in to switch the current application font of the target application's display page A to the target switching font, and the first field value is modified to the second field value. When navigating from display page A to display page B, and then navigating back from display page B to display page A, the font switching field value of display page A is retrieved. If the font switching field value is the second field value, the overridden lifecycle method of display page A is not triggered again.

[0112] Specifically, a boolean field switchStatus can be defined in the DynamicFontActivity base class to represent whether a font switching operation has been performed. Since each display page has a different Activity instance, the value of the switchStatus field is different for each display page.

[0113] As an example, we can first set the font switching field value of the display page A of the target application K to the first field value, that is, set its switchStatus field value to false (the first field value), indicating that no font switching operation was performed. Understandably, before starting the target application, the font switching field value of all display pages can be set to the first field value.

[0114] When entering display page A of the target application K, the write lifecycle method of display page A is triggered, and after executing the FontSwitchManager.switchFont() method in onResume(), the font switching field value of display page A is set to true (i.e., the second field value). When navigating from display page A to display page B, and then back from display page B to display page A, the font switching field value of display page A is retrieved. It is then determined whether the font switching field value of display page A is true or false. If it is true, the overridden lifecycle method of display page A is not triggered again; if it is false, the overridden lifecycle method of display page A is triggered again.

[0115] When a font switching command is issued from the cloud server or when the user switches manually, the value of the switchStatus field on the target application's display page can be reset.

[0116] The technical solution provided in this application, in the scenario of switching from display page A to display page B and back to display page A, can effectively reduce the frequent calls to the font switching method and improve page performance by setting the field retention time or setting the font switching field value.

[0117] All of the above-mentioned optional technical solutions can be combined in any way to form the optional embodiments of this application, and will not be described in detail here.

[0118] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.

[0119] Figure 5 This is a schematic diagram of a font switching device provided in an embodiment of this application. Figure 5 As shown, the font switching device includes:

[0120] The receiving module 501 is configured to receive a font switching instruction, which includes a target application and a target font to switch to.

[0121] Download module 502 is configured to retrieve the target font configuration file corresponding to the font switching instruction from the cloud server, and download the target switching font file corresponding to the target font configuration file from the cloud server to the application's local directory;

[0122] The conversion module 503 is configured to read the target switching font file from the application's local directory and convert the target switching font file into a font object that can be recognized and rendered by the Android system;

[0123] Parsing module 504 is configured to parse the target font configuration file to obtain switching configuration information, which includes the target switching font, switching mode, switching method, and the current application font of the target application.

[0124] The rewrite module 505 is configured to rewrite the lifecycle methods of the interface display controls of the target application's display page based on the switching configuration information, thereby obtaining the rewritten lifecycle methods of the interface display controls of the display page.

[0125] The switching module 506 is configured to trigger the overridden lifecycle method and pass in a font object when entering the display page of the target application, so as to switch the current application font of the display page of the target application to the target switching font.

[0126] The technical solution provided in this application has several advantages. First, by storing the target font configuration file and target font file corresponding to the font switching command in a cloud server, the size of the application's installation package is not increased, which helps improve the download and usage rate of the APP (application). Second, the entire font switching process does not require hooking system APIs, decompiling third-party applications, or repackaging, reducing system compatibility and security risks and improving stability. Third, the technical solution provided in this application supports flexible configuration of font switching and supports both local and cloud-based methods. It supports switching the font of the target application by issuing font switching commands from the cloud, improving the flexibility of font switching and expanding the applicable scenarios for font switching.

[0127] In some embodiments, the switching mode is a global switching mode. The aforementioned rewrite module 505 specifically includes:

[0128] The first determining unit is configured to determine each displayed page in the target application as the target switching page;

[0129] The first rewrite unit is configured to rewrite the lifecycle methods of the interface display controls for each target switching page based on the switching configuration information, thereby obtaining the corresponding rewritten lifecycle methods.

[0130] The aforementioned switching module 506 specifically includes:

[0131] The acquisition unit is configured to acquire the root view of the interface display controls of the target switching page when entering any target switching page in the target application;

[0132] The traversal unit is configured to traverse the root view and find the target display control that is a text control or its subclass in the interface display controls. The interface display controls include multiple display controls, and the target display control is one or more of the multiple display controls.

[0133] The first switching unit is configured to trigger the overridden lifecycle method of the target switching page and pass in a font object to switch the current application font of the page area corresponding to the target display control in the target switching page to the target switching font.

[0134] In some embodiments, the first switching unit specifically includes:

[0135] The loading component is configured to load the target font file corresponding to the font style from the target switching font file if the current application font in the page area corresponding to the target display control in the target switching page has a font style, and convert the target font file into a target font object that can be recognized and rendered by the Android system.

[0136] The switching component is configured to trigger the overridden lifecycle method of the target switching page, and is passed the target font object to switch the current application font of the page area corresponding to the target display control in the target switching page to the target switching font.

[0137] In some embodiments, the switching mode is a partial switching mode, and the switching configuration information also includes a text control label. The aforementioned rewrite module 505 specifically includes:

[0138] The second determining unit is configured to determine each displayed page in the target application as the target switching page;

[0139] The second rewrite unit is configured to rewrite the lifecycle methods of the interface display controls for each target switching page based on the switching configuration information, thereby obtaining the corresponding rewritten lifecycle methods.

[0140] The aforementioned switching module 506 specifically includes:

[0141] The tag acquisition unit is configured to acquire the tag information of the text display control in the interface display control of the target switching page when entering any target switching page of the target application. The interface display control includes multiple display controls, and the text display control is one or more of the multiple display controls.

[0142] The filtering unit is configured to filter out target text display controls whose label information matches the label of the text control from the text display control;

[0143] The second switching unit is configured to trigger the overridden lifecycle method of the target switching page and pass in a font object to switch the current application font of the page area corresponding to the target text display control in the target switching page to the target switching font.

[0144] The technical solution provided in this application embodiment can partially switch font effects on page elements. If an advertisement space exists on a display page, the font effect of the advertisement space in that area can be switched to highlight the advertisement space and reflect its advertising value.

[0145] In some embodiments, the switching mode is a multi-page switching mode, and the switching method includes a global font switching method or a local font switching method. The switching configuration information also includes multiple unique page identifiers. The aforementioned switching module 506 specifically includes:

[0146] The information acquisition unit is configured to acquire the page tag information of the currently displayed page when entering the currently displayed page of the target application;

[0147] The control determination unit is configured to determine the target control on the currently displayed page that needs to have its font changed, based on the switching method, if multiple page unique identifiers contain page tag information.

[0148] The third switching unit is configured to trigger the overridden lifecycle method of the currently displayed page and pass in a font object to switch the current application font of the page area corresponding to the target control in the current display page of the target application to the target switching font.

[0149] The technical solution provided in this application embodiment can determine the switching method of the current display page that needs to switch fonts based on the unique page identifier information, thereby calling different switching methods to realize multi-mode font switching for multiple display pages.

[0150] In some embodiments, the switching module 506 specifically includes:

[0151] The recording unit is configured to trigger the overridden lifecycle method of display page A when entering the display page A of the target application and pass in a font object to switch the current application font of display page A of the target application to the target switching font and record the font switching time.

[0152] The time acquisition unit is configured to acquire the jump time when jumping back to display page A after jumping from display page A to display page B and then back to display page A.

[0153] The calculation unit is configured to calculate the time difference between the jump time and the font switching time;

[0154] The fourth switching unit is configured to trigger the rewrite lifecycle method of display page A again and pass in the font object if the time difference exceeds the preset time threshold, so as to switch the current application font of the target application's display page A to the target switching font and update the font switching time.

[0155] In some embodiments, the switching module 506 specifically includes:

[0156] The setting unit is configured to set the font switching field value of the display page A of the target application to the first field value;

[0157] The modification unit is configured to trigger the overridden lifecycle method of display page A when entering the display page A of the target application and pass in a font object to switch the current application font of display page A of the target application to the target switching font and modify the value of the first field to the value of the second field.

[0158] The field acquisition unit is configured to acquire the font switching field value of display page A when the user jumps from display page A to display page B and then jumps back from display page B to display page A.

[0159] Skip unit, configured so that if the font switching field value is the second field value, the overridden lifecycle method of display page A will not be retried.

[0160] The technical solution provided in this application, in the scenario of switching from display page A to display page B and back to display page A, can effectively reduce the frequent calls to the font switching method and improve page performance by setting the field retention time or setting the font switching field value.

[0161] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0162] Figure 6 This is a schematic diagram of the electronic device 6 provided in an embodiment of this application. Figure 6 As shown, the electronic device 6 of this embodiment includes a processor 601, a memory 602, and a computer program 603 stored in the memory 602 and executable on the processor 601. When the processor 601 executes the computer program 603, it implements the steps in the various method embodiments described above. Alternatively, when the processor 601 executes the computer program 603, it implements the functions of each module / unit in the various device embodiments described above.

[0163] Electronic device 6 can be a desktop computer, laptop, handheld computer, cloud server, or other electronic device. Electronic device 6 may include, but is not limited to, processor 601 and memory 602. Those skilled in the art will understand that... Figure 6 This is merely an example of electronic device 6 and does not constitute a limitation on electronic device 6. It may include more or fewer components than shown, or different components.

[0164] The processor 601 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0165] The memory 602 can be an internal storage unit of the electronic device 6, such as a hard disk or RAM of the electronic device 6. The memory 602 can also be an external storage device of the electronic device 6, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., equipped on the electronic device 6. The memory 602 can also include both internal and external storage units of the electronic device 6. The memory 602 is used to store computer programs and other programs and data required by the electronic device.

[0166] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0167] If an integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program may include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added to or subtracted according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0168] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A font switching method, characterized in that, include: Receive a font switching instruction, the font switching instruction including a target application and a target font to switch to; Retrieve the target font configuration file corresponding to the font switching instruction from the cloud server, and download the target switching font file corresponding to the target switching font from the cloud server to the application's local directory; Read the target font switching file from the application's local directory and convert the target font switching file into a font object that can be recognized and rendered by the Android system; The target font configuration file is parsed to obtain switching configuration information, which includes the target switching font, switching mode, switching method, and the current application font of the target application. Based on the switching configuration information, the lifecycle methods of the interface display controls of the target application's display page are overridden to obtain the overridden lifecycle methods of the interface display controls of the display page. When entering the display page of the target application, the overridden lifecycle method is triggered and the font object is passed in, switching the current application font of the display page of the target application to the target switching font.

2. The method according to claim 1, characterized in that, The switching mode is a global switching mode; Based on the switching configuration information, the lifecycle methods of the interface display controls on the display page of the target application are rewritten to obtain the rewritten lifecycle methods of the interface display controls on the display page, including: Each displayed page in the target application is identified as the target switching page; Based on the switching configuration information, the lifecycle methods of the interface display controls of each target switching page are overridden to obtain the corresponding overridden lifecycle methods. When entering the display page of the target application, the overridden lifecycle method is triggered and the font object is passed in, switching the current application font of the display page of the target application to the target switching font, including: When entering any target switching page in the target application, obtain the root view of the interface display control of the target switching page; Traverse the root view to find the target display control that is a text control or its subclass among the interface display controls. The interface display controls include multiple display controls, and the target display control is one or more of the multiple display controls. The overridden lifecycle method of the target switching page is triggered, and the font object is passed in to switch the current application font of the page area corresponding to the target display control in the target switching page to the target switching font.

3. The method according to claim 2, characterized in that, The overridden lifecycle method of the target switching page is triggered and the font object is passed in. The current application font of the page area corresponding to the target display control on the target switching page is switched to the target switching font, including: If the current application font in the page area corresponding to the target display control in the target switching page has a font style, then load the target font file corresponding to the font style from the target switching font file, and convert the target font file into a target font object that can be recognized and rendered by the Android system; The overridden lifecycle method of the target switching page is triggered, and the target font object is passed in to switch the current application font of the page area corresponding to the target display control in the target switching page to the target switching font.

4. The method according to claim 1, characterized in that, The switching mode is a partial switching mode, and the switching configuration information also includes text control labels; Based on the switching configuration information, the lifecycle methods of the interface display controls on the display page of the target application are rewritten to obtain the rewritten lifecycle methods of the interface display controls on the display page, including: Each displayed page in the target application is identified as the target switching page; Based on the switching configuration information, the lifecycle methods of the interface display controls of each target switching page are overridden to obtain the corresponding overridden lifecycle methods. When entering the display page of the target application, the overridden lifecycle method is triggered and the font object is passed in, switching the current application font of the display page of the target application to the target switching font, including: When entering any target switching page in the target application, obtain the label information of the text display control in the interface display control of the target switching page, wherein the interface display control includes multiple display controls, and the text display control is one or more of the multiple display controls; Filter out target text display controls whose label information matches the label of the text control; The overridden lifecycle method of the target switching page is triggered, and the font object is passed in to switch the current application font of the page area corresponding to the target text display control in the target switching page to the target switching font.

5. The method according to claim 1, characterized in that, The switching mode is a multi-page switching mode, the switching method includes a global font switching method or a local font switching method, and the switching configuration information also includes multiple unique page identifiers; When entering the display page of the target application, the overridden lifecycle method is triggered and the font object is passed in, switching the current application font of the display page of the target application to the target switching font, including: When entering the currently displayed page of the target application, obtain the page tag information of the currently displayed page; If the page tag information is included in the multiple page unique identifier information, then based on the switching method, the target control on the currently displayed page that needs to have its font switched is determined; The overwrite lifecycle method of the currently displayed page is triggered, and the font object is passed in to switch the current application font of the page area corresponding to the target control in the current display page of the target application to the target switching font.

6. The method according to claim 1, characterized in that, When entering the display page of the target application, the overridden lifecycle method is triggered and the font object is passed in, switching the current application font of the display page of the target application to the target switching font, including: When entering the display page A of the target application, the overriding lifecycle method of the display page A is triggered and the font object is passed in. The current application font of the display page A of the target application is switched to the target switching font, and the font switching time is recorded. When jumping from display page A to display page B and then jumping back to display page A, obtain the jump time when jumping back to display page A; Calculate the time difference between the jump time and the font switching time; If the time difference exceeds a preset time threshold, the rewrite lifecycle method of the display page A is triggered again and the font object is passed in to switch the current application font of the target application's display page A to the target switching font and update the font switching time.

7. The method according to claim 1, characterized in that, When entering the display page of the target application, the overridden lifecycle method is triggered and the font object is passed in, switching the current application font of the display page of the target application to the target switching font, including: Set the font switching field value of the display page A of the target application to the first field value; When entering the display page A of the target application, the overwrite lifecycle method of the display page A is triggered and the font object is passed in, the current application font of the display page A of the target application is switched to the target switching font, and the first field value is modified to the second field value; When jumping from display page A to display page B, and then jumping back from display page B to display page A, obtain the font switching field value of display page A; If the font switching field value is the second field value, then the rewrite lifecycle method of the display page A will not be triggered again.

8. A font switching device, characterized in that, include: The receiving module is configured to receive a font switching instruction, the font switching instruction including a target application and a target font to switch; The download module is configured to retrieve the target font configuration file corresponding to the font switching instruction from the cloud server, and download the target switching font file corresponding to the target font configuration file from the cloud server to the application's local directory; The conversion module is configured to read the target switching font file from the application's local directory and convert the target switching font file into a font object that can be recognized and rendered by the Android system; The parsing module is configured to parse the target font configuration file to obtain switching configuration information, which includes the target switching font, switching mode, switching method, and the current application font of the target application. The rewrite module is configured to rewrite the lifecycle method of the interface display control of the display page of the target application according to the switching configuration information, so as to obtain the rewritten lifecycle method of the interface display control of the display page. The switching module is configured to trigger the overridden lifecycle method and pass in the font object when entering the display page of the target application, so as to switch the current application font of the display page of the target application to the target switching font.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.