Android efficient dynamic skin changing method and system

By packaging skin resources into multiple APK files and hook layoutInflater classes, listening to the Activity life cycle, and achieving efficient dynamic skinning of Android apps, solving the problems of code modification and resource loading delays in the existing technology, and improving rendering speed and code Optimize the effect.

CN118885159AInactive Publication Date: 2024-11-01HONGCHENG TECH DEV CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411378038.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-30
Publication Date
2024-11-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing Android app skinning framework requires extensive modification of existing code, and the resource loading is not optimized, resulting in delays in page opening.

Method used

By packaging skin resources into multiple APK files, creating SkinManager class, hook layoutInflater class, listening to the Activity life cycle, and adding custom attributes to the View that needs to be resized, realizing dynamic skinning, reducing code modification and resource loading delays .

Benefits of technology

Set the skin directly when the view is loaded, reducing the interface rendering time by 30%-80%, greatly reducing the amount of code modification, improving rendering speed, and supporting online skin updates.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The invention relates to the technical field of software skin changing, in particular to an Android efficient dynamic skin changing method and system.When a view is loaded, specified skin can be directly set through skin changing attributes set for the view, the view only needs to be drawn once, according to different interface complexity, 30%-80% of interface rendering time can be shortened approximately, and for an extremely complex interface, the interface rendering efficiency can be greatly improved. And the rendering speed can be increased by multiple times theoretically. The loading control is stored in the list of the skin change view cache, and only items in the list of the skin change view cache need to be changed during skin change, so that the code quantity for modifying the existing items can be greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software skinning, and in particular to an Android efficient dynamic skinning method and system. Background Art

[0002] Apps on mobile devices use skins as visual presentation interfaces, which are a very good choice for personalized human-computer interfaces. The application of skins is no longer limited to mobile devices. In mobile clients, the quality of mobile clients is no longer limited to powerful functions. Only by meeting the functions required by users and having a better-looking appearance interface can it attract users' attention. In this era, the appearance and interface of mobile clients are particularly important.

[0003] There are many open source frameworks for app skinning on the market, but these frameworks have the following two main problems: (1) If these skinning frameworks are added to existing apps, the existing code will be modified on a large scale, and even the entire app development framework will need to be reconstructed; (2) These skinning frameworks are not optimized for the project and often repeatedly load resources, causing noticeable delays when the app opens the page. Summary of the invention

[0004] In view of the above problems, the present invention provides an Android efficient dynamic skin changing method and system.

[0005] The technical solution adopted is an Android efficient dynamic skinning method, which includes the following steps: Package skin resources into multiple APK files; Create a SkinManager class for loading skin resources in the APK file; Hook the layoutInflater class in Android and replace the mFactory2 property in the layoutInflater class with a custom class to store the View that needs to be skinned; Monitor the Activity lifecycle globally, set layoutInflater.mFactory2 to the current Activity, and load layoutInflater into the corresponding layout file; Add a custom attribute to the View that needs to be skinned to indicate that it can be skinned; When changing the skin, the View with custom attributes that can be changed is changed and replaced with the skin resources in the APK file.

[0006] Optionally, the custom attribute for skinning is app:skin_enable="true".

[0007] Optionally, when the custom property is set to true, the control is saved to a list in the skinnable view cache.

[0008] Optionally, add an initialization item, the content of which is: SkinManager.setEnable(true); SkinManager.init(this); SkinManager.getInstance().loadSkin(Config.PATH, false, this).

[0009] This application also provides an Android efficient dynamic skinning system, including a loading module, a generating module, a monitoring module and a changing module; The loading module is used to package the skin resources into the APK file and load the SkinManager class of the skin resources in the APK file; The generation module is used to generate a View with a custom class; The monitoring module is used to monitor the Activity life cycle; The replacement module is used to replace the skin resources in the APK file with the View that can perform skinning custom attributes.

[0010] Optionally, the monitoring module is specifically used for: Monitor the Activity life cycle, set layoutInflater.mFactory2 to the current Activity, and load layoutInflater into the corresponding layout file.

[0011] The beneficial effects of the present invention include at least one of the following: 1. The technical solution provided in this application can directly set the specified skin by setting the skinning properties of the view when the view is loaded, and the view only needs to be drawn once. Depending on the complexity of the interface, the interface rendering time can be roughly reduced by 30%-80%. For extremely complex interfaces, the rendering speed can theoretically be increased many times.

[0012] 2. By saving the loaded controls to the list of the skinning view cache, only the items in the list of the skinning view cache need to be changed during skinning, which can greatly reduce the amount of code to modify existing items. DETAILED DESCRIPTION

[0013] The following describes the implementation of the present invention through specific examples. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific implementations, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.

[0014] An Android efficient dynamic skin changing method, characterized by comprising the following steps: Package skin resources into multiple APK files; Create a SkinManager class for loading skin resources in the APK file; Hook the layoutInflater class in Android and replace the mFactory2 property in the layoutInflater class with a custom class to store the View that needs to be skinned; Monitor the Activity lifecycle globally, set layoutInflater.mFactory2 to the current Activity, and load layoutInflater into the corresponding layout file; Add a custom attribute to the View that needs to be skinned to indicate that it can be skinned; When changing the skin, the View with custom attributes that can be changed is changed and replaced with the skin resources in the APK file.

[0015] The purpose of this design is to directly set the specified skin by setting the skinning properties of the view when the view is loaded, and only draw the view once. Depending on the complexity of the interface, it can reduce the interface rendering time by 30%-80%. For extremely complex interfaces, the rendering speed can be increased several times in theory. By saving the loaded controls to the list of the skinning view cache, only the items in the list of the skinning view cache need to be changed when skinning, which can greatly reduce the amount of code to modify existing items.

[0016] In the specific implementation, the upper layer only needs to add a custom attribute, app:skin_enable="true", in the View that needs to be skinned, which means that the control can be skinned. The principle of this attribute is that if the attribute is set to true when loading the control, the control will be saved in the list of the skin-changing view cache. When changing the skin, you only need to change the items in the list of the skin-changing view cache, which can greatly reduce the amount of code to modify existing items.

[0017] However, many open source skinning frameworks load the default resources first after the app is started, and then load the resources in the skin package, causing the view to be skinned to be drawn multiple times.

[0018] At the same time, in the specific implementation, the changes to the upper-level code can be minimal. You only need to modify the following three items to enable skinning: First add the initialization item, its content is: SkinManager.setEnable(true); SkinManager.init(this); SkinManager.getInstance().loadSkin(Config.PATH, false, this); Then add the app:skin_enable="true" attribute to the View to be skinned; Finally, each skin resource is put into a separate apk package. When you need the skin, you can dynamically load the corresponding apk package. This will reduce the size of the main apk package and update the latest skin online.

[0019] At execution time: <net.chinaedu.project.skindemo.custom.SkinCustomView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" app: skin_background="@color / global_background" app: skin_font_color="@color / global_text_color" app:skin_font_size="18dp" app:skin_text="Before skin change" app:skin_enable="true" / > This embodiment also provides an adaptive Android efficient dynamic skinning system, including a loading module, a generating module, a monitoring module and a changing module; The loading module is used to package the skin resources into the APK file and load the SkinManager class of the skin resources in the APK file; The generation module is used to generate a View with a custom class; The monitoring module is used to monitor the Activity life cycle; The replacement module is used to replace the skin resources in the APK file with the View that can perform skinning custom attributes.

[0020] The monitoring module is specifically used for: Monitor the Activity life cycle, set layoutInflater.mFactory2 to the current Activity, and load layoutInflater into the corresponding layout file.

[0021] Finally, it should be noted that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, it is still possible for those skilled in the art to modify the technical solutions described in the aforementioned embodiments, or to make equivalent substitutions for some of the technical features therein. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. An efficient dynamic skinning method for Android, characterized in that: The following steps are involved: Package skin resources into multiple APK files; Create a SkinManager class for loading skin resources in the APK file; Hook the layoutInflater class in Android and replace the mFactory2 property in the layoutInflater class with a custom class to store the View that needs to be skinned; Monitor the Activity lifecycle globally, set layoutInflater.mFactory2 to the current Activity, and load layoutInflater into the corresponding layout file; Add a custom attribute to the View that needs to be skinned to indicate that it can be skinned; When changing the skin, the View with custom attributes that can be changed is changed and replaced with the skin resources in the APK file.

2. According to claim 1, an Android efficient dynamic skinning method is characterized in that: The custom attribute for skinning is app:skin_enable="true".

3. The Android efficient dynamic skin changing method according to claim 2, characterized in that: When the custom property is set to true, the control is saved in the list of skinned view cache.

4. The Android efficient dynamic skin changing method according to claim 1, characterized in that: Add the initialization item, its content is: SkinManager.setEnable(true); SkinManager.init(this); SkinManager.getInstance().loadSkin(Config.PATH, false, this).

5. An Android efficient dynamic skin changing system, characterized in that: Including loading module, generating module, monitoring module and changing module; The loading module is used to package the skin resources into the APK file and load the SkinManager class of the skin resources in the APK file; The generation module is used to generate a View with a custom class; The monitoring module is used to monitor the Activity life cycle; The replacement module is used to replace the skin resources in the APK file with the View that can perform skinning custom attributes.

6. The Android efficient dynamic skin changing system according to claim 5, characterized in that The monitoring module is specifically used for: Monitor the Activity life cycle, set layoutInflater.mFactory2 to the current Activity, and load layoutInflater into the corresponding layout file.

Citation Information

Patent Citations

  • Method for uniformly replacing APP skin

    CN108008997A

  • Dynamic skin changing method and device for application program

    CN112231031A

  • Dynamically re-skinning a web user interface

    US20150278388A1