Merge "Fixing screen center not getting calculated properly" into ub-launcher3-master
diff --git a/res/layout/overview_panel.xml b/res/layout/overview_panel.xml
index 9ba3f09..2091721 100644
--- a/res/layout/overview_panel.xml
+++ b/res/layout/overview_panel.xml
@@ -15,11 +15,13 @@
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res-auto"
+ launcher:layout_ignoreInsets="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:gravity="top"
- android:orientation="horizontal" >
+ android:orientation="horizontal">
<TextView
android:id="@+id/wallpaper_button"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 316e748..b07a400 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -33,8 +33,6 @@
<dimen name="dynamic_grid_workspace_page_spacing">8dp</dimen>
<!-- Minimum space between workspace and hotseat in spring loaded mode -->
<dimen name="dynamic_grid_min_spring_loaded_space">8dp</dimen>
- <dimen name="dynamic_grid_container_land_left_padding">118dp</dimen>
- <dimen name="dynamic_grid_container_land_right_padding">66dp</dimen>
<!-- Drop target bar -->
<dimen name="dynamic_grid_drop_target_size">48dp</dimen>
diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java
index b7321d9..ac7cbaf 100644
--- a/src/com/android/launcher3/BaseContainerView.java
+++ b/src/com/android/launcher3/BaseContainerView.java
@@ -19,7 +19,6 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
-import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
@@ -41,13 +40,9 @@
public abstract class BaseContainerView extends FrameLayout
implements DeviceProfile.LauncherLayoutChangeListener {
- protected int mContainerPaddingLeft;
- protected int mContainerPaddingRight;
- protected int mContainerPaddingTop;
- protected int mContainerPaddingBottom;
+ private static final Rect sBgPaddingRect = new Rect();
protected final Drawable mBaseDrawable;
- private final Rect mBgPaddingRect = new Rect();
private View mRevealView;
private View mContent;
@@ -110,23 +105,56 @@
}
@Override
- protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
- super.onLayout(changed, left, top, right, bottom);
- getRevealView().getBackground().getPadding(mBgPaddingRect);
+ public void onLauncherLayoutChanged() {
+ updatePaddings();
+ }
- View touchDelegateTargetView = getTouchDelegateTargetView();
- if (touchDelegateTargetView != null) {
- mTouchDelegate.setBounds(
- touchDelegateTargetView.getLeft() - mBgPaddingRect.left,
- touchDelegateTargetView.getTop() - mBgPaddingRect.top,
- touchDelegateTargetView.getRight() + mBgPaddingRect.right,
- touchDelegateTargetView.getBottom() + mBgPaddingRect.bottom);
+ /**
+ * Calculate the background padding as it can change due to insets/content padding change.
+ */
+ private void updatePaddings() {
+ Context context = getContext();
+ int paddingLeft;
+ int paddingRight;
+ int paddingTop;
+ int paddingBottom;
+
+ DeviceProfile grid = Launcher.getLauncher(context).getDeviceProfile();
+ int[] padding = grid.getContainerPadding();
+ paddingLeft = padding[0] + grid.edgeMarginPx;
+ paddingRight = padding[1] + grid.edgeMarginPx;
+ if (!grid.isVerticalBarLayout()) {
+ paddingTop = paddingBottom = grid.edgeMarginPx;
+ } else {
+ paddingTop = paddingBottom = 0;
}
+ updateBackground(paddingLeft, paddingTop, paddingRight, paddingBottom);
+ }
+
+ /**
+ * Update the background for the reveal view and content view based on the background padding.
+ */
+ protected void updateBackground(int paddingLeft, int paddingTop,
+ int paddingRight, int paddingBottom) {
+ mRevealView.setBackground(new InsetDrawable(mBaseDrawable,
+ paddingLeft, paddingTop, paddingRight, paddingBottom));
+ mContent.setBackground(new InsetDrawable(mBaseDrawable,
+ paddingLeft, paddingTop, paddingRight, paddingBottom));
}
@Override
- public void onLauncherLayoutChanged() {
- updatePaddings();
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ super.onLayout(changed, left, top, right, bottom);
+
+ View touchDelegateTargetView = getTouchDelegateTargetView();
+ if (touchDelegateTargetView != null) {
+ getRevealView().getBackground().getPadding(sBgPaddingRect);
+ mTouchDelegate.setBounds(
+ touchDelegateTargetView.getLeft() - sBgPaddingRect.left,
+ touchDelegateTargetView.getTop() - sBgPaddingRect.top,
+ touchDelegateTargetView.getRight() + sBgPaddingRect.right,
+ touchDelegateTargetView.getBottom() + sBgPaddingRect.bottom);
+ }
}
@Override
@@ -152,33 +180,6 @@
return mRevealView;
}
- private void updatePaddings() {
- Context context = getContext();
- Launcher launcher = Launcher.getLauncher(context);
-
- if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP &&
- this instanceof AllAppsContainerView &&
- !launcher.getDeviceProfile().isVerticalBarLayout()) {
- mContainerPaddingLeft = mContainerPaddingRight = 0;
- mContainerPaddingTop = mContainerPaddingBottom = 0;
- } else {
- DeviceProfile grid = launcher.getDeviceProfile();
- int[] padding = grid.getContainerPadding(context);
- mContainerPaddingLeft = padding[0] + grid.edgeMarginPx;
- mContainerPaddingRight = padding[1] + grid.edgeMarginPx;
- if (!launcher.getDeviceProfile().isVerticalBarLayout()) {
- mContainerPaddingTop = mContainerPaddingBottom = grid.edgeMarginPx;
- } else {
- mContainerPaddingTop = mContainerPaddingBottom = 0;
- }
- }
-
- InsetDrawable revealDrawable = new InsetDrawable(mBaseDrawable,
- mContainerPaddingLeft, mContainerPaddingTop, mContainerPaddingRight,
- mContainerPaddingBottom);
- mRevealView.setBackground(revealDrawable);
- mContent.setBackground(revealDrawable);
- }
/**
* Handles the touch events that shows the workspace when clicking outside the bounds of the
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index b25c0a1..51e174f 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -116,10 +116,6 @@
public int allAppsIconDrawablePaddingPx;
public float allAppsIconTextSizePx;
- // Containers
- private final int containerLeftPaddingPx;
- private final int containerRightPaddingPx;
-
// Drop Target
public int dropTargetBarSizePx;
@@ -184,10 +180,6 @@
hotseatBarTopPaddingPx =
res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_top_padding);
hotseatLandGutterPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_hotseat_gutter_width);
- containerLeftPaddingPx =
- res.getDimensionPixelSize(R.dimen.dynamic_grid_container_land_left_padding);
- containerRightPaddingPx =
- res.getDimensionPixelSize(R.dimen.dynamic_grid_container_land_right_padding);
// Determine sizes.
widthPx = width;
@@ -555,18 +547,13 @@
// Layout the Overview Mode
ViewGroup overviewMode = launcher.getOverviewPanel();
if (overviewMode != null) {
- lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
- lp.gravity = Gravity.LEFT | Gravity.BOTTOM;
-
int visibleChildCount = getVisibleChildCount(overviewMode);
int totalItemWidth = visibleChildCount * overviewModeBarItemWidthPx;
- int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx;
+ int maxWidth = totalItemWidth + (visibleChildCount - 1) * overviewModeBarSpacerWidthPx;
+ lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams();
lp.width = Math.min(availableWidthPx, maxWidth);
- lp.height = getOverviewModeButtonBarHeight();
- // Center the overview buttons on the workspace page
- lp.leftMargin = workspacePadding.left + (availableWidthPx -
- workspacePadding.left - workspacePadding.right - lp.width) / 2;
+ lp.height = getOverviewModeButtonBarHeight() + mInsets.bottom;
overviewMode.setLayoutParams(lp);
}
@@ -593,9 +580,7 @@
/**
* @return the left/right paddings for all containers.
*/
- public final int[] getContainerPadding(Context context) {
- Resources res = context.getResources();
-
+ public final int[] getContainerPadding() {
// No paddings for portrait phone
if (isPhone && !isVerticalBarLayout()) {
return new int[] {0, 0};
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index c7fac87..f372d95 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -365,7 +365,7 @@
? app.getInvariantDeviceProfile().landscapeProfile
: app.getInvariantDeviceProfile().portraitProfile;
- if (Utilities.isNycOrAbove() && isInMultiWindowMode()) {
+ if (Utilities.ATLEAST_NOUGAT && isInMultiWindowMode()) {
Display display = getWindowManager().getDefaultDisplay();
Point mwSize = new Point();
display.getSize(mwSize);
@@ -466,7 +466,7 @@
private void loadExtractedColorsAndColorItems() {
// TODO: do this in pre-N as well, once the extraction part is complete.
- if (Utilities.isNycOrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT) {
mExtractedColors.load(this);
mHotseat.updateColor(mExtractedColors, !mPaused);
mWorkspace.getPageIndicator().updateColor(mExtractedColors);
@@ -913,7 +913,7 @@
mLauncherCallbacks.onStop();
}
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
mAppWidgetHost.stopListening();
}
}
@@ -927,7 +927,7 @@
mLauncherCallbacks.onStart();
}
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
mAppWidgetHost.startListening();
}
}
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 1ee4a1a..2a43aad 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -115,7 +115,7 @@
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNLOCKED);
// For extracting colors from the wallpaper
- if (Utilities.isNycOrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT) {
// TODO: add a broadcast entry to the manifest for pre-N.
filter.addAction(Intent.ACTION_WALLPAPER_CHANGED);
}
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 55bd0a4..955f51f 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -2692,7 +2692,7 @@
* use partial updates similar to {@link UserManagerCompat}
*/
public void refreshShortcutsIfRequired() {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
sWorker.removeCallbacks(mShortcutPermissionCheckRunnable);
sWorker.post(mShortcutPermissionCheckRunnable);
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 95e3d82..13a69f2 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -84,13 +84,11 @@
private static final int[] sLoc0 = new int[2];
private static final int[] sLoc1 = new int[2];
- public static boolean isNycMR1OrAbove() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
- }
+ public static final boolean ATLEAST_NOUGAT_MR1 =
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
- public static boolean isNycOrAbove() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
- }
+ public static final boolean ATLEAST_NOUGAT =
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
public static final boolean ATLEAST_MARSHMALLOW =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
@@ -137,7 +135,7 @@
}
public static boolean getAllowRotationDefaultValue(Context context) {
- if (isNycOrAbove()) {
+ if (ATLEAST_NOUGAT) {
// If the device was scaled, used the original dimensions to determine if rotation
// is allowed of not.
Resources res = context.getResources();
@@ -619,7 +617,7 @@
}
public static boolean isWallpaperAllowed(Context context) {
- if (isNycOrAbove()) {
+ if (ATLEAST_NOUGAT) {
try {
WallpaperManager wm = context.getSystemService(WallpaperManager.class);
return (Boolean) wm.getClass().getDeclaredMethod("isSetWallpaperAllowed")
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 768d17b..b5aed0d 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -16,7 +16,10 @@
package com.android.launcher3.allapps;
import android.content.Context;
+import android.graphics.Color;
import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.InsetDrawable;
import android.support.v7.widget.RecyclerView;
import android.text.Selection;
import android.text.Spannable;
@@ -100,6 +103,24 @@
Selection.setSelection(mSearchQueryBuilder, 0);
}
+ @Override
+ protected void updateBackground(
+ int paddingLeft, int paddingTop, int paddingRight, int paddingBottom) {
+ if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
+ if (mLauncher.getDeviceProfile().isVerticalBarLayout()) {
+ getRevealView().setBackground(new InsetDrawable(mBaseDrawable,
+ paddingLeft, paddingTop, paddingRight, paddingBottom));
+ getContentView().setBackground(
+ new InsetDrawable(new ColorDrawable(Color.TRANSPARENT),
+ paddingLeft, paddingTop, paddingRight, paddingBottom));
+ } else {
+ getRevealView().setBackground(mBaseDrawable);
+ }
+ } else {
+ super.updateBackground(paddingLeft, paddingTop, paddingRight, paddingBottom);
+ }
+ }
+
/**
* Sets the current set of predicted apps.
*/
diff --git a/src/com/android/launcher3/compat/AlphabeticIndexCompat.java b/src/com/android/launcher3/compat/AlphabeticIndexCompat.java
index c7a529d..84e82e3 100644
--- a/src/com/android/launcher3/compat/AlphabeticIndexCompat.java
+++ b/src/com/android/launcher3/compat/AlphabeticIndexCompat.java
@@ -23,7 +23,7 @@
BaseIndex index = null;
try {
- if (Utilities.isNycOrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT) {
index = new AlphabeticIndexVN(context);
}
} catch (Exception e) {
diff --git a/src/com/android/launcher3/compat/UserManagerCompat.java b/src/com/android/launcher3/compat/UserManagerCompat.java
index a5f8dd2..b40eaa2 100644
--- a/src/com/android/launcher3/compat/UserManagerCompat.java
+++ b/src/com/android/launcher3/compat/UserManagerCompat.java
@@ -32,9 +32,9 @@
public static UserManagerCompat getInstance(Context context) {
synchronized (sInstanceLock) {
if (sInstance == null) {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
sInstance = new UserManagerCompatVNMr1(context.getApplicationContext());
- } else if (Utilities.isNycOrAbove()) {
+ } else if (Utilities.ATLEAST_NOUGAT) {
sInstance = new UserManagerCompatVN(context.getApplicationContext());
} else if (Utilities.ATLEAST_MARSHMALLOW) {
sInstance = new UserManagerCompatVM(context.getApplicationContext());
diff --git a/src/com/android/launcher3/dragndrop/DragDriver.java b/src/com/android/launcher3/dragndrop/DragDriver.java
index 4db8c07..d0c8e16 100644
--- a/src/com/android/launcher3/dragndrop/DragDriver.java
+++ b/src/com/android/launcher3/dragndrop/DragDriver.java
@@ -92,7 +92,7 @@
public static DragDriver create(Context context, DragController dragController,
DragObject dragObject, DragOptions options) {
- if (Utilities.isNycOrAbove() && options.systemDndStartPoint != null) {
+ if (Utilities.ATLEAST_NOUGAT && options.systemDndStartPoint != null) {
return new SystemDragDriver(dragController, context, dragObject);
} else {
return new InternalDragDriver(dragController);
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 59d18c2..9618779 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -390,7 +390,7 @@
@TargetApi(Build.VERSION_CODES.N)
private void handleSystemDragStart(DragEvent event) {
- if (!FeatureFlags.LAUNCHER3_USE_SYSTEM_DRAG_DRIVER || !Utilities.isNycOrAbove()) {
+ if (!FeatureFlags.LAUNCHER3_USE_SYSTEM_DRAG_DRIVER || !Utilities.ATLEAST_NOUGAT) {
return;
}
if (mLauncher.isWorkspaceLocked()) {
diff --git a/src/com/android/launcher3/dynamicui/ExtractionUtils.java b/src/com/android/launcher3/dynamicui/ExtractionUtils.java
index 1e663a9..1cf5d55 100644
--- a/src/com/android/launcher3/dynamicui/ExtractionUtils.java
+++ b/src/com/android/launcher3/dynamicui/ExtractionUtils.java
@@ -62,7 +62,7 @@
}
private static boolean hasWallpaperIdChanged(Context context) {
- if (!Utilities.isNycOrAbove()) {
+ if (!Utilities.ATLEAST_NOUGAT) {
// TODO: update an id in sharedprefs in onWallpaperChanged broadcast, and read it here.
return false;
}
@@ -74,7 +74,7 @@
@TargetApi(Build.VERSION_CODES.N)
public static int getWallpaperId(WallpaperManager wallpaperManager) {
- return Utilities.isNycOrAbove() ?
+ return Utilities.ATLEAST_NOUGAT ?
wallpaperManager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) : -1;
}
diff --git a/src/com/android/launcher3/model/GridSizeMigrationTask.java b/src/com/android/launcher3/model/GridSizeMigrationTask.java
index fd647c7..599dcd0 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationTask.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationTask.java
@@ -42,7 +42,7 @@
*/
public class GridSizeMigrationTask {
- public static boolean ENABLED = Utilities.isNycOrAbove();
+ public static boolean ENABLED = Utilities.ATLEAST_NOUGAT;
private static final String TAG = "GridSizeMigrationTask";
private static final boolean DEBUG = true;
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java
index 9037af4..c2c7c17 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutManager.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutManager.java
@@ -91,7 +91,7 @@
*/
@TargetApi(25)
public void unpinShortcut(final ShortcutKey key) {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
String packageName = key.componentName.getPackageName();
String id = key.getId();
UserHandleCompat user = key.user;
@@ -113,7 +113,7 @@
*/
@TargetApi(25)
public void pinShortcut(final ShortcutKey key) {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
String packageName = key.componentName.getPackageName();
String id = key.getId();
UserHandleCompat user = key.user;
@@ -132,7 +132,7 @@
@TargetApi(25)
public void startShortcut(String packageName, String id, Rect sourceBounds,
Bundle startActivityOptions, UserHandleCompat user) {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
try {
mLauncherApps.startShortcut(packageName, id, sourceBounds,
startActivityOptions, user.getUser());
@@ -146,7 +146,7 @@
@TargetApi(25)
public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
try {
Drawable icon = mLauncherApps.getShortcutIconDrawable(
shortcutInfo.getShortcutInfo(), density);
@@ -191,7 +191,7 @@
@TargetApi(25)
private List<ShortcutInfoCompat> query(int flags, String packageName,
ComponentName activity, List<String> shortcutIds, UserHandleCompat user) {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
ShortcutQuery q = new ShortcutQuery();
q.setQueryFlags(flags);
if (packageName != null) {
@@ -222,7 +222,7 @@
@TargetApi(25)
public boolean hasHostPermission() {
- if (Utilities.isNycMR1OrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT_MR1) {
try {
return mLauncherApps.hasShortcutHostPermission();
} catch (SecurityException|IllegalStateException e) {
diff --git a/src/com/android/launcher3/util/PackageManagerHelper.java b/src/com/android/launcher3/util/PackageManagerHelper.java
index afd9b83..b61d609 100644
--- a/src/com/android/launcher3/util/PackageManagerHelper.java
+++ b/src/com/android/launcher3/util/PackageManagerHelper.java
@@ -69,7 +69,7 @@
// The value of FLAG_SUSPENDED was reused by a hidden constant
// ApplicationInfo.FLAG_PRIVILEGED prior to N, so only check for suspended flag on N
// or later.
- if (Utilities.isNycOrAbove()) {
+ if (Utilities.ATLEAST_NOUGAT) {
return (info.flags & FLAG_SUSPENDED) != 0;
} else {
return false;