Merge "Not using magic constants for navbar height" into ub-launcher3-qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
94dbfb9bdb
@@ -24,6 +24,7 @@ android_library {
|
||||
srcs: [
|
||||
"tests/tapl/**/*.java",
|
||||
"src/com/android/launcher3/util/SecureSettingsObserver.java",
|
||||
"src/com/android/launcher3/ResourceUtils.java",
|
||||
"src/com/android/launcher3/TestProtocol.java",
|
||||
],
|
||||
manifest: "tests/tapl/AndroidManifest.xml",
|
||||
|
||||
+7
-17
@@ -35,7 +35,6 @@ import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Region;
|
||||
@@ -58,6 +57,7 @@ import android.view.WindowManager;
|
||||
|
||||
import com.android.launcher3.MainThreadExecutor;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.logging.EventLogArray;
|
||||
@@ -90,9 +90,6 @@ public class TouchInteractionService extends Service implements
|
||||
public static final LooperExecutor BACKGROUND_EXECUTOR =
|
||||
new LooperExecutor(UiThreadHelper.getBackgroundLooper());
|
||||
|
||||
private static final String NAVBAR_VERTICAL_SIZE = "navigation_bar_frame_height";
|
||||
private static final String NAVBAR_HORIZONTAL_SIZE = "navigation_bar_width";
|
||||
|
||||
public static final EventLogArray TOUCH_INTERACTION_LOG =
|
||||
new EventLogArray("touch_interaction_log", 40);
|
||||
|
||||
@@ -291,15 +288,7 @@ public class TouchInteractionService extends Service implements
|
||||
}
|
||||
|
||||
private int getNavbarSize(String resName) {
|
||||
int frameSize;
|
||||
Resources res = getResources();
|
||||
int frameSizeResID = res.getIdentifier(resName, "dimen", "android");
|
||||
if (frameSizeResID != 0) {
|
||||
frameSize = res.getDimensionPixelSize(frameSizeResID);
|
||||
} else {
|
||||
frameSize = Utilities.pxFromDp(48, res.getDisplayMetrics());
|
||||
}
|
||||
return frameSize;
|
||||
return ResourceUtils.getNavbarSize(resName, getResources());
|
||||
}
|
||||
|
||||
private void initTouchBounds() {
|
||||
@@ -312,20 +301,21 @@ public class TouchInteractionService extends Service implements
|
||||
defaultDisplay.getRealSize(realSize);
|
||||
mSwipeTouchRegion.set(0, 0, realSize.x, realSize.y);
|
||||
if (mMode == Mode.NO_BUTTON) {
|
||||
mSwipeTouchRegion.top = mSwipeTouchRegion.bottom - getNavbarSize(NAVBAR_VERTICAL_SIZE);
|
||||
mSwipeTouchRegion.top = mSwipeTouchRegion.bottom - getNavbarSize(
|
||||
ResourceUtils.NAVBAR_VERTICAL_SIZE);
|
||||
} else {
|
||||
switch (defaultDisplay.getRotation()) {
|
||||
case Surface.ROTATION_90:
|
||||
mSwipeTouchRegion.left = mSwipeTouchRegion.right
|
||||
- getNavbarSize(NAVBAR_HORIZONTAL_SIZE);
|
||||
- getNavbarSize(ResourceUtils.NAVBAR_HORIZONTAL_SIZE);
|
||||
break;
|
||||
case Surface.ROTATION_270:
|
||||
mSwipeTouchRegion.right = mSwipeTouchRegion.left
|
||||
+ getNavbarSize(NAVBAR_HORIZONTAL_SIZE);
|
||||
+ getNavbarSize(ResourceUtils.NAVBAR_HORIZONTAL_SIZE);
|
||||
break;
|
||||
default:
|
||||
mSwipeTouchRegion.top = mSwipeTouchRegion.bottom
|
||||
- getNavbarSize(NAVBAR_VERTICAL_SIZE);
|
||||
- getNavbarSize(ResourceUtils.NAVBAR_VERTICAL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public class DeviceProfile {
|
||||
// Add a bit of space between nav bar and hotseat in multi-window vertical bar layout.
|
||||
hotseatBarSidePaddingStartPx = isMultiWindowMode && isVerticalBarLayout()
|
||||
? edgeMarginPx : 0;
|
||||
hotseatBarSizePx = Utilities.pxFromDp(inv.iconSize, dm) + (isVerticalBarLayout()
|
||||
hotseatBarSizePx = ResourceUtils.pxFromDp(inv.iconSize, dm) + (isVerticalBarLayout()
|
||||
? (hotseatBarSidePaddingStartPx + hotseatBarSidePaddingEndPx)
|
||||
: (res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_extra_vertical_size)
|
||||
+ hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx));
|
||||
@@ -319,7 +319,7 @@ public class DeviceProfile {
|
||||
// Workspace
|
||||
final boolean isVerticalLayout = isVerticalBarLayout();
|
||||
float invIconSizePx = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
|
||||
iconSizePx = Math.max(1, (int) (Utilities.pxFromDp(invIconSizePx, dm) * scale));
|
||||
iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizePx, dm) * scale));
|
||||
iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
|
||||
iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
|
||||
|
||||
@@ -399,7 +399,7 @@ public class DeviceProfile {
|
||||
}
|
||||
|
||||
private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) {
|
||||
folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
|
||||
folderChildIconSizePx = (int) (ResourceUtils.pxFromDp(inv.iconSize, dm) * scale);
|
||||
folderChildTextSizePx =
|
||||
(int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale);
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ public class InvariantDeviceProfile {
|
||||
iconSize = interpolatedDisplayOption.iconSize;
|
||||
iconShapePath = getIconShapePath(context);
|
||||
landscapeIconSize = interpolatedDisplayOption.landscapeIconSize;
|
||||
iconBitmapSize = Utilities.pxFromDp(iconSize, dm);
|
||||
iconBitmapSize = ResourceUtils.pxFromDp(iconSize, dm);
|
||||
iconTextSize = interpolatedDisplayOption.iconTextSize;
|
||||
fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
||||
public class ResourceUtils {
|
||||
public static final String NAVBAR_VERTICAL_SIZE = "navigation_bar_frame_height";
|
||||
public static final String NAVBAR_HORIZONTAL_SIZE = "navigation_bar_width";
|
||||
|
||||
public static int getNavbarSize(String resName, Resources res) {
|
||||
return getDimenByName(resName, res, 48);
|
||||
}
|
||||
|
||||
private static int getDimenByName(String resName, Resources res, int defaultValue) {
|
||||
final int frameSize;
|
||||
final int frameSizeResID = res.getIdentifier(resName, "dimen", "android");
|
||||
if (frameSizeResID != 0) {
|
||||
frameSize = res.getDimensionPixelSize(frameSizeResID);
|
||||
} else {
|
||||
frameSize = pxFromDp(defaultValue, res.getDisplayMetrics());
|
||||
}
|
||||
return frameSize;
|
||||
}
|
||||
|
||||
public static int pxFromDp(float size, DisplayMetrics metrics) {
|
||||
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size, metrics));
|
||||
}
|
||||
}
|
||||
@@ -477,10 +477,7 @@ public final class Utilities {
|
||||
float densityRatio = (float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT;
|
||||
return (size / densityRatio);
|
||||
}
|
||||
public static int pxFromDp(float size, DisplayMetrics metrics) {
|
||||
return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||
size, metrics));
|
||||
}
|
||||
|
||||
public static int pxFromSp(float size, DisplayMetrics metrics) {
|
||||
return (int) Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
|
||||
size, metrics));
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.CellLayout;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.ShortcutAndWidgetContainer;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.anim.PropertyResetListener;
|
||||
@@ -165,7 +166,7 @@ public class FolderAnimationManager {
|
||||
Math.round((totalOffsetX + initialSize) / initialScale),
|
||||
Math.round((paddingOffsetY + initialSize) / initialScale));
|
||||
Rect endRect = new Rect(0, 0, lp.width, lp.height);
|
||||
float finalRadius = Utilities.pxFromDp(2, mContext.getResources().getDisplayMetrics());
|
||||
float finalRadius = ResourceUtils.pxFromDp(2, mContext.getResources().getDisplayMetrics());
|
||||
|
||||
// Create the animators.
|
||||
AnimatorSet a = new AnimatorSet();
|
||||
|
||||
@@ -43,7 +43,7 @@ import android.view.View;
|
||||
import com.android.launcher3.CellLayout;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.Workspace;
|
||||
import com.android.launcher3.uioverrides.WallpaperColorInfo;
|
||||
import com.android.launcher3.util.Themes;
|
||||
@@ -148,7 +148,7 @@ public class WorkspaceAndHotseatScrim implements
|
||||
mLauncher = Launcher.getLauncher(view.getContext());
|
||||
mWallpaperColorInfo = WallpaperColorInfo.getInstance(mLauncher);
|
||||
|
||||
mMaskHeight = Utilities.pxFromDp(ALPHA_MASK_BITMAP_DP,
|
||||
mMaskHeight = ResourceUtils.pxFromDp(ALPHA_MASK_BITMAP_DP,
|
||||
view.getResources().getDisplayMetrics());
|
||||
mTopScrim = Themes.getAttrDrawable(view.getContext(), R.attr.workspaceStatusBarScrim);
|
||||
mBottomMask = mTopScrim == null ? null : createDitheredAlphaMask();
|
||||
@@ -297,8 +297,8 @@ public class WorkspaceAndHotseatScrim implements
|
||||
|
||||
public Bitmap createDitheredAlphaMask() {
|
||||
DisplayMetrics dm = mLauncher.getResources().getDisplayMetrics();
|
||||
int width = Utilities.pxFromDp(ALPHA_MASK_WIDTH_DP, dm);
|
||||
int gradientHeight = Utilities.pxFromDp(ALPHA_MASK_HEIGHT_DP, dm);
|
||||
int width = ResourceUtils.pxFromDp(ALPHA_MASK_WIDTH_DP, dm);
|
||||
int gradientHeight = ResourceUtils.pxFromDp(ALPHA_MASK_HEIGHT_DP, dm);
|
||||
Bitmap dst = Bitmap.createBitmap(width, mMaskHeight, Bitmap.Config.ALPHA_8);
|
||||
Canvas c = new Canvas(dst);
|
||||
Paint paint = new Paint(Paint.DITHER_FLAG);
|
||||
|
||||
@@ -36,7 +36,7 @@ import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.ItemInfo;
|
||||
import com.android.launcher3.LauncherAppState;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.anim.Interpolators;
|
||||
import com.android.launcher3.model.WidgetItem;
|
||||
import com.android.launcher3.util.PackageUserKey;
|
||||
@@ -126,7 +126,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
|
||||
// Otherwise, add an empty view to the start as padding (but still scroll edge to edge).
|
||||
View leftPaddingView = LayoutInflater.from(getContext()).inflate(
|
||||
R.layout.widget_list_divider, widgetRow, false);
|
||||
leftPaddingView.getLayoutParams().width = Utilities.pxFromDp(
|
||||
leftPaddingView.getLayoutParams().width = ResourceUtils.pxFromDp(
|
||||
16, getResources().getDisplayMetrics());
|
||||
widgetCells.addView(leftPaddingView, 0);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ else
|
||||
LOCAL_STATIC_JAVA_LIBRARIES += libSharedSystemUI
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, tapl) \
|
||||
../src/com/android/launcher3/ResourceUtils.java \
|
||||
../src/com/android/launcher3/util/SecureSettingsObserver.java \
|
||||
../src/com/android/launcher3/TestProtocol.java
|
||||
endif
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.android.launcher3.LauncherModel;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.LauncherState;
|
||||
import com.android.launcher3.MainThreadExecutor;
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.compat.LauncherAppsCompat;
|
||||
import com.android.launcher3.tapl.LauncherInstrumentation;
|
||||
@@ -208,7 +209,9 @@ public abstract class AbstractLauncherUiTest {
|
||||
* @return the matching object.
|
||||
*/
|
||||
protected UiObject2 scrollAndFind(UiObject2 container, BySelector condition) {
|
||||
container.setGestureMargins(0, 0, 0, 200);
|
||||
final int margin = ResourceUtils.getNavbarSize(
|
||||
ResourceUtils.NAVBAR_VERTICAL_SIZE, mLauncher.getResources()) + 1;
|
||||
container.setGestureMargins(0, 0, 0, margin);
|
||||
|
||||
int i = 0;
|
||||
for (; ; ) {
|
||||
@@ -216,7 +219,8 @@ public abstract class AbstractLauncherUiTest {
|
||||
mDevice.wait(Until.findObject(condition), SHORT_UI_TIMEOUT);
|
||||
UiObject2 widget = container.findObject(condition);
|
||||
if (widget != null && widget.getVisibleBounds().intersects(
|
||||
0, 0, mDevice.getDisplayWidth(), mDevice.getDisplayHeight() - 200)) {
|
||||
0, 0, mDevice.getDisplayWidth(),
|
||||
mDevice.getDisplayHeight() - margin)) {
|
||||
return widget;
|
||||
}
|
||||
if (++i > 40) fail("Too many attempts");
|
||||
|
||||
@@ -23,6 +23,7 @@ import androidx.test.uiautomator.BySelector;
|
||||
import androidx.test.uiautomator.Direction;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
import com.android.launcher3.TestProtocol;
|
||||
|
||||
/**
|
||||
@@ -66,12 +67,9 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
|
||||
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
|
||||
"want to get app icon on all apps")) {
|
||||
final UiObject2 allAppsContainer = verifyActiveContainer();
|
||||
if (mLauncher.getNavigationModel() != ZERO_BUTTON) {
|
||||
final UiObject2 navBar = mLauncher.waitForSystemUiObject("navigation_bar_frame");
|
||||
allAppsContainer.setGestureMargins(0, 0, 0, navBar.getVisibleBounds().height() + 1);
|
||||
} else {
|
||||
allAppsContainer.setGestureMargins(0, 0, 0, 200);
|
||||
}
|
||||
allAppsContainer.setGestureMargins(0, 0, 0,
|
||||
ResourceUtils.getNavbarSize(ResourceUtils.NAVBAR_VERTICAL_SIZE,
|
||||
mLauncher.getResources()) + 1);
|
||||
final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher);
|
||||
if (!hasClickableIcon(allAppsContainer, appIconSelector)) {
|
||||
scrollBackToBeginning();
|
||||
|
||||
@@ -586,6 +586,10 @@ public final class LauncherInstrumentation {
|
||||
return ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
||||
}
|
||||
|
||||
public Resources getResources() {
|
||||
return getContext().getResources();
|
||||
}
|
||||
|
||||
private static MotionEvent getMotionEvent(long downTime, long eventTime, int action,
|
||||
float x, float y) {
|
||||
MotionEvent.PointerProperties properties = new MotionEvent.PointerProperties();
|
||||
|
||||
@@ -19,6 +19,8 @@ package com.android.launcher3.tapl;
|
||||
import androidx.test.uiautomator.Direction;
|
||||
import androidx.test.uiautomator.UiObject2;
|
||||
|
||||
import com.android.launcher3.ResourceUtils;
|
||||
|
||||
/**
|
||||
* All widgets container.
|
||||
*/
|
||||
@@ -38,7 +40,9 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer {
|
||||
"want to fling forward in widgets")) {
|
||||
LauncherInstrumentation.log("Widgets.flingForward enter");
|
||||
final UiObject2 widgetsContainer = verifyActiveContainer();
|
||||
widgetsContainer.setGestureMargins(0, 0, 0, 200);
|
||||
widgetsContainer.setGestureMargins(0, 0, 0,
|
||||
ResourceUtils.getNavbarSize(ResourceUtils.NAVBAR_VERTICAL_SIZE,
|
||||
mLauncher.getResources()) + 1);
|
||||
widgetsContainer.fling(Direction.DOWN,
|
||||
(int) (FLING_SPEED * mLauncher.getDisplayDensity()));
|
||||
try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung forward")) {
|
||||
|
||||
Reference in New Issue
Block a user