对于Launcher3进行去抽屉式定制功能后(请参考:去抽屉式定制),现有项目整体横屏,导致部分定制失效。本文通过对Launcher3 UI部分代码的trace研究,在横屏状态下,完成基本的适配工作。
1.去除HOTESAT
在private void updateHotseatIconSize(int hotseatIconSizePx)方法中,将hotseat整体的高度设置为0,即可不显示,无论横屏还是竖屏。
Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java (版本 2027)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java (版本 2028)
@@ -34,10 +34,12 @@
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.DisplayMetrics;
+import android.util.Log;
import android.view.Surface;
import com.android.launcher3.CellLayout.ContainerType;
import com.android.launcher3.DevicePaddings.DevicePadding;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.icons.IconNormalizer;
@@ -52,6 +54,8 @@
@SuppressLint("NewApi")
public class DeviceProfile {
+ private static final String TAG = "DeviceProfile";
+
private static final int DEFAULT_DOT_SIZE = 100;
// Ratio of empty space, qsb should take up to appear visually centered.
private final float mQsbCenterFactor;
@@ -548,6 +552,10 @@
+ hotseatBarBottomPaddingPx + (isScalableGrid ? 0 : hotseatExtraVerticalSize)
+ hotseatBarSizeExtraSpacePx;
}
+ if (FeatureFlags.REMOVE_DRAWER) {
+ hotseatBarSizePx = 0;
+ }
}
2.主界面居中
由于横屏状态下,根据1提到的方法去除了hotseat,导致主界面的图标不居中。因为横屏状态下,hotseat在右侧,故去除后,原来配置的workspace界面会有偏差。
这部分代码通过将方法isVerticalBarLayout()强制设置为false,切换为竖屏,发现主界面图标居中了。
从这一点出发,找到了重新布局的代码,走竖屏的流程即可。
Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java (版本 2027)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java (版本 2028)
@@ -1013,7 +1021,7 @@
*/
private void updateWorkspacePadding() {
Rect padding = workspacePadding;
- if (isVerticalBarLayout()) {
+ if (isVerticalBarLayout() && !FeatureFlags.REMOVE_DRAWER) {
padding.top = 0;
padding.bottom = edgeMarginPx;
if (isSeascape()) {
3.长按图标拖动图标界面异常
有的同学为了减少修改,单独修改isVerticalBarLayout(),默认返回false,强制竖屏模式。
从源码也可以看出,
返回true表示横屏,hotseat居右
返回false表示竖屏或者横屏模式但是hotseat在底部。
/**
* When {@code true}, the device is in landscape mode and the hotseat is on the right column.
* When {@code false}, either device is in portrait mode or the device is in landscape mode and
* the hotseat is on the bottom row.
*/
public boolean isVerticalBarLayout() {
return isLandscape && transposeLayoutWithOrientation;
}
这样改动也是可以的,不过此时长按桌面图标,切换到拖动图标的模式,这个界面会非常小,在底部。
这时候同样是从isVerticalBarLayout() 入手,需要作出以下修改,即可放大。
Index: vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java
===================================================================
--- vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java (版本 2028)
+++ vendor/mediatek/proprietary/packages/apps/Launcher3/src/com/android/launcher3/DeviceProfile.java (工作副本)
@@ -264,7 +264,7 @@
isTaskbarPresent = isTablet && ApiWrapper.TASKBAR_DRAWN_IN_PROCESS;
// Some more constants.
- context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape)
+ context = getContext(context, info, false/*isVerticalBarLayout() || (isTablet && isLandscape)*/
? Configuration.ORIENTATION_LANDSCAPE
: Configuration.ORIENTATION_PORTRAIT,
windowBounds);