Detailed explanation of using PhonewindowManager

0297d4e5e0ff8c080cd3c7862bd5a8f4.gif

Learn with you for lifeXi, this is Programmer Android

Recommended classic articles. By reading this article, you will gain the following knowledge points:

1. Android button modification
2. Introduction to PhoneWindowManager
3. How to open or close the Navigation Bar
4. How to long press the Home button to start Google Now
5. How to long press the physical Menu button to enter multi-window mode
6. How to click the Menu button to bring up recent tasks List
7. How to let the App get the Power key Value
8. How to fix the Activity startup background window
9. Introduction to WindowManagerPolicy
10. References

1. Android button modification

Android There will be the following 5buttons (Back( Home, Menu, Power, ) in the layer Volumeto interact with the user, and Frameworkthe button function is implemented in the layer. Therefore, from the perspective of mobile phone system customization, the customer's customized requirements can be met. This article mainly Frameworkanalyzes the realization of these customized requirements from a layer-by-layer perspective.

147f6d8d92f49ced12fa78e60ef46cd3.jpeg

Back, Home, Menu, Power, Volume button diagram


Taking MTK the platform as an example, the code for button customization is mainly stored in the following classes

  1. PhoneWindowManager

PhoneWindowManagerThe code path is as follows:

alps\frameworks\base\services\core\java\com\android\server\policy\PhoneWindowManager.java
alps\frameworks\base\core\java\android\view\WindowManagerPolicy.java

2. Introduction to PhoneWindowManager

PhoneWindowManager The class implementation interface is as follows:

java.lang.Object
    ↳  android.view.WindowManagerPolicy.java
         ↳ com.android.server.policy.PhoneWindowManager.java

facf2a5d17b3d1e6da2acb48f38c1d79.jpeg

PhoneWindowManager class implementation relationship

PhoneWindowManagerIt is mainly used to implement various physical or virtual button processing. If special processing of buttons is required, please modify the source code.

3. How to open or close Navigation Bar

500a64a480448dadcc9435b3144aa76a.jpeg

virtual navigation bar

The solution for how to open or close the Navigation Bar is as follows:

1. Modify the config.xml file

Search for keywords config_showNavigationBarand check  config_showNavigationBar the value
true to indicate display false or not to display.

<!-- Whether a software navigation bar should be shown. NOTE: in the future this may be
         autodetected from the Configuration. -->
    <bool name="config_showNavigationBar">true</bool>

The reference path is as follows:
alps\frameworks\base\core\res\res\values\config.xml

2. Modify the system.prop file

Query the keyword  qemu.hw.mainkeysand check the value. 1It means closed 0. It means open.

# temporary enables NAV bar (soft keys)
qemu.hw.mainkeys=1

Different project files have different storage addresses. You can use the following command to find
how to find files in the terminal.

find 路径 -name "文件名.java"

Or directly find the string in the file

find 路径 -type f -name "文件名" | xargs grep "文件中的字符串"

3. Modify PhoneWindowManager code

If the above two modifications do not take effect (search keyword  , config_showNavigationBar) qemu.hw.mainkeys, please check whether the value in the method  is hard-coded, indicating that the navigation bar will be displayed or not.PhoneWindowManagersetInitialDisplaySizemHasNavigationBartruefalse

e1aa8d9dff139d617c18828d949b9039.jpeg

Bottom navigation card shows code control

4. How to start Google Now by long pressing the Home button

1. Prefabricated Google Now APK

Please install it yourselfAPK

2. Modify PhoneWindowManager code

HomePress and hold the key to start Google Now. For implementation methods, please refer to launchAssistLongPressAction function implementation.

6ecea714e98bad7b975574921a783d63.jpeg

PhoneWindowManager long press Home to start Google Now

Implement the constant Home key lifting Google Nowmethod by yourself, which can be called when the key is dispatched and processed.

b175d0a211ad7d04470a9fb886a3a4cb.jpeg

Implement your own method to launch Google Now by pressing the Home button often

3. Process key events before dispatching

Call the method of custom long Homepress key

6d66f55b51ddb70c95e5a9f48232cb4d.jpeg

How to customize the long press of the Home button

4. Double-click the Home button to bring up the recent task list, please use the following method

Modify the method in phoneWindowManager.java the interceptKeyBeforeQueueing method
as follows:

fa5f0dcaf25f8601866c2b8b23d1409d.jpeg

Double-click the Home button to bring up the recent tasks list

5. How to long press the physical Menu key to enter multi-window mode

Android NSupport Multi-Window, by recent keyentering multi-window, for mobile phones that do not open the virtual navigation bar and only have physical menubuttons, you can consider SystemUIsending broadcasts to enter Android split-screen multitasking mode.
The solution is as follows:

1. Register broadcast in PhoneStatusBar

PhoneStatusBar is SystemUIthe code of the module, the reference path is as follows:

frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java

For custom broadcast implementation, you can refer to the system mDemoReceiver 's implementation method
to dynamically register the broadcast method as follows:

590f31452d9050f06b638ff2c4555827.jpeg

Custom broadcast registration

After customizing the broadcast reception, onReceivethe method of handling the event to implement split screen is as follows:

573c70aaae81d58443d4744fb02ecdfe.jpeg

Custom broadcast processing

2. Send broadcast in PhoneWindowManager

Send broadcast in method  PhoneWindowManagerofinterceptKeyBeforeDispatching

8144e8a63ba9ce1de1e94b667a4f1260.jpeg

interceptKeyBeforeDispatching sends broadcast

3. Destory method to cancel broadcast

DestoryRemember to log out of the broadcast in the method

mContext.unregisterReceiver(mDemoReceiver);
 mContext.unregisterReceiver(mAppLongSwitchReceiver);

6. How to click the Menu button to bring up the recent task list

If you want to bring up the recent task list and menuthe events that need to be intercepted, just process them PhoneWindowManagerininterceptKeyBeforeDispatching 中

d9a3038775967e2d0ff1ab86642fd630.jpeg

menu key to bring up the recent task list

If you want to 长按Menucall it out, you can use the following method

a0b90413f4d918230b8101b2f90dae20.jpeg

Long press the menu key to bring up the task list

7. How to let the App get the Power key value

Under normal circumstances , the value Appcannot be obtained Power, Keybut it can be achieved through the following method.

1. Modify PhoneWindowManager file implementation

PhoneWindowManager Modify the method implementation in interceptKeyBeforeQueueingto allow specific  values APP​​to be obtainedPower key

9669b99de24eef37a4c029790c569a5b.jpeg

power key launch App

2. If you only want a certain Activity of a certain app to handle

6718afaf63a7eb36f6514a29c19a5c1b.jpeg

How to start Activity with Power key

8. How to fix the window when the Activity starts (white screen or black screen problem when the app starts)

When users enter other applications such as clock, contacts, file management, etc. from the main menu, the screen may flash black or white. This phenomenon occurs when the current mobile phone theme is light color (such as white) (Theme). More obvious.

This so-called "black screen" flash is actually the startup window of the application.
The conditions for the startup window to appear are as follows:

  1. The startup window may only be displayed if the program to be launched Activityis new Taskor new.Process

  2. The startup window is displayed before Activitythe window. When Activitythe contents of the window are ready, the startup window will be removed and showthe real activity window will appear.

  3. The startup window is similar to the normal one Activity window, except that no content is drawn. The default is a window with a black background.

Precisely because the startup window has a black background by default, when the current mobile phone theme is light-toned, it is easier to create a visual flashing feeling due to the contrast between colors.

The solution is as follows:

1. Remove the startup window

Set it to ActivityStack.javaboth in SHOW_APP_STARTING_PREVIEWfalse

2. Modify the startup window style

Add custom styles or backgrounds, etc. in the  PhoneWindowManagermethodaddStartingWindow

c99e58e5860c3b4bcebbfc3813cb49f5.jpeg

Modify startup window style

9. Introduction to WindowManagerPolicy

The interface classes implemented by PhoneWindowManager are as follows:

alps\frameworks\base\core\java\android\view\WindowManagerPolicy.java

751352034a181adf39bfad7efeda1802.jpeg

WindowManagerPolicy interface implementation

WindowManagerPolicy is an interface class that mainly provides some external interfaces.
Commonly used interfaces are as follows:

591725173b60c809388bd3f91c36b23f.jpeg

WindowState interface

69b26457c979376e0cd35a7677de0080.jpeg

WindowMangerFuncsinterface

f0289533f99b719e7cdf76fe1aa124f7.jpeg

Screen On interface

30807372bcffb0531de5879e482a1570.jpeg

Keyguard interface

references:

[Tencent Documentation] Android Framework Knowledge Base
https://docs.qq.com/doc/DSXBmSG9VbEROUXF5

Friendly recommendation:

Collection of useful information on Android development

At this point, this article has ended. The editor thinks the article is reprinted from the Internet and is excellent. You are welcome to click to read the original article and support the original author. If there is any infringement, please contact the editor to delete it. Your suggestions and corrections are welcome. We look forward to your attention and thank you for reading, thank you!

503cff6a185ee90f39fc7d2d9565e803.jpeg

Click to read the original article and like the boss!

Guess you like

Origin blog.csdn.net/wjky2014/article/details/131950349
Recommended