Disclosure of Invention
One of the objectives of the present invention is to overcome the above disadvantages, and to provide a method for adapting to multiple screen resolutions, which can adapt to android output screens with different resolutions only by using a set of resources and configurations with standard resolutions, thereby simplifying the development process and reducing the file size of the application program.
In order to solve the above technical problem, the present invention provides a method for adapting to a plurality of screen resolutions, comprising the steps of:
the service process calls a system interface to create a virtual screen and a display buffer area thereof;
the service process sets that an output screen and the virtual screen use the same display buffer area;
the service process acquires the resolutions of the virtual screen and the output screen and calculates a scaling parameter;
and the service process displays the user interface data in the display buffer area on an output screen according to the zooming parameters.
According to the technical scheme, the service process is set in the android system, the service process performs scaling adaptation processing on the user interface data according to the resolution of the virtual screen and the resolution of the screen device, and the application program draws the user interface data to the virtual screen with the fixed resolution.
Further, the method for adapting to multiple screen resolutions further comprises the following steps:
and when the output screen is changed, the service process acquires the resolution of the output screen again and recalculates the scaling parameters.
The server automatically recalculates the scaling, so that the resource allocation of a set of standard resolution and the adaptation of a screen with any resolution can be realized, and the application program end does not need to make any adjustment.
Further, the method for adapting multiple screen resolutions writes user interface data to a display buffer of the virtual screen by an application program.
Further, the output screen is a main screen and/or an external screen.
The technical scheme of the invention is suitable for a main screen or an external screen, and can realize the simultaneous output of a single screen or double screens of the application program.
Further, the scaling parameters include a lateral scaling parameter and a longitudinal scaling parameter.
Further, the service process is a surfaceFlinger system process.
Accordingly, the present invention also provides a storage device having stored therein a set of instructions for performing:
the service process calls a system interface to create a virtual screen and a display buffer area thereof;
the service process sets that an output screen and the virtual screen use the same display buffer area;
the service process acquires the resolutions of the virtual screen and the output screen and calculates a scaling parameter;
and the service process displays the user interface data in the display buffer area on an output screen according to the zooming parameters.
Further, the set of instructions is also for performing:
and when the output screen is changed, the service process acquires the resolution of the output screen again and recalculates the scaling parameters.
Correspondingly, the invention also provides an android device adapting to various screen resolutions, which stores a service process and an application program, wherein,
a service process for performing: the service process calls a system interface to create a virtual screen and a display buffer area thereof; the service process sets that an output screen and the virtual screen use the same display buffer area; the service process acquires the resolutions of the virtual screen and the output screen and calculates a scaling parameter; the service process displays the user interface data in the display buffer area on an output screen according to the zooming parameters;
an application for performing: and writing user interface data into the display buffer area of the virtual screen by the application program.
Further, the service process is further configured to perform: and when the output screen is changed, the service process acquires the resolution of the output screen again and recalculates the scaling parameters.
In summary, the technical scheme of the invention has the following beneficial effects:
the android system is provided with the service process, the service process performs scaling adaptation processing on the user interface data according to the resolution of the virtual screen and the resolution of the screen device, and the application program draws the user interface data to the virtual screen with fixed resolution; the server automatically recalculates the scaling, so that the resource allocation of a set of standard resolution and the adaptation of a screen with any resolution can be realized, and the application program end does not need to make any adjustment; the method is suitable for a main screen or an external screen, and can realize single-screen or double-screen simultaneous output of the application program.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the current android technical development field, in order to solve the technical problem that the android application program adapts to screens with different specifications, various different technical schemes exist, but adaptation processing of various resolutions is usually carried out at the application program end, and the following problems cannot be avoided by the processing mode all the time: firstly, all screen resolutions cannot be enumerated, and hundred percent adaptation cannot be realized; and secondly, the application programs pack resources or configurations under various resolutions, the file size of the application programs is increased invisibly, and the application programs with higher adaptation degree are bulkier.
According to the technical scheme, the service process is set in the android system, and the work of screen adaptation is transferred from the application end to the android frame layer, so that the development process of the application program is simplified, and the size of the file of the application program is reduced. Referring to fig. 1, it is a flowchart of the steps of a method for adapting to multiple screen resolutions, comprising the following steps:
step 1, a service process calls a system interface to create a virtual screen and a display buffer area thereof;
according to the technical scheme, a service process is deployed in a framework layer of the android system and used for uniformly managing display equipment of the android system and simultaneously processing screen display of all application programs. When the application program needing interface display is started, the application program communicates with the service process, User Interface (UI) data of the application program is sent to the service process, and the service process renders the user interface data of all the application programs and outputs the user interface data to a screen. In the service process initialization stage, a Virtual Display (Virtual Display) is created through the android system interface, the Virtual Display does not correspond to a real screen device, and the resolution of the Virtual Display is generally set to the resolution of the application program UI during design. In addition, the service process also creates a display buffer area corresponding to the virtual screen for storing the content required to be displayed by the virtual screen.
In a preferred embodiment, the service process according to the present invention may be a surfaceflag system process of an android system framework. In the current android framework, the SurfaceFlinger service runs in the system process of the android system, which is responsible for managing the Frame Buffer (Frame Buffer) of the android system, i.e., the content that is ultimately displayed to the screen. Android applications must communicate with the surfacemaker service in order to be able to draw their UI on the frame buffer of the system. The service process in the scheme of the invention can be used by correspondingly adjusting the code of the SurfaceFlinger system process.
Step 2, the service process sets that an output screen and the virtual screen use the same display buffer area;
types of android screen devices include, in addition to virtual screens: primary Display, default Display device, e.g. screen of smartphone; external Display (External Display), such as an lcd tv connected to an android set top box. The interface content output by the application program is finally displayed on the real screen devices, and the output screen in the technical scheme of the invention can be a main screen or an external screen (single screen) or can be the main screen and the external screen which are output simultaneously (double screens). In the bottom framework of the android system, a main screen, an external screen and a virtual screen respectively correspond to a display buffer area, UI data is written into the display buffer areas by an application program, and the corresponding screens are displayed. This step is typically implemented by pointing the pointer address of the display buffer of the main screen, the external screen, to the display buffer address of the virtual screen at the time of service process initialization.
Step 3, the service process obtains the resolutions of the virtual screen and the output screen and calculates a zooming parameter;
the service process acquires the resolutions of the virtual screen, the main screen and the external screen through the android system interface, and calculates scaling parameters, namely scaling proportion, wherein the scaling parameters comprise a horizontal scaling parameter and a vertical scaling parameter. In addition, the main screen and the external screen have respective zoom parameters.
For example, in a specific embodiment, the resolution of the virtual screen created when the service process initializes is 1280 × 720, the resolution of the service process acquiring the main screen is 800 × 600, the horizontal scaling parameter of the main screen is 800/1280 ═ 0.625, the vertical scaling parameter is 600/720 ═ 0.833, and the resolution of the service process acquiring the external screen is 1920 × 1080, the horizontal scaling parameter of the external screen is 1920/1280 ═ 1.5, and the vertical scaling parameter is 1080/720 ═ 1.5.
Step 4, the application program writes user interface data into the display buffer area of the virtual screen;
in specific application, when starting the android application program, the android application program establishes connection with a service process to communicate, meanwhile, User Interface (UI) data of the application program is sent to the service process, and the service process writes the User Interface (UI) data into a display buffer area corresponding to a virtual screen.
And 5, the service process displays the user interface data in the display buffer area on an output screen according to the zooming parameters.
And the service process amplifies or reduces the UI data in the virtual screen display buffer area according to the zooming parameters of the main screen and the external screen, and then sends the UI data to the frame buffer areas corresponding to the main screen and the external screen for display. The frame buffer here refers to a buffer area for the android system screen hardware device to directly read the display content, for example, according to the scaling parameters in the foregoing embodiment, the service process performs horizontal 0.625 times and vertical 0.833 times reduction on the UI data with 1280 × 720 resolution in the virtual screen display buffer, and then sends the UI data to the frame buffer area of the main screen for display; meanwhile, the service process amplifies the UI data with 1280 × 720 resolution in the virtual screen display buffer area by 1.5 times in the transverse direction and 1.5 times in the longitudinal direction, and then sends the amplified UI data to the frame buffer area of the external screen for display.
In a specific embodiment, the technical solution of the present invention further includes the following step 6: and when the output screen is changed, the service process acquires the resolution of the output screen again and recalculates the scaling parameters. When the external screen changes, for example, when an externally connected liquid crystal television of a certain android set-top box changes, and a service process receives an adding event of the screen, the android system interface is called again to obtain the resolution of the newly accessed external screen, and simultaneously, new scaling parameters are calculated to realize the adaptation of the newly accessed external screen.
In the following, a specific embodiment of the method for adapting multiple screen resolutions according to the present invention is described, wherein the standard resolution of the UI design of the application is 1920 × 1080, and the service process is modified and adjusted by the surface flicker system process:
step 1, when a SurfaceFlinger service system process starts initialization along with an android system, calling a system interface to create a virtual screen with a resolution of 1920 x 1080 and simultaneously creating a corresponding display buffer area;
step 2, when the surface flag service process is initialized, pointer addresses of display buffer areas of the main screen and the external screen are set at the same time and point to the virtual screen display buffer area, so that the main screen, the external screen and the virtual screen use the same display buffer area;
step 3, the resolution of the home screen acquired by the surface flicker service process is 800 × 600, the horizontal scaling parameter of the home screen is 800/1920 ═ 0.417, the vertical scaling parameter is 600/1080 ═ 0.556, and the resolution of the external screen acquired by the service process is 1366 × 768, the horizontal scaling parameter of the external screen is 1366/1920 ═ 0.711, and the vertical scaling parameter is 768/1080 ═ 0.711.
And 4, when the application program is started, establishing connection with the SurfaceFlinger service for communication, simultaneously sending User Interface (UI) data of the application program to the SurfaceFlinger service process, and writing the User Interface (UI) data into a display buffer area corresponding to the virtual screen by the SurfaceFlinger service process.
Step 5, the surface Flinger service process reduces the horizontal 0.417 times and the vertical 0.556 times of UI data with 1920 x 1080 resolution in the virtual screen display buffer area, and then sends the UI data into the frame buffer area of the main screen for display; meanwhile, the service process reduces the horizontal 0.711 times and the vertical 0.711 times of the 1920 × 1080 resolution UI data in the virtual screen display buffer, and then sends the UI data into the frame buffer of the external screen for display.
And 6, when the external screen changes, the resolution of the newly accessed external screen is 1920 × 1080, the service process acquires the resolution of the output screen again, recalculates the horizontal scaling parameter to be 1, and sends the UI data with the resolution of 1920 × 1080 in the display buffer into the frame buffer of the external screen for display, wherein the vertical scaling parameter is 1 (namely scaling processing is not needed).
Referring to fig. 2, a structure diagram of a storage device of the present invention is shown, in which an instruction set is stored, and the instruction set is used for executing: calling an android system interface to create a virtual screen when a service process is initialized, wherein the virtual screen does not correspond to real screen equipment, the resolution is usually set as the resolution when an application program UI is designed, and meanwhile, a corresponding display buffer area is created; setting an output screen and the virtual screen to use the same display buffer area while initializing the service process, wherein the display buffer area pointer address of the output screen points to the display buffer area of the virtual screen; the service process acquires the resolutions of the virtual screen and the output screen and calculates scaling parameters (namely a horizontal scaling ratio and a vertical scaling ratio); and the service process amplifies or reduces the user interface data in the display buffer area according to the zooming parameters and sends the user interface data to a frame buffer area of an output screen for display. And writing user interface data into the display buffer area of the virtual screen by an application program. For example: when the application program is started, the application program is communicated with the SurfaceFlinger service in a connection mode, meanwhile, User Interface (UI) data of the application program are sent to the SurfaceFlinger service process, and the SurfaceFlinger service process writes the User Interface (UI) data into a display buffer area corresponding to the virtual screen.
In a specific application, the storage device of the present invention may be a server hard disk storing the above instruction set, or may be other storage media such as a usb disk and an optical disk.
In a preferred embodiment, the storage device stores instruction sets for performing the following: and when the output screen is changed, the service process acquires the resolution of the output screen again and recalculates the scaling parameters. By including the part of instruction set, the situation that the application program only needs to provide resources and configuration with a set of resolution and can be adapted to screens with various resolutions in percentage can be realized.
Fig. 3 is a structural diagram of an android device adapted to multiple screen resolutions according to the present invention. The android device stores a service process and an application program, wherein,
a service process, initiated with the android system as a system process, for performing: calling an android system interface to create a virtual screen when a service process is initialized, wherein the virtual screen does not correspond to real screen equipment, the resolution is usually set as the resolution when an application program UI is designed, and meanwhile, a corresponding display buffer area is created; setting an output screen and the virtual screen to use the same display buffer area while initializing the service process, wherein the display buffer area pointer address of the output screen points to the display buffer area of the virtual screen; the service process acquires the resolutions of the virtual screen and the output screen and calculates scaling parameters (namely a horizontal scaling ratio and a vertical scaling ratio); the service process amplifies or reduces the user interface data in the display buffer area according to the zooming parameters and sends the user interface data to a frame buffer area of an output screen for display;
the application program refers to various programs installed and used on the android device by a user, and is used for executing the following steps: the application writes UI design resolution user interface data to the display buffer of the virtual screen without regard to adaptation of other resolutions.
For example, the android device adapted to multiple screen resolutions can be a certain android set-top box or an intelligent television, the service process and the application program of the invention are deployed in an android system of a device factory, the service process performs scaling adaptation processing on user interface data according to the resource resolution provided by the application program and the resolution of the screen device, and screen adaptation work is transferred from the application end to the android service end, so that the application program development process is simplified, and the size of an application program file is reduced.
In a preferred embodiment, the service process deployed on the android device adapted to multiple screen resolutions of the present invention is further configured to perform: and when the output screen is changed, the service process acquires the resolution of the output screen again, recalculates the scaling parameters and realizes the adaptation of the newly accessed screen.
The above embodiments are merely illustrative of the technical solutions of the present invention, and the present invention is not limited to the above embodiments, and any modifications or alterations according to the principles of the present invention should be within the protection scope of the present invention.