Language switching method and device, electronic equipment and storage medium
By filtering and processing non-ViewGroup type controls in the Android operating system, and determining and loading text resources of TextView controls, the problems of interface flickering and high program complexity during Chinese and English text string switching are solved, and efficient and accurate language switching is achieved.
Patent Information
- Application Number
- CN202311474352.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-07
- Publication Date
- 2025-05-09
AI Technical Summary
The prior art causes the user to perceive the interface flicker when switching Chinese and English text strings, and the program is complex and the error rate is high.
When receiving the language switching instruction, obtain all target controls in the Android operating system, filter out controls of non-ViewGroup type, traverse these controls to determine the TextView control, and load text resources on the text control based on the target language information in the language switching instruction to realize language switching.
Through this method, interface flickering is avoided, program complexity and error rate are reduced, and language switching is improved.
Smart Images

Figure CN119960860A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of system control technology, and in particular to a language switching method, device, electronic device and storage medium based on an Android operating system. Background Art
[0002] Currently, there are mainly the following solutions for switching between Chinese and English for text strings displayed in the system: re-create the Activity component, then reset the text of the TextView in the interface, and then load the corresponding text resources in the system. However, the display interface will flicker during the reconstruction, affecting user perception; or developers can manually reset the text of all TextViews in the Activity or window interface, and then load the corresponding text resources in the system. However, this solution requires the creation of a container that can accommodate TextView in advance, which not only increases the system and personnel costs, but also affects the system accuracy because the system program is more cumbersome. Summary of the invention
[0003] In order to solve the above technical problems or at least partially solve the above technical problems, an embodiment of the present invention provides a language switching method, device, electronic device and storage medium based on the Android operating system, which are used to solve the problem of high error rate caused by user perception and cumbersome procedures when switching between Chinese and English in the prior art.
[0004] In order to achieve the above purpose, the technical solution provided by the embodiment of the present invention is as follows:
[0005] In a first aspect, an embodiment of the present invention provides a language switching method based on an Android operating system, the method comprising: when a language switching instruction is received, obtaining all target controls in the Android operating system, the target controls are not ViewGroup controls;
[0006] Traversing the target controls, and determining a text control from the target controls, wherein the text control is a TextView control for displaying text;
[0007] According to the target language information in the language switching instruction, text resources are loaded into the text control to complete the language switching.
[0008] As an optional implementation, in a first aspect of the embodiment of the present invention, traversing the target controls and determining a text control from the target controls includes:
[0009] Determine whether the first control is a TextView control;
[0010] If yes, determining the first control as the text control;
[0011] If not, determining whether the second control is a TextView control, until the text control is determined from the target controls;
[0012] The first control and the second control are any one of the target controls.
[0013] As an optional implementation, in the first aspect of the embodiment of the present invention, when receiving the language switching instruction, obtaining the target control in the Android operating system includes:
[0014] When receiving the language switching instruction, determining a root node control in the Android operating system;
[0015] The target control is obtained through the root node control.
[0016] As an optional implementation, in the first aspect of the embodiment of the present invention, obtaining the target control through the root node control includes:
[0017] Obtain the initial controls through the root node control, and detect whether each initial control is a ViewGroup control;
[0018] An initial control that is not a ViewGroup control is determined as the target control.
[0019] As an optional implementation, in the first aspect of the embodiment of the present invention, the loading of text resources for the text control according to the target language information in the language switching instruction to complete the language switching includes:
[0020] Extract the text resources included in each text control through reflection technology;
[0021] The text resources are reset according to the target language information to complete the language switching.
[0022] As an optional implementation, in the first aspect of the embodiment of the present invention, the resetting of the text resources according to the target language information to complete the language switching includes:
[0023] Obtain the text resource flag corresponding to each text control through the reflection technology;
[0024] When the text resource flag indicates that it is valid, the text resource is reset according to the target language information to complete the language switch.
[0025] In a second aspect, an embodiment of the present invention provides a language switching device based on an Android operating system, the language switching device comprising: an acquisition module, for acquiring all target controls in the Android operating system when a language switching instruction is received, the target control being not a ViewGroup control;
[0026] A processing module, used for traversing the target controls and determining a text control from the target controls, wherein the text control is a TextView control for displaying text;
[0027] The resource loading module is used to load text resources into the text control according to the target language information in the language switching instruction to complete the language switching.
[0028] As an optional implementation, in the second aspect of the embodiment of the present invention, the processing module is specifically used to determine whether the first control is a TextView control;
[0029] If yes, the processing module is specifically configured to determine the first control as the text control;
[0030] If not, the processing module is specifically used to determine whether the second control is a TextView control until the text control is determined from the target controls;
[0031] The first control and the second control are any one of the target controls.
[0032] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module is specifically used to determine the root node control in the Android operating system when receiving the language switching instruction;
[0033] The acquisition module is specifically used to acquire the target control through the root node control.
[0034] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module is specifically used to acquire the initial control through the root node control, and detect whether each initial control is a ViewGroup control;
[0035] The processing module is specifically configured to determine an initial control that is not a ViewGroup control as the target control.
[0036] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module is specifically used to extract the text resources included in each text control through reflection technology;
[0037] The resource loading module is specifically used to reset the text resource according to the target language information to complete the language switching.
[0038] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module is specifically used to acquire the text resource flag corresponding to each text control through the reflection technology;
[0039] The resource loading module is specifically used to reset the text resource according to the target language information to complete the language switch when the text resource flag indicates that it is valid.
[0040] In a third aspect, an embodiment of the present invention provides an electronic device, the electronic device comprising:
[0041] A memory storing executable program code;
[0042] a processor connected to the memory;
[0043] The processor calls the executable program code stored in the memory to execute the language switching method based on the Android operating system in the first aspect of the embodiment of the present invention.
[0044] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the language switching method based on an Android operating system in the first aspect of the embodiment of the present invention. The computer-readable storage medium includes a ROM / RAM, a disk or an optical disk, etc.
[0045] In a fifth aspect, an embodiment of the present invention provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute part or all of the steps of any one of the methods of the first aspect.
[0046] In a sixth aspect, an embodiment of the present invention provides an application publishing platform, which is used to publish a computer program product, wherein when the computer program product runs on a computer, the computer executes part or all of the steps of any one method of the first aspect.
[0047] In a seventh aspect, the present invention provides a vehicle, comprising: a language switching device based on an Android operating system as described in the second aspect, or an electronic device as described in the third aspect.
[0048] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0049] The embodiment of the present invention provides a language switching method, device, electronic device and storage medium based on an Android operating system. When a language switching instruction is received, all target controls in the Android operating system are obtained. Here, it is necessary to ensure that all target controls are not ViewGroup controls, so that all target controls obtained here are already the bottom-level views, so as to ensure that no omissions in the traversal of views occur; then the target controls are traversed, and text controls are determined from the target controls. The text controls are TextView controls for displaying texts. These TextView controls all store text resources. Finally, according to the target language information in the language switching instruction, text resources are loaded into the text controls, so that language switching can be achieved. There are many subclasses of controls in the system architecture of the Android operating system, among which only the TextView control can indicate the text elements displayed on the interface. Therefore, through this solution, all controls at the bottom level can be screened out from a large number of controls, and all TextView controls can be determined therefrom, so that all text resources included in the TextView control can be ensured to be loaded, and the accuracy and integrity of the language switching can be effectively improved without affecting user operations and adding new system programs. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0051] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0052] Figure 1 is a schematic diagram of a calling scenario of a language switching method based on an Android operating system provided by an embodiment of the present invention;
[0053] Figure 2 This is a flow diagram of a language switching method based on an Android operating system provided by an embodiment of the present invention. Figure 1 ;
[0054] Figure 3 It is a structural diagram of a language switching method based on an Android operating system provided by an embodiment of the present invention;
[0055] Figure 4 This is a flow diagram of a language switching method based on an Android operating system provided by an embodiment of the present invention. Figure 2 ;
[0056] Figure 5 is a structural schematic diagram of a language switching device based on an Android operating system provided by an embodiment of the present invention;
[0057] Figure 6 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0058] In order to more clearly understand the above-mentioned purposes, features and advantages of the present application, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. It should be noted that the embodiments of the present application and the features in the embodiments can be combined with each other without conflict. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] The terms "first" and "second" and the like in the description and claims of the present invention are used to distinguish different objects rather than to describe a specific order of the objects.
[0060] The terms "including" and "having" and any variations thereof in the embodiments of the present invention are intended to cover non-exclusive inclusions. For example, a process, method, system, product or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products or apparatus.
[0061] It should be noted that, in the embodiments of the present invention, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0062] At present, there are mainly the following technical solutions to realize the switching between Chinese and English in text strings displayed in programs of Android operating system:
[0063] Technical Solution 1: When receiving the Chinese-English switching callback instruction from the system, the activity component (Activity) is rebuilt, and then the text of the TextView in the interface is reset, and then the corresponding text resources in the current system can be loaded to display the language text set by the current system.
[0064] The main problems of this technical solution are: the interface will flicker during reconstruction, affecting the user experience, and there are defects that can be perceived by users.
[0065] Technical Solution 2: When receiving the system's Chinese-English switching callback instruction, the developer manually resets the text of all TextViews in the Activity or window interface, and then loads the corresponding text resources in the current system to display the language text set by the current system.
[0066] The main problem of this technical solution is that developers need to develop and create a Textview container for storing texts displayed in all interfaces. This involves container management, which increases the development and maintenance costs of developers. At the same time, due to the complex program logic, the program error rate is also increased.
[0067] In order to solve some or all of the above technical problems, the embodiments of the present invention provide a language switching method, device, electronic device and storage medium based on the Android operating system. When a language switching instruction is received, all target controls in the Android operating system are obtained. Here, it is necessary to ensure that all target controls are not ViewGroup controls, so that all target controls obtained here are already the bottom-level views, so as to ensure that no omissions in the traversal view occur; then the target controls are traversed, and text controls are determined from the target controls. The text controls are TextView controls for displaying text. Text resources are stored in these TextView controls. Finally, according to the target language information in the language switching instruction, text resources are loaded for the text controls, and language switching can be achieved. There are many subclasses of controls in the system architecture of the Android operating system, among which only the TextView control can indicate the text elements displayed on the interface. Therefore, through this solution, all controls at the bottom level can be screened out from a large number of controls, and all TextView controls can be determined therefrom, so that all text resources included in the TextView control can be ensured to be loaded, and the accuracy and integrity of the language switching can be effectively improved without affecting user operations and adding new system programs.
[0068] The language switching method provided in the embodiment of the present invention is applied to the Android operating system. In the Android operating system, the base class of all controls is called view. Whether it is a simple TextView, Button or a complex LinearLayout and ListView, their common base class is view. View is the abstract name of the control of the Android display interface layer, which represents a control. In addition to view, there is also ViewGroup. ViewGroup can be understood as a control group, that is, a group of views; in Android, ViewGroup also inherits view, which means that view can be a single control or a group of controls composed of multiple controls.
[0069] The embodiments of the present invention involve concepts such as view, TextView and ViewGroup, among which view is the base class of all controls in the Android system, and the Android UI interface is composed of view and its derived classes. The type, color, content and other attributes of view determine the type, color, content and so on of the interface elements presented in the user interface. For example, the interface element corresponding to the view control (TextView) that displays text is text. When the content of the view is the text "Hello", the content of the interface element presented in the user interface is also the text "Hello".
[0070] ViewGroup is derived from view and is a container for view and its derived classes. That is to say, ViewGroup can contain at least one view and / or at least one other ViewGroup. In addition, for a large control that contains internal small controls, the internal small controls are child controls of the large control, and the large control is the parent control of the internal small controls. For example, if the hierarchy of a UI layout is ViewGroup1 containing ViewGroup2, and ViewGroup2 containing view3, then in the UI layout, ViewGroup1 is the parent container of ViewGroup2, and ViewGroup2 is the child view of ViewGroup1; similarly, ViewGroup2 is the parent container of view3, and view3 is the child view of ViewGroup2.
[0071] In the entire Android operating system, the architecture of the view control is similar to a tree, with a root node control (RootView), which is extended and forked based on the root node. It can include branch nodes, leaf nodes, etc. Each node is actually a view or ViewGroup.
[0072] Figure 1A calling scenario diagram of a language switching method based on an Android operating system is provided for an embodiment of the present invention, such as Figure 1 As shown, when the user needs to switch the system language, the system language will be switched actively. After the system settings (settings) receive the user's operation, a system callback will be performed. Specifically, the application (Application, App) is notified through the system configuration information change callback (onConfigurationChanged) method. Then the App can call the language switching method (UpdateAllTextViewByLocaleChanged) disclosed in the present invention to switch the language, and after the switch is completed, the execution result will be returned to indicate whether the switch is successful.
[0073] The specific steps of the language switching method (UpdateAllTextViewByLocaleChanged) used above will be described in detail in the following embodiment.
[0074] like Figure 2 As shown, Figure 2 A flow chart of a language switching method based on an Android operating system is provided for an embodiment of the present invention. The method may include the following steps:
[0075] 201. When a language switching instruction is received, all target controls in the Android operating system are acquired.
[0076] Wherein, the target control is not a ViewGroup control.
[0077] It should be noted that the control (view) is the base class of all controls in the Android system. The interface display of the Android operating system is represented by the view. Different categories of views can control different functions. In other words, the display of language text is also determined by some corresponding views. When switching languages, the text content displayed on the interface also needs to switch languages. Therefore, it is necessary to determine the view that displays the text content, that is, the TextView control.
[0078] In the embodiment of the present invention, the logic of the present invention is to first obtain all views in all Android operating systems, and then filter them to finally obtain all TextView controls.
[0079] In some embodiments, when a language switching instruction is received, all target controls in the Android operating system are obtained, which may specifically include: when the language switching instruction is received, a root node control in the Android operating system is determined; and the target control is obtained through the root node control.
[0080] In this embodiment, since all views in the Android operating system exist in the form of a view tree, there is a root node control in the view tree, namely, rootView. The root node control can be directly obtained from the Activity component of the Android operating system, which is the first view under the interface window directory. After obtaining the root node control, all child nodes of the root node control, namely, all target controls, can be obtained through the root node control.
[0081] In some embodiments, since the view in the system includes two types, namely view and ViewGroup, that is to say, some views are ViewGroup type controls, and this type of view includes some views. It can be seen that the views directly obtained through the root node control may include ViewGroup type views. Therefore, if a view is a ViewGroup control, it is necessary to further obtain the target controls included in the view, until each view finally obtained is not a ViewGroup control, that is, all target control views are determined.
[0082] In some embodiments, obtaining the target control through the root node control may specifically include: obtaining all initial controls through the root node control, and detecting whether each initial control is a ViewGroup control; if not, determining the initial control as the target control; if so, continuing to obtain all initial controls included in the ViewGroup control, and looping the above steps until it is detected that all initial controls are not ViewGroup controls, so as to obtain all target controls.
[0083] In this embodiment, multiple initial controls can be obtained through the root node control. These initial controls may include ViewGroup controls. Therefore, all initial controls need to be detected, that is, each initial control is detected to see whether it is a ViewGroup control. If it is not a ViewGroup control, the initial control can be determined as the target control; if it is a ViewGroup control, it can be explained that the initial control also includes some views and / or some ViewGroup controls. Therefore, it is necessary to continue to obtain all views included in the initial control which is a ViewGroup control, and continue to determine whether these views are ViewGroup controls.
[0084] Among them, Figure 3 Shown is the relationship between rootView, view and ViewGroup. Figure 3In the example, rootView may include M views from view1 to viewM and N ViewGroups from ViewGroup1 to ViewGroupN, and ViewGroup1 may include P views from view11 to view1P and Q ViewGroups from ViewGroup11 to ViewGroup1Q, and the same goes for other ViewGroups.
[0085] Combining this plan with Figure 3 For an exemplary explanation, first, four initial controls are obtained through the root node control (rootView), namely: view1, viewM, ViewGroup1 and ViewGroupN, and then view1, viewM, ViewGroup1 and ViewGroupN are respectively detected to see if they are ViewGroup controls. After detection, it can be obtained that ViewGroup1 and ViewGroupN are ViewGroup controls, and view1 and viewM are not ViewGroup controls. Therefore, view1 and viewM can be determined as target controls; take ViewGroup1 as an example for explanation, and then it is necessary to continue to obtain all the initial controls included in the ViewGroup1, and four initial controls are obtained, namely: view11, view1P, ViewGroup11 and ViewGroup1Q, and then view11, view1P, ViewGroup11 and ViewGroup1Q are respectively detected again to see if they are ViewGroup controls, and this cycle is repeated. During this cycle, as long as it is not a ViewGroup control, it can be directly determined as the target control. If it is a ViewGroup control, it is necessary to obtain the views it includes again, until all target controls that are not ViewGroup controls are finally obtained.
[0086] In some embodiments, after the root node control is determined, all child nodes can be traversed through the root node control to obtain all initial child views.
[0087] Traversal refers to visiting each node in the tree once and only once along a certain search route. The operation performed on the visited node depends on the specific application problem. Traversal is one of the most important operations on a binary tree and is the basis for other operations on a binary tree. All views are presented in the form of a view tree, so when obtaining all initial subviews, they can be executed by traversal, and the traversal process is usually implemented recursively.
[0088] It should be noted that, whether it is the process of obtaining all initial child views through the root node control, or the process of cyclically obtaining all initial controls included in each ViewGroup control, they are all obtained through traversal.
[0089] In this embodiment, by looping through all nodes and performing ViewGroup detection on each view, it is possible to ensure that all the bottom-level views included in the root node control are obtained, which can also ensure that all TextView controls can be screened subsequently to achieve accuracy in language switching.
[0090] In some embodiments, if the user wants to switch the system language, the system language will be actively switched. There are many ways to implement this operation, such as: the user directly manually selects the desired language after switching, or the user directly inputs the desired language after switching by voice, or the system determines the user's intention to switch languages and determines the language after switching according to the language frequently used by the user, or directly determines the language used by other electronic devices associated with the user's device as the language after switching, etc. Of course, many operating methods can also be included, and the embodiments of the present invention do not make specific limitations.
[0091] 202. Traverse the target controls and determine a text control from the target controls.
[0092] Wherein, the text control is a TextView control for displaying text.
[0093] In the embodiment of the present invention, all target controls are traversed to detect whether each target control is a TextView control. If so, the target control can be determined as a text control.
[0094] Of course, if it is detected that a target control is not a TextView control, then the target control is directly discarded to continue detecting the next target control.
[0095] It should be noted that there are 12 direct subclasses of view, each of which includes multiple indirect subclasses, for a total of 113 indirect subclasses.
[0096] Among them, direct subclasses of view may specifically include: AnalogClock, ImageView for displaying any image (such as an icon), KeyboardView for rendering a virtual keyboard view, MediaRouteButton for multimedia routing buttons, ProgressBar for visual indicators of operation progress, a lightweight subclass Space for creating blank areas between components in a general layout, a SurfaceView for playing videos with an embedded Surface specifically for drawing, a special subclass TabItem that allows tab items to be born for TabLayout in a layout, an editable TextView for displaying text to the user, a TextureView for displaying online videos or arbitrary data streams, a special view group ViewGroup that can include other views, an invisible control ViewStub that does not occupy layout space and occupies very little resources, and ViewStubCompat that is compatible with ViewStub.
[0097] From this we can see that if you want to switch the language of the system, you first need to filter out all the TextView controls and configure them.
[0098] In some embodiments, traversing the target controls and determining the text controls from the target controls may specifically include: determining whether the first control is a TextView control; if so, determining the first control as the text control; if not, determining whether the second control is a TextView control, until all the text controls are determined from all the target controls.
[0099] In this embodiment, after all target controls are obtained, a TextView judgment can be performed on each target control in turn, that is, whether each target control is a TextView control. If so, it means that the target control is a control corresponding to the displayed text, then the target control that is a TextView control can be determined as a text control, and then the next target control can be detected whether it is a TextView control; if not, then the next target control can be directly detected whether it is a TextView control; until all target controls are detected, all text controls can be screened out from all target controls.
[0100] Among them, the first control and the second control are any one of all target controls, that is, when judging the target control, a target control is arbitrarily selected for judgment, and after the judgment is completed, the next target control is arbitrarily selected for judgment, and there are no fixed selection requirements or orders.
[0101] It should be noted that to detect whether the target control is a TextView control, you can directly judge by the name of the target control. Each view will reflect the subclass in the name, so you can directly view the name of each target control to filter text controls.
[0102] 203. Load text resources into the text control according to the target language information in the language switching instruction to complete the language switching.
[0103] In an embodiment of the present invention, after all text controls are determined, language switching can be performed. During the language switching process, since each text control includes some text resources, it is necessary to load text resources for each text control to ensure that all language switching is completed.
[0104] In this embodiment, the language switching instruction will carry target language information, and the target language can be determined through the target language information. The target language is the language after the current language is switched. In this way, when the text resources of the text control are loaded, the text resources corresponding to the target language can be loaded, so that the language switch can switch the current language to the target language.
[0105] It should be noted that the Android operating system will pre-store texts in multiple languages. These language texts are all stored in the TextView control. The system will load the corresponding language text according to the current language settings. When the language needs to be switched, the system will also load the required language text according to the switching instructions.
[0106] In some embodiments, according to the target language information in the language switching instruction, text resources are loaded into the text control to complete the language switching, which may specifically include: extracting the text resources (mTextId) included in each text control through reflection technology; and resetting the text resources according to the target language information to complete the language switching.
[0107] In this embodiment, each view carries corresponding data, and the TextView control used to display text will correspondingly carry text data. Therefore, it is necessary to extract data from all text controls, and then reset the text resources in combination with the target language information to achieve language switching.
[0108] In some embodiments, the text resource included in the text control can be obtained through reflection technology.
[0109] It should be noted that the reflection mechanism is in the running state. For any class, all the properties and methods of this class can be known; for any object, any method and property of it can be called; that is, the core of the reflection mechanism is to dynamically load the class and obtain the detailed information of the class when the program is running, so as to operate the properties and methods of the class or object. The essence is that after the JVM obtains the class object, it decompiles it through the class object to obtain various information of the object.
[0110] The reflection technology includes many kinds of fixed reflection functions. Different reflection functions correspond to different functions. In this embodiment, the text resources included in each text control can be extracted through the corresponding reflection function.
[0111] In this embodiment, the getPackageName method of PackageManager may be executed through a reflection mechanism to extract the text resource of each text control.
[0112] Exemplarily, Chinese text, English text, Russian text, French text and Italian text are stored in the TextView control, and the current language is Chinese input method, that is, the text resources stored in all TextView controls are Chinese; if the user wants to switch to Russian input method, after the Android operating system receives the language switching instruction, it will analyze the language switching instruction and determine that the language the user wants after switching is Russian input method. Then, all TextView controls in the Android operating system can be screened out, and then the Chinese text resources included in all TextView controls can be extracted through reflection technology, and finally all Chinese text resources can be reset to Russian format. When all text resources are reset, the language switch is realized.
[0113] In some embodiments, in addition to extracting the text resources (mTextId) of each text control, the text resource flag (mTextFromResource or mTextSetFromXmlOrResourceId) of each text control can also be extracted. The text resources and text resource flags of each text control correspond to each other, and then the text resource flag can be tested. Only when the text resource flag of a text control is valid, the text resources of the text control will be reset; if the text resource flag of a text control is invalid, the text resources of the text control will not be reset, and the text resources and text resource flags of the next text control will continue to be extracted and tested.
[0114] The method of extracting the text resource flag of each text control is also obtained through the reflection technology; specifically, the text resource flag can be extracted from the text control through the reflection function corresponding to the extracted text resource.
[0115] An embodiment of the present invention provides a language switching method based on an Android operating system. When a language switching instruction is received, all target controls in the Android operating system are obtained. Here, it is necessary to ensure that all target controls are not ViewGroup controls, so that all target controls obtained here are already the bottom-level views, so as to ensure that no omissions in the traversal of views occur; then the target controls are traversed, and text controls are determined from the target controls. The text controls are TextView controls for displaying texts. Text resources are stored in these TextView controls. Finally, according to the target language information in the language switching instruction, text resources are loaded into the text controls to achieve language switching. There are many subclasses of controls in the system architecture of the Android operating system, among which only the TextView control can indicate the text elements displayed on the interface. Therefore, through this solution, all controls at the bottom level can be screened out from a large number of controls, and all TextView controls can be determined therefrom, so that all text resources included in the TextView control can be ensured to be loaded, and the accuracy and integrity of the language switching can be effectively improved without affecting user operations and adding new system programs.
[0116] In some embodiments, after the text resource is loaded and the language is switched, corresponding prompt information can be output for feedback. There are many ways to output the prompt information, such as: displaying the prompt information of successful language switching on the device screen through text, or directly outputting the prompt information of successful language switching through voice, or outputting the prompt information of successful language switching through a fixed prompt sound effect, etc. Of course, there are many other output methods, which are not specifically limited in the embodiments of the present invention.
[0117] It should be noted that, combined with Figure 2 In the process shown in the above disclosed embodiment, all initial controls are first obtained through the root node control, and then it is determined whether each initial control is a ViewGroup control, until all target controls that are not ViewGroup controls are determined; then, it is determined whether each target control is a TextView control, thereby determining all text controls, and finally all text resources included in all text controls are loaded to achieve language switching.
[0118] like Figure 4The figure shows another achievable flow chart of the language switching method disclosed in the embodiment of the present invention, wherein the specific steps include: (1) obtaining all subviews corresponding to the root node control; (2) looping through all subviews; (3) determining whether the subview is a ViewGroup; if so, re-executing step (1); if not, continuing to execute step (4); (4) determining whether the subview is a TextView; if so, continuing to execute step (5); if not, directly executing step (8); (5) obtaining the attributes of the subview: text resource and text resource flag; (6) checking whether the attributes of the subview are valid; if so, continuing to execute step (7); if not, directly executing step (8); (7) the subview loads the text resource according to the obtained attributes to complete the text switching; (8) ending the current subview processing flow; and then re-executing step (2).
[0119] From the above steps, it can be seen that Figure 4 In the process shown, all detection steps and text loading steps are performed for one subview. Only when all processing of this subview is completed will the next view be processed.
[0120] Exemplarily, after acquiring and traversing all subviews, there are three subviews in total: view1, view2, and view3. First, determine whether view1 is a ViewGroup. If yes, continue to acquire and traverse all subviews of view1. If no, continue to determine whether view1 is a TextView. If no, directly end the processing of view1 and start the processing flow of view2. If yes, continue to acquire the properties of view1. Then determine whether the properties of view1 are valid. If no, directly end the processing of view1 and start the processing flow of view2. If yes, continue to load text resources according to the properties of view1. This completes the processing of view1 and starts the processing flow of view2.
[0121] In the embodiment of the present invention, the above two different processes can both implement all the solutions of the language switching method disclosed in the embodiment of the present invention and achieve the same technical effect. The embodiment of the present invention does not limit the specific implementation process.
[0122] like Figure 5 As shown, an embodiment of the present invention provides a language switching device based on an Android operating system, and the language switching device based on an Android operating system may include:
[0123] An acquisition module 501 is used for acquiring all target controls in the Android operating system when a language switching instruction is received, wherein all target controls are not ViewGroup controls;
[0124] The processing module 502 is used to traverse the target controls and determine a text control from the target controls, where the text control is a TextView control for displaying text;
[0125] The resource loading module 503 is used to load text resources into the text control according to the target language information in the language switching instruction to complete the language switching.
[0126] As an optional implementation of the embodiment of the present invention, the processing module 502 is specifically used to determine whether the first control is a TextView control;
[0127] If yes, the processing module 502 is specifically configured to determine the first control as the text control;
[0128] If not, the processing module 502 is specifically used to determine whether the second control is a TextView control, until the text control is determined from the target controls;
[0129] The first control and the second control are any one of the target controls.
[0130] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module 501 is specifically configured to determine a root node control in the Android operating system when receiving the language switching instruction;
[0131] The acquisition module 501 is specifically configured to acquire the target control through the root node control.
[0132] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module 501 is specifically used to acquire the initial control through the root node control, and detect whether each initial control is a ViewGroup control;
[0133] The processing module 502 is specifically configured to determine an initial control that is not a ViewGroup control as the target control.
[0134] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module 501 is specifically used to extract the text resources included in each text control through reflection technology;
[0135] The resource loading module 503 is specifically used to reset the text resource according to the target language information to complete the language switching.
[0136] As an optional implementation, in the second aspect of the embodiment of the present invention, the acquisition module 501 is specifically used to acquire the text resource flag corresponding to each text control through the reflection technology;
[0137] The resource loading module 503 is specifically configured to reset the text resource according to the target language information to complete the language switch when the text resource flag indicates that the text resource is valid.
[0138] In the embodiment of the present invention, each module can implement the language switching method based on the Android operating system provided by the above method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be described here.
[0139] like Figure 6 As shown, an embodiment of the present invention further provides an electronic device, which may include:
[0140] A memory 601 storing executable program codes;
[0141] A processor 602 connected to the memory 601;
[0142] The processor 602 calls the executable program code stored in the memory 601 to execute the language switching method based on the Android operating system executed by the electronic device in the above-mentioned method embodiments.
[0143] An embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the language switching method based on the Android operating system in the above method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0144] An embodiment of the present invention provides a vehicle, the vehicle comprising the above-mentioned language switching device based on the Android operating system, or the above-mentioned electronic device. The vehicle is used to execute the language switching method based on the Android operating system provided by any embodiment of the present invention.
[0145] An embodiment of the present invention also provides a computer program product, which stores a computer program. When the computer program is executed by a processor, it implements the various processes of the language switching method based on the Android operating system in the above method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0146] Those skilled in the art will appreciate that the embodiments of the present disclosure may be provided as methods, systems, or computer program products. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.
[0147] In several embodiments provided by the present disclosure, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flowchart 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 a code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that 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 flowchart, and the combination of boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0148] In the present disclosure, the processor 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 also be any conventional processor, etc.
[0149] In the present disclosure, memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0150] In the present disclosure, a person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the relevant hardware through a program, and the program can be stored in a computer-readable storage medium, and the computer-readable medium includes permanent and non-permanent, removable and non-removable storage media. The storage medium can implement information storage by any method or technology, and the information can be a computer-readable instruction, a data structure, a module of a program, or other data. Examples of computer storage media include, but are not limited to, Parallel Random Access Memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Programmable Read Only Memory (PROM), Erasable Programmable Read Only Memory (EPROM), other types of Random Access Memory (RAM), Read Only Memory (ROM), One Time Programmable Read Only Memory (OTPROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, Compact Disc Read Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0151] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprises" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0152] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present invention. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. Those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present invention. The above-mentioned multiple embodiments are not necessarily multiple independent embodiments. Dividing into multiple embodiments is only used to highlight the different technical features in different embodiments. Those skilled in the art should be aware that the above-mentioned multiple embodiments can also be combined in any way.
[0153] In various embodiments of the present invention, it should be understood that the size of the serial numbers of the above-mentioned processes does not mean the necessary 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 the present invention.
[0154] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0155] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0156] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several requests for a computer device (which can be a personal computer, a server or a network device, etc., specifically a processor in a computer device) to perform some or all of the steps of the above methods of various embodiments of the present invention.
[0157] The above are only specific embodiments of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to these embodiments herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A language switching method based on an Android operating system, characterized in that: The method comprises: When a language switching instruction is received, all target controls in the Android operating system are obtained, where the target controls are not ViewGroup controls; Traversing the target controls, and determining a text control from the target controls, wherein the text control is a TextView control for displaying text; According to the target language information in the language switching instruction, text resources are loaded into the text control to complete the language switching.
2. The method according to claim 1, characterized in that The traversing the target controls and determining the text controls from the target controls includes: Determine whether the first control is a TextView control; If yes, determining the first control as the text control; If not, determining whether the second control is a TextView control, until the text control is determined from the target controls; The first control and the second control are any one of all the target controls.
3. The method according to claim 1, characterized in that When receiving the language switching instruction, obtaining the target control in the Android operating system includes: When receiving the language switching instruction, determining a root node control in the Android operating system; The target control is obtained through the root node control.
4. The method according to claim 3, characterized in that The step of obtaining the target control through the root node control includes: Obtain the initial controls through the root node control, and detect whether each initial control is a ViewGroup control; An initial control that is not a ViewGroup control is determined as the target control.
5. The method according to claim 1, characterized in that The step of loading text resources for the text control according to the target language information in the language switching instruction to complete the language switching includes: Through reflection technology, extract the text resources included in each text control; The text resources are reset according to the target language information to complete the language switching.
6. The method according to claim 5, characterized in that The resetting of the text resources according to the target language information to complete the language switching includes: Using the reflection technology, obtain the text resource flag corresponding to each text control; When the text resource flag indicates that it is valid, the text resource is reset according to the target language information to complete the language switch.
7. A language switching device based on an Android operating system, characterized in that: include: An acquisition module, configured to acquire all target controls in the Android operating system when a language switching instruction is received, wherein none of the target controls is a ViewGroup control; A processing module, used for traversing the target controls and determining a text control from the target controls, wherein the text control is a TextView control for displaying text; The resource loading module is used to load text resources into the text control according to the target language information in the language switching instruction to complete the language switching.
8. An electronic device, characterized in that: include: A memory storing executable program code; and a processor connected to the memory; The processor calls the executable program code stored in the memory to execute the language switching method based on the Android operating system as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: include: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by the processor, the language switching method based on the Android operating system as described in any one of claims 1 to 6 is implemented.
10. A vehicle, characterized in that: include: The language switching device based on the Android operating system as claimed in claim 7, or the electronic device as claimed in claim 8.