Method and system for realizing black and white mode in Android application program

By obtaining and configuration of Android applications, View container DecorView, combined with hardware accelerated drawing technology, realized the overall black and white mode display of Android applications, solved the high code invasion, large adaptation volume, WebVIEW and video playback in existing technology. Insufficient issues.

CN111833417BActive Publication Date: 2025-01-24GUANGZHOU TANTU NETWORK TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010675080.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-14
Publication Date
2025-01-24
Estimated Expiration
2040-07-14

AI Technical Summary

Technical Problem

When implementing black and white mode, existing Android applications have high code intrusion, large adaptation volume and cumbersome problems, especially in terms of compatibility with webView and video playback.

Method used

By obtaining the top parent View container Decorview of the Android application display window, the color matrix and brush control of the Android system are configured, the color image is adjusted to the gray image, and the hardware is accelerated to draw the overall black and white mode display of Android applications.

Benefits of technology

It realizes simple and fast overall black and white grayscale conversion of Android applications, reduces the amount of adaptation and code intrusion, and solves the adaptation problem of webView and video playback.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111833417B_ABST
    Figure CN111833417B_ABST
Patent Text Reader

Abstract

The present disclosure is about a method, system and terminal device for realizing black and white mode in an Android application. The method includes: obtaining the top-level parent View container of the Android application display window; configuring the color matrix and brush control of the Android system, adjusting the color image displayed by the Android application to the expected grayscale image; using the hardware accelerated drawing method to draw through the top-level parent View container, and displaying the Android application globally in black and white mode. The solution provided by the present disclosure can realize the overall black and white grayscale conversion of Android applications in a simple and fast manner.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of software technology, and in particular to a method and system for implementing a black and white mode in an Android application. Background Art

[0002] Currently, many websites and apps (Applications) can achieve black and white grayscale (also known as black and white mode). The web side can add this effect to the entire page through CSS (Cascading Style Sheets), but the implementation of apps is generally more complicated.

[0003] Android Q released by Google began to provide a new Dark theme, which is suitable for Android system UI (User Interface) and applications running on the device. Android application "black and white mode" can switch between two themes of Android Q (mainly various background colors, font colors and icons). It is necessary to define two different themes and switch themes according to whether it is black and white mode. This solution requires defining and setting a large number of attributes and fields to configure the corresponding controls, and also requires grayscale processing of the images sent by the server. The adaptation is large and cumbersome, the code is highly invasive, and it is not well compatible with webView (web page view) and video playback.

[0004] In summary, the relevant technology obviously has inconveniences and defects in actual use, so it is necessary to improve it. Summary of the invention

[0005] In order to overcome the problems existing in the related art, the present disclosure provides a method and system for realizing a black and white mode in an Android application, so as to realize a simple and quick overall black and white grayscale conversion of the Android application.

[0006] According to a first aspect of an embodiment of the present disclosure, a method for implementing a black and white mode in an Android application is provided, the method comprising:

[0007] Get the top-level parent View container of the Android application display window;

[0008] Configuring the color matrix and brush control of the Android system to adjust the color image displayed by the Android application to an expected grayscale image;

[0009] The top-level parent View container is drawn using a hardware accelerated drawing method, and the Android application is globally displayed in a black and white mode.

[0010] In one implementation, the top-level parent View container is DecorView; the top-level parent View container for obtaining the Android application display window is DecorView for obtaining the top-level parent View container for the Android application display window;

[0011] The top-level parent View container DecorView is obtained after setContentView in the Activity life cycle in the Android system is completed.

[0012] In one embodiment, configuring the color matrix and brush control of the Android system to adjust the color image displayed by the Android application to the expected grayscale image includes:

[0013] Configuring the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image;

[0014] Configuring a filter of the color matrix of the Android system to add a grayscale filter to the process grayscale image;

[0015] A plurality of drawing parameters of the brush control of the Android system are configured to adjust the process grayscale image after adding the grayscale filter to the expected grayscale image.

[0016] In one implementation, configuring the color matrix of the Android system includes:

[0017] The three groups of values ​​corresponding to the three color channels representing RGB in the color matrix of the Android system are configured to be equal, and their sum is close to 1.

[0018] In one embodiment, the drawing using the hardware accelerated drawing method through the top-level parent View container to globally display the Android application in black and white mode includes:

[0019] The top-level parent View container calls setLayerType to perform hardware accelerated drawing;

[0020] Obtaining a hardware accelerated drawing model of the Android application after hardware acceleration is enabled;

[0021] According to the hardware accelerated rendering model, the Android application is globally displayed in black and white mode.

[0022] According to a second aspect of an embodiment of the present disclosure, a system for implementing a black and white mode in an Android application is provided, comprising:

[0023] Get module, used to get the top parent View container of the Android application display window;

[0024] A configuration module, used to configure the color matrix and brush control of the Android system, and adjust the color image displayed by the Android application to an expected grayscale image;

[0025] The processing module is used to draw the top-level parent View container component using a hardware accelerated drawing method to display the Android application globally in black and white mode.

[0026] In one implementation, the obtaining module obtains the top-level parent View container of the Android application display window by obtaining the top-level parent View container DecorView of the Android application display window;

[0027] The acquisition module acquires the top-level parent View container DecorView after setContentView in the Activity life cycle in the Android system is completed.

[0028] In one embodiment, the configuration module includes:

[0029] A first configuration submodule is used to configure the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image;

[0030] A second configuration submodule is used to configure a filter of the color matrix of the Android system to add a grayscale filter to the process grayscale image;

[0031] The third configuration submodule is used to configure multiple drawing parameters of the brush control of the Android system, and adjust the process grayscale image after adding the grayscale filter to the expected grayscale image.

[0032] In one embodiment, the first configuration submodule configures three groups of values ​​corresponding to the three color channels representing RGB in the color matrix of the Android system to be equal and their sum is close to 1, so as to adjust the color image displayed by the Android application to a process grayscale image.

[0033] In one embodiment, the processing module comprises:

[0034] Call the submodule and call setLayerType through the top-level parent View container to perform hardware accelerated drawing;

[0035] An acquisition submodule, used to acquire a hardware accelerated drawing model of the Android application after hardware acceleration is enabled;

[0036] The drawing submodule is used to display the Android application globally in black and white mode according to the hardware accelerated drawing model.

[0037] According to a third aspect of an embodiment of the present disclosure, a terminal device is provided, including:

[0038] Processor; and

[0039] The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method as described above.

[0040] The technical solution provided by the embodiment of the present disclosure may include the following beneficial effects: first, the top-level parent View container of the Android application display window is obtained; then the color matrix and brush control of the Android system are configured to adjust the color image displayed by the Android application to the expected grayscale image; finally, the top-level parent View container is drawn using the hardware accelerated drawing method to display the Android application globally in black and white mode. Therefore, by configuring the top-level window displayed by the application program and using the top-level parent View container for unified processing, the overall black and white grayscale of the Android application, i.e., the black and white mode, can be simply and quickly performed, reducing the amount of adaptation and reducing the intrusion of the original code.

[0041] In the embodiment of the present disclosure, after the setContentView in the Activity life cycle of the Android system is completed, the top-level parent View container DecorView of the Android application display window can be obtained. When configuring the color matrix and brush control of the Android system, the color image displayed by the Android application is adjusted to a process grayscale image by configuring the color matrix of the Android system; a grayscale filter is added to the process grayscale image by configuring the filter of the color matrix of the Android system; and finally, the process grayscale image after adding the grayscale filter is adjusted to the expected grayscale image by configuring multiple drawing parameters of the brush control of the Android system. And, hardware accelerated drawing is performed by calling setLayerType through the top-level parent View container; then the hardware accelerated drawing model of the Android application after enabling hardware acceleration is obtained, and the Android application is globally displayed in black and white mode according to the hardware accelerated drawing model. In this way, the overall black and white grayscale of the Android application is simply realized, the adaptation amount is reduced, and the intrusion of the original code is reduced, and the adaptation problem of webView and video playback in the black and white scheme of the Android application can also be solved.

[0042] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.

[0044] Figure 1 is a flowchart of a method for implementing a black and white mode in an Android application according to an exemplary embodiment of the present disclosure;

[0045] Figure 2 This is a diagram of the view hierarchy of the relevant Android application;

[0046] Figure 3 It is a flow chart of the connection method between the life cycle of Activity and Window view in the relevant Android system;

[0047] Figure 4 is another schematic diagram of a process of a method for implementing a black and white mode in an Android application according to an exemplary embodiment of the present disclosure;

[0048] Figure 5 is a structural diagram of a system for implementing a black and white mode using an Android application according to an exemplary embodiment of the present disclosure;

[0049] Figure 6 is another schematic diagram of the structure of a system for implementing a black and white mode using an Android application according to an exemplary embodiment of the present disclosure;

[0050] Figure 7 It is a schematic diagram of the structure of a terminal device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0051] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0052] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0053] It should be understood that although the terms "first", "second", "third", etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present disclosure, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.

[0054] The present disclosure provides a method for implementing a black and white mode in an Android application, which can realize the overall black and white grayscale conversion of the Android application in a simple and quick manner.

[0055] The technical solution of the embodiments of the present disclosure is described in detail below with reference to the accompanying drawings.

[0056] Figure 1 The flowchart of a method for implementing a black and white mode in an Android application program according to an exemplary embodiment of the present disclosure is shown. In the following description, the Android application program is referred to as an Android application for short.

[0057] See also Figure 1 , the method comprising:

[0058] Step S101: Get the top-level parent View container of the Android application display window.

[0059] In this embodiment, the top-level parent View container of the Android application display window may be first obtained; Figure 2 The view hierarchy of the Android application shown in the figure, whether it is Activity, Fragment, Toast or Dialog, their views are attached to the Window, so the Window can be understood as the carrier and manager of the View. There are three types of Windows, namely application Window, child Window and system Window. Among them, the application class Window corresponds to an Acitivity, and the child Window cannot exist alone and needs to be attached to a specific parent Window. For example, the common Fragment and Dialog are child Windows. System Windows are Windows that require declared permissions to be created, such as Toast and the system status bar are both system Windows.

[0060] In one embodiment of the present disclosure, the top-level parent View container is DecorView; the top-level parent View container for obtaining the display window of the Android application is to obtain the top-level parent View container DecorView for obtaining the display window of the Android application. DecorView is the top-level View in Windows and a subclass of FrameLayout. It contains a LinearLayout with an ActionBar and mContentParent (application root layout). The setContentView (set view layout) in Activity or the onCreateView (create view corresponding to Fragment) of Fragment actually converts the XML (Extensible Markup Language) layout written by the technician into View through LayoutInflater and adds it to mContentParent. Therefore, you only need to obtain the top-level container of the DecorView of the Activity to uniformly process and encapsulate the Activity base class, so as to achieve the effect of global overall adaptation of the Android application and solve the adaptation problems of the sub-Window and sub-View at one time.

[0061] Step S102: configuring the color matrix and brush control of the Android system, and adjusting the color image displayed by the Android application to an expected grayscale image.

[0062] After obtaining the top-level parent View container of the Android application display window, you need to configure the color matrix and brush control of the Android system. In the Android system, a color matrix is ​​used to process the color effect of the image, and the brush control is a very important tool in the custom control of the Android system. It is used to adjust multiple drawing parameters. By configuring the color matrix and brush control, the color image displayed by the Android application can be adjusted to the grayscale image required by the operator, that is, the expected grayscale image.

[0063] Step S103: The top-level parent View container is rendered using hardware accelerated rendering to globally display the Android application in black and white mode.

[0064] Finally, the top-level parent View container is drawn using a hardware-accelerated drawing method that is compatible with the Android system. After the top-level parent View container is started, the framework of the Android application will update a new framework drawing model, that is, a hardware-accelerated drawing model. This hardware-accelerated drawing model is used for drawing, and the Android application is globally displayed in black and white mode. This achieves a simple and quick overall black and white grayscale conversion of the Android application, reduces the amount of adaptation, reduces the invasiveness of the original code, and can also solve the adaptation problems of webView and video playback in the black and white conversion solution of the Android application.

[0065] Figure 3 It is a flow chart of the connection method between the Activity life cycle and the Window view in the relevant Android system.

[0066] In one embodiment of the present disclosure, the top-level parent View container DecorView is obtained after setContentView is completed in the Activity life cycle in the Android system. Figure 3 The figure shows the life cycle of the Activity in the Android system, including the connection method flow with the Window view in this process, where the black dotted line indicates that the object pointed by the arrow is created when the method is executed. Specifically, it may include:

[0067] In step S301, a Window object is created when Activity.attach0 is executed;

[0068] In step S302, when Activity.attach1 is executed, Window is associated with WindowManager (window management);

[0069] WindowManager inherits from the ViewManager interface, and ViewManager provides methods for adding View, deleting View, and updating View.

[0070] In step S303, Window is called to initialize DecorView;

[0071] In step S304, ViewRootimpl is initialized.

[0072] ViewRootImpl is the top of a view hierarchy that implements the required protocol between View and WindowManager, as most of the internal implementation in WindowManagerGlobal.

[0073] From this process and Figure 3It can be seen that the initialization of DecorView is completed in the setContentView of Activity, so in the encapsulation of the Activity base class, getting DecorView needs to be after setContentView.

[0074] In one embodiment of the present disclosure, configuring the color matrix and brush control of the Android system to adjust the color image displayed by the Android application to the expected grayscale image includes:

[0075] Configuring the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image;

[0076] Configuring a filter of the color matrix of the Android system to add a grayscale filter to the process grayscale image;

[0077] A plurality of drawing parameters of the brush control of the Android system are configured to adjust the process grayscale image after adding the grayscale filter to the expected grayscale image.

[0078] In this embodiment, for the color matrix of the Android system, a color matrix-ColorMatrix is ​​used to process the color effect of the image. For each pixel of the image, there is a color component matrix for storing the RGBA (display channel) value of the color. The color matrix in the Android system is a 4x5 digital matrix, which is used to process the color of the picture. If the color display effect needs to be changed, in the Android system, the value of the color component matrix is ​​modified by matrix multiplication, as calculated by the following formula 1.

[0079]

[0080] in:

[0081] a, b, c, d, e represent the red color among the three primary colors;

[0082] f, g, h, i, j represent the green color among the three primary colors;

[0083] k, l, m, n, o represent the blue color among the three primary colors;

[0084] p, q, r, s, t represent the transparency of the color;

[0085] The fifth column is used to indicate the color offset;

[0086] In this step, configuring the color matrix of the Android system includes:

[0087] The three sets of values ​​corresponding to the three color channels representing RGB (red, green, blue) in the color matrix of the Android system are configured to be equal, and the sum is close to 1. That is, in order to achieve the grayscale effect of black and white, the values ​​of the three color channels of RGB need to be set to the same, that is, R=G=B; at the same time, in order to ensure the brightness of the image, the result of R+G+B in the same channel needs to be close to 1. Therefore, in the Android system, the pixel grayscale value can be composed according to the ratio of 0.213R, 0.715G and 0.072B to adjust the color image displayed by the Android application to a process grayscale image (relative to the final expected grayscale image). The sample code of the process grayscale image is as follows:

[0088]

[0089] For the configuration of the color matrix filter of the Android system, the configuration result in the previous step, that is, the obtained process grayscale image, can be added to the color matrix filter instance of the Android system, which is equivalent to adding a layer of grayscale filter to the View, thereby adding a grayscale filter to the process grayscale image; the sample code is as follows:

[0090]

[0091] Regarding the configuration of the paint brush control (Paint) of the Android system, the paint brush in the Android system is a very important tool in the custom control, which can be used to set multiple drawing parameters such as color, text measurement, layer blending mode, color filter, etc. The medium gray filter effect in the previous step is finally set on the brush instance to draw the required black and white grayscale effect on the window, thereby adjusting the grayscale image after adding the grayscale filter to the expected grayscale image. The sample code is as follows:

[0092]

[0093] In one embodiment of the present disclosure, the top-level parent View container is drawn using a hardware accelerated drawing method, and the Android application is globally displayed in a black and white mode, including:

[0094] The top-level parent View container calls setLayerType to perform hardware accelerated drawing;

[0095] Obtaining a hardware accelerated drawing model of the Android application after hardware acceleration is enabled;

[0096] According to the hardware accelerated rendering model, the Android application is globally displayed in black and white mode.

[0097] In this embodiment, after the aforementioned multiple steps are completed, hardware accelerated drawing is finally performed in this step by calling setLayerType through the View container to achieve the overall black and white effect of the Android application. Starting from Android 3.0, Android's 2D rendering pipeline can better support hardware acceleration. Hardware acceleration generally uses a GPU (Graphics Processing Unit) to perform drawing operations on a View. Hardware acceleration can be enabled at four levels: Application, Activity, Window, and View. Since only the View level supports brush configuration among the four levels, View-level acceleration is selected in the solution of this application.

[0098] After hardware acceleration is enabled, a new framework drawing model in the Android framework, namely a hardware accelerated drawing model, is obtained, and the Android application can be globally displayed in black and white mode according to the hardware accelerated drawing model.

[0099] The new framework drawing model, i.e., the hardware accelerated drawing model, may be drawn as follows:

[0100] 1.Invalidate the hierarchy;

[0101] 2. Record and update the display list;

[0102] 3. Draw the display list.

[0103] It should be noted that, unlike the model drawn using software, in the hardware-accelerated drawing model, the Android system records the drawing commands to the display list instead of executing them immediately; and only records and updates Views marked as dirty (via invalidate()), thus avoiding unnecessary drawing.

[0104] See also Figure 4 , a flowchart of a method for globally implementing a black and white mode for an Android application is shown according to an exemplary embodiment of the present disclosure.

[0105] See also Figure 4 , the method comprising:

[0106] In step S401, the top-level parent View container DecorView of the Android application display window is obtained.

[0107] In this step, you need to get the top-level parent View container DecorView of the Android application display window; Figure 2The view hierarchy of the Android application shown in the figure, whether it is Activity, Fragment, Toast or Dialog, their views are attached to Window, so Window can be understood as the carrier and manager of View. There are three types of Window, namely application Window, child Window and system Window. The application class Window corresponds to an Acitivity, and the child Window cannot exist alone and needs to be attached to a specific parent Window. For example, the common Fragment and Dialog are child Windows. The system Window is a Window that needs to declare permissions to be created, such as Toast and the system status bar are both system Windows. In one embodiment of the present disclosure, the top-level parent View container is DecorView; the top-level parent View container for obtaining the display window of the Android application is DecorView for obtaining the top-level parent View container for obtaining the display window of the Android application. DecorView is the top-level View in Windows and is also a subclass of FrameLayout. It contains a LinearLayout with ActionBar and mContentParent. The setContentView in Activity or onCreateView of Fragment actually converts the XML layout written by the technician into View through LayoutInflater and adds it to mContentParent. Therefore, you only need to obtain the top-level container of the Activity's DecorView to uniformly process and encapsulate it with the Activity base class, so as to achieve the effect of global adaptation of the Android application and solve the adaptation problems of the sub-Window and sub-View at one time.

[0108] In step S402, the color matrix of the Android application is configured.

[0109] For the color matrix used in the Android system, ColorMatrix is ​​used to process the color effect of the image. For each pixel of the image, there is a color component matrix used to save the RGBA (display channel) value of the color. The color matrix in the Android system is a 4x5 digital matrix calculated as shown in the above formula 1. The three sets of values ​​corresponding to the three color channels representing RGB (red, green, blue, red, green and blue color representation) in the color matrix of the Android system are configured to be equal, and the sum is close to 1. That is, in order to achieve the grayscale effect of black and white, the values ​​of the three color channels of RGB need to be set to the same, that is, R=G=B; at the same time, in order to ensure the brightness of the image, the result of R+G+B in the same channel needs to be close to 1. In this way, the color image displayed by the Android application can be adjusted to a process grayscale image.

[0110] In step S403, a filter is configured for the color matrix of the Android application.

[0111] In this step, the configuration result in the previous step, that is, the process grayscale image, can be added to the color matrix filter instance of the Android system to add a grayscale filter to the process grayscale image.

[0112] In step S404, the brush control of the Android application is configured.

[0113] In the Android system, the paint brush is a very important tool in the custom control. It can be used to set color, measure text, set layer blending mode, color filter and other drawing parameters. The grayscale filter effect in the previous step is finally set on the brush control instance, which is used to draw the required black and white grayscale effect on the window, thereby adjusting the process grayscale image after adding the grayscale filter to the expected grayscale image.

[0114] In step S405, the top-level View container is rendered using hardware accelerated rendering.

[0115] After the above four steps are completed, in this step, the View container is called to setLayerType to perform hardware accelerated drawing to achieve the overall black and white effect of the Android application. Hardware acceleration uses the GPU to perform drawing operations on the View. Hardware acceleration uses View-level acceleration. After enabling hardware acceleration, the Android framework will use the new framework drawing model, that is, the hardware accelerated drawing model, and then complete the process of achieving black and white grayscale for the entire Android application based on the hardware accelerated drawing model.

[0116] Corresponding to the aforementioned application function implementation method embodiment, the present disclosure also provides a system, a terminal device and corresponding embodiments for implementing a black and white mode in an Android application.

[0117] Figure 5 It is a structural diagram of a system for implementing a black and white mode in an Android application according to an exemplary embodiment of the present disclosure.

[0118] The Android application realizes a black and white mode system, including: an acquisition module 10, a configuration module 20, and a processing module 30.

[0119] An acquisition module 10 is used to acquire a top-level parent View container of an Android application display window;

[0120] A configuration module 20, configured to configure a color matrix and a brush control of the Android system, and adjust the color image displayed by the Android application to an expected grayscale image;

[0121] The processing module 30 is used to draw the top-level parent View container component using a hardware accelerated drawing method to globally display the Android application in a black and white mode.

[0122] In this embodiment, the acquisition module 10 acquires the top-level parent View container of the Android application display window. The top-level parent View container is DecorView; the acquisition module 10 acquires the top-level parent View container of the Android application display window to acquire the top-level parent View container DecorView of the Android application display window. By acquiring the top-level container DecorView of the Activity, the processing and Activity base class encapsulation can be unified to achieve the effect of global overall adaptation of the Android application, and the adaptation problem of the sub-Window and the sub-View can be solved at one time. After that, the configuration module 20 configures the color matrix and brush control of the Android system, and the color image displayed by the Android application can be adjusted to the grayscale image required by the operator, that is, the color image displayed by the Android application is adjusted to the expected grayscale image. Finally, the processing module 30 is included to draw by the top-level parent View container component using the hardware accelerated drawing method, and the Android application is globally displayed in black and white mode. In this way, the overall black and white grayscale of the Android application is realized simply and quickly, the adaptation amount is reduced, the intrusion of the original code is reduced, and the adaptation problem of webView and video playback in other solutions is solved.

[0123] See also Figure 3The life cycle of the Activity in the Android system shown includes the connection with the Window view in this process. The initialization of DecorView is completed in the setContentView of the Activity, so in one embodiment of the present disclosure, the acquisition module 10 acquires the top-level parent View container DecorView after the setContentView in the life cycle of the Activity in the Android system is completed.

[0124] Figure 6 is another schematic diagram of the structure of a system for implementing a black and white mode using an Android application according to an exemplary embodiment of the present disclosure.

[0125] The Android application realizes a black and white mode system, including: an acquisition module 10, a configuration module 20, and a processing module 30.

[0126] The configuration module 20 includes: a first configuration submodule 21 , a second configuration submodule 22 , and a third configuration submodule 23 .

[0127] A first configuration submodule 21 is used to configure the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image;

[0128] A second configuration submodule 22 is used to configure a filter of the color matrix of the Android system to add a grayscale filter to the process grayscale image;

[0129] The third configuration submodule 23 is used to configure multiple drawing parameters of the brush control of the Android system, and adjust the process grayscale image after adding the grayscale filter to the expected grayscale image.

[0130] In this embodiment, the first configuration submodule 21 configures the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image; specifically, the first configuration submodule 21 configures the three groups of values ​​corresponding to the three color channels representing RGB in the color matrix of the Android system to be equal, and the sum is close to 1, so as to adjust the color image displayed by the Android application to a process grayscale image. For example, according to the above formula (1), in the Android system, the pixel grayscale value is composed of 0.218R, 0.711G and 0.071B in a ratio to adjust the color image displayed by the Android application to a process grayscale image. The second configuration submodule 22 configures the filter of the color matrix of the Android system, and can add the configuration result of the first configuration submodule 21, that is, the obtained process grayscale image, to the color matrix filter instance of the Android system to add a grayscale filter to the process grayscale image. Finally, the third configuration submodule 23 configures the color of the brush control of the Android system, measures text, sets layer blending mode, color filters and other drawing parameters, and adjusts the grayscale image after adding the grayscale filter to the expected grayscale image.

[0131] The processing module 30 includes: a calling submodule 31 , an acquiring submodule 32 , and a drawing submodule 33 .

[0132] Calling submodule 31, used to call setLayerType through the top-level parent View container to perform hardware accelerated drawing;

[0133] An acquisition submodule 32 is used to acquire a hardware acceleration drawing model of the Android application after hardware acceleration is enabled;

[0134] The drawing submodule 33 is used to display the Android application globally in black and white mode according to the hardware accelerated drawing model.

[0135] In this embodiment, hardware accelerated drawing is performed by calling setLayerType through the top-level parent View container; hardware accelerated drawing is performed to achieve the overall black and white effect of the Android application. After hardware acceleration is enabled, the acquisition submodule 32 obtains the hardware accelerated drawing model of the Android application after hardware acceleration is enabled; the drawing submodule 33 displays the Android application globally in black and white mode according to the hardware accelerated drawing model.

[0136] Therefore, by configuring the top-level window displayed by the application, the present invention can more simply and quickly perform the overall black and white grayscale conversion of the Android application, reduce the adaptation amount, reduce the invasiveness of the original code, and also solve the adaptation problem of webView and video playback in the black and white conversion solution of the Android application.

[0137] Figure 71 is a schematic diagram of a terminal device according to an exemplary embodiment of the present disclosure. The terminal device may be, for example, a mobile terminal device or a server device.

[0138] The present disclosure provides a terminal device 1000, including:

[0139] Processor 1020; and

[0140] The memory 1010 stores executable codes thereon. When the executable codes are executed by the processor, the processor 1020 executes the method described in any of the above embodiments.

[0141] See also Figure 7 , the terminal device 1000 includes a memory 1010 and a processor 1020.

[0142] The processor 1020 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.

[0143] The memory 1010 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage systems. Among them, ROM can store static data or instructions required by the processor 1020 or other modules of the computer. The permanent storage system may be a readable and writable storage system. The permanent storage system may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage system uses a large-capacity storage system (such as a magnetic or optical disk, flash memory) as a permanent storage system. In some other embodiments, the permanent storage system may be a removable storage device (such as a floppy disk, an optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 1010 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 1010 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.

[0144] The memory 1010 stores executable codes, and when the executable codes are processed by the processor 1020 , the processor 1020 can execute part or all of the methods described above.

[0145] The scheme of the present disclosure has been described in detail above with reference to the accompanying drawings. In the above embodiments, the descriptions of the various embodiments have their own emphases. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments. Those skilled in the art should also be aware that the actions and modules involved in the specification are not necessarily required for the present disclosure. In addition, it can be understood that the steps in the method of the embodiment of the present disclosure can be adjusted in order, merged and deleted according to actual needs, and the modules in the device and system of the embodiment of the present disclosure can be merged, divided and deleted according to actual needs.

[0146] In addition, the method according to the present disclosure may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing some or all of the steps in the above method of the present disclosure.

[0147] Alternatively, the present disclosure may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or terminal device, computing device, server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present disclosure.

[0148] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.

[0149] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the system and method according to multiple embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0150] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A method for implementing a black and white mode in an Android application, characterized in that: The method comprises: Get the top-level parent View container of the Android application display window; Configuring the color matrix and brush control of the Android system to adjust the color image displayed by the Android application to an expected grayscale image; The top-level parent View container is used to draw using hardware accelerated drawing method, and the Android application is globally displayed in black and white mode; the method includes: the top-level parent View container calls setLayerType to perform hardware accelerated drawing; obtains the hardware accelerated drawing model of the Android application after hardware acceleration is enabled; and according to the hardware accelerated drawing model, the Android application is globally displayed in black and white mode.

2. The method according to claim 1, characterized in that: The top-level parent View container is DecorView; The obtaining of the top-level parent View container of the Android application display window is to obtain the top-level parent View container DecorView of the Android application display window; The top-level parent View container DecorView is obtained after setContentView in the Activity life cycle in the Android system is completed.

3. The method according to claim 1, characterized in that The configuring the color matrix and brush control of the Android system to adjust the color image displayed by the Android application to the expected grayscale image includes: Configuring the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image; Configuring a filter of the color matrix of the Android system to add a grayscale filter to the process grayscale image; A plurality of drawing parameters of the brush control of the Android system are configured to adjust the process grayscale image after adding the grayscale filter to the expected grayscale image.

4. The method according to claim 3, characterized in that The configuring the color matrix of the Android system comprises: The three groups of values ​​corresponding to the three color channels representing RGB in the color matrix of the Android system are configured to be equal, and their sum is close to 1.

5. A system for implementing black and white mode in an Android application, characterized in that: include: Get module, used to get the top parent View container of the Android application display window; A configuration module, used to configure the color matrix and brush control of the Android system, and adjust the color image displayed by the Android application to an expected grayscale image; A processing module, used for rendering by using the hardware accelerated rendering method through the top-level parent View container component to globally display the Android application in black and white mode; The processing module comprises: Call the submodule to perform hardware accelerated drawing by calling setLayerType through the top-level parent View container; An acquisition submodule, used to acquire a hardware accelerated drawing model of the Android application after hardware acceleration is enabled; The drawing submodule is used to display the Android application globally in black and white mode according to the hardware accelerated drawing model.

6. The system according to claim 5, characterized in that: The acquisition module acquires the top-level parent View container of the Android application display window to acquire the top-level parent View container DecorView of the Android application display window; The acquisition module acquires the top-level parent View container DecorView after setContentView in the Activity life cycle in the Android system is completed.

7. The system according to claim 5, characterized in that The configuration module includes: A first configuration submodule is used to configure the color matrix of the Android system to adjust the color image displayed by the Android application to a process grayscale image; A second configuration submodule is used to configure a filter of the color matrix of the Android system to add a grayscale filter to the process grayscale image; The third configuration submodule is used to configure multiple drawing parameters of the brush control of the Android system, and adjust the process grayscale image after adding the grayscale filter to the expected grayscale image.

8. The system according to claim 7, characterized in that: The first configuration submodule configures three groups of values ​​corresponding to the three color channels representing RGB in the color matrix of the Android system to be equal and their sum is close to 1, so as to adjust the color image displayed by the Android application to a process grayscale image.

Citation Information

Patent Citations

  • Android television background quick switch method, frame, server and storage medium

    CN108989872A