Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92
直接移除导航栏在 [RK3288][Android6.0] 调试笔记 — 移除导航栏(虚拟按键) 已经给出,
此文实现以广播的形式动态显示和隐藏导航栏,这样不仅避免了系统通过了自带只针对Activity显示和隐藏的不便(比如一个app有N多个Activity),而且可以在任何地方去动态修改。
改动:
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 7c73b83..7da188d 100755
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -204,6 +204,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,
HeadsUpManager.OnHeadsUpChangedListener {
static final String TAG = "PhoneStatusBar";
+ /*Kris, 170726, hide/show NavigationBar dynamicly. {*/
+ static final String HIDE_NAVIGATION_BAR = "android.intent.action.HIDE_NAVIGATION_BAR";
+ static final String SHOW_NAVIGATION_BAR = "android.intent.action.SHOW_NAVIGATION_BAR";
+ /*Kris, 170726, hide/show NavigationBar dynamicly. }*/
public static final boolean DEBUG = BaseStatusBar.DEBUG;
public static final boolean SPEW = false;
public static final boolean DUMPTRUCK = true; // extra dumpsys info
@@ -1069,6 +1073,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
demoFilter.addAction(ACTION_FAKE_ARTWORK);
}
demoFilter.addAction(ACTION_DEMO);
+ /*Kris, 170726, hide/show NavigationBar dynamicly. {*/
+ demoFilter.addAction(HIDE_NAVIGATION_BAR);
+ demoFilter.addAction(SHOW_NAVIGATION_BAR);
+ /*Kris, 170726, hide/show NavigationBar dynamicly. }*/
context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter,
android.Manifest.permission.DUMP, null);
@@ -1304,9 +1312,48 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
}
+ /*Kris, 170726, hide/show NavigationBar dynamicly. {*/
+ private void addNavigationBarInnerLocked(){
+ if(mNavigationBarView == null){
+ mNavigationBarView = (NavigationBarView) View.inflate(mContext, R.layout.navigation_bar, null);
+ mNavigationBarView.setDisabledFlags(mDisabled1);
+ mNavigationBarView.setBar(this);
+ mNavigationBarView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ checkUserAutohide(v, event);
+ return false;
+ }
+ });
+ if (mNavigationBarView == null)
+ return;
+ prepareNavigationBarView();
+ try {
+ mWindowManager.addView(mNavigationBarView, getNavigationBarLayoutParams());
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ private void removeNavigationBar() {
+ if (mNavigationBarView == null)
+ return;
+ mWindowManager.removeView(mNavigationBarView);
+ mNavigationBarView = null;
+ }
+
+ public void displayNavigation(){
+ addNavigationBarInnerLocked();
+ }
+ public void hideNavigation(){
+ removeNavigationBar();
+ }
+ /*Kris, 170726, hide/show NavigationBar dynamicly. }*/
+
private void repositionNavigationBar() {
if (mNavigationBarView == null || !mNavigationBarView.isAttachedToWindow()) return;
+
prepareNavigationBarView();
mWindowManager.updateViewLayout(mNavigationBarView, getNavigationBarLayoutParams());
@@ -3117,7 +3164,13 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
if (DEBUG_MEDIA_FAKE_ARTWORK) {
updateMediaMetaData(true);
}
- }
+ /*Kris, 170726, hide/show NavigationBar dynamicly. {*/
+ } else if(HIDE_NAVIGATION_BAR.equals(action)){
+ hideNavigation();
+ }else if(SHOW_NAVIGATION_BAR.equals(action)){
+ displayNavigation();
+ }
+ /*Kris, 170726, hide/show NavigationBar dynamicly. }*/
}
};
测试:
隐藏:
root@rk3288:/ # am broadcast -a android.intent.action.HIDE_NAVIGATION_BAR
Broadcasting: Intent { act=android.intent.action.HIDE_NAVIGATION_BAR }
Broadcast completed: result=0
显示:
root@rk3288:/ # am broadcast -a android.intent.action.SHOW_NAVIGATION_BAR
Broadcasting: Intent { act=android.intent.action.SHOW_NAVIGATION_BAR }
Broadcast completed: result=0