Android 5.1修改底部导航栏NavigationBar动态显示和隐藏

本文按照https://blog.csdn.net/way_ping_li/article/details/45727335这篇文章一步一步实现的,再次非常感谢,直接贴代码

diff --git a/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl b/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl
old mode 100644
new mode 100755
index 5b2b2f8..c0eee72
--- a/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -31,6 +31,7 @@ oneway interface IStatusBar
     void animateCollapsePanels();
     void setSystemUiVisibility(int vis, int mask);
     void topAppWindowChanged(boolean menuVisible);
+	void showNavigationBar();//add frankchen
     void setImeWindowStatus(in IBinder token, int vis, int backDisposition,
             boolean showImeSwitcher);
     void setWindowState(int window, int state);
diff --git a/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl
old mode 100644
new mode 100755
index 9997a98..d9a7eb8
--- a/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/alps/frameworks/base/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -32,6 +32,7 @@ interface IStatusBarService
     void setIconVisibility(String slot, boolean visible);
     void removeIcon(String slot);
     void topAppWindowChanged(boolean menuVisible);
+	void showNavigationBar();//add frankchen
     void setImeWindowStatus(in IBinder token, int vis, int backDisposition,
             boolean showImeSwitcher);
     void expandSettingsPanel();
diff --git a/alps/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_sysbar_hide.png b/alps/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_sysbar_hide.png
new file mode 100755
index 0000000..c138916
Binary files /dev/null and b/alps/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_sysbar_hide.png differ
diff --git a/alps/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_sysbar_hide_land.png b/alps/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_sysbar_hide_land.png
new file mode 100755
index 0000000..5c472b9
Binary files /dev/null and b/alps/frameworks/base/packages/SystemUI/res/drawable-hdpi/ic_sysbar_hide_land.png differ
diff --git a/alps/frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_sysbar_hide.png b/alps/frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_sysbar_hide.png
new file mode 100755
index 0000000..c138916
Binary files /dev/null and b/alps/frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_sysbar_hide.png differ
diff --git a/alps/frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_sysbar_hide_land.png b/alps/frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_sysbar_hide_land.png
new file mode 100755
index 0000000..5c472b9
Binary files /dev/null and b/alps/frameworks/base/packages/SystemUI/res/drawable-mdpi/ic_sysbar_hide_land.png differ
diff --git a/alps/frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_hide.png b/alps/frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_hide.png
new file mode 100755
index 0000000..2fe4f81
Binary files /dev/null and b/alps/frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_hide.png differ
diff --git a/alps/frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_hide_land.png b/alps/frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_hide_land.png
new file mode 100755
index 0000000..47feb27
Binary files /dev/null and b/alps/frameworks/base/packages/SystemUI/res/drawable-xhdpi/ic_sysbar_hide_land.png differ
diff --git a/alps/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml b/alps/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml
old mode 100644
new mode 100755
index 898389d..d5637c6
--- a/alps/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/layout/navigation_bar.xml
@@ -42,12 +42,28 @@
             >
 
             
-            
+				-->
+			
+                
+            
+			
+
             
+			
+				
+
+                
+            
+            
         
 
         
diff --git a/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
old mode 100644
new mode 100755
index 319cf8f..4137bca
--- a/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -78,6 +78,7 @@
     "作为相机(PTP)装载"
     "安装适用于Mac的Android文件传输应用"
     "返回"
+	"隐藏"
     "主屏幕"
     "菜单"
     "概览"
diff --git a/alps/frameworks/base/packages/SystemUI/res/values/strings.xml b/alps/frameworks/base/packages/SystemUI/res/values/strings.xml
old mode 100644
new mode 100755
index 5608bdb..e8850bf
--- a/alps/frameworks/base/packages/SystemUI/res/values/strings.xml
+++ b/alps/frameworks/base/packages/SystemUI/res/values/strings.xml
@@ -196,6 +196,7 @@
 
     
     Back
+	"Hide"
     
     Home
     
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
old mode 100644
new mode 100755
index 82bbffa..74066af
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -71,6 +71,7 @@ public class CommandQueue extends IStatusBar.Stub {
     private static final int MSG_SHOW_APPLICATION_GUIDE = 21 << MSG_SHIFT;
     /// @}
 
+    private static final int MSG_SHOW_NAVIGATIONBAR   = 22 << MSG_SHIFT;//add frankchen
     public static final int FLAG_EXCLUDE_NONE = 0;
     public static final int FLAG_EXCLUDE_SEARCH_PANEL = 1 << 0;
     public static final int FLAG_EXCLUDE_RECENTS_PANEL = 1 << 1;
@@ -97,6 +98,7 @@ public class CommandQueue extends IStatusBar.Stub {
         public void animateCollapsePanels(int flags);
         public void animateExpandSettingsPanel();
         public void setSystemUiVisibility(int vis, int mask);
+		public void showNavigationBar();//add frankchen
         public void topAppWindowChanged(boolean visible);
         public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
                 boolean showImeSwitcher);
@@ -182,6 +184,15 @@ public class CommandQueue extends IStatusBar.Stub {
             mHandler.obtainMessage(MSG_SET_SYSTEMUI_VISIBILITY, vis, mask, null).sendToTarget();
         }
     }
+	
+	//noted by frankchen start 20200227
+	public void showNavigationBar() {
+       synchronized (mList) {
+            mHandler.removeMessages(MSG_SHOW_NAVIGATIONBAR);
+            mHandler.sendEmptyMessage(MSG_SHOW_NAVIGATIONBAR);
+        }
+    }
+	//noted by frankchen end
 
     public void topAppWindowChanged(boolean menuVisible) {
         synchronized (mList) {
@@ -317,6 +328,11 @@ public class CommandQueue extends IStatusBar.Stub {
                 case MSG_SET_SYSTEMUI_VISIBILITY:
                     mCallbacks.setSystemUiVisibility(msg.arg1, msg.arg2);
                     break;
+				//noted by frankchen start 20200227
+                case MSG_SHOW_NAVIGATIONBAR:
+                   mCallbacks.showNavigationBar();
+                   break;
+                //noted by frankchen end
                 case MSG_TOP_APP_WINDOW_CHANGED:
                     mCallbacks.topAppWindowChanged(msg.arg1 != 0);
                     break;
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
old mode 100644
new mode 100755
index 624683b..abca7ac
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -55,6 +55,7 @@ import com.android.systemui.statusbar.BaseStatusBar;
 import com.android.systemui.statusbar.DelegateViewHelper;
 import com.android.systemui.statusbar.policy.DeadZone;
 import com.android.systemui.statusbar.policy.KeyButtonView;
+import com.android.systemui.statusbar.policy.KeyButtonRipple;
 import android.widget.Button;
 import android.content.Intent;
 
@@ -347,6 +348,14 @@ public class NavigationBarView extends LinearLayout {
     public View getImeSwitchButton() {
         return mCurrentView.findViewById(R.id.ime_switcher);
     }
+	//noted by frankchen start 20200227
+    public View getHideBarButton() {
+       View view = mCurrentView.findViewById(R.id.hide_bar_btn);
+       view.setBackground(new KeyButtonRipple(getContext(), view));
+        return view;
+    }
+    //noted by frankchen end
+
 
     private void getIcons(Resources res) {
         mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
old mode 100644
new mode 100755
index 153586f..f289dc1
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -191,6 +191,7 @@ import com.mediatek.systemui.statusbar.policy.HotKnotControllerImpl;
 import com.mediatek.systemui.statusbar.util.SIMHelper;
 import com.mediatek.systemui.ext.PluginFactory;
 import com.mediatek.xlog.Xlog;
+import android.graphics.Color;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -610,6 +611,24 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
             goToLockedShade(null);
         }
     };
+	
+	//noted by frankchen start 20200227
+    private final View.OnClickListener mHideBarClickListener = new View.OnClickListener() {
+        @Override
+        public void onClick(View view) {
+           Log.i("chen", "mHideBarClickListener  onClick...");
+           removeNavigationBar();
+        }
+    };
+     
+    private void removeNavigationBar() {
+        if (DEBUG) Log.d(TAG, "removeNavigationBar: about to remove " + mNavigationBarView);
+        if (mNavigationBarView == null) return;
+
+        mWindowManager.removeView(mNavigationBarView);
+        mNavigationBarView = null;
+    }
+    //noted by frankchen end
 
     @Override
     public void start() {
@@ -1433,6 +1452,18 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
             }
         }
     }
+	
+	//展示导航栏
+public void showNavigationBar() {
+    mNavigationBarView =(NavigationBarView) View.inflate(mContext, R.layout.navigation_bar, null);
+    mNavigationBarView.setBar(this);
+    prepareNavigationBarView();
+    addNavigationBar();
+    
+    //防止在桌面时上拉出导航栏时,导航栏背景为黑色
+    mNavigationBarView.setBackgroundColor(Color.TRANSPARENT);
+    Log.d("chen", "show navigation");
+}
 
     private void prepareNavigationBarView() {
         mNavigationBarView.reorient();
@@ -1444,6 +1475,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
         mNavigationBarView.getBackButton().setLongClickable(true);
         mNavigationBarView.getBackButton().setOnLongClickListener(mLongPressBackRecentsListener);
         mNavigationBarView.getHomeButton().setOnTouchListener(mHomeActionListener);
+		
+		mNavigationBarView.getHideBarButton().setOnClickListener(mHideBarClickListener);
+		
     /// M: add for multi window @{
         if(RecentsActivity.FLOAT_WINDOW_SUPPORT){
             mNavigationBarView.getFloatButton().setOnClickListener(mFloatClickListener);
diff --git a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
old mode 100644
new mode 100755
index 08732e5..e49c5e4
--- a/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
+++ b/alps/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java
@@ -77,6 +77,11 @@ public class TvStatusBar extends BaseStatusBar {
     @Override
     public void topAppWindowChanged(boolean visible) {
     }
+	//noted by frankchen start 20200227
+	@Override
+    public void showNavigationBar() {
+    }
+	//noted by frankchen end
 
     @Override
     public void setImeWindowStatus(IBinder token, int vis, int backDisposition,
diff --git a/alps/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/alps/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index f73700f..79f9540 100755
--- a/alps/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/alps/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1473,7 +1473,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                             return;
                         if (mNavigationBar != null && mNavigationBarOnBottom) {
                             requestTransientBars(mNavigationBar);
+							Log.i("way", "onSwipeFromBottom... mNavigationBar != null && mNavigationBarOnBottom");
                         }
+						//noted by frankchen start 20200227
+						else{
+							Log.i("way", "onSwipeFromBottom...");
+							showNavigationBar();
+						}
+						//noted by frankchen end
                     }
                     @Override
                     public void onSwipeFromRight() {
@@ -1481,7 +1488,14 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                             return;
                         if (mNavigationBar != null && !mNavigationBarOnBottom) {
                             requestTransientBars(mNavigationBar);
+							Log.i("way", "onSwipeFromRight... mNavigationBar != null && !mNavigationBarOnBottom");
                         }
+						//noted by frankchen start 20200227
+						else{
+							Log.i("way", "onSwipeFromRight...");
+							showNavigationBar();
+						}
+						//noted by frankchen end
                     }
                     @Override
                     public void onDebug() {
@@ -1530,7 +1544,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
         /// M:[AppLaunchTime] Improve the mechanism of AppLaunchTime
         mAppLaunchTimeEnabled = (1 == SystemProperties.getInt("ro.mtk_perf_response_time", 0)) ? true : false;
     }
-
+	
     /**
      * Read values from config.xml that may be overridden depending on
      * the configuration of the device.
@@ -3180,6 +3194,26 @@ public class PhoneWindowManager implements WindowManagerPolicy {
             mStatusBarService = null;
         }
     }
+	
+	//noted by frankchen start 20200227
+	private void showNavigationBar(){
+        mHandler.post(new Runnable() {
+            @Override
+            public void run() {
+                try {
+                    IStatusBarService statusbar = getStatusBarService();
+                    if (statusbar != null) {
+                        statusbar.showNavigationBar();
+                    }
+                } catch (RemoteException e) {
+                    // re-acquire status bar service next time it is needed.
+                    mStatusBarService = null;
+                }
+            }
+        });
+    }
+	//noted by frankchen end
+
 
     private void cancelPreloadRecentApps() {
         if (mPreloadedRecentApps) {
diff --git a/alps/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/alps/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
old mode 100644
new mode 100755
index 0de5701..19b7635
--- a/alps/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/alps/frameworks/base/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -396,6 +396,27 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
         }
     }
 
+    //noted by frankchen start 20200227
+	@Override
+    public void showNavigationBar() {
+        enforceStatusBar();
+
+        android.util.Log.d("way", TAG + " showNavigationBar...");
+
+        synchronized(mLock) {
+            mHandler.post(new Runnable() {
+                    public void run() {
+                        if (mBar != null) {
+                            try {
+                                mBar.showNavigationBar();
+                            } catch (RemoteException ex) {
+                            }
+                        }
+                    }
+               });
+        }
+    }
+	//noted by frankchen end
     private void updateUiVisibilityLocked(final int vis, final int mask) {
         if (mSystemUiVisibility != vis) {
             mSystemUiVisibility = vis;

 

你可能感兴趣的:(Android,L)