Android 13 大屏显示时关于SystemUI和Launcher3问题
当系统运行在大屏上时,原来显示SystemUI导航栏的位置会变成Launcher3的任务栏,然后导航栏的3个按键显示靠右下角显示
1.先看SystemUI的导航栏为什么会消失,移动
/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
public void createNavigationBars(final boolean includeDefaultDisplay,
RegisterStatusBarResult result) {
//更新辅助功能按钮模式
updateAccessibilityButtonModeIfNeeded();
// 判断是否初始化TaskBar,不需要TaskBar就默认显示上创建导航栏
final boolean shouldCreateDefaultNavbar = includeDefaultDisplay
&& !initializeTaskbarIfNecessary();
Display[] displays = mDisplayManager.getDisplays();
for (Display display : displays) {
if (shouldCreateDefaultNavbar || display.getDisplayId() != DEFAULT_DISPLAY) {
createNavigationBar(display, null /* savedState */, result);
}
}
}
/** @return {@code true} if taskbar is enabled, false otherwise */
private boolean initializeTaskbarIfNecessary() {
//判断是否是平板
if (mIsTablet) {
// Remove navigation bar when taskbar is showing
//移除导航栏的时候任务栏显示
Trace.beginSection("NavigationBarController#initializeTaskbarIfNecessary");
removeNavigationBar(mContext.getDisplayId());
mTaskbarDelegate.init(mContext.getDisplayId());
Trace.endSection();
} else {
mTaskbarDelegate.destroy();
}
return mIsTablet;
}
...
{
mIsTablet = isTablet(mContext);//如果判断它是平板
}
/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
/** @return whether or not {@param context} represents that of a large screen device or not */
@TargetApi(Build.VERSION_CODES.R)
//如果屏幕的(最小边长度*160/dpi值)< 600,就会判断为设备是平板设备
public static boolean isTablet(Context context) {
final WindowManager windowManager = context.getSystemService(WindowManager.class);
final Rect bounds = windowManager.getCurrentWindowMetrics().getBounds();
float smallestWidth = dpiFromPx(Math.min(bounds.width(), bounds.height()),
context.getResources().getConfiguration().densityDpi);
//add text
return false;//smallestWidth >= TABLET_MIN_DPS; 如果想要显示导航栏,直接返回false
//add text
}
//判断屏幕dpi
public static float dpiFromPx(float size, int densityDpi) {
float densityRatio = (float) densityDpi / DisplayMetrics.DENSITY_DEFAULT;
return (size / densityRatio);
}
补充:系统dpi也会影响导航栏的显示,不同的分辨率会走不同的布局,不同的配置config_navBarLayout
frameworks/base/packages/SystemUI/res/values-sw900dp/config.xml
<!-- Nav bar button default ordering/layout -->
<string name="config_navBarLayout" translatable="false">back,home,left;space;right,recent</string>
./frameworks/base/packages/SystemUI/res/values/config.xml
<string name="config_navBarLayout" translatable="false">left[.5W];volume_sub,back,home,recent,volume_add,screenshot;right[.5W]</string>
然后还有一个属性:导航栏是否跟随屏幕旋转移动
frameworks/base/core/res/res/values/config.xml
<!-- Controls whether the nav bar can move from the bottom to the side in landscape.
Only applies if the device display is not square. -->
<bool name="config_navBarCanMove">true</bool>
2.找到Launcher3显示任务栏的部分,也做类似的修改不让任务栏显示
/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
private void recreateTaskbar() {
destroyExistingTaskbar();
DeviceProfile dp =
mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;
//add text
boolean isTaskBarEnabled = false;//dp != null && dp.isTaskbarPresent;
//add text
if (!isTaskBarEnabled) {
SystemUiProxy.INSTANCE.get(mContext)
.notifyTaskbarStatus(/* visible */ false, /* stashed */ false);
return;
}
...
}
/Launcher3/src/com/android/launcher3/states/RotationHelper.java
public static boolean getAllowRotationDefaultValue(DeviceProfile deviceProfile) {
// If the device's pixel density was scaled (usually via settings for A11y), use the
// original dimensions to determine if rotation is allowed of not.
float originalSmallestWidth = dpiFromPx(
Math.min(deviceProfile.widthPx, deviceProfile.heightPx), DENSITY_DEVICE_STABLE);
//add text
return false;//originalSmallestWidth >= MIN_TABLET_WIDTH;
//add text
}
/Launcher3/src/com/android/launcher3/util/DisplayController.java
/**
* Returns {@code true} if the bounds represent a tablet.
*/
public boolean isTablet(WindowBounds bounds) {
//add text
return false;//smallestSizeDp(bounds) >= MIN_TABLET_WIDTH;
//add text
}
/Launcher3/src/com/android/launcher3/util/window/WindowManagerProxy.java
public class WindowManagerProxy implements ResourceBasedOverride {
Resources systemRes = context.getResources();
Configuration config = systemRes.getConfiguration();
- boolean isTablet = config.smallestScreenWidthDp > MIN_TABLET_WIDTH;
+ boolean isTablet = false;//config.smallestScreenWidthDp > MIN_TABLET_WIDTH;
boolean isGesture = isGestureNav(context);
boolean isPortrait = config.screenHeightDp > config.screenWidthDp;
- boolean isTablet = swDp >= MIN_TABLET_WIDTH;
+ boolean isTablet = false;//swDp >= MIN_TABLET_WIDTH;
boolean isTabletOrGesture = isTablet
|| (Utilities.ATLEAST_R && isGestureNav(context));