基于Android9.0,SystemUI定制化主要需要修改FW中的PhoneWindowManager.java这个类。
StatusBar:
在PhoneWindowManager.java中通过mStatusBarHeightForRotation[mPortraitRotation]控制StatusBar的高度,这个属性会根据StatusBar的位置显示不同的高度。
控制StatusBar具体的显示和隐藏是在下面这个方法中控制的:
4839 private boolean layoutStatusBar(DisplayFrames displayFrames, Rect pf, Rect df, Rect of, Rect vf,
4840 Rect dcf, int sysui, boolean isKeyguardShowing) {
4841 // decide where the status bar goes ahead of time
4842 if (mStatusBar == null) {
4843 return false;
4844 }
4845 // apply any navigation bar insets
4846 of.set(displayFrames.mUnrestricted);
4847 df.set(displayFrames.mUnrestricted);
4848 pf.set(displayFrames.mUnrestricted);
4849 vf.set(displayFrames.mStable);
4850
4851 mStatusBarLayer = mStatusBar.getSurfaceLayer();
4852
4853 // Let the status bar determine its size.
4854 mStatusBar.computeFrameLw(pf /* parentFrame /, df / displayFrame */,
4855 vf /* overlayFrame /, vf / contentFrame /, vf / visibleFrame */,
4856 dcf /* decorFrame /, vf / stableFrame /, vf / outsetFrame */,
4857 displayFrames.mDisplayCutout, false /* parentFrameWasClippedByDisplayCutout */);
4858
4859 // For layout, the status bar is always at the top with our fixed height.
4860 displayFrames.mStable.top = displayFrames.mUnrestricted.top
4861 + mStatusBarHeightForRotation[displayFrames.mRotation];
4862 // Make sure the status bar covers the entire cutout height
4863 displayFrames.mStable.top = Math.max(displayFrames.mStable.top,
4864 displayFrames.mDisplayCutoutSafe.top);
4865
4866 // Tell the bar controller where the collapsed status bar content is
4867 mTmpRect.set(mStatusBar.getContentFrameLw());
4868 mTmpRect.intersect(displayFrames.mDisplayCutoutSafe);
4869 mTmpRect.top = mStatusBar.getContentFrameLw().top; // Ignore top display cutout inset
4870 mTmpRect.bottom = displayFrames.mStable.top; // Use collapsed status bar size
4871 mStatusBarController.setContentFrame(mTmpRect);
4872
4873 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
4874 boolean statusBarTranslucent = (sysui
4875 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
4876 if (!isKeyguardShowing) {
4877 statusBarTranslucent &= areTranslucentBarsAllowed();
4878 }
4879
4880 // If the status bar is hidden, we don't want to cause windows behind it to scroll.
4881 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
4882 // Status bar may go away, so the screen area it occupies is available to apps but just
4883 // covering them when the status bar is visible.
4884 final Rect dockFrame = displayFrames.mDock;
4885 dockFrame.top = displayFrames.mStable.top;
4886 displayFrames.mContent.set(dockFrame);
4887 displayFrames.mVoiceContent.set(dockFrame);
4888 displayFrames.mCurrent.set(dockFrame);
4889
4890 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + String.format(
4891 "dock=%s content=%s cur=%s", dockFrame.toString(),
4892 displayFrames.mContent.toString(), displayFrames.mCurrent.toString()));
4893
4894 if (!mStatusBar.isAnimatingLw() && !statusBarTranslucent
4895 && !mStatusBarController.wasRecentlyTranslucent()) {
4896 // If the opaque status bar is currently requested to be visible, and not in the
4897 // process of animating on or off, then we can tell the app that it is covered by it.
4898 displayFrames.mSystem.top = displayFrames.mStable.top;
4899 }
4900 }
4901 return mStatusBarController.checkHiddenLw();
4902 }
NavigationBar:
在PhoneWindowManager.java中通过mNavigationBarHeightForRotationDefault[rotation]控制StatusBar的高度,这个属性会根据NavigationBar的位置显示不同的高度。
控制NavigationBar具体的显示和隐藏是在下面这个方法中控制的:
private boolean layoutNavigationBar(DisplayFrames displayFrames, int uiMode, Rect dcf,
4904 boolean navVisible, boolean navTranslucent, boolean navAllowedHidden,
4905 boolean statusBarExpandedNotKeyguard) {
4906 if (mNavigationBar == null) {
4907 return false;
4908 }
4909 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
4910 // Force the navigation bar to its appropriate place and size. We need to do this directly,
4911 // instead of relying on it to bubble up from the nav bar, because this needs to change
4912 // atomically with screen rotations.
4913 final int rotation = displayFrames.mRotation;
4914 final int displayHeight = displayFrames.mDisplayHeight;
4915 final int displayWidth = displayFrames.mDisplayWidth;
4916 final Rect dockFrame = displayFrames.mDock;
4917 mNavigationBarPosition = navigationBarPosition(displayWidth, displayHeight, rotation);
4918
4919 final Rect cutoutSafeUnrestricted = mTmpRect;
4920 cutoutSafeUnrestricted.set(displayFrames.mUnrestricted);
4921 cutoutSafeUnrestricted.intersectUnchecked(displayFrames.mDisplayCutoutSafe);
4922
4923 if (mNavigationBarPosition == NAV_BAR_BOTTOM) {
4924 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
4925 final int top = cutoutSafeUnrestricted.bottom
4926 - getNavigationBarHeight(rotation, uiMode);
4927 mTmpNavigationFrame.set(0, top, displayWidth, displayFrames.mUnrestricted.bottom);
4928 displayFrames.mStable.bottom = displayFrames.mStableFullscreen.bottom = top;
4929 if (transientNavBarShowing) {
4930 mNavigationBarController.setBarShowingLw(true);
4931 } else if (navVisible) {
4932 mNavigationBarController.setBarShowingLw(true);
4933 dockFrame.bottom = displayFrames.mRestricted.bottom
4934 = displayFrames.mRestrictedOverscan.bottom = top;
4935 } else {
4936 // We currently want to hide the navigation UI - unless we expanded the status bar.
4937 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4938 }
4939 if (navVisible && !navTranslucent && !navAllowedHidden
4940 && !mNavigationBar.isAnimatingLw()
4941 && !mNavigationBarController.wasRecentlyTranslucent()) {
4942 // If the opaque nav bar is currently requested to be visible and not in the process
4943 // of animating on or off, then we can tell the app that it is covered by it.
4944 displayFrames.mSystem.bottom = top;
4945 }
4946 } else if (mNavigationBarPosition == NAV_BAR_RIGHT) {
4947 // Landscape screen; nav bar goes to the right.
4948 final int left = cutoutSafeUnrestricted.right
4949 - getNavigationBarWidth(rotation, uiMode);
4950 mTmpNavigationFrame.set(left, 0, displayFrames.mUnrestricted.right, displayHeight);
4951 displayFrames.mStable.right = displayFrames.mStableFullscreen.right = left;
4952 if (transientNavBarShowing) {
4953 mNavigationBarController.setBarShowingLw(true);
4954 } else if (navVisible) {
4955 mNavigationBarController.setBarShowingLw(true);
4956 dockFrame.right = displayFrames.mRestricted.right
4957 = displayFrames.mRestrictedOverscan.right = left;
4958 } else {
4959 // We currently want to hide the navigation UI - unless we expanded the status bar.
4960 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4961 }
4962 if (navVisible && !navTranslucent && !navAllowedHidden
4963 && !mNavigationBar.isAnimatingLw()
4964 && !mNavigationBarController.wasRecentlyTranslucent()) {
4965 // If the nav bar is currently requested to be visible, and not in the process of
4966 // animating on or off, then we can tell the app that it is covered by it.
4967 displayFrames.mSystem.right = left;
4968 }
4969 } else if (mNavigationBarPosition == NAV_BAR_LEFT) {
4970 // Seascape screen; nav bar goes to the left.
4971 final int right = cutoutSafeUnrestricted.left
4972 + getNavigationBarWidth(rotation, uiMode);
4973 mTmpNavigationFrame.set(displayFrames.mUnrestricted.left, 0, right, displayHeight);
4974 displayFrames.mStable.left = displayFrames.mStableFullscreen.left = right;
4975 if (transientNavBarShowing) {
4976 mNavigationBarController.setBarShowingLw(true);
4977 } else if (navVisible) {
4978 mNavigationBarController.setBarShowingLw(true);
4979 dockFrame.left = displayFrames.mRestricted.left =
4980 displayFrames.mRestrictedOverscan.left = right;
4981 } else {
4982 // We currently want to hide the navigation UI - unless we expanded the status bar.
4983 mNavigationBarController.setBarShowingLw(statusBarExpandedNotKeyguard);
4984 }
4985 if (navVisible && !navTranslucent && !navAllowedHidden
4986 && !mNavigationBar.isAnimatingLw()
4987 && !mNavigationBarController.wasRecentlyTranslucent()) {
4988 // If the nav bar is currently requested to be visible, and not in the process of
4989 // animating on or off, then we can tell the app that it is covered by it.
4990 displayFrames.mSystem.left = right;
4991 }
4992 }
4993
4994 // Make sure the content and current rectangles are updated to account for the restrictions
4995 // from the navigation bar.
4996 displayFrames.mCurrent.set(dockFrame);
4997 displayFrames.mVoiceContent.set(dockFrame);
4998 displayFrames.mContent.set(dockFrame);
4999 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
5000 // And compute the final frame.
5001 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
5002 mTmpNavigationFrame, displayFrames.mDisplayCutoutSafe, mTmpNavigationFrame, dcf,
5003 mTmpNavigationFrame, displayFrames.mDisplayCutoutSafe,
5004 displayFrames.mDisplayCutout, false /* parentFrameWasClippedByDisplayCutout */);
5005 mNavigationBarController.setContentFrame(mNavigationBar.getContentFrameLw());
5006
5007 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
5008 return mNavigationBarController.checkHiddenLw();
5009 }
版权归原作者 海角&天涯 所有, 如有侵权,请联系我们删除。