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 5
buttons (Back
( Home
, Menu
, Power
, ) in the layer Volume
to interact with the user, and Framework
the 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 Framework
analyzes the realization of these customized requirements from a layer-by-layer perspective.
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
PhoneWindowManager
PhoneWindowManager
The 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
PhoneWindowManager class implementation relationship
PhoneWindowManager
It 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
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_showNavigationBar
and 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.mainkeys
and check the value. 1
It 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.PhoneWindowManager
setInitialDisplaySize
mHasNavigationBar
true
false
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
Home
Press and hold the key to start Google Now
. For implementation methods, please refer to launchAssistLongPressAction
function implementation.
PhoneWindowManager long press Home to start Google Now
Implement the constant Home
key lifting Google Now
method by yourself, which can be called when the key is dispatched and processed.
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 Home
press key
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:
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 N
Support Multi-Window
, by recent key
entering multi-window, for mobile phones that do not open the virtual navigation bar and only have physical menu
buttons, you can consider SystemUI
sending broadcasts to enter Android
split-screen multitasking mode.
The solution is as follows:
1. Register broadcast in PhoneStatusBar
PhoneStatusBar
is SystemUI
the 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:
Custom broadcast registration
After customizing the broadcast reception, onReceive
the method of handling the event to implement split screen is as follows:
Custom broadcast processing
2. Send broadcast in PhoneWindowManager
Send broadcast in method PhoneWindowManager
ofinterceptKeyBeforeDispatching
interceptKeyBeforeDispatching sends broadcast
3. Destory method to cancel broadcast
Destory
Remember 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 menu
the events that need to be intercepted, just process them PhoneWindowManager
ininterceptKeyBeforeDispatching 中
menu key to bring up the recent task list
If you want to 长按Menu
call it out, you can use the following method
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 App
cannot be obtained Power
, Key
but it can be achieved through the following method.
1. Modify PhoneWindowManager file implementation
PhoneWindowManager
Modify the method implementation in interceptKeyBeforeQueueing
to allow specific values APP
to be obtainedPower key
power key launch App
2. If you only want a certain Activity of a certain app to handle
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:
The startup window may only be displayed if the program to be launched
Activity
is newTask
or new.Process
The startup window is displayed before
Activity
the window. WhenActivity
the contents of the window are ready, the startup window will be removed andshow
the realactivity
window will appear.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.java
both in SHOW_APP_STARTING_PREVIEW
false
2. Modify the startup window style
Add custom styles or backgrounds, etc. in the PhoneWindowManager
methodaddStartingWindow
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
WindowManagerPolicy interface implementation
WindowManagerPolicy is an interface class that mainly provides some external interfaces.
Commonly used interfaces are as follows:
WindowState interface
WindowMangerFuncsinterface
Screen On interface
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!
Click to read the original article and like the boss!