diff --git a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java index 62a8da787d..05b81671c3 100644 --- a/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java +++ b/quickstep/src/com/android/launcher3/hybridhotseat/HotseatPredictionController.java @@ -55,13 +55,13 @@ import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.touch.ItemLongClickListener; import com.android.launcher3.uioverrides.PredictedAppIcon; import com.android.launcher3.uioverrides.QuickstepLauncher; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.OnboardingPrefs; import com.android.launcher3.views.Snackbar; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -480,8 +480,8 @@ public class HotseatPredictionController implements DragController.DragListener, * * @param matcher filter matching items that have been removed */ - public void onModelItemsRemoved(ItemInfoMatcher matcher) { - if (mPredictedItems.removeIf(matcher::matchesInfo)) { + public void onModelItemsRemoved(Predicate matcher) { + if (mPredictedItems.removeIf(matcher)) { fillGapsWithPrediction(true); } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java index 5c10565dc1..c522888fce 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java @@ -73,6 +73,7 @@ import com.android.systemui.shared.recents.model.Task; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; +import java.util.function.Predicate; /** * Handles long click on Taskbar items to start a system drag and drop operation. @@ -439,12 +440,12 @@ public class TaskbarDragController extends DragController im target = taskbarViewController.getAllAppsButtonView(); } else if (item.container >= 0) { // Since folders close when the drag starts, target the folder icon instead. - ItemInfoMatcher matcher = ItemInfoMatcher.forFolderMatch( + Predicate matcher = ItemInfoMatcher.forFolderMatch( ItemInfoMatcher.ofItemIds(IntSet.wrap(item.id))); target = taskbarViewController.getFirstIconMatch(matcher); } else if (item.itemType == ITEM_TYPE_DEEP_SHORTCUT) { // Find first icon with same package/user as the deep shortcut. - ItemInfoMatcher packageUserMatcher = ItemInfoMatcher.ofPackages( + Predicate packageUserMatcher = ItemInfoMatcher.ofPackages( Collections.singleton(item.getTargetPackage()), item.user); target = taskbarViewController.getFirstIconMatch(packageUserMatcher); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java index af8825e020..5e670d2946 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarModelCallbacks.java @@ -37,6 +37,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.function.Predicate; /** * Launcher model Callbacks for rendering taskbar. @@ -137,16 +138,16 @@ public class TaskbarModelCallbacks implements } @Override - public void bindWorkspaceComponentsRemoved(ItemInfoMatcher matcher) { + public void bindWorkspaceComponentsRemoved(Predicate matcher) { if (handleItemsRemoved(matcher)) { commitItemsToUI(); } } - private boolean handleItemsRemoved(ItemInfoMatcher matcher) { + private boolean handleItemsRemoved(Predicate matcher) { boolean modified = false; for (int i = mHotseatItems.size() - 1; i >= 0; i--) { - if (matcher.matchesInfo(mHotseatItems.valueAt(i))) { + if (matcher.test(mHotseatItems.valueAt(i))) { modified = true; mHotseatItems.removeAt(i); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java index 7548398be2..6f88d649fb 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarView.java @@ -41,12 +41,13 @@ import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.uioverrides.ApiWrapper; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.LauncherBindableItemsContainer; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.views.AllAppsButton; import com.android.launcher3.views.DoubleShadowBubbleTextView; +import java.util.function.Predicate; + /** * Hosts the Taskbar content such as Hotseat and Recent Apps. Drawn on top of other apps. */ @@ -424,8 +425,8 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar * Finds the first icon to match one of the given matchers, from highest to lowest priority. * @return The first match, or All Apps button if no match was found. */ - public View getFirstMatch(ItemInfoMatcher... matchers) { - for (ItemInfoMatcher matcher : matchers) { + public View getFirstMatch(Predicate... matchers) { + for (Predicate matcher : matchers) { for (int i = 0; i < getChildCount(); i++) { View item = getChildAt(i); if (!(item.getTag() instanceof ItemInfo)) { @@ -433,7 +434,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar continue; } ItemInfo info = (ItemInfo) item.getTag(); - if (matcher.matchesInfo(info)) { + if (matcher.test(info)) { return item; } } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java index 74b1c6ca1a..d899d5f1ed 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarViewController.java @@ -47,6 +47,7 @@ import com.android.launcher3.util.MultiValueAlpha; import com.android.quickstep.AnimatedFloat; import java.io.PrintWriter; +import java.util.function.Predicate; /** * Handles properties/data collection, then passes the results to TaskbarView to render. @@ -318,8 +319,8 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar * 2) FolderIcon of the Folder containing the given icon * 3) All Apps button */ - public View getFirstIconMatch(ItemInfoMatcher matcher) { - ItemInfoMatcher folderMatcher = ItemInfoMatcher.forFolderMatch(matcher); + public View getFirstIconMatch(Predicate matcher) { + Predicate folderMatcher = ItemInfoMatcher.forFolderMatch(matcher); return mTaskbarView.getFirstMatch(matcher, folderMatcher); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 7c52e806cb..4bb43431bc 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -70,7 +70,6 @@ import com.android.launcher3.uioverrides.touchcontrollers.TransposedQuickSwitchT import com.android.launcher3.uioverrides.touchcontrollers.TwoButtonNavbarTouchController; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController.NavigationMode; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.PendingRequestArgs; import com.android.launcher3.util.TouchController; import com.android.launcher3.util.UiThreadHelper; @@ -86,6 +85,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Objects; +import java.util.function.Predicate; import java.util.stream.Stream; public class QuickstepLauncher extends BaseQuickstepLauncher { @@ -245,7 +245,7 @@ public class QuickstepLauncher extends BaseQuickstepLauncher { } @Override - public void bindWorkspaceComponentsRemoved(ItemInfoMatcher matcher) { + public void bindWorkspaceComponentsRemoved(Predicate matcher) { super.bindWorkspaceComponentsRemoved(matcher); mHotseatPredictionController.onModelItemsRemoved(matcher); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java index c25a815050..621dfb8dc9 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/AllAppsState.java @@ -89,9 +89,9 @@ public class AllAppsState extends LauncherState { @Override public int getVisibleElements(Launcher launcher) { - // Don't add HOTSEAT_ICONS for phones in ALL_APPS state. - return launcher.getDeviceProfile().isPhone ? ALL_APPS_CONTENT - : ALL_APPS_CONTENT | HOTSEAT_ICONS; + // Don't add HOTSEAT_ICONS for non-tablets in ALL_APPS state. + return launcher.getDeviceProfile().isTablet ? ALL_APPS_CONTENT | HOTSEAT_ICONS + : ALL_APPS_CONTENT; } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java index 699ce9783c..5f62749590 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java @@ -66,9 +66,9 @@ public class OverviewState extends LauncherState { @Override public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) { RecentsView recentsView = launcher.getOverviewPanel(); - float workspacePageWidth = launcher.getDeviceProfile().getWorkspaceWidth(); + float workspacePageHeight = launcher.getDeviceProfile().getCellLayoutHeight(); recentsView.getTaskSize(sTempRect); - float scale = (float) sTempRect.width() / workspacePageWidth; + float scale = (float) sTempRect.height() / workspacePageHeight; float parallaxFactor = 0.5f; return new ScaleAndTranslation(scale, 0, -getDefaultSwipeHeight(launcher) * parallaxFactor); } diff --git a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java index dc65b503c2..fd9f922005 100644 --- a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java +++ b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java @@ -16,6 +16,7 @@ package com.android.quickstep; +import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; import static com.android.launcher3.BaseActivity.INVISIBLE_ALL; import static com.android.launcher3.BaseActivity.INVISIBLE_BY_PENDING_FLAGS; import static com.android.launcher3.BaseActivity.PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION; @@ -37,6 +38,7 @@ import android.view.animation.Interpolator; import android.window.BackEvent; import android.window.IOnBackInvokedCallback; +import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.BaseQuickstepLauncher; import com.android.launcher3.QuickstepTransitionManager; import com.android.launcher3.R; @@ -274,6 +276,10 @@ public class LauncherBackAnimationController { mLauncher.getStateManager().moveToRestState(); } + // Explicitly close opened floating views (which is typically called from + // Launcher#onResumed, but in the predictive back flow launcher is not resumed until + // the transition is fully finished.) + AbstractFloatingView.closeAllOpenViewsExcept(mLauncher, false, TYPE_REBIND_SAFE); float cornerRadius = Utilities.mapRange( mBackProgress, mWindowScaleStartCornerRadius, mWindowScaleEndCornerRadius); Pair pair = diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java b/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java index fe31f1d8bb..51ae56b96d 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationCallbacks.java @@ -104,8 +104,7 @@ public class RecentsAnimationCallbacks implements .map(RemoteAnimationTargetCompat::unwrap) .toArray(RemoteAnimationTarget[]::new); - RemoteAnimationTarget[] nonAppTargets = - mSystemUiProxy.onGoingToRecentsLegacy(mCancelled, nonHomeApps); + RemoteAnimationTarget[] nonAppTargets = mSystemUiProxy.onGoingToRecentsLegacy(nonHomeApps); RecentsAnimationTargets targets = new RecentsAnimationTargets(appTargets, wallpaperTargets, RemoteAnimationTargetCompat.wrap(nonAppTargets), diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index 4a93eab5cf..b2f22731d3 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -680,14 +680,12 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI * Call this when going to recents so that shell can set-up and provide appropriate leashes * for animation (eg. DividerBar). * - * @param cancel true if recents starting is being cancelled. * @return RemoteAnimationTargets of windows that need to animate but only exist in shell. */ - public RemoteAnimationTarget[] onGoingToRecentsLegacy(boolean cancel, - RemoteAnimationTarget[] apps) { + public RemoteAnimationTarget[] onGoingToRecentsLegacy(RemoteAnimationTarget[] apps) { if (mSplitScreen != null) { try { - return mSplitScreen.onGoingToRecentsLegacy(cancel, apps); + return mSplitScreen.onGoingToRecentsLegacy(apps); } catch (RemoteException e) { Log.w(TAG, "Failed call onGoingToRecentsLegacy"); } @@ -695,6 +693,17 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI return null; } + public RemoteAnimationTarget[] onStartingSplitLegacy(RemoteAnimationTarget[] apps) { + if (mSplitScreen != null) { + try { + return mSplitScreen.onStartingSplitLegacy(apps); + } catch (RemoteException e) { + Log.w(TAG, "Failed call onStartingSplitLegacy"); + } + } + return null; + } + // // One handed // diff --git a/quickstep/src/com/android/quickstep/TaskAnimationManager.java b/quickstep/src/com/android/quickstep/TaskAnimationManager.java index f094d712a1..2565674763 100644 --- a/quickstep/src/com/android/quickstep/TaskAnimationManager.java +++ b/quickstep/src/com/android/quickstep/TaskAnimationManager.java @@ -177,8 +177,9 @@ public class TaskAnimationManager implements RecentsAnimationCallbacks.RecentsAn ((RecentsActivity) activityInterface.getCreatedActivity()).startHome(); return; } - RemoteAnimationTarget[] nonAppTargets = SystemUiProxy.INSTANCE.get(mCtx) - .onGoingToRecentsLegacy(false, nonHomeApps); + + RemoteAnimationTarget[] nonAppTargets = + SystemUiProxy.INSTANCE.getNoCreate().onStartingSplitLegacy(nonHomeApps); if (ENABLE_QUICKSTEP_LIVE_TILE.get() && activityInterface.isInLiveTileMode() && activityInterface.getCreatedActivity() != null) { diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 224c1f6c75..72f422128f 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -2704,13 +2704,6 @@ public abstract class RecentsView { - TransformParams params = remoteTargetHandle.getTransformParams(); - anim.setFloat(params, TransformParams.TARGET_ALPHA, 0, - clampToProgress(FINAL_FRAME, 0, 0.5f)); - }); - } anim.setFloat(taskView, VIEW_ALPHA, 0, clampToProgress(isOnGridBottomRow(taskView) ? ACCEL : FINAL_FRAME, 0, 0.5f)); FloatProperty secondaryViewTranslate = diff --git a/res/values-en-rAU/strings.xml b/res/values-en-rAU/strings.xml index f5aaf56a4c..62fa92d033 100644 --- a/res/values-en-rAU/strings.xml +++ b/res/values-en-rAU/strings.xml @@ -102,7 +102,7 @@ "Folder: %1$s, %2$d items" "Folder: %1$s, %2$d or more items" "Wallpapers" - "Wallpaper & style" + "Wallpaper and style" "Home settings" "Disabled by your admin" "Allow home screen rotation" diff --git a/res/values-en-rCA/strings.xml b/res/values-en-rCA/strings.xml index f5aaf56a4c..62fa92d033 100644 --- a/res/values-en-rCA/strings.xml +++ b/res/values-en-rCA/strings.xml @@ -102,7 +102,7 @@ "Folder: %1$s, %2$d items" "Folder: %1$s, %2$d or more items" "Wallpapers" - "Wallpaper & style" + "Wallpaper and style" "Home settings" "Disabled by your admin" "Allow home screen rotation" diff --git a/res/values-en-rGB/strings.xml b/res/values-en-rGB/strings.xml index f5aaf56a4c..62fa92d033 100644 --- a/res/values-en-rGB/strings.xml +++ b/res/values-en-rGB/strings.xml @@ -102,7 +102,7 @@ "Folder: %1$s, %2$d items" "Folder: %1$s, %2$d or more items" "Wallpapers" - "Wallpaper & style" + "Wallpaper and style" "Home settings" "Disabled by your admin" "Allow home screen rotation" diff --git a/res/values-en-rIN/strings.xml b/res/values-en-rIN/strings.xml index f5aaf56a4c..62fa92d033 100644 --- a/res/values-en-rIN/strings.xml +++ b/res/values-en-rIN/strings.xml @@ -102,7 +102,7 @@ "Folder: %1$s, %2$d items" "Folder: %1$s, %2$d or more items" "Wallpapers" - "Wallpaper & style" + "Wallpaper and style" "Home settings" "Disabled by your admin" "Allow home screen rotation" diff --git a/res/values-hy/strings.xml b/res/values-hy/strings.xml index 867fcb7823..e76ed7ec14 100644 --- a/res/values-hy/strings.xml +++ b/res/values-hy/strings.xml @@ -78,11 +78,11 @@ "Թաքցնել առաջարկը" "Ամրացնել առաջարկվող հավելվածը" "Դյուրանցումների տեղադրում" - "Ծրագրին թույլ է տալիս ավելացնել դյուրանցումներ՝ առանց օգտագործողի միջամտության:" + "Հավելվածին թույլ է տալիս ավելացնել դյուրանցումներ՝ առանց օգտագործողի միջամտության:" "կարդալ հիմնական էկրանի կարգավորումներն ու դյուրանցումները" - "Ծրագրին թույլ է տալիս կարդալ հիմնական էկրանի կարգավորումներն ու դյուրանցումները։" + "Հավելվածին թույլ է տալիս կարդալ հիմնական էկրանի կարգավորումներն ու դյուրանցումները։" "փոփոխել հիմնական էկրանի կարգավորումներն ու դյուրանցումները" - "Ծրագրին թույլ է տալիս փոփոխել հիմնական էկրանի կարգավորումներն ու դյուրանցումները։" + "Հավելվածին թույլ է տալիս փոփոխել հիմնական էկրանի կարգավորումներն ու դյուրանցումները։" "%1$s հավելվածին չի թույլատրվում հեռախոսազանգեր կատարել" "Չհաջողվեց բեռնել վիջեթը" "Վիջեթի կարգավորումներ" diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml index 281ca5aa07..ceca83c5eb 100644 --- a/res/values-pl/strings.xml +++ b/res/values-pl/strings.xml @@ -157,7 +157,7 @@ "Zamknij" "Zamknij" "Powiadomienie odrzucone" - "Prywatne" + "Osobiste" "Służbowe" "Profil służbowy" "Aplikacje służbowe mają plakietki i są widoczne dla administratora IT" diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 88030ae61f..561f9b937c 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -501,7 +501,7 @@ public class DeviceProfile { */ private int calculateQsbWidth() { if (isQsbInline) { - int columns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns; + int columns = getPanelCount() * inv.numColumns; return getIconToIconWidthForColumns(columns) - iconSizePx * numShownHotseatIcons - hotseatBorderSpace * numShownHotseatIcons; @@ -665,11 +665,10 @@ public class DeviceProfile { updateIconSize(1f, res); updateWorkspacePadding(); - Point workspacePadding = getTotalWorkspacePadding(); // Check to see if the icons fit within the available height. float usedHeight = getCellLayoutHeightSpecification(); - final int maxHeight = getWorkspaceHeight(workspacePadding); + final int maxHeight = getCellLayoutHeight(); float extraHeight = Math.max(0, maxHeight - usedHeight); float scaleY = maxHeight / usedHeight; boolean shouldScale = scaleY < 1f; @@ -702,7 +701,7 @@ public class DeviceProfile { } private int getCellLayoutWidthSpecification() { - int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns; + int numColumns = getPanelCount() * inv.numColumns; return (cellWidthPx * numColumns) + (cellLayoutBorderSpacePx.x * (numColumns - 1)) + cellLayoutPaddingPx.left + cellLayoutPaddingPx.right; } @@ -902,18 +901,20 @@ public class DeviceProfile { result = new Point(); } - // Since we are only concerned with the overall padding, layout direction does - // not matter. - Point padding = getTotalWorkspacePadding(); - - int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns; - int screenWidthPx = getWorkspaceWidth(padding); - result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacePx.x, numColumns); - int screenHeightPx = getWorkspaceHeight(padding); - result.y = calculateCellHeight(screenHeightPx, cellLayoutBorderSpacePx.y, inv.numRows); + result.x = calculateCellWidth(getShortcutAndWidgetContainerWidth(), + cellLayoutBorderSpacePx.x, inv.numColumns); + result.y = calculateCellHeight(getShortcutAndWidgetContainerHeight(), + cellLayoutBorderSpacePx.y, inv.numRows); return result; } + /** + * Gets the number of panels within the workspace. + */ + public int getPanelCount() { + return isTwoPanels ? 2 : 1; + } + /** * Gets the space in px from the bottom of last item in the vertical-bar hotseat to the * bottom of the screen. @@ -932,7 +933,7 @@ public class DeviceProfile { /** * Gets the scaled top of the workspace in px for the spring-loaded edit state. */ - public float getWorkspaceSpringLoadShrunkTop() { + public float getCellLayoutSpringLoadShrunkTop() { workspaceSpringLoadShrunkTop = mInsets.top + dropTargetBarTopMarginPx + dropTargetBarSizePx + dropTargetBarBottomMarginPx; return workspaceSpringLoadShrunkTop; @@ -941,7 +942,7 @@ public class DeviceProfile { /** * Gets the scaled bottom of the workspace in px for the spring-loaded edit state. */ - private float getWorkspaceSpringLoadShrunkBottom() { + private float getCellLayoutSpringLoadShrunkBottom() { int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx; workspaceSpringLoadShrunkBottom = heightPx - (isVerticalBarLayout() ? getVerticalHotseatLastItemBottomOffset() @@ -960,9 +961,8 @@ public class DeviceProfile { * Gets the scale of the workspace for the spring-loaded edit state. */ public float getWorkspaceSpringLoadScale() { - float cellLayoutHeight = availableHeightPx - workspacePadding.top - workspacePadding.bottom; - float scale = (getWorkspaceSpringLoadShrunkBottom() - getWorkspaceSpringLoadShrunkTop()) - / cellLayoutHeight; + float scale = (getCellLayoutSpringLoadShrunkBottom() - getCellLayoutSpringLoadShrunkTop()) + / getCellLayoutHeight(); scale = Math.min(scale, 1f); // Reduce scale if next pages would not be visible after scaling the workspace @@ -976,19 +976,55 @@ public class DeviceProfile { return scale; } + /** + * Gets the width of the Workspace, aka a scrollable page of the homescreen. + */ public int getWorkspaceWidth() { - return getWorkspaceWidth(getTotalWorkspacePadding()); + return availableWidthPx; } - public int getWorkspaceWidth(Point workspacePadding) { - int cellLayoutTotalPadding = - (isTwoPanels ? 2 : 1) * (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right); - return availableWidthPx - workspacePadding.x - cellLayoutTotalPadding; + /** + * Gets the height of the Workspace, aka a scrollable page of the homescreen. + */ + public int getWorkspaceHeight() { + return availableHeightPx; } - private int getWorkspaceHeight(Point workspacePadding) { - return availableHeightPx - workspacePadding.y - (cellLayoutPaddingPx.top - + cellLayoutPaddingPx.bottom); + /** + * Gets the width of a single Cell Layout, aka a single panel within a Workspace. + * + *

This is the width of a Workspace, less its horizontal padding. Note that two-panel + * layouts have two Cell Layouts per workspace. + */ + public int getCellLayoutWidth() { + return (getWorkspaceWidth() - getTotalWorkspacePadding().x) / getPanelCount(); + } + + /** + * Gets the height of a single Cell Layout, aka a single panel within a Workspace. + * + *

This is the height of a Workspace, less its vertical padding. + */ + public int getCellLayoutHeight() { + return getWorkspaceHeight() - getTotalWorkspacePadding().y; + } + + /** + * Gets the width of the container holding the shortcuts and widgets. + * + *

This is the width of one Cell Layout less its horizontal padding. + */ + public int getShortcutAndWidgetContainerWidth() { + return getCellLayoutWidth() - (cellLayoutPaddingPx.left + cellLayoutPaddingPx.right); + } + + /** + * Gets the height of the container holding the shortcuts and widgets. + * + *

This is the height of one Cell Layout less its vertical padding. + */ + public int getShortcutAndWidgetContainerHeight() { + return getCellLayoutHeight() - (cellLayoutPaddingPx.top + cellLayoutPaddingPx.bottom); } public Point getTotalWorkspacePadding() { diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 89b177165f..0373eefd09 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -61,6 +61,8 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; @@ -628,8 +630,21 @@ public class InvariantDeviceProfile { float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; - return getBestMatch(screenWidth, screenHeight, - WindowManagerProxy.INSTANCE.get(context).getRotation(context)); + int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context); + + if (Utilities.IS_DEBUG_DEVICE) { + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + DisplayController.INSTANCE.get(context).dump(printWriter); + printWriter.flush(); + Log.d("b/231312158", "getDeviceProfile -" + + "\nconfig: " + config + + "\ndisplayMetrics: " + res.getDisplayMetrics() + + "\nrotation: " + rotation + + "\n" + stringWriter.toString(), + new Exception()); + } + return getBestMatch(screenWidth, screenHeight, rotation); } /** diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 1c62ded7ab..2ad1d47128 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -182,7 +182,6 @@ import com.android.launcher3.util.ActivityTracker; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.OnboardingPrefs; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.PackageUserKey; @@ -2739,9 +2738,9 @@ public class Launcher extends StatefulActivity */ public View getFirstMatchForAppClose(int preferredItemId, String packageName, UserHandle user, boolean supportsAllAppsState) { - final ItemInfoMatcher preferredItem = (info, cn) -> + final Predicate preferredItem = info -> info != null && info.id == preferredItemId; - final ItemInfoMatcher packageAndUserAndApp = (info, cn) -> + final Predicate packageAndUserAndApp = info -> info != null && info.itemType == ITEM_TYPE_APPLICATION && info.user.equals(user) @@ -2770,8 +2769,8 @@ public class Launcher extends StatefulActivity * @param operators List of operators, in order starting from best matching operator. */ private static View getFirstMatch(Iterable containers, - final ItemInfoMatcher... operators) { - for (ItemInfoMatcher operator : operators) { + final Predicate... operators) { + for (Predicate operator : operators) { for (ViewGroup container : containers) { View match = mapOverViewGroup(container, operator); if (match != null) { @@ -2786,11 +2785,11 @@ public class Launcher extends StatefulActivity * Returns the first view matching the operator in the given ViewGroups, or null if none. * Forward iteration matters. */ - private static View mapOverViewGroup(ViewGroup container, ItemInfoMatcher op) { + private static View mapOverViewGroup(ViewGroup container, Predicate op) { final int itemCount = container.getChildCount(); for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { View item = container.getChildAt(itemIdx); - if (op.matchesInfo((ItemInfo) item.getTag())) { + if (op.test((ItemInfo) item.getTag())) { return item; } } @@ -2887,7 +2886,7 @@ public class Launcher extends StatefulActivity * package-removal should clear all items by package name. */ @Override - public void bindWorkspaceComponentsRemoved(final ItemInfoMatcher matcher) { + public void bindWorkspaceComponentsRemoved(Predicate matcher) { mWorkspace.removeItemsByMatcher(matcher); mDragController.onAppsRemoved(matcher); PopupContainerWithArrow.dismissInvalidPopup(this); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 836d4b8fc8..fb028b9862 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -102,7 +102,6 @@ import com.android.launcher3.util.Executors; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.IntSparseArrayMap; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.LauncherBindableItemsContainer; import com.android.launcher3.util.OverlayEdgeEffect; import com.android.launcher3.util.PackageUserKey; @@ -3235,7 +3234,7 @@ public class Workspace extends PagedView * as a part of an update, this is called to ensure that other widgets and application * shortcuts are not removed. */ - public void removeItemsByMatcher(final ItemInfoMatcher matcher) { + public void removeItemsByMatcher(final Predicate matcher) { for (CellLayout layout : getWorkspaceAndHotseatCellLayouts()) { ShortcutAndWidgetContainer container = layout.getShortcutsAndWidgets(); // Iterate in reverse order as we are removing items @@ -3243,7 +3242,7 @@ public class Workspace extends PagedView View child = container.getChildAt(i); ItemInfo info = (ItemInfo) child.getTag(); - if (matcher.matchesInfo(info)) { + if (matcher.test(info)) { layout.removeViewInLayout(child); if (child instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) child); @@ -3251,7 +3250,7 @@ public class Workspace extends PagedView } else if (child instanceof FolderIcon) { FolderInfo folderInfo = (FolderInfo) info; List matches = folderInfo.contents.stream() - .filter(matcher::matchesInfo) + .filter(matcher) .collect(Collectors.toList()); if (!matches.isEmpty()) { folderInfo.removeAll(matches, false); @@ -3330,7 +3329,7 @@ public class Workspace extends PagedView * * @param matcher the matcher generated by the caller. */ - public void persistRemoveItemsByMatcher(ItemInfoMatcher matcher) { + public void persistRemoveItemsByMatcher(Predicate matcher) { mLauncher.getModelWriter().deleteItemsFromDatabase(matcher); removeItemsByMatcher(matcher); } diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java index 2a16210861..cdaf80a804 100644 --- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java +++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java @@ -21,17 +21,18 @@ import android.content.Context; import com.android.launcher3.allapps.BaseAllAppsAdapter.AdapterItem; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; -import com.android.launcher3.util.ItemInfoMatcher; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.util.LabelComparator; import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Locale; -import java.util.Map; import java.util.Objects; import java.util.TreeMap; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * The alphabetically sorted list of applications. @@ -82,7 +83,7 @@ public class AlphabeticalAppsList implement private AppInfoComparator mAppNameComparator; private final int mNumAppsPerRowAllApps; private int mNumAppRowsInAdapter; - private ItemInfoMatcher mItemFilter; + private Predicate mItemFilter; public AlphabeticalAppsList(Context context, AllAppsStore appsStore, WorkAdapterProvider adapterProvider) { @@ -94,7 +95,7 @@ public class AlphabeticalAppsList implement mAllAppsStore.addUpdateListener(this); } - public void updateItemFilter(ItemInfoMatcher itemFilter) { + public void updateItemFilter(Predicate itemFilter) { this.mItemFilter = itemFilter; onAppsUpdated(); } @@ -200,13 +201,11 @@ public class AlphabeticalAppsList implement // Sort the list of apps mApps.clear(); - for (AppInfo app : mAllAppsStore.getApps()) { - if (mItemFilter == null || mItemFilter.matches(app, null) || hasFilter()) { - mApps.add(app); - } + Stream appSteam = Stream.of(mAllAppsStore.getApps()); + if (!hasFilter() && mItemFilter != null) { + appSteam = appSteam.filter(mItemFilter); } - - Collections.sort(mApps, mAppNameComparator); + appSteam = appSteam.sorted(mAppNameComparator); // As a special case for some languages (currently only Simplified Chinese), we may need to // coalesce sections @@ -215,27 +214,16 @@ public class AlphabeticalAppsList implement if (localeRequiresSectionSorting) { // Compute the section headers. We use a TreeMap with the section name comparator to // ensure that the sections are ordered when we iterate over it later - TreeMap> sectionMap = new TreeMap<>(new LabelComparator()); - for (AppInfo info : mApps) { - // Add the section to the cache - String sectionName = info.sectionName; - - // Add it to the mapping - ArrayList sectionApps = sectionMap.get(sectionName); - if (sectionApps == null) { - sectionApps = new ArrayList<>(); - sectionMap.put(sectionName, sectionApps); - } - sectionApps.add(info); - } - - // Add each of the section apps to the list in order - mApps.clear(); - for (Map.Entry> entry : sectionMap.entrySet()) { - mApps.addAll(entry.getValue()); - } + appSteam = appSteam.collect(Collectors.groupingBy( + info -> info.sectionName, + () -> new TreeMap<>(new LabelComparator()), + Collectors.toCollection(ArrayList::new))) + .values() + .stream() + .flatMap(ArrayList::stream); } + appSteam.forEachOrdered(mApps::add); // Recompose the set of adapter items from the current set of apps if (mSearchResults.isEmpty()) { updateAdapterItems(); diff --git a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java index f913aa9093..891fe8f53c 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsContainerView.java @@ -58,7 +58,7 @@ import com.android.launcher3.Utilities; import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.keyboard.FocusedItemDecorator; import com.android.launcher3.model.StringCache; -import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.Themes; import com.android.launcher3.views.ActivityContext; @@ -69,6 +69,8 @@ import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.OnActivePag import java.util.Arrays; import java.util.List; +import java.util.function.Predicate; +import java.util.stream.Stream; /** * Base all apps view container. @@ -91,7 +93,7 @@ public abstract class BaseAllAppsContainerView mAH; - protected final ItemInfoMatcher mPersonalMatcher = ItemInfoMatcher.ofUser( + protected final Predicate mPersonalMatcher = ItemInfoMatcher.ofUser( Process.myUserHandle()); private final SearchAdapterProvider mMainAdapterProvider; private final AllAppsStore mAllAppsStore = new AllAppsStore(); @@ -229,17 +231,10 @@ public abstract class BaseAllAppsContainerView matcher) { mAppsList.updateItemFilter(matcher); mRecyclerView = (AllAppsRecyclerView) rv; mRecyclerView.setEdgeEffectFactory(createEdgeEffectFactory()); diff --git a/src/com/android/launcher3/allapps/WorkProfileManager.java b/src/com/android/launcher3/allapps/WorkProfileManager.java index 6203cead2d..c5b02dd1f5 100644 --- a/src/com/android/launcher3/allapps/WorkProfileManager.java +++ b/src/com/android/launcher3/allapps/WorkProfileManager.java @@ -27,7 +27,6 @@ import android.os.UserHandle; import android.os.UserManager; import android.util.Log; import android.view.ViewGroup; -import android.view.WindowInsets; import androidx.annotation.IntDef; import androidx.annotation.Nullable; @@ -35,11 +34,12 @@ import androidx.annotation.RequiresApi; import com.android.launcher3.R; import com.android.launcher3.config.FeatureFlags; -import com.android.launcher3.util.ItemInfoMatcher; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.function.Predicate; /** * Companion class for {@link BaseAllAppsContainerView} to manage work tab and personal tab @@ -70,7 +70,7 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP private final BaseAllAppsContainerView mAllApps; private final WorkAdapterProvider mAdapterProvider; - private final ItemInfoMatcher mMatcher; + private final Predicate mMatcher; private WorkModeSwitch mWorkModeSwitch; @@ -176,7 +176,7 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP return mAdapterProvider; } - public ItemInfoMatcher getMatcher() { + public Predicate getMatcher() { return mMatcher; } diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index fdb27998de..35cdfef465 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -18,7 +18,6 @@ package com.android.launcher3.dragndrop; import static com.android.launcher3.Utilities.ATLEAST_Q; -import android.content.ComponentName; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -36,12 +35,12 @@ import com.android.launcher3.logging.InstanceId; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.testing.TestProtocol; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.TouchController; import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; import java.util.Optional; +import java.util.function.Predicate; /** * Class for initiating a drag within a view or across multiple views. @@ -275,15 +274,12 @@ public abstract class DragController protected abstract void exitDrag(); - public void onAppsRemoved(ItemInfoMatcher matcher) { + public void onAppsRemoved(Predicate matcher) { // Cancel the current drag if we are removing an app that we are dragging if (mDragObject != null) { ItemInfo dragInfo = mDragObject.dragInfo; - if (dragInfo instanceof WorkspaceItemInfo) { - ComponentName cn = dragInfo.getTargetComponent(); - if (cn != null && matcher.matches(dragInfo, cn)) { - cancelDrag(); - } + if (dragInfo instanceof WorkspaceItemInfo && matcher.test(dragInfo)) { + cancelDrag(); } } } diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java index b8c9762c24..4875d83942 100644 --- a/src/com/android/launcher3/model/AllAppsList.java +++ b/src/com/android/launcher3/model/AllAppsList.java @@ -36,9 +36,9 @@ import com.android.launcher3.compat.AlphabeticIndexCompat; import com.android.launcher3.icons.IconCache; import com.android.launcher3.model.BgDataModel.Callbacks; import com.android.launcher3.model.data.AppInfo; +import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.pm.PackageInstallInfo; import com.android.launcher3.util.FlagOp; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.SafeCloseable; @@ -47,6 +47,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.function.Consumer; +import java.util.function.Predicate; /** @@ -257,11 +258,11 @@ public class AllAppsList { /** * Updates the disabled flags of apps matching {@param matcher} based on {@param op}. */ - public void updateDisabledFlags(ItemInfoMatcher matcher, FlagOp op) { + public void updateDisabledFlags(Predicate matcher, FlagOp op) { final List data = this.data; for (int i = data.size() - 1; i >= 0; i--) { AppInfo info = data.get(i); - if (matcher.matches(info, info.componentName)) { + if (matcher.test(info)) { info.runtimeStatusFlags = op.apply(info.runtimeStatusFlags); mDataChanged = true; } diff --git a/src/com/android/launcher3/model/BaseModelUpdateTask.java b/src/com/android/launcher3/model/BaseModelUpdateTask.java index a3a471775c..832c1dd166 100644 --- a/src/com/android/launcher3/model/BaseModelUpdateTask.java +++ b/src/com/android/launcher3/model/BaseModelUpdateTask.java @@ -27,7 +27,6 @@ import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; import com.android.launcher3.util.ComponentKey; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.widget.model.WidgetsListBaseEntry; import java.util.ArrayList; @@ -35,6 +34,7 @@ import java.util.HashMap; import java.util.List; import java.util.Objects; import java.util.concurrent.Executor; +import java.util.function.Predicate; import java.util.stream.Collectors; /** @@ -128,7 +128,7 @@ public abstract class BaseModelUpdateTask implements ModelUpdateTask { scheduleCallbackTask(c -> c.bindAllWidgets(widgets)); } - public void deleteAndBindComponentsRemoved(final ItemInfoMatcher matcher) { + public void deleteAndBindComponentsRemoved(final Predicate matcher) { getModelWriter().deleteItemsFromDatabase(matcher); // Call the components-removed callback diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index 866d18a86b..d52537e074 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -50,7 +50,6 @@ import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.IntSet; import com.android.launcher3.util.IntSparseArrayMap; -import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.RunnableList; import com.android.launcher3.widget.model.WidgetsListBaseEntry; @@ -66,6 +65,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -495,7 +495,7 @@ public class BgDataModel { default void bindWorkspaceItemsChanged(List updated) { } default void bindWidgetsRestored(ArrayList widgets) { } default void bindRestoreItemsChange(HashSet updates) { } - default void bindWorkspaceComponentsRemoved(ItemInfoMatcher matcher) { } + default void bindWorkspaceComponentsRemoved(Predicate matcher) { } default void bindAllWidgets(List widgets) { } default void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks) { diff --git a/src/com/android/launcher3/model/ModelWriter.java b/src/com/android/launcher3/model/ModelWriter.java index 94e06d16ce..015abe94bc 100644 --- a/src/com/android/launcher3/model/ModelWriter.java +++ b/src/com/android/launcher3/model/ModelWriter.java @@ -53,6 +53,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -278,10 +279,9 @@ public class ModelWriter { /** * Removes all the items from the database matching {@param matcher}. */ - public void deleteItemsFromDatabase(ItemInfoMatcher matcher) { + public void deleteItemsFromDatabase(Predicate matcher) { deleteItemsFromDatabase(StreamSupport.stream(mBgDataModel.itemsIdMap.spliterator(), false) - .filter(matcher::matchesInfo) - .collect(Collectors.toList())); + .filter(matcher).collect(Collectors.toList())); } /** diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index d47edff223..239dd4565a 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -57,6 +57,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.function.Predicate; /** * Handles updates due to changes in package manager (app installed/updated/removed) @@ -95,7 +96,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { final int N = packages.length; final FlagOp flagOp; final HashSet packageSet = new HashSet<>(Arrays.asList(packages)); - final ItemInfoMatcher matcher = mOp == OP_USER_AVAILABILITY_CHANGE + final Predicate matcher = mOp == OP_USER_AVAILABILITY_CHANGE ? ItemInfoMatcher.ofUser(mUser) // We want to update all packages for this user : ItemInfoMatcher.ofPackages(packageSet, mUser); final HashSet removedComponents = new HashSet<>(); @@ -206,7 +207,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { } ComponentName cn = si.getTargetComponent(); - if (cn != null && matcher.matches(si, cn)) { + if (cn != null && matcher.test(si)) { String packageName = cn.getPackageName(); if (si.hasStatusFlag(WorkspaceItemInfo.FLAG_SUPPORTS_WEB_UI)) { @@ -336,7 +337,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { } if (!removedPackages.isEmpty() || !removedComponents.isEmpty()) { - ItemInfoMatcher removeMatch = ItemInfoMatcher.ofPackages(removedPackages, mUser) + Predicate removeMatch = ItemInfoMatcher.ofPackages(removedPackages, mUser) .or(ItemInfoMatcher.ofComponents(removedComponents, mUser)) .and(ItemInfoMatcher.ofItemIds(forceKeepShortcuts).negate()); deleteAndBindComponentsRemoved(removeMatch); diff --git a/src/com/android/launcher3/states/SpringLoadedState.java b/src/com/android/launcher3/states/SpringLoadedState.java index 15cdc20cef..a205ab55ca 100644 --- a/src/com/android/launcher3/states/SpringLoadedState.java +++ b/src/com/android/launcher3/states/SpringLoadedState.java @@ -51,7 +51,7 @@ public class SpringLoadedState extends LauncherState { return super.getWorkspaceScaleAndTranslation(launcher); } - float shrunkTop = grid.getWorkspaceSpringLoadShrunkTop(); + float shrunkTop = grid.getCellLayoutSpringLoadShrunkTop(); float scale = grid.getWorkspaceSpringLoadScale(); float halfHeight = ws.getHeight() / 2; diff --git a/src/com/android/launcher3/util/ItemInfoMatcher.java b/src/com/android/launcher3/util/ItemInfoMatcher.java index 7917410b3b..b6af3140fa 100644 --- a/src/com/android/launcher3/util/ItemInfoMatcher.java +++ b/src/com/android/launcher3/util/ItemInfoMatcher.java @@ -19,6 +19,8 @@ package com.android.launcher3.util; import android.content.ComponentName; import android.os.UserHandle; +import androidx.annotation.NonNull; + import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; @@ -27,90 +29,64 @@ import com.android.launcher3.shortcuts.ShortcutKey; import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.function.Predicate; /** * A utility class to check for {@link ItemInfo} */ -public interface ItemInfoMatcher { +public abstract class ItemInfoMatcher { /** * Empty component used for match testing */ - ComponentName EMPTY_COMPONENT = new ComponentName("", ""); + private static final ComponentName EMPTY_COMPONENT = new ComponentName("", ""); - boolean matches(ItemInfo info, ComponentName cn); - - /** - * Returns true if the itemInfo matches this check - */ - default boolean matchesInfo(ItemInfo info) { - if (info != null) { - ComponentName cn = info.getTargetComponent(); - return matches(info, cn != null ? cn : EMPTY_COMPONENT); - } else { - return false; - } + public static Predicate ofUser(UserHandle user) { + return info -> info != null && info.user.equals(user); } - /** - * Returns a new matcher with returns true if either this or {@param matcher} returns true. - */ - default ItemInfoMatcher or(ItemInfoMatcher matcher) { - return (info, cn) -> matches(info, cn) || matcher.matches(info, cn); + public static Predicate ofComponents( + HashSet components, UserHandle user) { + return info -> info != null && info.user.equals(user) + && components.contains(getNonNullComponent(info)); } - /** - * Returns a new matcher with returns true if both this and {@param matcher} returns true. - */ - default ItemInfoMatcher and(ItemInfoMatcher matcher) { - return (info, cn) -> matches(info, cn) && matcher.matches(info, cn); + public static Predicate ofPackages(Set packageNames, UserHandle user) { + return info -> info != null && info.user.equals(user) + && packageNames.contains(getNonNullComponent(info).getPackageName()); } - /** - * Returns a new matcher with returns the opposite value of this. - */ - default ItemInfoMatcher negate() { - return (info, cn) -> !matches(info, cn); - } - - static ItemInfoMatcher ofUser(UserHandle user) { - return (info, cn) -> info.user.equals(user); - } - - static ItemInfoMatcher ofComponents(HashSet components, UserHandle user) { - return (info, cn) -> components.contains(cn) && info.user.equals(user); - } - - static ItemInfoMatcher ofPackages(Set packageNames, UserHandle user) { - return (info, cn) -> packageNames.contains(cn.getPackageName()) && info.user.equals(user); - } - - static ItemInfoMatcher ofShortcutKeys(Set keys) { - return (info, cn) -> info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT + public static Predicate ofShortcutKeys(Set keys) { + return info -> info != null && info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT && keys.contains(ShortcutKey.fromItemInfo(info)); } /** * Returns a matcher for items within folders. */ - static ItemInfoMatcher forFolderMatch(ItemInfoMatcher childOperator) { - return (info, cn) -> info instanceof FolderInfo && ((FolderInfo) info).contents.stream() - .anyMatch(childOperator::matchesInfo); + public static Predicate forFolderMatch(Predicate childOperator) { + return info -> info instanceof FolderInfo && ((FolderInfo) info).contents.stream() + .anyMatch(childOperator); } /** * Returns a matcher for items with provided ids */ - static ItemInfoMatcher ofItemIds(IntSet ids) { - return (info, cn) -> ids.contains(info.id); + public static Predicate ofItemIds(IntSet ids) { + return info -> info != null && ids.contains(info.id); } /** * Returns a matcher for items with provided items */ - static ItemInfoMatcher ofItems(Collection items) { + public static Predicate ofItems(Collection items) { IntSet ids = new IntSet(); items.forEach(item -> ids.add(item.id)); return ofItemIds(ids); } + + private static ComponentName getNonNullComponent(@NonNull ItemInfo info) { + ComponentName cn = info.getTargetComponent(); + return cn != null ? cn : EMPTY_COMPONENT; + } } diff --git a/tests/src/com/android/launcher3/DeviceProfileGridDimensionsTest.kt b/tests/src/com/android/launcher3/DeviceProfileGridDimensionsTest.kt new file mode 100644 index 0000000000..63abc7d650 --- /dev/null +++ b/tests/src/com/android/launcher3/DeviceProfileGridDimensionsTest.kt @@ -0,0 +1,258 @@ +/* + * Copyright (C) 2022 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.graphics.PointF +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.launcher3.util.WindowBounds +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers +import org.mockito.Mockito.`when` as whenever + +/** + * Test for [DeviceProfile] grid dimensions. + * + * This includes workspace, cell layout, shortcut and widget container, cell sizes, etc. + */ +@SmallTest +@RunWith(AndroidJUnit4::class) +class DeviceProfileGridDimensionsTest : DeviceProfileBaseTest() { + + @Test + fun getWorkspaceWidth_twoPanelLandscapeScalable4By4GridTablet_workspaceWidthIsFullPage() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceWidth = availableWidth + assertThat(dp.workspaceWidth).isEqualTo(expectedWorkspaceWidth) + } + + @Test + fun getWorkspaceHeight_twoPanelLandscapeScalable4By4GridTablet_workspaceHeightIsFullPage() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceHeight = availableHeight + assertThat(dp.workspaceHeight).isEqualTo(expectedWorkspaceHeight) + } + + @Test + fun getCellLayoutWidth_twoPanelLandscapeScalable4By4GridTablet_equalsSinglePanelWidth() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceWidth = availableWidth + val expectedCellLayoutWidth = + (expectedWorkspaceWidth - (dp.workspacePadding.right + dp.workspacePadding.left)) / + dp.panelCount + assertThat(dp.cellLayoutWidth).isEqualTo(expectedCellLayoutWidth) + } + + @Test + fun getCellLayoutHeight_twoPanelLandscapeScalable4By4GridTablet_equalsSinglePanelHeight() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceHeight = availableHeight + val expectedCellLayoutHeight = + expectedWorkspaceHeight - (dp.workspacePadding.top + dp.workspacePadding.bottom) + assertThat(dp.cellLayoutHeight).isEqualTo(expectedCellLayoutHeight) + } + + @Test + fun getShortcutAndWidgetContainerWidth_twoPanelLandscapeScalable4By4GridTablet_equalsIconsPlusBorderSpacesWidth() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceWidth = availableWidth + val expectedCellLayoutWidth = + (expectedWorkspaceWidth - (dp.workspacePadding.right + dp.workspacePadding.left)) / + dp.panelCount + val expectedShortcutAndWidgetContainerWidth = expectedCellLayoutWidth - + (dp.cellLayoutPaddingPx.left + dp.cellLayoutPaddingPx.right) + assertThat(dp.shortcutAndWidgetContainerWidth).isEqualTo(expectedShortcutAndWidgetContainerWidth) + } + + @Test + fun getShortcutAndWidgetContainerHeight_twoPanelLandscapeScalable4By4GridTablet_equalsIconsPlusBorderSpacesHeight() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceHeight = availableHeight + val expectedCellLayoutHeight = + expectedWorkspaceHeight - (dp.workspacePadding.top + dp.workspacePadding.bottom) + val expectedShortcutAndWidgetContainerHeight = expectedCellLayoutHeight - + (dp.cellLayoutPaddingPx.top + dp.cellLayoutPaddingPx.bottom) + assertThat(dp.shortcutAndWidgetContainerHeight).isEqualTo( + expectedShortcutAndWidgetContainerHeight) + } + + @Test + fun getCellSize_twoPanelLandscapeScalable4By4GridTablet_equalsSinglePanelWidth() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + val expectedWorkspaceWidth = availableWidth + val expectedCellLayoutWidth = + (expectedWorkspaceWidth - (dp.workspacePadding.right + dp.workspacePadding.left)) / + dp.panelCount + val expectedShortcutAndWidgetContainerWidth = + expectedCellLayoutWidth - + (dp.cellLayoutPaddingPx.left + dp.cellLayoutPaddingPx.right) + assertThat(dp.getCellSize().x).isEqualTo( + (expectedShortcutAndWidgetContainerWidth - + ((inv!!.numColumns - 1) * dp.cellLayoutBorderSpacePx.x)) / inv!!.numColumns) + val expectedWorkspaceHeight = availableHeight + val expectedCellLayoutHeight = + expectedWorkspaceHeight - (dp.workspacePadding.top + dp.workspacePadding.bottom) + val expectedShortcutAndWidgetContainerHeight = expectedCellLayoutHeight - + (dp.cellLayoutPaddingPx.top + dp.cellLayoutPaddingPx.bottom) + assertThat(dp.getCellSize().y).isEqualTo( + (expectedShortcutAndWidgetContainerHeight - + ((inv!!.numRows - 1) * dp.cellLayoutBorderSpacePx.y)) / inv!!.numRows) + } + + @Test + fun getPanelCount_twoPanelLandscapeScalable4By4GridTablet_equalsTwoPanels() { + val tabletWidth = 2560 + val tabletHeight = 1600 + val availableWidth = 2560 + val availableHeight = 1500 + windowBounds = WindowBounds(tabletWidth, tabletHeight, availableWidth, availableHeight, 0) + useTwoPanels = true + whenever(info.isTablet(ArgumentMatchers.any())).thenReturn(true) + whenever(info.getDensityDpi()).thenReturn(320) + inv = getScalable4By4InvariantDeviceProfile() + + val dp = newDP() + + assertThat(dp.panelCount).isEqualTo(2) + } + + fun getScalable4By4InvariantDeviceProfile(): InvariantDeviceProfile { + return InvariantDeviceProfile().apply { + isScalable = true + numColumns = 4 + numRows = 4 + numShownHotseatIcons = 4 + numDatabaseHotseatIcons = 6 + numShrunkenHotseatIcons = 5 + horizontalMargin = FloatArray(4) { 22f } + borderSpaces = listOf( + PointF(16f, 16f), + PointF(16f, 16f), + PointF(16f, 16f), + PointF(16f, 16f) + ).toTypedArray() + allAppsBorderSpaces = listOf( + PointF(16f, 16f), + PointF(16f, 16f), + PointF(16f, 16f), + PointF(16f, 16f) + ).toTypedArray() + hotseatBorderSpaces = FloatArray(4) { 16f } + hotseatColumnSpan = IntArray(4) { 4 } + iconSize = FloatArray(4) { 56f } + allAppsIconSize = FloatArray(4) { 56f } + iconTextSize = FloatArray(4) { 14f } + allAppsIconTextSize = FloatArray(4) { 14f } + minCellSize = listOf( + PointF(64f, 83f), + PointF(64f, 83f), + PointF(64f, 83f), + PointF(64f, 83f) + ).toTypedArray() + allAppsCellSize = listOf( + PointF(64f, 83f), + PointF(64f, 83f), + PointF(64f, 83f), + PointF(64f, 83f) + ).toTypedArray() + inlineQsb = booleanArrayOf( + false, + false, + false, + false + ) + } + } +} \ No newline at end of file