当前位置:   article > 正文

Android13系统导航栏添加隐藏导航栏功能按钮_we may show taskbar on the default display for lar

we may show taskbar on the default display for large screen device. don't ne

最近有个项目,客户要求在底部导航栏中添加一个可以隐藏整个导航栏的功能按钮,效果如下图:

具体方法如下:

1. 在frameworks/base做如下修改:

  1. diff --git a/packages/SystemUI/res/layout/navigation_bar.xml b/packages/SystemUI/res/layout/navigation_bar.xml
  2. old mode 100644
  3. new mode 100755
  4. index 5f59e781ef5e..538a0119cd09
  5. --- a/packages/SystemUI/res/layout/navigation_bar.xml
  6. +++ b/packages/SystemUI/res/layout/navigation_bar.xml
  7. @@ -33,4 +33,12 @@
  8. android:clipChildren="false"
  9. android:clipToPadding="false" />
  10. + <ImageView
  11. + android:layout_width="30dp"
  12. + android:layout_height="30dp"
  13. + android:id="@+id/navigation_hide_iv"
  14. + android:src="@drawable/ic_sysbar_hide"
  15. + android:layout_gravity="start|center_vertical"
  16. + android:layout_marginStart="@dimen/navigation_hide_button_start_margin" />
  17. +
  18. </com.android.systemui.navigationbar.NavigationBarView>
  19. diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml
  20. old mode 100644
  21. new mode 100755
  22. index e09f7a6f0b57..6b19713923d6
  23. --- a/packages/SystemUI/res/values-land/dimens.xml
  24. +++ b/packages/SystemUI/res/values-land/dimens.xml
  25. @@ -60,4 +60,6 @@
  26. <dimen name="qs_panel_padding_top">@dimen/qqs_layout_margin_top</dimen>
  27. <dimen name="qs_panel_padding_top_combined_headers">@dimen/qs_panel_padding_top</dimen>
  28. +
  29. + <dimen name="navigation_hide_button_start_margin">40dp</dimen>
  30. </resources>
  31. diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
  32. old mode 100644
  33. new mode 100755
  34. index 6f1a13de60ed..40659c8542b9
  35. --- a/packages/SystemUI/res/values/dimens.xml
  36. +++ b/packages/SystemUI/res/values/dimens.xml
  37. @@ -1567,4 +1567,6 @@
  38. <dimen name="dream_overlay_status_bar_ambient_text_shadow_dx">0.5dp</dimen>
  39. <dimen name="dream_overlay_status_bar_ambient_text_shadow_dy">0.5dp</dimen>
  40. <dimen name="dream_overlay_status_bar_ambient_text_shadow_radius">2dp</dimen>
  41. +
  42. + <dimen name="navigation_hide_button_start_margin">24dp</dimen>
  43. </resources>
  44. diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
  45. old mode 100644
  46. new mode 100755
  47. index 3789cbb1fb65..53d3fa4855aa
  48. --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
  49. +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBarController.java
  50. @@ -25,6 +25,7 @@ import static com.android.systemui.shared.recents.utilities.Utilities.isTablet;
  51. import android.content.ContentResolver;
  52. import android.content.Context;
  53. +import android.content.Intent;
  54. import android.content.pm.ActivityInfo;
  55. import android.content.res.Configuration;
  56. import android.hardware.display.DisplayManager;
  57. @@ -47,6 +48,7 @@ import androidx.annotation.Nullable;
  58. import com.android.internal.annotations.VisibleForTesting;
  59. import com.android.internal.statusbar.RegisterStatusBarResult;
  60. import com.android.settingslib.applications.InterestingConfigChanges;
  61. +import com.android.systemui.R;
  62. import com.android.systemui.Dumpable;
  63. import com.android.systemui.dagger.SysUISingleton;
  64. import com.android.systemui.dagger.qualifiers.Main;
  65. @@ -63,6 +65,7 @@ import com.android.systemui.statusbar.phone.BarTransitions.TransitionMode;
  66. import com.android.systemui.statusbar.phone.LightBarController;
  67. import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
  68. import com.android.systemui.statusbar.policy.ConfigurationController;
  69. +import com.android.systemui.statusbar.phone.CentralSurfacesImpl;
  70. import com.android.wm.shell.back.BackAnimation;
  71. import com.android.wm.shell.pip.Pip;
  72. @@ -294,6 +297,8 @@ public class NavigationBarController implements
  73. }
  74. }
  75. + private int displayId;
  76. +
  77. /**
  78. * Adds a navigation bar on default display or an external display if the display supports
  79. * system decorations.
  80. @@ -306,7 +311,7 @@ public class NavigationBarController implements
  81. return;
  82. }
  83. - final int displayId = display.getDisplayId();
  84. + displayId = display.getDisplayId();
  85. final boolean isOnDefaultDisplay = displayId == DEFAULT_DISPLAY;
  86. // We may show TaskBar on the default display for large screen device. Don't need to create
  87. @@ -343,6 +348,7 @@ public class NavigationBarController implements
  88. result.mImeWindowVis, result.mImeBackDisposition,
  89. result.mShowImeSwitcher);
  90. }
  91. + context.sendBroadcast(new Intent(CentralSurfacesImpl.ACTION_HIDE_NAVIGATIONBAR));
  92. }
  93. @Override
  94. @@ -352,6 +358,13 @@ public class NavigationBarController implements
  95. });
  96. }
  97. + //edit by chain
  98. + public void initHideButton() {
  99. + NavigationBarView navigationBarView = getNavigationBarView(displayId);
  100. + View navigationHideIv = navigationBarView.findViewById(R.id.navigation_hide_iv);
  101. + navigationHideIv.setOnClickListener(v -> removeNavigationBar(displayId));
  102. + }
  103. +
  104. void removeNavigationBar(int displayId) {
  105. NavigationBar navBar = mNavigationBars.get(displayId);
  106. if (navBar != null) {
  107. @@ -368,6 +381,11 @@ public class NavigationBarController implements
  108. }
  109. }
  110. + public boolean canShowNavigationBar() {
  111. + NavigationBar navBar = mNavigationBars.get(displayId);
  112. + return navBar == null;
  113. + }
  114. +
  115. /** @see NavigationBar#finishBarAnimations() */
  116. public void finishBarAnimations(int displayId) {
  117. NavigationBar navBar = mNavigationBars.get(displayId);
  118. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
  119. old mode 100644
  120. new mode 100755
  121. index 0b63bbfec877..f78b86556d28
  122. --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
  123. +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java
  124. @@ -879,6 +879,8 @@ public class CentralSurfacesImpl extends CoreStartable implements
  125. wiredChargingRippleController.registerCallbacks();
  126. }
  127. + private RegisterStatusBarResult mBarRresult;
  128. +
  129. @Override
  130. public void start() {
  131. mScreenLifecycle.addObserver(mScreenObserver);
  132. @@ -917,14 +919,14 @@ public class CentralSurfacesImpl extends CoreStartable implements
  133. mKeyguardManager = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
  134. mWallpaperSupported = mWallpaperManager.isWallpaperSupported();
  135. - RegisterStatusBarResult result = null;
  136. + //RegisterStatusBarResult result = null;
  137. try {
  138. - result = mBarService.registerStatusBar(mCommandQueue);
  139. + mBarRresult = mBarService.registerStatusBar(mCommandQueue);
  140. } catch (RemoteException ex) {
  141. ex.rethrowFromSystemServer();
  142. }
  143. - createAndAddWindows(result);
  144. + createAndAddWindows(mBarRresult);
  145. if (mWallpaperSupported) {
  146. // Make sure we always have the most current wallpaper info.
  147. @@ -939,30 +941,30 @@ public class CentralSurfacesImpl extends CoreStartable implements
  148. // Set up the initial notification state. This needs to happen before CommandQueue.disable()
  149. setUpPresenter();
  150. - if (containsType(result.mTransientBarTypes, ITYPE_STATUS_BAR)) {
  151. + if (containsType(mBarRresult.mTransientBarTypes, ITYPE_STATUS_BAR)) {
  152. showTransientUnchecked();
  153. }
  154. - mCommandQueueCallbacks.onSystemBarAttributesChanged(mDisplayId, result.mAppearance,
  155. - result.mAppearanceRegions, result.mNavbarColorManagedByIme, result.mBehavior,
  156. - result.mRequestedVisibilities, result.mPackageName, result.mLetterboxDetails);
  157. + mCommandQueueCallbacks.onSystemBarAttributesChanged(mDisplayId, mBarRresult.mAppearance,
  158. + mBarRresult.mAppearanceRegions, mBarRresult.mNavbarColorManagedByIme, mBarRresult.mBehavior,
  159. + mBarRresult.mRequestedVisibilities, mBarRresult.mPackageName, mBarRresult.mLetterboxDetails);
  160. // StatusBarManagerService has a back up of IME token and it's restored here.
  161. - mCommandQueueCallbacks.setImeWindowStatus(mDisplayId, result.mImeToken,
  162. - result.mImeWindowVis, result.mImeBackDisposition, result.mShowImeSwitcher);
  163. + mCommandQueueCallbacks.setImeWindowStatus(mDisplayId, mBarRresult.mImeToken,
  164. + mBarRresult.mImeWindowVis, mBarRresult.mImeBackDisposition, mBarRresult.mShowImeSwitcher);
  165. // Set up the initial icon state
  166. - int numIcons = result.mIcons.size();
  167. + int numIcons = mBarRresult.mIcons.size();
  168. for (int i = 0; i < numIcons; i++) {
  169. - mCommandQueue.setIcon(result.mIcons.keyAt(i), result.mIcons.valueAt(i));
  170. + mCommandQueue.setIcon(mBarRresult.mIcons.keyAt(i), mBarRresult.mIcons.valueAt(i));
  171. }
  172. if (DEBUG) {
  173. Log.d(TAG, String.format(
  174. "init: icons=%d disabled=0x%08x lights=0x%08x imeButton=0x%08x",
  175. numIcons,
  176. - result.mDisabledFlags1,
  177. - result.mAppearance,
  178. - result.mImeWindowVis));
  179. + mBarRresult.mDisabledFlags1,
  180. + mBarRresult.mAppearance,
  181. + mBarRresult.mImeWindowVis));
  182. }
  183. IntentFilter internalFilter = new IntentFilter();
  184. @@ -1028,8 +1030,8 @@ public class CentralSurfacesImpl extends CoreStartable implements
  185. mAccessibilityFloatingMenuController.init();
  186. // set the initial view visibility
  187. - int disabledFlags1 = result.mDisabledFlags1;
  188. - int disabledFlags2 = result.mDisabledFlags2;
  189. + int disabledFlags1 = mBarRresult.mDisabledFlags1;
  190. + int disabledFlags2 = mBarRresult.mDisabledFlags2;
  191. mInitController.addPostInitTask(
  192. () -> setUpDisableFlags(disabledFlags1, disabledFlags2));
  193. @@ -1398,11 +1400,15 @@ public class CentralSurfacesImpl extends CoreStartable implements
  194. return mLifecycle;
  195. }
  196. + public static final String ACTION_HIDE_NAVIGATIONBAR = "action_hide_navigationbar";
  197. + public static final String ACTION_SHOW_NAVIGATIONBAR = "action_show_navigationbar";
  198. @VisibleForTesting
  199. protected void registerBroadcastReceiver() {
  200. IntentFilter filter = new IntentFilter();
  201. filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  202. filter.addAction(Intent.ACTION_SCREEN_OFF);
  203. + filter.addAction(ACTION_HIDE_NAVIGATIONBAR);
  204. + filter.addAction(ACTION_SHOW_NAVIGATIONBAR);
  205. mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, filter, null, UserHandle.ALL);
  206. }
  207. @@ -2660,6 +2666,13 @@ public class CentralSurfacesImpl extends CoreStartable implements
  208. }
  209. finishBarAnimations();
  210. resetUserExpandedStates();
  211. + }else if (ACTION_HIDE_NAVIGATIONBAR.equals(action)){
  212. + mNavigationBarController.initHideButton();
  213. + }else if (ACTION_SHOW_NAVIGATIONBAR.equals(action)){
  214. + //Log.d("wzh", "mBroadcastReceiver.action="+action);
  215. + if (mNavigationBarController.canShowNavigationBar()){
  216. + createNavigationBar(mBarRresult);
  217. + }
  218. }
  219. Trace.endSection();
  220. }
  221. diff --git a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java
  222. old mode 100644
  223. new mode 100755
  224. index 658f4efbdb2f..c095df9b0adb
  225. --- a/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java
  226. +++ b/services/core/java/com/android/server/wm/SystemGesturesPointerEventListener.java
  227. @@ -23,12 +23,14 @@ import static android.view.DisplayCutout.BOUNDS_POSITION_TOP;
  228. import android.annotation.NonNull;
  229. import android.content.Context;
  230. +import android.content.Intent;
  231. import android.content.res.Resources;
  232. import android.graphics.Rect;
  233. import android.graphics.Region;
  234. import android.hardware.display.DisplayManagerGlobal;
  235. import android.os.Handler;
  236. import android.os.SystemClock;
  237. +import android.util.Log;
  238. import android.util.Slog;
  239. import android.view.Display;
  240. import android.view.DisplayCutout;
  241. @@ -194,12 +196,15 @@ class SystemGesturesPointerEventListener implements PointerEventListener {
  242. if (mSwipeFireable) {
  243. final int swipe = detectSwipe(event);
  244. mSwipeFireable = swipe == SWIPE_NONE;
  245. + //Log.d("wzh", "onPointerEvent().MotionEvent.ACTION_MOVE.swipe="+swipe);
  246. if (swipe == SWIPE_FROM_TOP) {
  247. if (DEBUG) Slog.d(TAG, "Firing onSwipeFromTop");
  248. mCallbacks.onSwipeFromTop();
  249. + mContext.sendBroadcast(new Intent("action_show_navigationbar"));
  250. } else if (swipe == SWIPE_FROM_BOTTOM) {
  251. if (DEBUG) Slog.d(TAG, "Firing onSwipeFromBottom");
  252. mCallbacks.onSwipeFromBottom();
  253. + mContext.sendBroadcast(new Intent("action_show_navigationbar"));
  254. } else if (swipe == SWIPE_FROM_RIGHT) {
  255. if (DEBUG) Slog.d(TAG, "Firing onSwipeFromRight");
  256. mCallbacks.onSwipeFromRight();

2. 上面修改中有一行代码android:src="@drawable/ic_sysbar_hide"引用了一个ic_sysbar_hide.xml文件,该文件内容如下:其实就是那个隐藏按钮的矢量图代码

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <vector xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:width="18dp"
  4. android:height="18dp"
  5. android:viewportWidth="35"
  6. android:viewportHeight="35">
  7. <path
  8. android:fillColor="#66cccccc"
  9. android:pathData="M21.314,25.837l9.898-9.9c0.782-0.782,2.049-0.782,2.829,0c0.78,0.781,0.781,2.049,0,2.831L22.73,30.079
  10. c-0.001,0.002-0.001,0.002-0.001,0.002c-0.39,0.391-0.902,0.586-1.415,0.586s-1.024-0.195-1.415-0.586L8.585,18.768
  11. c-0.782-0.781-0.779-2.049,0-2.831c0.781-0.782,2.049-0.782,2.831,0L21.314,25.837z"/>
  12. </vector>

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号