Android13 Launcher3 禁用Hotseat应用功能只需要修改两部分代码
(前提是没有配置谷歌的GMS包)
- Launcher3/res/xml/device_profiles.xml
- Launcher3/src/com/android/launcher3/DeviceProfile.java
Launcher3/res/xml/device_profiles.xml修改桌面布局
--- a/res/xml/device_profiles.xml
+++ b/res/xml/device_profiles.xml
@@ -23,7 +23,7 @@
launcher:numColumns="3"
launcher:numFolderRows="2"
launcher:numFolderColumns="3"
- launcher:numHotseatIcons="3"
+ launcher:numHotseatIcons="0"
launcher:dbFile="launcher_3_by_3.db"
launcher:defaultLayoutId="@xml/default_workspace_3x3"
launcher:deviceCategory="phone|multi_display" >
@@ -56,7 +56,7 @@
launcher:numColumns="4"
launcher:numFolderRows="3"
launcher:numFolderColumns="4"
- launcher:numHotseatIcons="4"
+ launcher:numHotseatIcons="0"
launcher:dbFile="launcher_4_by_4.db"
launcher:defaultLayoutId="@xml/default_workspace_4x4"
launcher:deviceCategory="phone|multi_display" >
@@ -119,7 +119,7 @@
launcher:numColumns="5"
launcher:numFolderRows="4"
launcher:numFolderColumns="4"
- launcher:numHotseatIcons="5"
+ launcher:numHotseatIcons="0"
launcher:dbFile="launcher.db"
launcher:defaultLayoutId="@xml/default_workspace_5x5"
launcher:deviceCategory="phone|multi_display" >
@@ -163,7 +163,7 @@
launcher:numSearchContainerColumns="3"
launcher:numFolderRows="3"
launcher:numFolderColumns="3"
- launcher:numHotseatIcons="6"
+ launcher:numHotseatIcons="0"
launcher:hotseatColumnSpanLandscape="4"
launcher:numAllAppsColumns="6"
launcher:isScalable="true"
将所有的numHotseatIcons修改为0,无论是哪个布局上所有的hotseats将为0不会显示。防止设置里面 更改显示大小 适配布局显示出来。
Launcher3/src/com/android/launcher3/DeviceProfile.java 防止除数除以0
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -776,16 +776,19 @@ public class DeviceProfile {
* This method calculates the space between the icons to achieve that width.
*/
private int calculateHotseatBorderSpace() {
- if (!isScalableGrid) return 0;
- //TODO(http://b/228998082) remove this when 3 button spaces are fixed
- if (areNavButtonsInline) {
- return pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics);
- } else {
- int columns = inv.hotseatColumnSpan[mTypeIndex];
- float hotseatWidthPx = getIconToIconWidthForColumns(columns);
- float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
- return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
- }
+ // if (!isScalableGrid) return 0;
+ // //TODO(http://b/228998082) remove this when 3 button spaces are fixed
+ // if (areNavButtonsInline) {
+ // return pxFromDp(inv.hotseatBorderSpaces[mTypeIndex], mMetrics);
+ // } else {
+ // int columns = inv.hotseatColumnSpan[mTypeIndex];
+ // float hotseatWidthPx = getIconToIconWidthForColumns(columns);
+ // float hotseatIconsTotalPx = iconSizePx * numShownHotseatIcons;
+ // return (int) (hotseatWidthPx - hotseatIconsTotalPx) / (numShownHotseatIcons - 1);
+ // }
+ return iconSizePx;
}
@@ -1117,7 +1120,10 @@ public class DeviceProfile {
// for this, we pad the left and right of the hotseat with half of the difference of a
// workspace cell vs a hotseat cell.
float workspaceCellWidth = (float) widthPx / inv.numColumns;
- float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
+ // float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
+ float hotseatCellWidth = (float) widthPx / numShownHotseatIcons== 0 ? 3 : numShownHotseatIcons;
int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
mHotseatPadding.set(hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
+ mInsets.left, hotseatBarTopPaddingPx,
@@ -1207,13 +1213,25 @@ public class DeviceProfile {
}
}
public static int calculateCellWidth(int width, int borderSpacing, int countX) {
- return (width - ((countX - 1) * borderSpacing)) / countX;
+ // return (width - ((countX - 1) * borderSpacing)) / countX;
+ if(countX > 1){
+ return (width - ((countX - 1) * borderSpacing)) / countX;
+ }else{
+ return (width - borderSpacing) / 2;
+ }
}
public static int calculateCellHeight(int height, int borderSpacing, int countY) {
- return (height - ((countY - 1) * borderSpacing)) / countY;
+ //return (height - ((countY - 1) * borderSpacing)) / countY;
+ if (countY > 1){
+ return (height - ((countY - 1) * borderSpacing)) / countY;
+ }else{
+ return (height - (borderSpacing)) / 2;
+ }
}
因为在源码中有多处地方在计算布局的时候,都会获取numHotseatIcons的值来做计算,包括除法运算,所以numHotseatIcons的值设为0或者1之后,会引发 java.lang.ArithmeticException: divide by zero等报错。
最后展示结果如下: