summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/AppWidgetResizeFrame.java14
-rw-r--r--src/com/android/launcher3/BubbleTextView.java6
-rw-r--r--src/com/android/launcher3/DeviceProfile.java48
-rw-r--r--src/com/android/launcher3/Launcher.java12
-rw-r--r--src/com/android/launcher3/LauncherModel.kt60
-rw-r--r--src/com/android/launcher3/LauncherProvider.java72
-rw-r--r--src/com/android/launcher3/Utilities.java7
-rw-r--r--src/com/android/launcher3/Workspace.java37
-rw-r--r--src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java37
-rw-r--r--src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java29
-rw-r--r--src/com/android/launcher3/allapps/AllAppsTransitionController.java3
-rw-r--r--src/com/android/launcher3/allapps/AlphabeticalAppsList.java4
-rw-r--r--src/com/android/launcher3/allapps/PrivateProfileManager.java7
-rw-r--r--src/com/android/launcher3/dagger/LauncherBaseAppComponent.java3
-rw-r--r--src/com/android/launcher3/debug/TestEventEmitter.java4
-rw-r--r--src/com/android/launcher3/dot/FolderDotInfo.java13
-rw-r--r--src/com/android/launcher3/dragndrop/DragController.java18
-rw-r--r--src/com/android/launcher3/dragndrop/LauncherDragController.java43
-rw-r--r--src/com/android/launcher3/folder/Folder.java173
-rw-r--r--src/com/android/launcher3/folder/FolderIcon.java107
-rw-r--r--src/com/android/launcher3/folder/FolderPagedView.java3
-rw-r--r--src/com/android/launcher3/graphics/GridCustomizationsProxy.java14
-rw-r--r--src/com/android/launcher3/graphics/LauncherPreviewRenderer.java6
-rw-r--r--src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java67
-rw-r--r--src/com/android/launcher3/graphics/ShapeDelegate.kt88
-rw-r--r--src/com/android/launcher3/logging/StatsLogManager.java3
-rw-r--r--src/com/android/launcher3/model/AddWorkspaceItemsTask.java13
-rw-r--r--src/com/android/launcher3/model/AllAppsList.java10
-rw-r--r--src/com/android/launcher3/model/BaseLauncherBinder.java73
-rw-r--r--src/com/android/launcher3/model/BgDataModel.java14
-rw-r--r--src/com/android/launcher3/model/CacheDataUpdatedTask.java2
-rw-r--r--src/com/android/launcher3/model/FirstScreenBroadcast.java6
-rw-r--r--src/com/android/launcher3/model/LoaderCursor.java47
-rw-r--r--src/com/android/launcher3/model/LoaderTask.java175
-rw-r--r--src/com/android/launcher3/model/ModelDbController.java99
-rw-r--r--src/com/android/launcher3/model/ModelLauncherCallbacks.kt4
-rw-r--r--src/com/android/launcher3/model/ModelTaskController.kt21
-rw-r--r--src/com/android/launcher3/model/ModelWriter.java15
-rw-r--r--src/com/android/launcher3/model/PackageInstallStateChangedTask.java4
-rw-r--r--src/com/android/launcher3/model/PackageUpdatedTask.java8
-rw-r--r--src/com/android/launcher3/model/SdCardAvailableReceiver.java8
-rw-r--r--src/com/android/launcher3/model/SessionFailureTask.kt4
-rw-r--r--src/com/android/launcher3/model/ShortcutsChangedTask.kt5
-rw-r--r--src/com/android/launcher3/model/UserLockStateChangedTask.java6
-rw-r--r--src/com/android/launcher3/model/WidgetsModel.java70
-rw-r--r--src/com/android/launcher3/model/WorkspaceItemProcessor.kt24
-rw-r--r--src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java35
-rw-r--r--src/com/android/launcher3/model/data/FolderInfo.java106
-rw-r--r--src/com/android/launcher3/model/data/ItemInfo.java9
-rw-r--r--src/com/android/launcher3/pageindicators/PageIndicator.java10
-rw-r--r--src/com/android/launcher3/pageindicators/PageIndicatorArrowClickListener.kt26
-rw-r--r--src/com/android/launcher3/pageindicators/PageIndicatorDots.java198
-rw-r--r--src/com/android/launcher3/popup/PopupContainerWithArrow.java9
-rw-r--r--src/com/android/launcher3/popup/PopupDataProvider.java7
-rw-r--r--src/com/android/launcher3/provider/LauncherDbUtils.kt7
-rw-r--r--src/com/android/launcher3/provider/RestoreDbTask.java9
-rw-r--r--src/com/android/launcher3/touch/AllAppsSwipeController.java26
-rw-r--r--src/com/android/launcher3/touch/WorkspaceTouchListener.java2
-rw-r--r--src/com/android/launcher3/util/ContentWriter.java3
-rw-r--r--src/com/android/launcher3/util/ItemInflater.kt10
-rw-r--r--src/com/android/launcher3/util/SimpleBroadcastReceiver.java26
-rw-r--r--src/com/android/launcher3/views/OptionsPopupView.java20
-rw-r--r--src/com/android/launcher3/views/ScrimView.java3
-rw-r--r--src/com/android/launcher3/widget/WidgetInflater.kt16
-rw-r--r--src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java8
65 files changed, 1169 insertions, 847 deletions
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index b51e850c04..213d88f852 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -216,6 +216,13 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
AppWidgetResizeFrame frame = (AppWidgetResizeFrame) launcher.getLayoutInflater()
.inflate(R.layout.app_widget_resize_frame, dl, false);
frame.setupForWidget(widget, cellLayout, dl);
+ // Save widget item info as tag on resize frame; so that, the accessibility delegate can
+ // attach actions that typically happen on widget (e.g. resize, move) also on the resize
+ // frame.
+ frame.setTag(widget.getTag());
+ frame.setAccessibilityDelegate(launcher.getAccessibilityDelegate());
+ frame.setContentDescription(launcher.asContext().getString(R.string.widget_frame_name,
+ widget.getContentDescription()));
((DragLayer.LayoutParams) frame.getLayoutParams()).customPosition = true;
dl.addView(frame);
@@ -235,6 +242,13 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
}
}
+ /**
+ * Retrieves the view where accessibility actions happen.
+ */
+ public View getViewForAccessibility() {
+ return mWidgetView;
+ }
+
private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout,
DragLayer dragLayer) {
mCellLayout = cellLayout;
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 783e82cae9..30e3a2b577 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -26,6 +26,7 @@ import static com.android.launcher3.BubbleTextView.RunningAppState.NOT_RUNNING;
import static com.android.launcher3.BubbleTextView.RunningAppState.MINIMIZED;
import static com.android.launcher3.Flags.enableContrastTiles;
import static com.android.launcher3.Flags.enableCursorHoverStates;
+import static com.android.launcher3.allapps.AlphabeticalAppsList.PRIVATE_SPACE_PACKAGE;
import static com.android.launcher3.graphics.PreloadIconDrawable.newPendingIcon;
import static com.android.launcher3.icons.BitmapInfo.FLAG_NO_BADGE;
import static com.android.launcher3.icons.BitmapInfo.FLAG_SKIP_USER_BADGE;
@@ -104,6 +105,7 @@ import com.android.launcher3.views.FloatingIconViewCompanion;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Locale;
+import java.util.Objects;
/**
* TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
@@ -589,7 +591,9 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
}
private void setNonPendingIcon(ItemInfoWithIcon info) {
- int flags = shouldUseTheme() ? FLAG_THEMED : info.bitmap.creationFlags;
+ // Set nonPendingIcon acts as a restart which should refresh the flag state when applicable.
+ int flags = Objects.equals(info.getTargetPackage(), PRIVATE_SPACE_PACKAGE)
+ ? info.bitmap.creationFlags : shouldUseTheme() ? FLAG_THEMED : 0;
// Remove badge on icons smaller than 48dp.
if (mHideBadge || mDisplay == DISPLAY_SEARCH_RESULT_SMALL) {
flags |= FLAG_NO_BADGE;
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index c85ca49c43..090208a33c 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -30,8 +30,8 @@ import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURC
import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
import static com.android.wm.shell.Flags.enableBubbleBar;
-import static com.android.wm.shell.Flags.enableTinyTaskbar;
import static com.android.wm.shell.Flags.enableBubbleBarOnPhones;
+import static com.android.wm.shell.Flags.enableTinyTaskbar;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -508,9 +508,11 @@ public class DeviceProfile {
bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
bottomSheetCloseDuration = res.getInteger(R.integer.config_bottomSheetCloseDuration);
- if (isTablet) {
+ if (shouldShowAllAppsOnSheet()) {
bottomSheetWorkspaceScale = workspaceContentScale;
- if (isMultiDisplay) {
+ if (Flags.allAppsBlur()) {
+ bottomSheetDepth = 2f;
+ } else if (isMultiDisplay) {
// TODO(b/259893832): Revert to use maxWallpaperScale to calculate bottomSheetDepth
// when screen recorder bug is fixed.
if (enableScalingRevealHomeAnimation()) {
@@ -1830,10 +1832,17 @@ public class DeviceProfile {
workspacePageIndicatorHeight - mWorkspacePageIndicatorOverlapWorkspace;
}
int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx);
- // On isFixedLandscapeMode on phones we already have padding because of the camera hole
- int paddingSide = inv.isFixedLandscape ? 0 : desiredWorkspaceHorizontalMarginPx;
+ int paddingLeft = desiredWorkspaceHorizontalMarginPx;
+ int paddingRight = desiredWorkspaceHorizontalMarginPx;
- padding.set(paddingSide, paddingTop, paddingSide, paddingBottom);
+ // In fixed Landscape we don't need padding on the side next to the cutout because
+ // the cutout is already adding padding to all of Launcher, we only need on the other
+ // side
+ if (inv.isFixedLandscape) {
+ paddingLeft = isSeascape() ? desiredWorkspaceHorizontalMarginPx : 0;
+ paddingRight = isSeascape() ? 0 : desiredWorkspaceHorizontalMarginPx;
+ }
+ padding.set(paddingLeft, paddingTop, paddingRight, paddingBottom);
}
insetPadding(workspacePadding, cellLayoutPaddingPx);
}
@@ -1931,7 +1940,24 @@ public class DeviceProfile {
hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop,
mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom);
}
- } else if (isTaskbarPresent || inv.isFixedLandscape) {
+ } else if (inv.isFixedLandscape) {
+ // Center the QSB vertically with hotseat
+ int hotseatBarBottomPadding = getHotseatBarBottomPadding();
+ int hotseatPlusQSBWidth = getHotseatRequiredWidth();
+ int qsbWidth = getAdditionalQsbSpace();
+ int availableWidthPxForHotseat = availableWidthPx - Math.abs(workspacePadding.width())
+ - Math.abs(cellLayoutPaddingPx.width());
+ int remainingSpaceOnSide = (availableWidthPxForHotseat - hotseatPlusQSBWidth) / 2;
+
+ hotseatBarPadding.set(
+ (remainingSpaceOnSide + qsbWidth) + mInsets.left + workspacePadding.left
+ + cellLayoutPaddingPx.left,
+ hotseatBarSizePx - hotseatBarBottomPadding - hotseatCellHeightPx,
+ remainingSpaceOnSide + mInsets.right + workspacePadding.right
+ + cellLayoutPaddingPx.right,
+ hotseatBarBottomPadding
+ );
+ } else if (isTaskbarPresent) {
// Center the QSB vertically with hotseat
int hotseatBarBottomPadding = getHotseatBarBottomPadding();
int hotseatBarTopPadding =
@@ -1950,11 +1976,6 @@ public class DeviceProfile {
}
startSpacing += getAdditionalQsbSpace();
- if (inv.isFixedLandscape) {
- endSpacing += mInsets.right;
- startSpacing += mInsets.left;
- }
-
hotseatBarPadding.top = hotseatBarTopPadding;
hotseatBarPadding.bottom = hotseatBarBottomPadding;
boolean isRtl = Utilities.isRtl(context.getResources());
@@ -2164,7 +2185,8 @@ public class DeviceProfile {
}
public boolean isSeascape() {
- return rotationHint == Surface.ROTATION_270 && isVerticalBarLayout();
+ return rotationHint == Surface.ROTATION_270
+ && (isVerticalBarLayout() || inv.isFixedLandscape);
}
public boolean shouldFadeAdjacentWorkspaceScreens() {
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 289f175aa9..5c9392d69d 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1472,8 +1472,7 @@ public class Launcher extends StatefulActivity<LauncherState>
// Adding a shortcut to a Folder.
FolderIcon folderIcon = findFolderIcon(container);
if (folderIcon != null) {
- FolderInfo folderInfo = (FolderInfo) folderIcon.getTag();
- folderInfo.add(info, args.rank, false);
+ folderIcon.getFolder().addFolderContent(info, args.rank, false);
} else {
Log.e(TAG, "Could not find folder with id " + container + " to add shortcut.");
}
@@ -1792,7 +1791,6 @@ public class Launcher extends StatefulActivity<LauncherState>
SettingsCache.INSTANCE.get(this).unregister(TOUCHPAD_NATURAL_SCROLLING,
mNaturalScrollingChangedListener);
ScreenOnTracker.INSTANCE.get(this).removeListener(mScreenOnListener);
- mWorkspace.removeFolderListeners();
PluginManagerWrapper.INSTANCE.get(this).removePluginListener(this);
mModel.removeCallbacks(this);
@@ -2053,9 +2051,10 @@ public class Launcher extends StatefulActivity<LauncherState>
@Nullable final String reason) {
if (itemInfo instanceof WorkspaceItemInfo) {
View collectionIcon = mWorkspace.getViewByItemId(itemInfo.container);
- if (collectionIcon instanceof FolderIcon) {
+ if (collectionIcon instanceof FolderIcon folderIcon) {
// Remove the shortcut from the folder before removing it from launcher
- ((FolderInfo) collectionIcon.getTag()).remove((WorkspaceItemInfo) itemInfo, true);
+ Folder folder = folderIcon.getFolder();
+ folder.removeFolderContent(true, itemInfo);
} else if (collectionIcon instanceof AppPairIcon appPairIcon) {
removeItem(appPairIcon, appPairIcon.getInfo(), deleteFromDb,
"removing app pair because one of its member apps was removed");
@@ -2066,9 +2065,6 @@ public class Launcher extends StatefulActivity<LauncherState>
getModelWriter().deleteItemFromDatabase(itemInfo, reason);
}
} else if (itemInfo instanceof CollectionInfo ci) {
- if (v instanceof FolderIcon) {
- ((FolderIcon) v).removeListeners();
- }
mWorkspace.removeWorkspaceItem(v);
if (deleteFromDb) {
getModelWriter().deleteCollectionAndContentsFromDatabase(ci);
diff --git a/src/com/android/launcher3/LauncherModel.kt b/src/com/android/launcher3/LauncherModel.kt
index add0ad843c..557ad67386 100644
--- a/src/com/android/launcher3/LauncherModel.kt
+++ b/src/com/android/launcher3/LauncherModel.kt
@@ -28,11 +28,12 @@ import com.android.launcher3.dagger.LauncherAppSingleton
import com.android.launcher3.icons.IconCache
import com.android.launcher3.model.AddWorkspaceItemsTask
import com.android.launcher3.model.AllAppsList
-import com.android.launcher3.model.BaseLauncherBinder
+import com.android.launcher3.model.BaseLauncherBinder.BaseLauncherBinderFactory
import com.android.launcher3.model.BgDataModel
import com.android.launcher3.model.CacheDataUpdatedTask
import com.android.launcher3.model.ItemInstallQueue
import com.android.launcher3.model.LoaderTask
+import com.android.launcher3.model.LoaderTask.LoaderTaskFactory
import com.android.launcher3.model.ModelDbController
import com.android.launcher3.model.ModelDelegate
import com.android.launcher3.model.ModelInitializer
@@ -43,6 +44,8 @@ import com.android.launcher3.model.PackageUpdatedTask
import com.android.launcher3.model.ReloadStringCacheTask
import com.android.launcher3.model.ShortcutsChangedTask
import com.android.launcher3.model.UserLockStateChangedTask
+import com.android.launcher3.model.UserManagerState
+import com.android.launcher3.model.WorkspaceItemSpaceFinder
import com.android.launcher3.model.data.ItemInfo
import com.android.launcher3.model.data.WorkspaceItemInfo
import com.android.launcher3.pm.UserCache
@@ -70,30 +73,24 @@ class LauncherModel
@Inject
constructor(
@ApplicationContext private val context: Context,
- private val appProvider: Provider<LauncherAppState>,
+ private val taskControllerProvider: Provider<ModelTaskController>,
private val iconCache: IconCache,
private val prefs: LauncherPrefs,
private val installQueue: ItemInstallQueue,
- appFilter: AppFilter,
@Named("ICONS_DB") dbFileName: String?,
initializer: ModelInitializer,
lifecycle: DaggerSingletonTracker,
val modelDelegate: ModelDelegate,
+ private val mBgAllAppsList: AllAppsList,
+ private val mBgDataModel: BgDataModel,
+ private val loaderFactory: LoaderTaskFactory,
+ private val binderFactory: BaseLauncherBinderFactory,
+ private val spaceFinderFactory: Provider<WorkspaceItemSpaceFinder>,
+ val modelDbController: ModelDbController,
) {
private val mCallbacksList = ArrayList<BgDataModel.Callbacks>(1)
- // < only access in worker thread >
- private val mBgAllAppsList = AllAppsList(iconCache, appFilter)
-
- /**
- * All the static data should be accessed on the background thread, A lock should be acquired on
- * this object when accessing any data from this model.
- */
- private val mBgDataModel = BgDataModel()
-
- val modelDbController = ModelDbController(context)
-
private val mLock = Any()
private var mLoaderTask: LoaderTask? = null
@@ -139,7 +136,7 @@ constructor(
/** Adds the provided items to the workspace. */
fun addAndBindAddedWorkspaceItems(itemList: List<Pair<ItemInfo?, Any?>?>) {
callbacks.forEach { it.preAddApps() }
- enqueueModelUpdateTask(AddWorkspaceItemsTask(itemList))
+ enqueueModelUpdateTask(AddWorkspaceItemsTask(itemList, spaceFinderFactory.get()))
}
fun getWriter(
@@ -299,13 +296,7 @@ constructor(
// Clear any pending bind-runnables from the synchronized load process.
callbacksList.forEach { MAIN_EXECUTOR.execute(it::clearPendingBinds) }
- val launcherBinder =
- BaseLauncherBinder(
- appProvider.get(),
- mBgDataModel,
- mBgAllAppsList,
- callbacksList,
- )
+ val launcherBinder = binderFactory.createBinder(callbacksList)
if (bindDirectly) {
// Divide the set of loaded items into those that we are binding synchronously,
// and everything else that is to be bound normally (asynchronously).
@@ -317,14 +308,7 @@ constructor(
launcherBinder.bindWidgets()
return true
} else {
- val task =
- LoaderTask(
- appProvider.get(),
- mBgAllAppsList,
- mBgDataModel,
- this.modelDelegate,
- launcherBinder,
- )
+ val task = loaderFactory.newLoaderTask(launcherBinder, UserManagerState())
mLoaderTask = task
// Always post the loader task, instead of running directly
@@ -425,7 +409,7 @@ constructor(
/** Called when the labels for the widgets has updated in the icon cache. */
fun onWidgetLabelsUpdated(updatedPackages: HashSet<String?>, user: UserHandle) {
enqueueModelUpdateTask { taskController, dataModel, _ ->
- dataModel.widgetsModel.onPackageIconsUpdated(updatedPackages, user, appProvider.get())
+ dataModel.widgetsModel.onPackageIconsUpdated(updatedPackages, user)
taskController.bindUpdatedWidgets(dataModel)
}
}
@@ -439,17 +423,7 @@ constructor(
// Loader has not yet run.
return@execute
}
- task.execute(
- ModelTaskController(
- appProvider.get(),
- mBgDataModel,
- mBgAllAppsList,
- this,
- MAIN_EXECUTOR,
- ),
- mBgDataModel,
- mBgAllAppsList,
- )
+ task.execute(taskControllerProvider.get(), mBgDataModel, mBgAllAppsList)
}
}
@@ -476,7 +450,7 @@ constructor(
fun refreshAndBindWidgetsAndShortcuts(packageUser: PackageUserKey?) {
enqueueModelUpdateTask { taskController, dataModel, _ ->
- dataModel.widgetsModel.update(taskController.app, packageUser)
+ dataModel.widgetsModel.update(packageUser)
taskController.bindUpdatedWidgets(dataModel)
}
}
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 03ecf14ef6..acb2b48aeb 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -26,13 +26,13 @@ import android.content.ContentUris;
import android.content.ContentValues;
import android.content.pm.PackageManager;
import android.database.Cursor;
-import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.Process;
import android.text.TextUtils;
import android.util.Log;
+import android.util.Pair;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.ModelDbController;
@@ -74,24 +74,20 @@ public class LauncherProvider extends ContentProvider {
@Override
public String getType(Uri uri) {
- SqlArguments args = new SqlArguments(uri, null, null);
- if (TextUtils.isEmpty(args.where)) {
- return "vnd.android.cursor.dir/" + args.table;
+ if (TextUtils.isEmpty(parseUri(uri, null, null).first)) {
+ return "vnd.android.cursor.dir/" + Favorites.TABLE_NAME;
} else {
- return "vnd.android.cursor.item/" + args.table;
+ return "vnd.android.cursor.item/" + Favorites.TABLE_NAME;
}
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
- SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- qb.setTables(args.table);
-
+ Pair<String, String[]> args = parseUri(uri, selection, selectionArgs);
Cursor[] result = new Cursor[1];
executeControllerTask(controller -> {
- result[0] = controller.query(args.table, projection, args.where, args.args, sortOrder);
+ result[0] = controller.query(projection, args.first, args.second, sortOrder);
return 0;
});
return result[0];
@@ -108,7 +104,7 @@ public class LauncherProvider extends ContentProvider {
// attempt allocate and bind the widget.
Integer itemType = values.getAsInteger(Favorites.ITEM_TYPE);
if (itemType != null
- && itemType.intValue() == Favorites.ITEM_TYPE_APPWIDGET
+ && itemType == Favorites.ITEM_TYPE_APPWIDGET
&& !values.containsKey(Favorites.APPWIDGET_ID)) {
ComponentName cn = ComponentName.unflattenFromString(
@@ -135,8 +131,7 @@ public class LauncherProvider extends ContentProvider {
}
}
- SqlArguments args = new SqlArguments(uri);
- return controller.insert(args.table, values);
+ return controller.insert(values);
});
return rowId < 0 ? null : ContentUris.withAppendedId(uri, rowId);
@@ -144,14 +139,14 @@ public class LauncherProvider extends ContentProvider {
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
- SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
- return executeControllerTask(c -> c.delete(args.table, args.where, args.args));
+ Pair<String, String[]> args = parseUri(uri, selection, selectionArgs);
+ return executeControllerTask(c -> c.delete(args.first, args.second));
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
- SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
- return executeControllerTask(c -> c.update(args.table, values, args.where, args.args));
+ Pair<String, String[]> args = parseUri(uri, selection, selectionArgs);
+ return executeControllerTask(c -> c.update(values, args.first, args.second));
}
@Override
@@ -209,35 +204,24 @@ public class LauncherProvider extends ContentProvider {
}
}
- static class SqlArguments {
- public final String table;
- public final String where;
- public final String[] args;
-
- SqlArguments(Uri url, String where, String[] args) {
- if (url.getPathSegments().size() == 1) {
- this.table = url.getPathSegments().get(0);
- this.where = where;
- this.args = args;
- } else if (url.getPathSegments().size() != 2) {
- throw new IllegalArgumentException("Invalid URI: " + url);
- } else if (!TextUtils.isEmpty(where)) {
- throw new UnsupportedOperationException("WHERE clause not supported: " + url);
- } else {
- this.table = url.getPathSegments().get(0);
- this.where = "_id=" + ContentUris.parseId(url);
- this.args = null;
+ /**
+ * Parses the uri and returns the where and arg clause.
+ *
+ * Note: This should be called on the binder thread (before posting on any executor) so that
+ * any parsing error gets propagated to the caller.
+ */
+ private static Pair<String, String[]> parseUri(Uri url, String where, String[] args) {
+ switch (url.getPathSegments().size()) {
+ case 1 -> {
+ return Pair.create(where, args);
}
- }
-
- SqlArguments(Uri url) {
- if (url.getPathSegments().size() == 1) {
- table = url.getPathSegments().get(0);
- where = null;
- args = null;
- } else {
- throw new IllegalArgumentException("Invalid URI: " + url);
+ case 2 -> {
+ if (!TextUtils.isEmpty(where)) {
+ throw new UnsupportedOperationException("WHERE clause not supported: " + url);
+ }
+ return Pair.create("_id=" + ContentUris.parseId(url), null);
}
+ default -> throw new IllegalArgumentException("Invalid URI: " + url);
}
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 9a9bc1d97e..d6ae3a6335 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -100,6 +100,7 @@ import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
+import java.util.Objects;
import java.util.function.Predicate;
/**
@@ -276,8 +277,12 @@ public final class Utilities {
*/
public static void mapCoordInSelfToDescendant(View descendant, View root, float[] coord) {
sMatrix.reset();
+ //TODO(b/307488755) when implemented this check should be removed
+ if (!Objects.equals(descendant.getWindowId(), root.getWindowId())) {
+ return;
+ }
View v = descendant;
- while(v != root) {
+ while (v != root) {
sMatrix.postTranslate(-v.getScrollX(), -v.getScrollY());
sMatrix.postConcat(v.getMatrix());
sMatrix.postTranslate(v.getLeft(), v.getTop());
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 6ed183ab23..59f84ab891 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -137,7 +137,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
/**
* The workspace is a wide area with a wallpaper and a finite number of pages.
@@ -659,7 +658,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
}
// Remove the pages and clear the screen models
- removeFolderListeners();
removeAllViews();
mScreenOrder.clear();
mWorkspaceScreens.clear();
@@ -1914,7 +1912,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
boolean aboveShortcut = Folder.willAccept(dropOverView.getTag())
&& ((ItemInfo) dropOverView.getTag()).container != CONTAINER_HOTSEAT_PREDICTION;
- boolean willBecomeShortcut = Folder.willAcceptItemType(info.itemType);
+ boolean willBecomeShortcut = FolderInfo.willAcceptItemType(info.itemType);
return (aboveShortcut && willBecomeShortcut);
}
@@ -1994,8 +1992,8 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
fi.performCreateAnimation(destInfo, v, sourceInfo, d, folderLocation, scale);
} else {
fi.prepareCreateAnimation(v);
- fi.addItem(destInfo);
- fi.addItem(sourceInfo);
+ fi.getFolder().addFolderContent(destInfo);
+ fi.getFolder().addFolderContent(sourceInfo);
}
return true;
}
@@ -3209,21 +3207,6 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
});
}
- /**
- * Removes all folder listeners
- */
- public void removeFolderListeners() {
- mapOverItems(new ItemOperator() {
- @Override
- public boolean evaluate(ItemInfo info, View view) {
- if (view instanceof FolderIcon) {
- ((FolderIcon) view).removeListeners();
- }
- return false;
- }
- });
- }
-
public boolean isDropEnabled() {
return true;
}
@@ -3349,15 +3332,15 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
if (child instanceof DropTarget) {
mDragController.removeDropTarget((DropTarget) child);
}
- } else if (child instanceof FolderIcon) {
+ } else if (child instanceof FolderIcon folderIcon) {
FolderInfo folderInfo = (FolderInfo) info;
- List<ItemInfo> matches = folderInfo.getContents().stream()
+ ItemInfo[] matches = folderInfo.getContents().stream()
.filter(matcher)
- .collect(Collectors.toList());
- if (!matches.isEmpty()) {
- folderInfo.removeAll(matches, false);
- if (((FolderIcon) child).getFolder().isOpen()) {
- ((FolderIcon) child).getFolder().close(false /* animate */);
+ .toArray(ItemInfo[]::new);
+ if (matches.length > 0) {
+ folderIcon.getFolder().removeFolderContent(false, matches);
+ if (folderIcon.getFolder().isOpen()) {
+ folderIcon.getFolder().close(false /* animate */);
}
}
} else if (info instanceof AppPairInfo api) {
diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
index 78b53a96bd..df34ccf090 100644
--- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
+++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java
@@ -25,6 +25,7 @@ import android.view.accessibility.AccessibilityEvent;
import androidx.annotation.Nullable;
import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.AppWidgetResizeFrame;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.ButtonDropTarget;
import com.android.launcher3.CellLayout;
@@ -82,6 +83,7 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace;
protected static final int RESIZE = R.id.action_resize;
public static final int DEEP_SHORTCUTS = R.id.action_deep_shortcuts;
+ public static final int CLOSE = R.id.action_close;
public LauncherAccessibilityDelegate(Launcher launcher) {
super(launcher);
@@ -104,6 +106,8 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
RESIZE, R.string.action_resize, KeyEvent.KEYCODE_R));
mActions.put(DEEP_SHORTCUTS, new LauncherAction(DEEP_SHORTCUTS,
R.string.action_deep_shortcut, KeyEvent.KEYCODE_S));
+ mActions.put(CLOSE, new LauncherAction(CLOSE,
+ R.string.action_close, KeyEvent.KEYCODE_X));
}
private static boolean isNotInShortcutMenu(@Nullable View view) {
@@ -137,6 +141,10 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
}
}
+ if (host instanceof AppWidgetResizeFrame) {
+ out.add(mActions.get(CLOSE));
+ }
+
if (supportAddToWorkSpace(item)) {
out.add(mActions.get(ADD_TO_WORKSPACE));
}
@@ -183,22 +191,28 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
}
return dragCondition != null;
} else if (action == MOVE) {
- return beginAccessibleDrag(host, item, fromKeyboard);
+ final View itemView = (host instanceof AppWidgetResizeFrame)
+ ? ((AppWidgetResizeFrame) host).getViewForAccessibility()
+ : host;
+ return beginAccessibleDrag(itemView, item, fromKeyboard);
} else if (action == ADD_TO_WORKSPACE) {
return addToWorkspace(item, true /*accessibility*/, null /*finishCallback*/);
} else if (action == MOVE_TO_WORKSPACE) {
return moveToWorkspace(item);
} else if (action == RESIZE) {
+ final View itemView = (host instanceof AppWidgetResizeFrame)
+ ? ((AppWidgetResizeFrame) host).getViewForAccessibility()
+ : host;
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
- List<OptionItem> actions = getSupportedResizeActions(host, info);
+ List<OptionItem> actions = getSupportedResizeActions(itemView, info);
Rect pos = new Rect();
- mContext.getDragLayer().getDescendantRectRelativeToSelf(host, pos);
+ mContext.getDragLayer().getDescendantRectRelativeToSelf(itemView, pos);
ArrowPopup popup = OptionsPopupView.show(mContext, new RectF(pos), actions, false);
popup.requestFocus();
popup.addOnCloseCallback(() -> {
- host.requestFocus();
- host.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
- host.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null);
+ itemView.requestFocus();
+ itemView.sendAccessibilityEvent(TYPE_VIEW_FOCUSED);
+ itemView.performAccessibilityAction(ACTION_ACCESSIBILITY_FOCUS, null);
AbstractFloatingView.closeOpenViews(mContext, /* animate= */ false,
AbstractFloatingView.TYPE_WIDGET_RESIZE_FRAME);
});
@@ -208,6 +222,11 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
: (host instanceof BubbleTextHolder
? ((BubbleTextHolder) host).getBubbleText() : null);
return btv != null && PopupContainerWithArrow.showForIcon(btv) != null;
+ } else if (action == CLOSE) {
+ if (host instanceof AppWidgetResizeFrame) {
+ AbstractFloatingView.closeOpenViews(mContext, /* animate= */ false,
+ AbstractFloatingView.TYPE_WIDGET_RESIZE_FRAME);
+ }
} else {
for (ButtonDropTarget dropTarget : mContext.getDropTargetBar().getDropTargets()) {
if (dropTarget.supportsAccessibilityDrop(item, host)
@@ -222,6 +241,10 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
private List<OptionItem> getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
List<OptionItem> actions = new ArrayList<>();
+ if (host instanceof AppWidgetResizeFrame) {
+ return getSupportedResizeActions(
+ ((AppWidgetResizeFrame) host).getViewForAccessibility(), info);
+ }
AppWidgetProviderInfo providerInfo = ((LauncherAppWidgetHostView) host).getAppWidgetInfo();
if (providerInfo == null) {
return actions;
@@ -496,7 +519,7 @@ public class LauncherAccessibilityDelegate extends BaseAccessibilityDelegate<Lau
Folder folder = Folder.getOpen(mContext);
folder.close(true);
WorkspaceItemInfo info = (WorkspaceItemInfo) item;
- folder.getInfo().remove(info, false);
+ folder.removeFolderContent(false, info);
final int[] coordinates = new int[2];
final int screenId = findSpaceOnWorkspace(item, coordinates);
diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
index fafa60bf6d..f60896eb6d 100644
--- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
@@ -181,6 +181,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
private ScrimView mScrimView;
private int mHeaderColor;
private int mBottomSheetBackgroundColor;
+ private float mBottomSheetBackgroundAlpha = 1f;
private int mTabsProtectionAlpha;
@Nullable private AllAppsTransitionController mAllAppsTransitionController;
@@ -311,7 +312,17 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
0,
0 // Bottom left
};
- mBottomSheetBackgroundColor = getContext().getColor(R.color.materialColorSurfaceDim);
+ if (Flags.allAppsBlur()) {
+ int resId = Utilities.isDarkTheme(getContext())
+ ? android.R.color.system_accent1_800 : android.R.color.system_accent1_100;
+ int layerAbove = ColorUtils.setAlphaComponent(getResources().getColor(resId, null),
+ (int) (0.4f * 255));
+ int layerBelow = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.1f * 255));
+ mBottomSheetBackgroundColor = ColorUtils.compositeColors(layerAbove, layerBelow);
+ } else {
+ mBottomSheetBackgroundColor = getContext().getColor(R.color.materialColorSurfaceDim);
+ }
+ mBottomSheetBackgroundAlpha = Color.alpha(mBottomSheetBackgroundColor) / 255.0f;
updateBackgroundVisibility(mActivityContext.getDeviceProfile());
mSearchUiManager.initializeSearch(this);
}
@@ -1152,7 +1163,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
if (!grid.isVerticalBarLayout() || FeatureFlags.enableResponsiveWorkspace()) {
int topPadding = grid.allAppsPadding.top;
- if (isSearchBarFloating() && !grid.isTablet) {
+ if (isSearchBarFloating() && !grid.shouldShowAllAppsOnSheet()) {
topPadding += getResources().getDimensionPixelSize(
R.dimen.all_apps_additional_top_padding_floating_search);
}
@@ -1401,7 +1412,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
// Draw full background panel for tablets.
if (hasBottomSheet) {
mHeaderPaint.setColor(mBottomSheetBackgroundColor);
- mHeaderPaint.setAlpha(255);
+ mHeaderPaint.setAlpha((int) (mBottomSheetBackgroundAlpha * 255));
mTmpRectF.set(
leftWithScale,
@@ -1424,6 +1435,10 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
return;
}
+ if (hasBottomSheet) {
+ mHeaderPaint.setAlpha((int) (mHeaderPaint.getAlpha() * mBottomSheetBackgroundAlpha));
+ }
+
// Draw header on background panel
final float headerBottomNoScale =
getHeaderBottom() + getVisibleContainerView().getPaddingTop();
@@ -1455,7 +1470,11 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
mHeaderPaint.setColor(Color.BLUE);
mHeaderPaint.setAlpha(255);
} else {
- mHeaderPaint.setAlpha((int) (getAlpha() * mTabsProtectionAlpha));
+ float tabAlpha = getAlpha() * mTabsProtectionAlpha;
+ if (hasBottomSheet) {
+ tabAlpha *= mBottomSheetBackgroundAlpha;
+ }
+ mHeaderPaint.setAlpha((int) tabAlpha);
}
float left = 0f;
float right = canvas.getWidth();
@@ -1507,7 +1526,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
public int getHeaderBottom() {
int bottom = (int) getTranslationY() + mHeader.getClipTop();
if (isSearchBarFloating()) {
- if (mActivityContext.getDeviceProfile().isTablet) {
+ if (mActivityContext.getDeviceProfile().shouldShowAllAppsOnSheet()) {
return bottom + mBottomSheetBackground.getTop();
}
return bottom;
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 4cc31d296e..350f763939 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -290,7 +290,8 @@ public class AllAppsTransitionController
private void onScaleProgressChanged() {
final float scaleProgress = mAllAppScale.value;
SCALE_PROPERTY.set(mLauncher.getAppsView(), scaleProgress);
- if (!mLauncher.getAppsView().isSearching() || !mLauncher.getDeviceProfile().isTablet) {
+ if (!mLauncher.getAppsView().isSearching()
+ || !mLauncher.getDeviceProfile().shouldShowAllAppsOnSheet()) {
mLauncher.getScrimView().setScrimHeaderScale(scaleProgress);
}
diff --git a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
index 5f632fe25d..f223eaa600 100644
--- a/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
+++ b/src/com/android/launcher3/allapps/AlphabeticalAppsList.java
@@ -64,7 +64,7 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
AllAppsStore.OnUpdateListener {
public static final String TAG = "AlphabeticalAppsList";
- private static final String PRIVATE_SPACE_PACKAGE = "com.android.privatespace";
+ public static final String PRIVATE_SPACE_PACKAGE = "com.android.privatespace";
private final WorkProfileManager mWorkProviderManager;
@@ -436,6 +436,8 @@ public class AlphabeticalAppsList<T extends Context & ActivityContext> implement
if (currentItem.itemInfo != null && Objects.equals(
currentItem.itemInfo.getTargetPackage(), PRIVATE_SPACE_PACKAGE)) {
currentItem.itemInfo.bitmap.creationFlags |= FLAG_NO_BADGE;
+ currentItem.itemInfo.contentDescription =
+ mPrivateProviderManager.getPsAppContentDesc();
privateSpaceAppIndex = i;
}
}
diff --git a/src/com/android/launcher3/allapps/PrivateProfileManager.java b/src/com/android/launcher3/allapps/PrivateProfileManager.java
index 609edd2c99..1bc1b17d15 100644
--- a/src/com/android/launcher3/allapps/PrivateProfileManager.java
+++ b/src/com/android/launcher3/allapps/PrivateProfileManager.java
@@ -142,6 +142,7 @@ public class PrivateProfileManager extends UserProfileManager {
private PrivateSpaceSettingsButton mPrivateSpaceSettingsButton;
@Nullable
private ConstraintLayout mFloatingMaskView;
+ private final String mPrivateSpaceAppContentDesc;
private final String mLockedStateContentDesc;
private final String mUnLockedStateContentDesc;
@@ -157,6 +158,8 @@ public class PrivateProfileManager extends UserProfileManager {
UI_HELPER_EXECUTOR.post(() -> initializeInBackgroundThread(appContext));
mPsHeaderHeight = mAllApps.getContext().getResources().getDimensionPixelSize(
R.dimen.ps_header_height);
+ mPrivateSpaceAppContentDesc = mAllApps.getContext()
+ .getString(R.string.ps_app_content_description);
mLockedStateContentDesc = mAllApps.getContext()
.getString(R.string.ps_container_lock_button_content_description);
mUnLockedStateContentDesc = mAllApps.getContext()
@@ -929,6 +932,10 @@ public class PrivateProfileManager extends UserProfileManager {
return mPsHeaderHeight;
}
+ String getPsAppContentDesc() {
+ return mPrivateSpaceAppContentDesc;
+ }
+
boolean isPrivateSpaceItem(BaseAllAppsAdapter.AdapterItem item) {
return getItemInfoMatcher().test(item.itemInfo) || item.decorationInfo != null
|| (item.itemInfo instanceof PrivateSpaceInstallAppButtonInfo);
diff --git a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
index 06643d3cbf..c49909772e 100644
--- a/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
+++ b/src/com/android/launcher3/dagger/LauncherBaseAppComponent.java
@@ -28,6 +28,7 @@ import com.android.launcher3.graphics.GridCustomizationsProxy;
import com.android.launcher3.graphics.ThemeManager;
import com.android.launcher3.icons.LauncherIcons.IconPool;
import com.android.launcher3.model.ItemInstallQueue;
+import com.android.launcher3.model.LoaderCursor.LoaderCursorFactory;
import com.android.launcher3.model.WidgetsFilterDataProvider;
import com.android.launcher3.pm.InstallSessionHelper;
import com.android.launcher3.pm.UserCache;
@@ -87,6 +88,8 @@ public interface LauncherBaseAppComponent {
GridCustomizationsProxy getGridCustomizationsProxy();
WidgetsFilterDataProvider getWidgetsFilterDataProvider();
+ LoaderCursorFactory getLoaderCursorFactory();
+
/** Builder for LauncherBaseAppComponent. */
interface Builder {
@BindsInstance Builder appContext(@ApplicationContext Context context);
diff --git a/src/com/android/launcher3/debug/TestEventEmitter.java b/src/com/android/launcher3/debug/TestEventEmitter.java
index ed3b4bbac9..db69bc2130 100644
--- a/src/com/android/launcher3/debug/TestEventEmitter.java
+++ b/src/com/android/launcher3/debug/TestEventEmitter.java
@@ -34,7 +34,9 @@ public class TestEventEmitter {
RESIZE_FRAME_SHOWING("RESIZE_FRAME_SHOWING"),
WORKSPACE_FINISH_LOADING("WORKSPACE_FINISH_LOADING"),
SPRING_LOADED_STATE_STARTED("SPRING_LOADED_STATE_STARTED"),
- SPRING_LOADED_STATE_COMPLETED("SPRING_LOADED_STATE_COMPLETED");
+ SPRING_LOADED_STATE_COMPLETED("SPRING_LOADED_STATE_COMPLETED"),
+
+ LAUNCHER_STATE_COMPLETED("LAUNCHER_STATE_COMPLETED");
TestEvent(String event) {
}
diff --git a/src/com/android/launcher3/dot/FolderDotInfo.java b/src/com/android/launcher3/dot/FolderDotInfo.java
index 54800a07a8..cb91db7654 100644
--- a/src/com/android/launcher3/dot/FolderDotInfo.java
+++ b/src/com/android/launcher3/dot/FolderDotInfo.java
@@ -30,6 +30,10 @@ public class FolderDotInfo extends DotInfo {
private int mNumNotifications;
+ public void reset() {
+ mNumNotifications = 0;
+ }
+
public void addDotInfo(DotInfo dotToAdd) {
if (dotToAdd == null) {
return;
@@ -39,15 +43,6 @@ public class FolderDotInfo extends DotInfo {
mNumNotifications, MIN_COUNT, DotInfo.MAX_COUNT);
}
- public void subtractDotInfo(DotInfo dotToSubtract) {
- if (dotToSubtract == null) {
- return;
- }
- mNumNotifications -= dotToSubtract.getNotificationKeys().size();
- mNumNotifications = Utilities.boundToRange(
- mNumNotifications, MIN_COUNT, DotInfo.MAX_COUNT);
- }
-
@Override
public int getNotificationCount() {
return mNumNotifications;
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index 613b4308eb..415a2c6230 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -16,6 +16,7 @@
package com.android.launcher3.dragndrop;
+import static com.android.launcher3.Flags.removeAppsRefreshOnRightClick;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_NOT_PINNABLE;
import android.graphics.Point;
@@ -521,17 +522,21 @@ public abstract class DragController<T extends ActivityContext>
mDragObject.dragComplete = true;
if (mIsInPreDrag) {
- if (dropTarget != null) {
- dropTarget.onDragExit(mDragObject);
+ if (removeAppsRefreshOnRightClick()) {
+ mDragObject.cancelled = true;
+ } else {
+ if (dropTarget != null) {
+ dropTarget.onDragExit(mDragObject);
+ }
+ return;
}
- return;
}
// Drop onto the target.
boolean accepted = false;
if (dropTarget != null) {
dropTarget.onDragExit(mDragObject);
- if (dropTarget.acceptDrop(mDragObject)) {
+ if (!mIsInPreDrag && dropTarget.acceptDrop(mDragObject)) {
if (flingAnimation != null) {
flingAnimation.run();
} else {
@@ -539,9 +544,10 @@ public abstract class DragController<T extends ActivityContext>
}
accepted = true;
}
+
+ final View dropTargetAsView = dropTarget.getDropView();
+ dispatchDropComplete(dropTargetAsView, accepted);
}
- final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null;
- dispatchDropComplete(dropTargetAsView, accepted);
}
private DropTarget findDropTarget(final int x, final int y) {
diff --git a/src/com/android/launcher3/dragndrop/LauncherDragController.java b/src/com/android/launcher3/dragndrop/LauncherDragController.java
index 4aa3673586..dd433c02d3 100644
--- a/src/com/android/launcher3/dragndrop/LauncherDragController.java
+++ b/src/com/android/launcher3/dragndrop/LauncherDragController.java
@@ -15,7 +15,10 @@
*/
package com.android.launcher3.dragndrop;
+import static android.view.View.VISIBLE;
+
import static com.android.launcher3.AbstractFloatingView.TYPE_DISCOVERY_BOUNCE;
+import static com.android.launcher3.Flags.removeAppsRefreshOnRightClick;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.LauncherState.EDIT_MODE;
import static com.android.launcher3.LauncherState.NORMAL;
@@ -25,6 +28,7 @@ import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.HapticFeedbackConstants;
+import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.Nullable;
@@ -33,10 +37,13 @@ import androidx.annotation.VisibleForTesting;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
+import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
+import com.android.launcher3.dragndrop.DragOptions.PreDragCondition;
import com.android.launcher3.model.data.ItemInfo;
+import com.android.launcher3.util.TouchUtil;
import com.android.launcher3.widget.util.WidgetDragScaleUtils;
/**
@@ -47,6 +54,9 @@ public class LauncherDragController extends DragController<Launcher> {
private static final boolean PROFILE_DRAWING_DURING_DRAG = false;
private final FlingToDeleteHelper mFlingToDeleteHelper;
+ /** Whether or not the drag operation is triggered by mouse right click. */
+ private boolean mIsInMouseRightClick = false;
+
public LauncherDragController(Launcher launcher) {
super(launcher);
mFlingToDeleteHelper = new FlingToDeleteHelper(launcher);
@@ -69,6 +79,28 @@ public class LauncherDragController extends DragController<Launcher> {
android.os.Debug.startMethodTracing("Launcher");
}
+ if (removeAppsRefreshOnRightClick() && mIsInMouseRightClick
+ && options.preDragCondition == null
+ && originalView instanceof View v) {
+ options.preDragCondition = new PreDragCondition() {
+
+ @Override
+ public boolean shouldStartDrag(double distanceDragged) {
+ return false;
+ }
+
+ @Override
+ public void onPreDragStart(DragObject dragObject) {
+ // Set it to visible so the text of FolderIcon would not flash (avoid it from
+ // being invisible and then visible)
+ v.setVisibility(VISIBLE);
+ }
+
+ @Override
+ public void onPreDragEnd(DragObject dragObject, boolean dragStarted) { }
+ };
+ }
+
mActivity.hideKeyboard();
AbstractFloatingView.closeOpenViews(mActivity, false, TYPE_DISCOVERY_BOUNCE);
@@ -191,7 +223,7 @@ public class LauncherDragController extends DragController<Launcher> {
@Override
protected void exitDrag() {
- if (!mActivity.isInState(EDIT_MODE)) {
+ if (!mIsInPreDrag && !mActivity.isInState(EDIT_MODE)) {
mActivity.getStateManager().goToState(NORMAL, SPRING_LOADED_EXIT_DELAY);
}
}
@@ -218,4 +250,13 @@ public class LauncherDragController extends DragController<Launcher> {
dropCoordinates);
return mActivity.getWorkspace();
}
+
+ /**
+ * Intercepts touch events from a drag source view.
+ */
+ @Override
+ public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
+ mIsInMouseRightClick = TouchUtil.isMouseRightClickDownOrMove(ev);
+ return super.onControllerInterceptTouchEvent(ev);
+ }
}
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index 28032569b2..967af053fb 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -19,9 +19,6 @@ package com.android.launcher3.folder;
import static android.text.TextUtils.isEmpty;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
-import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
-import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APP_PAIR;
-import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
import static com.android.launcher3.LauncherState.EDIT_MODE;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
@@ -29,6 +26,7 @@ import static com.android.launcher3.config.FeatureFlags.ALWAYS_USE_HARDWARE_OPTI
import static com.android.launcher3.folder.FolderGridOrganizer.createFolderGridOrganizer;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_LABEL_UPDATED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED;
+import static com.android.launcher3.model.data.FolderInfo.willAcceptItemType;
import static com.android.launcher3.testing.shared.TestProtocol.FOLDER_OPENED_MESSAGE;
import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs;
@@ -95,14 +93,12 @@ import com.android.launcher3.logger.LauncherAtom.ToState;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogManager.StatsLogger;
import com.android.launcher3.model.data.FolderInfo;
-import com.android.launcher3.model.data.FolderInfo.FolderListener;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemFactory;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.pageindicators.PageIndicatorDots;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.LauncherBindableItemsContainer;
-import com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
@@ -112,6 +108,7 @@ import com.android.launcher3.widget.PendingAddShortcutInfo;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
@@ -123,7 +120,7 @@ import java.util.stream.Stream;
* Represents a set of icons chosen by the user or generated by the system.
*/
public class Folder extends AbstractFloatingView implements ClipPathView, DragSource,
- View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener,
+ View.OnLongClickListener, DropTarget, TextView.OnEditorActionListener,
View.OnFocusChangeListener, DragListener, ExtendedEditText.OnBackKeyListener,
LauncherBindableItemsContainer {
private static final String TAG = "Launcher.Folder";
@@ -180,15 +177,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
return o instanceof ItemInfo info && willAcceptItemType(info.itemType);
}
- /**
- * Checks if {@code itemType} is a type that can be placed in folders.
- */
- public static boolean willAcceptItemType(int itemType) {
- return itemType == ITEM_TYPE_APPLICATION
- || itemType == ITEM_TYPE_DEEP_SHORTCUT
- || itemType == ITEM_TYPE_APP_PAIR;
- }
-
private Alarm mReorderAlarm = new Alarm(Looper.getMainLooper());
private Alarm mOnExitAlarm = new Alarm(Looper.getMainLooper());
private Alarm mOnScrollHintAlarm = new Alarm(Looper.getMainLooper());
@@ -244,7 +232,10 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
private boolean mIsExternalDrag;
private boolean mIsDragInProgress = false;
private boolean mDeleteFolderOnDropCompleted = false;
+
private boolean mSuppressFolderDeletion = false;
+ private boolean mSuppressContentUpdate = false;
+
private boolean mItemAddedBackToSelfViaIcon = false;
private boolean mIsEditingName = false;
@@ -386,9 +377,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
// We do not want to get events for the item being removed, as they will get handled
// when the drop completes
- try (SuppressInfoChanges s = new SuppressInfoChanges()) {
- mInfo.remove(dragObject.dragInfo, true);
- }
+ executeWithContentUpdateSuppressed(() -> removeFolderContent(true, dragObject.dragInfo));
+
mIsDragInProgress = true;
mItemAddedBackToSelfViaIcon = false;
}
@@ -533,8 +523,17 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
lp.customPosition = true;
setLayoutParams(lp);
}
+ reapplyItemInfo();
+ // In case any children didn't come across during loading, clean up the folder accordingly
+ mFolderIcon.post(() -> {
+ if (getItemCount() <= 1) {
+ replaceFolderWithFinalItem();
+ }
+ });
+ }
+
+ public void reapplyItemInfo() {
mItemsInvalidated = true;
- mInfo.addListener(this);
if (!isEmpty(mInfo.title)) {
mFolderName.setText(mInfo.title);
@@ -543,15 +542,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
mFolderName.setText("");
mFolderName.setHint(R.string.folder_hint_text);
}
- // In case any children didn't come across during loading, clean up the folder accordingly
- mFolderIcon.post(() -> {
- if (getItemCount() <= 1) {
- replaceFolderWithFinalItem();
- }
- });
}
-
/**
* Show suggested folder title in FolderEditText if the first suggestion is non-empty, push
* rest of the suggestions to InputMethodManager.
@@ -681,7 +673,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
if (!shouldAnimateOpen(items)) {
return;
}
-
Folder openFolder = getOpen(mActivityContext);
closeOpenFolder(openFolder);
@@ -955,9 +946,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
@Override
public boolean acceptDrop(DragObject d) {
- final ItemInfo item = d.dragInfo;
- final int itemType = item.itemType;
- return Folder.willAcceptItemType(itemType);
+ return willAcceptItemType(d.dragInfo.itemType);
}
public void onDragEnter(DragObject d) {
@@ -1116,13 +1105,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info)
? mCurrentDragView : mContent.createNewView(info);
ArrayList<View> views = getIconsInReadingOrder();
- info.rank = Utilities.boundToRange(info.rank, 0, views.size());
- views.add(info.rank, icon);
- mContent.arrangeChildren(views);
- mItemsInvalidated = true;
-
- try (SuppressInfoChanges s = new SuppressInfoChanges()) {
- mFolderIcon.onDrop(d, true /* itemReturnedOnFailedDrop */);
+ if (!views.contains(icon)) {
+ info.rank = Utilities.boundToRange(info.rank, 0, views.size());
+ views.add(info.rank, icon);
+ mContent.arrangeChildren(views);
+ mItemsInvalidated = true;
+
+ executeWithContentUpdateSuppressed(
+ () -> mFolderIcon.onDrop(d, true /* itemReturnedOnFailedDrop */));
}
}
@@ -1416,9 +1406,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
rearrangeChildren();
// Temporarily suppress the listener, as we did all the work already here.
- try (SuppressInfoChanges s = new SuppressInfoChanges()) {
- mInfo.add(si, mEmptyCellRank, false);
- }
+ executeWithContentUpdateSuppressed(() -> addFolderContent(si, mEmptyCellRank, false));
// We only need to update the locations if it doesn't get handled in
// #onDropCompleted.
@@ -1464,37 +1452,66 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
}
- @Override
- public void onAdd(ItemInfo item, int rank) {
- FolderGridOrganizer verifier = createFolderGridOrganizer(
- mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
- verifier.updateRankAndPos(item, rank);
- mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX,
- item.cellY);
- updateItemLocationsInDatabaseBatch(false);
+ /** Add an app or shortcut */
+ public void addFolderContent(ItemInfo item) {
+ addFolderContent(item, mInfo.getContents().size(), true);
+ }
- if (mContent.areViewsBound()) {
- mContent.createAndAddViewForRank(item, rank);
+ /** Add an app or shortcut for a specified rank */
+ public void addFolderContent(ItemInfo item, int rank, boolean animate) {
+ if (!willAcceptItemType(item.itemType)) {
+ throw new RuntimeException("tried to add an illegal type into a folder");
}
- mItemsInvalidated = true;
+
+ rank = Utilities.boundToRange(rank, 0, mInfo.getContents().size());
+ mInfo.getContents().add(rank, item);
+
+ if (!mSuppressContentUpdate) {
+ FolderGridOrganizer verifier = createFolderGridOrganizer(
+ mActivityContext.getDeviceProfile()).setFolderInfo(mInfo);
+ verifier.updateRankAndPos(item, rank);
+ mLauncherDelegate.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0,
+ item.cellX,
+ item.cellY);
+ updateItemLocationsInDatabaseBatch(false);
+
+ if (mContent.areViewsBound()) {
+ mContent.createAndAddViewForRank(item, rank);
+ }
+ mItemsInvalidated = true;
+ updateTextViewFocus();
+ }
+
+ mLauncherDelegate.getModelWriter().notifyItemModified(mInfo);
+ mFolderIcon.onItemsChanged(animate);
}
- @Override
- public void onRemove(List<ItemInfo> items) {
- mItemsInvalidated = true;
- items.stream().map(this::getViewForInfo).forEach(mContent::removeItem);
- if (mState == STATE_ANIMATING) {
- mRearrangeOnClose = true;
- } else {
- rearrangeChildren();
+ /** Remove all matching app or shortcut. Does not change the DB. */
+ public void removeFolderContent(boolean animate, ItemInfo... items) {
+ List<ItemInfo> itemArray = Arrays.asList(items);
+ if (mInfo.getContents().removeAll(itemArray)) {
+ mLauncherDelegate.getModelWriter().notifyItemModified(mInfo);
}
- if (getItemCount() <= 1) {
- if (mIsOpen) {
- close(true);
+
+ if (!mSuppressContentUpdate) {
+ mItemsInvalidated = true;
+ itemArray.forEach(item -> mContent.removeItem(getViewForInfo(item)));
+ if (mState == STATE_ANIMATING) {
+ mRearrangeOnClose = true;
} else {
- replaceFolderWithFinalItem();
+ rearrangeChildren();
}
+ if (getItemCount() <= 1) {
+ if (mIsOpen) {
+ close(true);
+ } else {
+ replaceFolderWithFinalItem();
+ }
+ }
+ updateTextViewFocus();
}
+
+ mFolderIcon.onItemsChanged(animate);
}
@VisibleForTesting
@@ -1502,16 +1519,6 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
return mContent.iterateOverItems((info, view) -> info == item);
}
- @Override
- public void onItemsChanged(boolean animate) {
- updateTextViewFocus();
- }
-
- @Override
- public void onTitleChanged(CharSequence title) {
- mFolderName.setText(title);
- }
-
/**
* Utility methods to iterate over items of the view
*/
@@ -1665,18 +1672,14 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
}
};
- /**
- * Temporary resource held while we don't want to handle info changes
- */
- private class SuppressInfoChanges implements AutoCloseable {
-
- SuppressInfoChanges() {
- mInfo.removeListener(Folder.this);
- }
-
- @Override
- public void close() {
- mInfo.addListener(Folder.this);
+ /** Executes the task while suppressing the content update for the folder */
+ private void executeWithContentUpdateSuppressed(Runnable task) {
+ if (mSuppressContentUpdate) {
+ task.run();
+ } else {
+ mSuppressContentUpdate = true;
+ task.run();
+ mSuppressContentUpdate = false;
updateTextViewFocus();
}
}
diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java
index 0ed87871cc..1cd9bcc965 100644
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -23,6 +23,7 @@ import static com.android.launcher3.folder.PreviewItemManager.INITIAL_ITEM_ANIMA
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_AUTO_LABELED;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_SUGGESTIONS;
+import static com.android.launcher3.model.data.FolderInfo.willAcceptItemType;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -73,7 +74,6 @@ import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.model.data.AppPairInfo;
import com.android.launcher3.model.data.FolderInfo;
-import com.android.launcher3.model.data.FolderInfo.FolderListener;
import com.android.launcher3.model.data.FolderInfo.LabelState;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemFactory;
@@ -92,7 +92,7 @@ import java.util.function.Predicate;
/**
* An icon that can appear on in the workspace representing an {@link Folder}.
*/
-public class FolderIcon extends FrameLayout implements FolderListener, FloatingIconViewCompanion,
+public class FolderIcon extends FrameLayout implements FloatingIconViewCompanion,
DraggableView, Reorderable {
private final MultiTranslateDelegate mTranslateDelegate = new MultiTranslateDelegate(this);
@@ -127,7 +127,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
private boolean mForceHideDot;
@ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
- private FolderDotInfo mDotInfo = new FolderDotInfo();
+ private final FolderDotInfo mDotInfo = new FolderDotInfo();
private DotRenderer mDotRenderer;
@ViewDebug.ExportedProperty(category = "launcher", deepExport = true)
private DotRenderer.DrawParams mDotParams;
@@ -178,7 +178,6 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
folder.bind(folderInfo);
icon.setFolder(folder);
- folderInfo.addListener(icon);
return icon;
}
@@ -217,13 +216,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
icon.mDotRenderer = grid.mDotRendererWorkSpace;
icon.setContentDescription(icon.getAccessiblityTitle(folderInfo.title));
-
- // Keep the notification dot up to date with the sum of all the content's dots.
- FolderDotInfo folderDotInfo = new FolderDotInfo();
- for (ItemInfo si : folderInfo.getContents()) {
- folderDotInfo.addDotInfo(activity.getDotInfoForItem(si));
- }
- icon.setDotInfo(folderDotInfo);
+ icon.updateDotInfo();
icon.setAccessibilityDelegate(activity.getAccessibilityDelegate());
@@ -264,22 +257,13 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
}
private boolean willAcceptItem(ItemInfo item) {
- final int itemType = item.itemType;
- return (Folder.willAcceptItemType(itemType) && item != mInfo && !mFolder.isOpen());
+ return (willAcceptItemType(item.itemType) && item != mInfo && !mFolder.isOpen());
}
public boolean acceptDrop(ItemInfo dragInfo) {
return !mFolder.isDestroyed() && willAcceptItem(dragInfo);
}
- public void addItem(ItemInfo item) {
- mInfo.add(item, true);
- }
-
- public void removeItem(ItemInfo item, boolean animate) {
- mInfo.remove(item, animate);
- }
-
public void onDragEnter(ItemInfo dragInfo) {
if (mFolder.isDestroyed() || !willAcceptItem(dragInfo)) return;
CellLayoutLayoutParams lp = (CellLayoutLayoutParams) getLayoutParams();
@@ -308,9 +292,8 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
public void performCreateAnimation(final ItemInfo destInfo, final View destView,
final ItemInfo srcInfo, final DragObject d, Rect dstRect,
float scaleRelativeToDragLayer) {
- final DragView srcView = d.dragView;
prepareCreateAnimation(destView);
- addItem(destInfo);
+ getFolder().addFolderContent(destInfo);
// This will animate the first item from it's position as an icon into its
// position as the first item in the preview
mPreviewItemManager.createFirstItemAnimation(false /* reverse */, null)
@@ -364,7 +347,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
boolean itemAdded = false;
if (itemReturnedOnFailedDrop || index >= MAX_NUM_ITEMS_IN_PREVIEW) {
List<ItemInfo> oldPreviewItems = new ArrayList<>(mCurrentPreviewItems);
- mInfo.add(item, index, false);
+ getFolder().addFolderContent(item, index, false);
mCurrentPreviewItems.clear();
mCurrentPreviewItems.addAll(getPreviewItemsOnPage(0));
@@ -380,12 +363,12 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
mPreviewItemManager.onDrop(oldPreviewItems, mCurrentPreviewItems, item);
itemAdded = true;
} else {
- removeItem(item, false);
+ getFolder().removeFolderContent(false, item);
}
}
if (!itemAdded) {
- mInfo.add(item, index, true);
+ getFolder().addFolderContent(item, index, true);
}
int[] center = new int[2];
@@ -431,7 +414,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
}, DROP_IN_ANIMATION_DURATION);
});
} else {
- addItem(item);
+ getFolder().addFolderContent(item);
}
}
@@ -500,9 +483,23 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
);
}
- public void setDotInfo(FolderDotInfo dotInfo) {
- updateDotScale(mDotInfo.hasDot(), dotInfo.hasDot());
- mDotInfo = dotInfo;
+ /** Keep the notification dot up to date with the sum of all the content's dots. */
+ public void updateDotInfo() {
+ boolean hadDot = mDotInfo.hasDot();
+ mDotInfo.reset();
+ for (ItemInfo si : mInfo.getContents()) {
+ mDotInfo.addDotInfo(mActivity.getDotInfoForItem(si));
+ }
+ boolean isDotted = mDotInfo.hasDot();
+ float newDotScale = isDotted ? 1f : 0f;
+ // Animate when a dot is first added or when it is removed.
+ if ((hadDot ^ isDotted) && isShown()) {
+ animateDotScale(newDotScale);
+ } else {
+ cancelDotScaleAnim();
+ mDotScale = newDotScale;
+ invalidate();
+ }
}
public ClippedFolderIconLayoutRule getLayoutRule() {
@@ -523,22 +520,6 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
}
}
- /**
- * Sets mDotScale to 1 or 0, animating if wasDotted or isDotted is false
- * (the dot is being added or removed).
- */
- private void updateDotScale(boolean wasDotted, boolean isDotted) {
- float newDotScale = isDotted ? 1f : 0f;
- // Animate when a dot is first added or when it is removed.
- if ((wasDotted ^ isDotted) && isShown()) {
- animateDotScale(newDotScale);
- } else {
- cancelDotScaleAnim();
- mDotScale = newDotScale;
- invalidate();
- }
- }
-
private void cancelDotScaleAnim() {
if (mDotScaleAnim != null) {
mDotScaleAnim.cancel();
@@ -682,13 +663,6 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
return mPreviewItemManager.verifyDrawable(who) || super.verifyDrawable(who);
}
- @Override
- public void onItemsChanged(boolean animate) {
- updatePreviewItems(animate);
- invalidate();
- requestLayout();
- }
-
private void updatePreviewItems(boolean animate) {
mPreviewItemManager.updatePreviewItems(animate);
mCurrentPreviewItems.clear();
@@ -702,31 +676,15 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
mPreviewItemManager.updatePreviewItems(itemCheck);
}
- @Override
- public void onAdd(ItemInfo item, int rank) {
- updatePreviewItems(false);
- boolean wasDotted = mDotInfo.hasDot();
- mDotInfo.addDotInfo(mActivity.getDotInfoForItem(item));
- boolean isDotted = mDotInfo.hasDot();
- updateDotScale(wasDotted, isDotted);
- setContentDescription(getAccessiblityTitle(mInfo.title));
- invalidate();
- requestLayout();
- }
-
- @Override
- public void onRemove(List<ItemInfo> items) {
+ public void onItemsChanged(boolean animate) {
updatePreviewItems(false);
- boolean wasDotted = mDotInfo.hasDot();
- items.stream().map(mActivity::getDotInfoForItem).forEach(mDotInfo::subtractDotInfo);
- boolean isDotted = mDotInfo.hasDot();
- updateDotScale(wasDotted, isDotted);
+ updateDotInfo();
setContentDescription(getAccessiblityTitle(mInfo.title));
+ updatePreviewItems(animate);
invalidate();
requestLayout();
}
- @Override
public void onTitleChanged(CharSequence title) {
mFolderName.setText(title);
setContentDescription(getAccessiblityTitle(title));
@@ -762,11 +720,6 @@ public class FolderIcon extends FrameLayout implements FolderListener, FloatingI
mLongPressHelper.cancelLongPress();
}
- public void removeListeners() {
- mInfo.removeListener(this);
- mInfo.removeListener(mFolder);
- }
-
private boolean isInHotseat() {
return mInfo.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT;
}
diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java
index bebe1a49ef..0963421f8a 100644
--- a/src/com/android/launcher3/folder/FolderPagedView.java
+++ b/src/com/android/launcher3/folder/FolderPagedView.java
@@ -47,6 +47,7 @@ import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.model.data.AppPairInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
+import com.android.launcher3.pageindicators.Direction;
import com.android.launcher3.pageindicators.PageIndicatorDots;
import com.android.launcher3.util.LauncherBindableItemsContainer.ItemOperator;
import com.android.launcher3.util.Thunk;
@@ -129,6 +130,8 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> implements Cli
public void setFolder(Folder folder) {
mFolder = folder;
mPageIndicator = folder.findViewById(R.id.folder_page_indicator);
+ mPageIndicator.setArrowClickListener(direction -> snapToPageImmediately(
+ (Direction.END == direction) ? mCurrentPage + 1 : mCurrentPage - 1));
initParentViews(folder);
}
diff --git a/src/com/android/launcher3/graphics/GridCustomizationsProxy.java b/src/com/android/launcher3/graphics/GridCustomizationsProxy.java
index 70b9f46c1f..48519ce8bc 100644
--- a/src/com/android/launcher3/graphics/GridCustomizationsProxy.java
+++ b/src/com/android/launcher3/graphics/GridCustomizationsProxy.java
@@ -113,6 +113,7 @@ public class GridCustomizationsProxy implements ProxyProvider {
private static final String KEY_SHAPE_OPTIONS = "/shape_options";
// default_grid is for setting grid and shape to system settings
private static final String KEY_DEFAULT_GRID = "/default_grid";
+ private static final String SET_SHAPE = "/shape";
private static final String METHOD_GET_PREVIEW = "get_preview";
@@ -130,6 +131,7 @@ public class GridCustomizationsProxy implements ProxyProvider {
private static final int MESSAGE_ID_UPDATE_SHAPE = 2586;
private static final int MESSAGE_ID_UPDATE_GRID = 7414;
private static final int MESSAGE_ID_UPDATE_COLOR = 856;
+ private static final int MESSAGE_ID_UPDATE_ICON_THEMED = 311;
// Set of all active previews used to track duplicate memory allocations
private final Set<PreviewLifecycleObserver> mActivePreviews =
@@ -264,6 +266,12 @@ public class GridCustomizationsProxy implements ProxyProvider {
mContext.getContentResolver().notifyChange(uri, null);
return 1;
}
+ case SET_SHAPE:
+ if (Flags.newCustomizationPickerUi()) {
+ mPrefs.put(PREF_ICON_SHAPE,
+ requireNonNullElse(values.getAsString(KEY_SHAPE_KEY), ""));
+ }
+ return 1;
case ICON_THEMED:
case SET_ICON_THEMED: {
mThemeManager.setMonoThemeEnabled(values.getAsBoolean(BOOLEAN_VALUE));
@@ -384,6 +392,12 @@ public class GridCustomizationsProxy implements ProxyProvider {
renderer.previewColor(message.getData());
}
break;
+ case MESSAGE_ID_UPDATE_ICON_THEMED:
+ if (Flags.newCustomizationPickerUi()) {
+ Boolean iconThemed = message.getData().getBoolean(BOOLEAN_VALUE);
+ // TODO Update icon themed in the preview
+ }
+ break;
default:
// Unknown command, destroy lifecycle
Log.d(TAG, "Unknown preview command: " + message.what + ", destroying preview");
diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
index b80238cb1e..e4e4b900fa 100644
--- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
+++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
@@ -80,8 +80,10 @@ import com.android.launcher3.dagger.LauncherAppComponent;
import com.android.launcher3.dagger.LauncherAppModule;
import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.model.BaseLauncherBinder.BaseLauncherBinderFactory;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
+import com.android.launcher3.model.LoaderTask.LoaderTaskFactory;
import com.android.launcher3.model.data.AppPairInfo;
import com.android.launcher3.model.data.CollectionInfo;
import com.android.launcher3.model.data.FolderInfo;
@@ -605,6 +607,10 @@ public class LauncherPreviewRenderer extends BaseContext
@Component(modules = LauncherAppModule.class)
public interface PreviewAppComponent extends LauncherAppComponent {
+ LoaderTaskFactory getLoaderTaskFactory();
+ BaseLauncherBinderFactory getBaseLauncherBinderFactory();
+ BgDataModel getDataModel();
+
/** Builder for NexusLauncherAppComponent. */
@Component.Builder
interface Builder extends LauncherAppComponent.Builder {
diff --git a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
index d425f03712..457d12e8ca 100644
--- a/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
+++ b/src/com/android/launcher3/graphics/PreviewSurfaceRenderer.java
@@ -21,7 +21,6 @@ import static android.content.res.Configuration.UI_MODE_NIGHT_YES;
import static android.view.Display.DEFAULT_DISPLAY;
import static com.android.launcher3.LauncherPrefs.GRID_NAME;
-import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.graphics.ThemeManager.PREF_ICON_SHAPE;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
@@ -58,19 +57,21 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.Workspace;
+import com.android.launcher3.dagger.LauncherComponentProvider;
+import com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewAppComponent;
import com.android.launcher3.graphics.LauncherPreviewRenderer.PreviewContext;
-import com.android.launcher3.model.BaseLauncherBinder;
import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.ModelDbController;
+import com.android.launcher3.model.UserManagerState;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.RunnableList;
import com.android.launcher3.util.Themes;
import com.android.launcher3.widget.LocalColorExtractor;
import com.android.systemui.shared.Flags;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -177,7 +178,7 @@ public class PreviewSurfaceRenderer {
ModelDbController mainController =
LauncherAppState.getInstance(mContext).getModel().getModelDbController();
- try (Cursor c = mainController.query(TABLE_NAME,
+ try (Cursor c = mainController.query(
new String[] {
LauncherSettings.Favorites.APPWIDGET_ID,
LauncherSettings.Favorites.SPANX,
@@ -338,38 +339,32 @@ public class PreviewSurfaceRenderer {
// Start the migration
PreviewContext previewContext =
new PreviewContext(inflationContext, mGridName, mShapeKey);
+ PreviewAppComponent appComponent =
+ (PreviewAppComponent) LauncherComponentProvider.get(previewContext);
+
+ LoaderTask task = appComponent.getLoaderTaskFactory().newLoaderTask(
+ appComponent.getBaseLauncherBinderFactory().createBinder(new Callbacks[0]),
+ new UserManagerState());
+
+ InvariantDeviceProfile idp = appComponent.getIDP();
+ DeviceProfile deviceProfile = idp.getDeviceProfile(previewContext);
+ String query =
+ LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID
+ + " or " + LauncherSettings.Favorites.CONTAINER + " = "
+ + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
+ if (deviceProfile.isTwoPanels) {
+ query += " or " + LauncherSettings.Favorites.SCREEN + " = "
+ + Workspace.SECOND_SCREEN_ID;
+ }
- BgDataModel bgModel = new BgDataModel();
- new LoaderTask(
- LauncherAppState.getInstance(previewContext),
- /* bgAllAppsList= */ null,
- bgModel,
- LauncherAppState.getInstance(previewContext).getModel().getModelDelegate(),
- new BaseLauncherBinder(LauncherAppState.getInstance(previewContext), bgModel,
- /* bgAllAppsList= */ null, new Callbacks[0])) {
-
- @Override
- public void run() {
- InvariantDeviceProfile idp = LauncherAppState.getIDP(previewContext);
- DeviceProfile deviceProfile = idp.getDeviceProfile(previewContext);
- String query =
- LauncherSettings.Favorites.SCREEN + " = " + Workspace.FIRST_SCREEN_ID
- + " or " + LauncherSettings.Favorites.CONTAINER + " = "
- + LauncherSettings.Favorites.CONTAINER_HOTSEAT;
- if (deviceProfile.isTwoPanels) {
- query += " or " + LauncherSettings.Favorites.SCREEN + " = "
- + Workspace.SECOND_SCREEN_ID;
- }
- loadWorkspace(new ArrayList<>(), query, null, null);
-
- final SparseArray<Size> spanInfo = getLoadedLauncherWidgetInfo();
- MAIN_EXECUTOR.execute(() -> {
- renderView(previewContext, mBgDataModel, mWidgetProvidersMap, spanInfo,
- idp);
- mLifeCycleTracker.add(previewContext::onDestroy);
- });
- }
- }.run();
+ Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap = new HashMap<>();
+ task.loadWorkspaceForPreview(query, widgetProviderInfoMap);
+ final SparseArray<Size> spanInfo = getLoadedLauncherWidgetInfo();
+ MAIN_EXECUTOR.execute(() -> {
+ renderView(previewContext, appComponent.getDataModel(), widgetProviderInfoMap,
+ spanInfo, idp);
+ mLifeCycleTracker.add(previewContext::onDestroy);
+ });
} else {
LauncherAppState.getInstance(inflationContext).getModel().loadAsync(dataModel -> {
if (dataModel != null) {
@@ -420,7 +415,6 @@ public class PreviewSurfaceRenderer {
view.setTranslationY((mHeight - scale * view.getHeight()) / 2);
}
-
if (!Flags.newCustomizationPickerUi()) {
view.setAlpha(mSkipAnimations ? 1 : 0);
view.animate().alpha(1)
@@ -477,5 +471,4 @@ public class PreviewSurfaceRenderer {
MAIN_EXECUTOR.execute(mLifecycleTracker::executeAllAndDestroy);
}
}
-
}
diff --git a/src/com/android/launcher3/graphics/ShapeDelegate.kt b/src/com/android/launcher3/graphics/ShapeDelegate.kt
index 7c042929e2..01bfe3018c 100644
--- a/src/com/android/launcher3/graphics/ShapeDelegate.kt
+++ b/src/com/android/launcher3/graphics/ShapeDelegate.kt
@@ -18,6 +18,7 @@ package com.android.launcher3.graphics
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
+import android.animation.ValueAnimator.AnimatorUpdateListener
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Matrix
@@ -41,7 +42,6 @@ import androidx.graphics.shapes.SvgPathParser
import androidx.graphics.shapes.rectangle
import androidx.graphics.shapes.toPath
import androidx.graphics.shapes.transformed
-import com.android.launcher3.anim.RoundedRectRevealOutlineProvider
import com.android.launcher3.icons.GraphicsUtils
import com.android.launcher3.views.ClipPathView
@@ -127,16 +127,20 @@ interface ShapeDelegate {
endRadius: Float,
isReversed: Boolean,
): ValueAnimator where T : View, T : ClipPathView {
- return object :
- RoundedRectRevealOutlineProvider(
- (startRect.width() / 2f) * radiusRatio,
- endRadius,
- startRect,
- endRect,
- ) {
- override fun shouldRemoveElevationDuringAnimation() = true
- }
- .createRevealAnimator(target, isReversed)
+ val startRadius = (startRect.width() / 2f) * radiusRatio
+ return ClipAnimBuilder(target) { progress, path ->
+ val radius = (1 - progress) * startRadius + progress * endRadius
+ path.addRoundRect(
+ (1 - progress) * startRect.left + progress * endRect.left,
+ (1 - progress) * startRect.top + progress * endRect.top,
+ (1 - progress) * startRect.right + progress * endRect.right,
+ (1 - progress) * startRect.bottom + progress * endRect.bottom,
+ radius,
+ radius,
+ Path.Direction.CW,
+ )
+ }
+ .toAnim(isReversed)
}
override fun equals(other: Any?) =
@@ -220,38 +224,44 @@ interface ShapeDelegate {
),
)
- val va =
- if (isReversed) ValueAnimator.ofFloat(1f, 0f) else ValueAnimator.ofFloat(0f, 1f)
- va.addListener(
- object : AnimatorListenerAdapter() {
- private var oldOutlineProvider: ViewOutlineProvider? = null
-
- override fun onAnimationStart(animation: Animator) {
- target.apply {
- oldOutlineProvider = outlineProvider
- outlineProvider = null
- translationZ = -target.elevation
- }
- }
+ return ClipAnimBuilder(target, morph::toPath).toAnim(isReversed)
+ }
+ }
- override fun onAnimationEnd(animation: Animator) {
- target.apply {
- translationZ = 0f
- setClipPath(null)
- outlineProvider = oldOutlineProvider
- }
- }
- }
- )
+ private class ClipAnimBuilder<T>(val target: T, val pathProvider: (Float, Path) -> Unit) :
+ AnimatorListenerAdapter(), AnimatorUpdateListener where T : View, T : ClipPathView {
- val path = Path()
- va.addUpdateListener { anim: ValueAnimator ->
- path.reset()
- morph.toPath(anim.animatedValue as Float, path)
- target.setClipPath(path)
+ private var oldOutlineProvider: ViewOutlineProvider? = null
+ val path = Path()
+
+ override fun onAnimationStart(animation: Animator) {
+ target.apply {
+ oldOutlineProvider = outlineProvider
+ outlineProvider = null
+ translationZ = -target.elevation
+ }
+ }
+
+ override fun onAnimationEnd(animation: Animator) {
+ target.apply {
+ translationZ = 0f
+ setClipPath(null)
+ outlineProvider = oldOutlineProvider
}
- return va
}
+
+ override fun onAnimationUpdate(anim: ValueAnimator) {
+ path.reset()
+ pathProvider.invoke(anim.animatedValue as Float, path)
+ target.setClipPath(path)
+ }
+
+ fun toAnim(isReversed: Boolean) =
+ (if (isReversed) ValueAnimator.ofFloat(1f, 0f) else ValueAnimator.ofFloat(0f, 1f))
+ .also {
+ it.addListener(this)
+ it.addUpdateListener(this)
+ }
}
companion object {
diff --git a/src/com/android/launcher3/logging/StatsLogManager.java b/src/com/android/launcher3/logging/StatsLogManager.java
index 45ed489dbe..44d2e266f7 100644
--- a/src/com/android/launcher3/logging/StatsLogManager.java
+++ b/src/com/android/launcher3/logging/StatsLogManager.java
@@ -166,6 +166,9 @@ public class StatsLogManager implements ResourceBasedOverride {
@UiEvent(doc = "User tapped or long pressed on settings icon inside launcher settings.")
LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS(463),
+ @UiEvent(doc = "User tapped or long pressed on apps icon inside launcher settings.")
+ LAUNCHER_ALL_APPS_TAP_OR_LONGPRESS(2204),
+
@UiEvent(doc = "User tapped or long pressed on widget tray icon inside launcher settings.")
LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS(464),
diff --git a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
index ddbbdc722a..dfba4bb192 100644
--- a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
+++ b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java
@@ -66,13 +66,6 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
/**
* @param itemList items to add on the workspace
- */
- public AddWorkspaceItemsTask(@NonNull final List<Pair<ItemInfo, Object>> itemList) {
- this(itemList, new WorkspaceItemSpaceFinder());
- }
-
- /**
- * @param itemList items to add on the workspace
* @param itemSpaceFinder inject WorkspaceItemSpaceFinder dependency for testing
*/
public AddWorkspaceItemsTask(@NonNull final List<Pair<ItemInfo, Object>> itemList,
@@ -91,7 +84,7 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
final IntArray addedWorkspaceScreensFinal = new IntArray();
- final Context context = taskController.getApp().getContext();
+ final Context context = taskController.getContext();
synchronized (dataModel) {
IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
@@ -133,7 +126,7 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
for (ItemInfo item : filteredItems) {
// Find appropriate space for the item.
- int[] coords = mItemSpaceFinder.findSpaceForItem(taskController.getApp(), dataModel,
+ int[] coords = mItemSpaceFinder.findSpaceForItem(
workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
int screenId = coords[0];
@@ -192,7 +185,7 @@ public class AddWorkspaceItemsTask implements ModelUpdateTask {
continue;
}
- IconCache cache = taskController.getApp().getIconCache();
+ IconCache cache = taskController.getIconCache();
WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
wii.title = "";
wii.bitmap = cache.getDefaultIcon(item.user);
diff --git a/src/com/android/launcher3/model/AllAppsList.java b/src/com/android/launcher3/model/AllAppsList.java
index 98f9afdaaa..2311239025 100644
--- a/src/com/android/launcher3/model/AllAppsList.java
+++ b/src/com/android/launcher3/model/AllAppsList.java
@@ -34,6 +34,7 @@ import androidx.annotation.Nullable;
import com.android.launcher3.AppFilter;
import com.android.launcher3.compat.AlphabeticIndexCompat;
+import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.data.AppInfo;
@@ -53,11 +54,13 @@ import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
+import javax.inject.Inject;
+
/**
* Stores the list of all applications for the all apps view.
*/
-@SuppressWarnings("NewApi")
+@LauncherAppSingleton
public class AllAppsList {
private static final String TAG = "AllAppsList";
@@ -70,10 +73,10 @@ public class AllAppsList {
public final ArrayList<AppInfo> data = new ArrayList<>(DEFAULT_APPLICATIONS_NUMBER);
@NonNull
- private IconCache mIconCache;
+ private final IconCache mIconCache;
@NonNull
- private AppFilter mAppFilter;
+ private final AppFilter mAppFilter;
private boolean mDataChanged = false;
private Consumer<AppInfo> mRemoveListener = NO_OP_CONSUMER;
@@ -92,6 +95,7 @@ public class AllAppsList {
/**
* Boring constructor.
*/
+ @Inject
public AllAppsList(IconCache iconCache, AppFilter appFilter) {
mIconCache = iconCache;
mAppFilter = appFilter;
diff --git a/src/com/android/launcher3/model/BaseLauncherBinder.java b/src/com/android/launcher3/model/BaseLauncherBinder.java
index 262bf678c7..c4bbae416b 100644
--- a/src/com/android/launcher3/model/BaseLauncherBinder.java
+++ b/src/com/android/launcher3/model/BaseLauncherBinder.java
@@ -26,6 +26,7 @@ import static com.android.launcher3.model.ModelUtils.currentScreenContentFilter;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
+import android.content.Context;
import android.os.Trace;
import android.util.Log;
import android.util.Pair;
@@ -34,11 +35,12 @@ import android.view.View;
import androidx.annotation.NonNull;
import com.android.launcher3.InvariantDeviceProfile;
-import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.celllayout.CellPosMapper;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.BgDataModel.FixedContainerItems;
import com.android.launcher3.model.data.AppInfo;
@@ -55,6 +57,10 @@ import com.android.launcher3.util.RunnableList;
import com.android.launcher3.widget.model.WidgetsListBaseEntriesBuilder;
import com.android.launcher3.widget.model.WidgetsListBaseEntry;
+import dagger.assisted.Assisted;
+import dagger.assisted.AssistedFactory;
+import dagger.assisted.AssistedInject;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -76,7 +82,9 @@ public class BaseLauncherBinder {
protected final LooperExecutor mUiExecutor;
- protected final LauncherAppState mApp;
+ private final Context mContext;
+ private final InvariantDeviceProfile mIDP;
+ private final LauncherModel mModel;
protected final BgDataModel mBgDataModel;
private final AllAppsList mBgAllAppsList;
@@ -84,10 +92,18 @@ public class BaseLauncherBinder {
private int mMyBindingId;
- public BaseLauncherBinder(LauncherAppState app, BgDataModel dataModel,
- AllAppsList allAppsList, Callbacks[] callbacksList) {
+ @AssistedInject
+ public BaseLauncherBinder(
+ @ApplicationContext Context context,
+ InvariantDeviceProfile idp,
+ LauncherModel model,
+ BgDataModel dataModel,
+ AllAppsList allAppsList,
+ @Assisted Callbacks[] callbacksList) {
mUiExecutor = MAIN_EXECUTOR;
- mApp = app;
+ mContext = context;
+ mIDP = idp;
+ mModel = model;
mBgDataModel = dataModel;
mBgAllAppsList = allAppsList;
mCallbacksList = callbacksList;
@@ -110,15 +126,14 @@ public class BaseLauncherBinder {
mBgDataModel.extraItems.forEach(extraItems::add);
if (incrementBindId) {
mBgDataModel.lastBindId++;
- mBgDataModel.lastLoadId = mApp.getModel().getLastLoadId();
+ mBgDataModel.lastLoadId = mModel.getLastLoadId();
}
mMyBindingId = mBgDataModel.lastBindId;
workspaceItemCount = mBgDataModel.itemsIdMap.size();
}
for (Callbacks cb : mCallbacksList) {
- new UnifiedWorkspaceBinder(cb, mUiExecutor, mApp, mBgDataModel, mMyBindingId,
- itemsIdMap, extraItems, orderedScreenIds)
+ new UnifiedWorkspaceBinder(cb, itemsIdMap, extraItems, orderedScreenIds)
.bind(isBindSync, workspaceItemCount);
}
} finally {
@@ -162,9 +177,8 @@ public class BaseLauncherBinder {
if (!WIDGETS_ENABLED) {
return;
}
- List<WidgetsListBaseEntry> widgets = new WidgetsListBaseEntriesBuilder(mApp.getContext())
+ List<WidgetsListBaseEntry> widgets = new WidgetsListBaseEntriesBuilder(mContext)
.build(mBgDataModel.widgetsModel.getWidgetsByPackageItemForPicker());
-
executeCallbacksTask(c -> c.bindAllWidgets(widgets), mUiExecutor);
}
@@ -181,10 +195,9 @@ public class BaseLauncherBinder {
/**
* Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to right)
*/
- protected void sortWorkspaceItemsSpatially(InvariantDeviceProfile profile,
- ArrayList<ItemInfo> workspaceItems) {
- final int screenCols = profile.numColumns;
- final int screenCellCount = profile.numColumns * profile.numRows;
+ protected void sortWorkspaceItemsSpatially(ArrayList<ItemInfo> workspaceItems) {
+ final int screenCols = mIDP.numColumns;
+ final int screenCellCount = mIDP.numColumns * mIDP.numRows;
Collections.sort(workspaceItems, (lhs, rhs) -> {
if (lhs.container == rhs.container) {
// Within containers, order by their spatial position in that container
@@ -240,30 +253,18 @@ public class BaseLauncherBinder {
private class UnifiedWorkspaceBinder {
- private final Executor mUiExecutor;
private final Callbacks mCallbacks;
- private final LauncherAppState mApp;
- private final BgDataModel mBgDataModel;
-
- private final int mMyBindingId;
private final IntSparseArrayMap<ItemInfo> mItemIdMap;
private final IntArray mOrderedScreenIds;
private final ArrayList<FixedContainerItems> mExtraItems;
- UnifiedWorkspaceBinder(Callbacks callbacks,
- Executor uiExecutor,
- LauncherAppState app,
- BgDataModel bgDataModel,
- int myBindingId,
+ UnifiedWorkspaceBinder(
+ Callbacks callbacks,
IntSparseArrayMap<ItemInfo> itemIdMap,
ArrayList<FixedContainerItems> extraItems,
IntArray orderedScreenIds) {
mCallbacks = callbacks;
- mUiExecutor = uiExecutor;
- mApp = app;
- mBgDataModel = bgDataModel;
- mMyBindingId = myBindingId;
mItemIdMap = itemIdMap;
mExtraItems = extraItems;
mOrderedScreenIds = orderedScreenIds;
@@ -289,9 +290,8 @@ public class BaseLauncherBinder {
(WIDGET_FILTER.test(item) ? otherAppWidgets : otherWorkspaceItems).add(item);
}
});
- final InvariantDeviceProfile idp = mApp.getInvariantDeviceProfile();
- sortWorkspaceItemsSpatially(idp, currentWorkspaceItems);
- sortWorkspaceItemsSpatially(idp, otherWorkspaceItems);
+ sortWorkspaceItemsSpatially(currentWorkspaceItems);
+ sortWorkspaceItemsSpatially(otherWorkspaceItems);
// Tell the workspace that we're about to start binding items
executeCallbacksTask(c -> {
@@ -352,7 +352,7 @@ public class BaseLauncherBinder {
executeCallbacksTask(c -> c.bindStringCache(cacheClone), pendingExecutor);
executeCallbacksTask(c -> c.finishBindingItems(currentScreenIds), pendingExecutor);
- pendingExecutor.execute(() -> ItemInstallQueue.INSTANCE.get(mApp.getContext())
+ pendingExecutor.execute(() -> ItemInstallQueue.INSTANCE.get(mContext)
.resumeModelPush(FLAG_LOADER_RUNNING));
}
@@ -367,8 +367,8 @@ public class BaseLauncherBinder {
return;
}
- ModelWriter writer = mApp.getModel()
- .getWriter(false /* verifyChanges */, CellPosMapper.DEFAULT, null);
+ ModelWriter writer = mModel.getWriter(
+ false /* verifyChanges */, CellPosMapper.DEFAULT, null);
List<Pair<ItemInfo, View>> bindItems = items.stream()
.map(i -> Pair.create(i, inflater.inflateItem(i, writer, null)))
.collect(Collectors.toList());
@@ -398,4 +398,9 @@ public class BaseLauncherBinder {
});
}
}
+
+ @AssistedFactory
+ public interface BaseLauncherBinderFactory {
+ BaseLauncherBinder createBinder(Callbacks[] callbacks);
+ }
}
diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java
index d9eccaf4f3..ea9f36c419 100644
--- a/src/com/android/launcher3/model/BgDataModel.java
+++ b/src/com/android/launcher3/model/BgDataModel.java
@@ -46,6 +46,7 @@ import androidx.annotation.Nullable;
import com.android.launcher3.BuildConfig;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.CollectionInfo;
@@ -79,9 +80,15 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import javax.inject.Inject;
+
/**
* All the data stored in-memory and managed by the LauncherModel
+ *
+ * All the static data should be accessed on the background thread, A lock should be acquired on
+ * this object when accessing any data from this model.
*/
+@LauncherAppSingleton
public class BgDataModel {
private static final String TAG = "BgDataModel";
@@ -105,7 +112,7 @@ public class BgDataModel {
/**
* Entire list of widgets.
*/
- public final WidgetsModel widgetsModel = new WidgetsModel();
+ public final WidgetsModel widgetsModel;
/**
* Cache for strings used in launcher
@@ -124,6 +131,11 @@ public class BgDataModel {
public boolean isFirstPagePinnedItemEnabled = QSB_ON_FIRST_SCREEN
&& !enableSmartspaceRemovalToggle();
+ @Inject
+ public BgDataModel(WidgetsModel widgetsModel) {
+ this.widgetsModel = widgetsModel;
+ }
+
/**
* Clears all the data
*/
diff --git a/src/com/android/launcher3/model/CacheDataUpdatedTask.java b/src/com/android/launcher3/model/CacheDataUpdatedTask.java
index 48934e2c11..f740b49694 100644
--- a/src/com/android/launcher3/model/CacheDataUpdatedTask.java
+++ b/src/com/android/launcher3/model/CacheDataUpdatedTask.java
@@ -59,7 +59,7 @@ public class CacheDataUpdatedTask implements ModelUpdateTask {
@Override
public void execute(@NonNull ModelTaskController taskController, @NonNull BgDataModel dataModel,
@NonNull AllAppsList apps) {
- IconCache iconCache = taskController.getApp().getIconCache();
+ IconCache iconCache = taskController.getIconCache();
ArrayList<ItemInfo> updatedItems = new ArrayList<>();
synchronized (dataModel) {
diff --git a/src/com/android/launcher3/model/FirstScreenBroadcast.java b/src/com/android/launcher3/model/FirstScreenBroadcast.java
index f443f8142e..829e0fe08b 100644
--- a/src/com/android/launcher3/model/FirstScreenBroadcast.java
+++ b/src/com/android/launcher3/model/FirstScreenBroadcast.java
@@ -45,9 +45,9 @@ import com.android.launcher3.util.PackageUserKey;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@@ -76,9 +76,9 @@ public class FirstScreenBroadcast {
private static final String VERIFICATION_TOKEN_EXTRA = "verificationToken";
- private final HashMap<PackageUserKey, SessionInfo> mSessionInfoForPackage;
+ private final Map<PackageUserKey, SessionInfo> mSessionInfoForPackage;
- public FirstScreenBroadcast(HashMap<PackageUserKey, SessionInfo> sessionInfoForPackage) {
+ public FirstScreenBroadcast(Map<PackageUserKey, SessionInfo> sessionInfoForPackage) {
mSessionInfoForPackage = sessionInfoForPackage;
}
diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java
index bd8c36b576..efe61572fe 100644
--- a/src/com/android/launcher3/model/LoaderCursor.java
+++ b/src/com/android/launcher3/model/LoaderCursor.java
@@ -21,7 +21,6 @@ import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APP_PAIR;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
-import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.Utilities.SHOULD_SHOW_FIRST_PAGE_WIDGET;
import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED;
@@ -45,13 +44,14 @@ import androidx.annotation.VisibleForTesting;
import com.android.launcher3.Flags;
import com.android.launcher3.InvariantDeviceProfile;
-import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger;
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger.RestoreError;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.data.AppInfo;
@@ -70,6 +70,10 @@ import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.UserIconInfo;
+import dagger.assisted.Assisted;
+import dagger.assisted.AssistedFactory;
+import dagger.assisted.AssistedInject;
+
import java.net.URISyntaxException;
import java.security.InvalidParameterException;
@@ -82,8 +86,8 @@ public class LoaderCursor extends CursorWrapper {
private final LongSparseArray<UserHandle> allUsers;
- private final LauncherAppState mApp;
private final Context mContext;
+ private final LauncherModel mModel;
private final PackageManagerHelper mPmHelper;
private final IconCache mIconCache;
private final InvariantDeviceProfile mIDP;
@@ -130,17 +134,24 @@ public class LoaderCursor extends CursorWrapper {
public int itemType;
public int restoreFlag;
- public LoaderCursor(Cursor cursor, LauncherAppState app, UserManagerState userManagerState,
- PackageManagerHelper pmHelper,
- @Nullable LauncherRestoreEventLogger restoreEventLogger) {
+ @AssistedInject
+ public LoaderCursor(
+ @Assisted Cursor cursor,
+ @Assisted UserManagerState userManagerState,
+ @Assisted @Nullable LauncherRestoreEventLogger restoreEventLogger,
+ @ApplicationContext Context context,
+ IconCache iconCache,
+ InvariantDeviceProfile idp,
+ LauncherModel model,
+ PackageManagerHelper pmHelper) {
super(cursor);
+ mContext = context;
+ mIconCache = iconCache;
+ mIDP = idp;
+ mModel = model;
+ mPmHelper = pmHelper;
- mApp = app;
allUsers = userManagerState.allUsers;
- mContext = app.getContext();
- mIconCache = app.getIconCache();
- mPmHelper = pmHelper;
- mIDP = app.getInvariantDeviceProfile();
mRestoreEventLogger = restoreEventLogger;
// Init column indices
@@ -432,7 +443,7 @@ public class LoaderCursor extends CursorWrapper {
*/
public ContentWriter updater() {
return new ContentWriter(mContext, new ContentWriter.CommitParams(
- mApp.getModel().getModelDbController(),
+ mModel.getModelDbController(),
BaseColumns._ID + "= ?", new String[]{Integer.toString(id)}));
}
@@ -454,7 +465,7 @@ public class LoaderCursor extends CursorWrapper {
public boolean commitDeleted() {
if (mItemsToRemove.size() > 0) {
// Remove dead items
- mApp.getModel().getModelDbController().delete(TABLE_NAME,
+ mModel.getModelDbController().delete(
Utilities.createDbSelectionQuery(Favorites._ID, mItemsToRemove), null);
return true;
}
@@ -480,7 +491,7 @@ public class LoaderCursor extends CursorWrapper {
// Update restored items that no longer require special handling
ContentValues values = new ContentValues();
values.put(Favorites.RESTORED, 0);
- mApp.getModel().getModelDbController().update(TABLE_NAME, values,
+ mModel.getModelDbController().update(values,
Utilities.createDbSelectionQuery(Favorites._ID, mRestoredRows), null);
}
if (mRestoreEventLogger != null) {
@@ -645,4 +656,12 @@ public class LoaderCursor extends CursorWrapper {
return false;
}
}
+
+ @AssistedFactory
+ public interface LoaderCursorFactory {
+
+ LoaderCursor createLoaderCursor(Cursor cursor,
+ UserManagerState userManagerState,
+ @Nullable LauncherRestoreEventLogger restoreEventLogger);
+ }
}
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index fb1ebaf3c4..78e5d898cd 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -23,7 +23,6 @@ import static com.android.launcher3.Flags.enableSmartspaceRemovalToggle;
import static com.android.launcher3.LauncherPrefs.IS_FIRST_LOAD_AFTER_RESTORE;
import static com.android.launcher3.LauncherPrefs.SHOULD_SHOW_SMARTSPACE;
import static com.android.launcher3.LauncherSettings.Favorites.DESKTOP_ICON_FLAG;
-import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.icons.CacheableShortcutInfo.convertShortcutsToCacheableShortcuts;
import static com.android.launcher3.icons.cache.CacheLookupFlag.DEFAULT_LOOKUP_FLAG;
import static com.android.launcher3.model.BgDataModel.Callbacks.FLAG_HAS_SHORTCUT_PERMISSION;
@@ -53,7 +52,6 @@ import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
-import android.util.ArrayMap;
import android.util.Log;
import android.util.LongSparseArray;
@@ -63,13 +61,14 @@ import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import com.android.launcher3.Flags;
-import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderGridOrganizer;
import com.android.launcher3.folder.FolderNameInfos;
@@ -82,6 +81,7 @@ import com.android.launcher3.icons.cache.CachedObjectCachingLogic;
import com.android.launcher3.icons.cache.IconCacheUpdateHandler;
import com.android.launcher3.icons.cache.LauncherActivityCachingLogic;
import com.android.launcher3.logging.FileLog;
+import com.android.launcher3.model.LoaderCursor.LoaderCursorFactory;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.AppPairInfo;
import com.android.launcher3.model.data.FolderInfo;
@@ -106,6 +106,10 @@ import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.TraceHelper;
import com.android.launcher3.widget.WidgetInflater;
+import dagger.assisted.Assisted;
+import dagger.assisted.AssistedFactory;
+import dagger.assisted.AssistedInject;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -117,6 +121,8 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CancellationException;
+import javax.inject.Named;
+
/**
* Runnable for the thread that loads the contents of the launcher:
* - workspace icons
@@ -131,10 +137,14 @@ public class LoaderTask implements Runnable {
private static final boolean DEBUG = true;
- @NonNull
- protected final LauncherAppState mApp;
+ private final Context mContext;
+ private final LauncherModel mModel;
+ private final InvariantDeviceProfile mIDP;
+ private final boolean mIsSafeModeEnabled;
private final AllAppsList mBgAllAppsList;
protected final BgDataModel mBgDataModel;
+ private final LoaderCursorFactory mLoaderCursorFactory;
+
private final ModelDelegate mModelDelegate;
private boolean mIsRestoreFromBackup;
@@ -152,7 +162,6 @@ public class LoaderTask implements Runnable {
private final IconCache mIconCache;
private final UserManagerState mUserManagerState;
- protected final Map<ComponentKey, AppWidgetProviderInfo> mWidgetProvidersMap = new ArrayMap<>();
private Map<ShortcutKey, ShortcutInfo> mShortcutKeyToPinnedShortcuts;
private HashMap<PackageUserKey, SessionInfo> mInstallingPkgsCached;
@@ -164,26 +173,36 @@ public class LoaderTask implements Runnable {
private boolean mItemsDeleted = false;
private String mDbName;
- public LoaderTask(@NonNull LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel bgModel,
- ModelDelegate modelDelegate, @NonNull BaseLauncherBinder launcherBinder) {
- this(app, bgAllAppsList, bgModel, modelDelegate, launcherBinder, new UserManagerState());
- }
-
- @VisibleForTesting
- LoaderTask(@NonNull LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel bgModel,
- ModelDelegate modelDelegate, @NonNull BaseLauncherBinder launcherBinder,
- UserManagerState userManagerState) {
- mApp = app;
+ @AssistedInject
+ LoaderTask(
+ @ApplicationContext Context context,
+ InvariantDeviceProfile idp,
+ LauncherModel model,
+ UserCache userCache,
+ PackageManagerHelper pmHelper,
+ InstallSessionHelper sessionHelper,
+ IconCache iconCache,
+ AllAppsList bgAllAppsList,
+ BgDataModel bgModel,
+ LoaderCursorFactory loaderCursorFactory,
+ @Named("SAFE_MODE") boolean isSafeModeEnabled,
+ @Assisted @NonNull BaseLauncherBinder launcherBinder,
+ @Assisted UserManagerState userManagerState) {
+ mContext = context;
+ mIDP = idp;
+ mModel = model;
+ mIsSafeModeEnabled = isSafeModeEnabled;
mBgAllAppsList = bgAllAppsList;
mBgDataModel = bgModel;
- mModelDelegate = modelDelegate;
+ mModelDelegate = model.getModelDelegate();
mLauncherBinder = launcherBinder;
- mLauncherApps = mApp.getContext().getSystemService(LauncherApps.class);
- mUserManager = mApp.getContext().getSystemService(UserManager.class);
- mUserCache = UserCache.INSTANCE.get(mApp.getContext());
- mPmHelper = PackageManagerHelper.INSTANCE.get(mApp.getContext());
- mSessionHelper = InstallSessionHelper.INSTANCE.get(mApp.getContext());
- mIconCache = mApp.getIconCache();
+ mLoaderCursorFactory = loaderCursorFactory;
+ mLauncherApps = mContext.getSystemService(LauncherApps.class);
+ mUserManager = mContext.getSystemService(UserManager.class);
+ mUserCache = userCache;
+ mPmHelper = pmHelper;
+ mSessionHelper = sessionHelper;
+ mIconCache = iconCache;
mUserManagerState = userManagerState;
mInstallingPkgsCached = null;
}
@@ -215,7 +234,7 @@ public class LoaderTask implements Runnable {
.filter(currentScreenContentFilter(firstScreens))
.toList();
final int disableArchivingLauncherBroadcast = Settings.Secure.getInt(
- mApp.getContext().getContentResolver(),
+ mContext.getContentResolver(),
"disable_launcher_broadcast_installed_apps",
/* default */ 0);
boolean shouldAttachArchivingExtras = mIsRestoreFromBackup
@@ -230,10 +249,10 @@ public class LoaderTask implements Runnable {
mBgDataModel.itemsIdMap.stream().filter(WIDGET_FILTER).toList()
);
logASplit("Sending first screen broadcast with additional archiving Extras");
- FirstScreenBroadcastHelper.sendBroadcastsForModels(mApp.getContext(), broadcastModels);
+ FirstScreenBroadcastHelper.sendBroadcastsForModels(mContext, broadcastModels);
} else {
logASplit("Sending first screen broadcast");
- mFirstScreenBroadcast.sendBroadcasts(mApp.getContext(), firstScreenItems);
+ mFirstScreenBroadcast.sendBroadcasts(mContext, firstScreenItems);
}
}
@@ -249,16 +268,14 @@ public class LoaderTask implements Runnable {
MODEL_EXECUTOR.elevatePriority(CALLER_LOADER_TASK);
LoaderMemoryLogger memoryLogger = new LoaderMemoryLogger();
mIsRestoreFromBackup =
- LauncherPrefs.get(mApp.getContext()).get(IS_FIRST_LOAD_AFTER_RESTORE);
+ LauncherPrefs.get(mContext).get(IS_FIRST_LOAD_AFTER_RESTORE);
LauncherRestoreEventLogger restoreEventLogger = null;
if (enableLauncherBrMetricsFixed()) {
- restoreEventLogger = LauncherRestoreEventLogger.Companion
- .newInstance(mApp.getContext());
+ restoreEventLogger = LauncherRestoreEventLogger.Companion.newInstance(mContext);
}
- try (LauncherModel.LoaderTransaction transaction = mApp.getModel().beginLoader(this)) {
-
+ try (LauncherModel.LoaderTransaction transaction = mModel.beginLoader(this)) {
List<CacheableShortcutInfo> allShortcuts = new ArrayList<>();
- loadWorkspace(allShortcuts, "", memoryLogger, restoreEventLogger);
+ loadWorkspace(allShortcuts, "", new HashMap<>(), memoryLogger, restoreEventLogger);
// Sanitize data re-syncs widgets/shortcuts based on the workspace loaded from db.
// sanitizeData should not be invoked if the workspace is loaded from a db different
@@ -267,7 +284,7 @@ public class LoaderTask implements Runnable {
// TODO(b/384731096): Write Unit Test to make sure sanitizeWidgetsShortcutsAndPackages
// actually re-pins shortcuts that are in model but not in ShortcutManager, if possible
// after a simulated restore.
- if (Objects.equals(mApp.getInvariantDeviceProfile().dbFile, mDbName)) {
+ if (Objects.equals(mIDP.dbFile, mDbName)) {
verifyNotStopped();
sanitizeFolders(mItemsDeleted);
sanitizeAppPairs();
@@ -307,13 +324,13 @@ public class LoaderTask implements Runnable {
setIgnorePackages(updateHandler);
updateHandler.updateIcons(allActivityList,
LauncherActivityCachingLogic.INSTANCE,
- mApp.getModel()::onPackageIconsUpdated);
+ mModel::onPackageIconsUpdated);
logASplit("update AllApps icon cache finished");
verifyNotStopped();
logASplit("saving all shortcuts in icon cache");
updateHandler.updateIcons(allShortcuts, CacheableShortcutCachingLogic.INSTANCE,
- mApp.getModel()::onPackageIconsUpdated);
+ mModel::onPackageIconsUpdated);
// Take a break
waitForIdle();
@@ -342,14 +359,14 @@ public class LoaderTask implements Runnable {
// fourth step
WidgetsModel widgetsModel = mBgDataModel.widgetsModel;
- List<CachedObject> allWidgetsList = widgetsModel.update(mApp, /*packageUser=*/null);
+ List<CachedObject> allWidgetsList = widgetsModel.update(/*packageUser=*/null);
logASplit("load widgets finished");
verifyNotStopped();
mLauncherBinder.bindWidgets();
logASplit("bindWidgets finished");
verifyNotStopped();
- LauncherPrefs prefs = LauncherPrefs.get(mApp.getContext());
+ LauncherPrefs prefs = LauncherPrefs.get(mContext);
if (enableSmartspaceAsAWidget() && prefs.get(SHOULD_SHOW_SMARTSPACE)) {
mLauncherBinder.bindSmartspaceWidget();
@@ -366,7 +383,7 @@ public class LoaderTask implements Runnable {
logASplit("saving all widgets in icon cache");
updateHandler.updateIcons(allWidgetsList,
CachedObjectCachingLogic.INSTANCE,
- mApp.getModel()::onWidgetLabelsUpdated);
+ mModel::onWidgetLabelsUpdated);
// fifth step
loadFolderNames();
@@ -380,7 +397,7 @@ public class LoaderTask implements Runnable {
memoryLogger.clearLogs();
if (mIsRestoreFromBackup) {
mIsRestoreFromBackup = false;
- LauncherPrefs.get(mApp.getContext()).putSync(IS_FIRST_LOAD_AFTER_RESTORE.to(false));
+ LauncherPrefs.get(mContext).putSync(IS_FIRST_LOAD_AFTER_RESTORE.to(false));
if (restoreEventLogger != null) {
restoreEventLogger.reportLauncherRestoreResults();
}
@@ -402,35 +419,42 @@ public class LoaderTask implements Runnable {
this.notify();
}
- protected void loadWorkspace(
+ public void loadWorkspaceForPreview(String selection,
+ Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
+ loadWorkspace(new ArrayList<>(), selection, widgetProviderInfoMap, null, null);
+ }
+
+ private void loadWorkspace(
List<CacheableShortcutInfo> allDeepShortcuts,
String selection,
+ Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap,
@Nullable LoaderMemoryLogger memoryLogger,
@Nullable LauncherRestoreEventLogger restoreEventLogger
) {
Trace.beginSection("LoadWorkspace");
try {
- loadWorkspaceImpl(allDeepShortcuts, selection, memoryLogger, restoreEventLogger);
+ loadWorkspaceImpl(allDeepShortcuts, selection, widgetProviderInfoMap,
+ memoryLogger, restoreEventLogger);
} finally {
Trace.endSection();
}
logASplit("loadWorkspace finished");
mBgDataModel.isFirstPagePinnedItemEnabled = FeatureFlags.QSB_ON_FIRST_SCREEN
- && (!enableSmartspaceRemovalToggle() || LauncherPrefs.getPrefs(
- mApp.getContext()).getBoolean(SMARTSPACE_ON_HOME_SCREEN, true));
+ && (!enableSmartspaceRemovalToggle()
+ || LauncherPrefs.getPrefs(mContext).getBoolean(SMARTSPACE_ON_HOME_SCREEN, true));
}
private void loadWorkspaceImpl(
List<CacheableShortcutInfo> allDeepShortcuts,
String selection,
+ Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap,
@Nullable LoaderMemoryLogger memoryLogger,
@Nullable LauncherRestoreEventLogger restoreEventLogger) {
- final Context context = mApp.getContext();
final boolean isSdCardReady = Utilities.isBootCompleted();
- final WidgetInflater widgetInflater = new WidgetInflater(context);
+ final WidgetInflater widgetInflater = new WidgetInflater(mContext, mIsSafeModeEnabled);
- ModelDbController dbController = mApp.getModel().getModelDbController();
+ ModelDbController dbController = mModel.getModelDbController();
if (Flags.gridMigrationRefactor()) {
try {
dbController.attemptMigrateDb(restoreEventLogger, mModelDelegate);
@@ -452,28 +476,29 @@ public class LoaderTask implements Runnable {
if (Flags.enableSupportForArchiving()) {
mInstallingPkgsCached = installingPkgs;
}
- installingPkgs.forEach(mApp.getIconCache()::updateSessionCache);
+ installingPkgs.forEach(mIconCache::updateSessionCache);
FileLog.d(TAG, "loadWorkspace: Packages with active install/update sessions: "
+ installingPkgs.keySet().stream().map(info -> info.mPackageName).toList());
mFirstScreenBroadcast = new FirstScreenBroadcast(installingPkgs);
mShortcutKeyToPinnedShortcuts = new HashMap<>();
- final LoaderCursor c = new LoaderCursor(
- dbController.query(TABLE_NAME, null, selection, null, null),
- mApp, mUserManagerState, mPmHelper,
+ final LoaderCursor c = mLoaderCursorFactory.createLoaderCursor(
+ dbController.query(null, selection, null, null),
+ mUserManagerState,
mIsRestoreFromBackup ? restoreEventLogger : null);
final Bundle extras = c.getExtras();
mDbName = extras == null ? null : extras.getString(ModelDbController.EXTRA_DB_NAME);
try {
final LongSparseArray<Boolean> unlockedUsers = new LongSparseArray<>();
- queryPinnedShortcutsForUnlockedUsers(context, unlockedUsers);
+ queryPinnedShortcutsForUnlockedUsers(mContext, unlockedUsers);
mWorkspaceIconRequestInfos = new ArrayList<>();
WorkspaceItemProcessor itemProcessor = new WorkspaceItemProcessor(c, memoryLogger,
mUserCache, mUserManagerState, mLauncherApps, mPendingPackages,
- mShortcutKeyToPinnedShortcuts, mApp, mBgDataModel,
- mWidgetProvidersMap, installingPkgs, isSdCardReady,
+ mShortcutKeyToPinnedShortcuts, mContext, mIDP, mIconCache,
+ mIsSafeModeEnabled, mBgDataModel,
+ widgetProviderInfoMap, installingPkgs, isSdCardReady,
widgetInflater, mPmHelper, mWorkspaceIconRequestInfos, unlockedUsers,
allDeepShortcuts);
@@ -577,7 +602,7 @@ public class LoaderTask implements Runnable {
@WorkerThread
private void processFolderItems() {
// Sort the folder items, update ranks, and make sure all preview items are high res.
- List<FolderGridOrganizer> verifiers = mApp.getInvariantDeviceProfile().supportedProfiles
+ List<FolderGridOrganizer> verifiers = mIDP.supportedProfiles
.stream().map(FolderGridOrganizer::createFolderGridOrganizer).toList();
for (ItemInfo itemInfo : mBgDataModel.itemsIdMap) {
if (!(itemInfo instanceof FolderInfo folder)) {
@@ -617,7 +642,7 @@ public class LoaderTask implements Runnable {
if (mIconCache.isDefaultIcon(wai.bitmap, wai.user)) {
logASplit("tryLoadWorkspaceIconsInBulk: default icon found for "
+ wai.getTargetComponent() + ", will attempt to load from iconBlob");
- iconRequestInfo.loadIconFromDbBlob(mApp.getContext());
+ iconRequestInfo.loadIconFromDbBlob(mContext);
}
}
} finally {
@@ -649,7 +674,7 @@ public class LoaderTask implements Runnable {
private void sanitizeFolders(boolean itemsDeleted) {
if (itemsDeleted) {
// Remove any empty folder
- IntArray deletedFolderIds = mApp.getModel().getModelDbController().deleteEmptyFolders();
+ IntArray deletedFolderIds = mModel.getModelDbController().deleteEmptyFolders();
synchronized (mBgDataModel) {
for (int folderId : deletedFolderIds) {
mBgDataModel.itemsIdMap.remove(folderId);
@@ -660,8 +685,8 @@ public class LoaderTask implements Runnable {
/** Cleans up app pairs if they don't have the right number of member apps (2). */
private void sanitizeAppPairs() {
- IntArray deletedAppPairIds = mApp.getModel().getModelDbController().deleteBadAppPairs();
- IntArray deletedAppIds = mApp.getModel().getModelDbController().deleteUnparentedApps();
+ IntArray deletedAppPairIds = mModel.getModelDbController().deleteBadAppPairs();
+ IntArray deletedAppIds = mModel.getModelDbController().deleteUnparentedApps();
IntArray deleted = new IntArray();
deleted.addAll(deletedAppPairIds);
@@ -675,17 +700,15 @@ public class LoaderTask implements Runnable {
}
private void sanitizeWidgetsShortcutsAndPackages() {
- Context context = mApp.getContext();
-
// Remove any ghost widgets
- mApp.getModel().getModelDbController().removeGhostWidgets();
+ mModel.getModelDbController().removeGhostWidgets();
// Update pinned state of model shortcuts
- mBgDataModel.updateShortcutPinnedState(context);
+ mBgDataModel.updateShortcutPinnedState(mContext);
if (!Utilities.isBootCompleted() && !mPendingPackages.isEmpty()) {
- context.registerReceiver(
- new SdCardAvailableReceiver(mApp, mPendingPackages),
+ mContext.registerReceiver(
+ new SdCardAvailableReceiver(mContext, mModel, mPendingPackages),
new IntentFilter(Intent.ACTION_BOOT_COMPLETED),
null,
MODEL_EXECUTOR.getHandler());
@@ -722,7 +745,7 @@ public class LoaderTask implements Runnable {
for (int i = 0; i < apps.size(); i++) {
LauncherActivityInfo app = apps.get(i);
AppInfo appInfo = new AppInfo(app, mUserCache.getUserInfo(user),
- ApiWrapper.INSTANCE.get(mApp.getContext()), mPmHelper, quietMode);
+ ApiWrapper.INSTANCE.get(mContext), mPmHelper, quietMode);
if (Flags.enableSupportForArchiving() && app.getApplicationInfo().isArchived) {
// For archived apps, include progress info in case there is a pending
// install session post restart of device.
@@ -751,7 +774,7 @@ public class LoaderTask implements Runnable {
for (PackageInstaller.SessionInfo info :
mSessionHelper.getAllVerifiedSessions()) {
AppInfo promiseAppInfo = mBgAllAppsList.addPromiseApp(
- mApp.getContext(),
+ mContext,
PackageInstallInfo.fromInstallingState(info),
false);
@@ -776,7 +799,7 @@ public class LoaderTask implements Runnable {
+ appInfo.getTargetComponent()
+ ", will attempt to load from iconBlob: "
+ Arrays.toString(iconRequestInfo.iconBlob));
- iconRequestInfo.loadIconFromDbBlob(mApp.getContext());
+ iconRequestInfo.loadIconFromDbBlob(mContext);
}
}
}
@@ -794,9 +817,9 @@ public class LoaderTask implements Runnable {
mUserManagerState.isAnyProfileQuietModeEnabled());
}
mBgAllAppsList.setFlags(FLAG_HAS_SHORTCUT_PERMISSION,
- hasShortcutsPermission(mApp.getContext()));
+ hasShortcutsPermission(mContext));
mBgAllAppsList.setFlags(FLAG_QUIET_MODE_CHANGE_PERMISSION,
- mApp.getContext().checkSelfPermission("android.permission.MODIFY_QUIET_MODE")
+ mContext.checkSelfPermission("android.permission.MODIFY_QUIET_MODE")
== PackageManager.PERMISSION_GRANTED);
mBgAllAppsList.getAndResetChangeFlag();
@@ -827,7 +850,7 @@ public class LoaderTask implements Runnable {
workspaceIconRequest.get().iconBlob,
false /* useLowResIcon= */
);
- if (!iconRequestInfo.loadIconFromDbBlob(mApp.getContext())) {
+ if (!iconRequestInfo.loadIconFromDbBlob(mContext)) {
Log.d(TAG, "AppInfo Icon failed to load from blob, using cache.");
mIconCache.getTitleAndIcon(
appInfo,
@@ -853,7 +876,7 @@ public class LoaderTask implements Runnable {
if (mBgAllAppsList.hasShortcutHostPermission()) {
for (UserHandle user : mUserCache.getUserProfiles()) {
if (mUserManager.isUserUnlocked(user)) {
- List<ShortcutInfo> shortcuts = new ShortcutRequest(mApp.getContext(), user)
+ List<ShortcutInfo> shortcuts = new ShortcutRequest(mContext, user)
.query(ShortcutRequest.ALL);
allShortcuts.addAll(shortcuts);
mBgDataModel.updateDeepShortcutCounts(null, user, shortcuts);
@@ -864,7 +887,7 @@ public class LoaderTask implements Runnable {
}
private void loadFolderNames() {
- FolderNameProvider provider = FolderNameProvider.newInstance(mApp.getContext(),
+ FolderNameProvider provider = FolderNameProvider.newInstance(mContext,
mBgAllAppsList.data, FolderNameProvider.getCollectionForSuggestions(mBgDataModel));
synchronized (mBgDataModel) {
@@ -874,7 +897,7 @@ public class LoaderTask implements Runnable {
.forEach(info -> {
FolderInfo fi = (FolderInfo) info;
FolderNameInfos suggestionInfos = new FolderNameInfos();
- provider.getSuggestedFolderName(mApp.getContext(), fi.getAppContents(),
+ provider.getSuggestedFolderName(mContext, fi.getAppContents(),
suggestionInfos);
fi.suggestedFolderNames = suggestionInfos;
});
@@ -891,4 +914,10 @@ public class LoaderTask implements Runnable {
Log.d(TAG, label);
}
}
+
+ @AssistedFactory
+ public interface LoaderTaskFactory {
+
+ LoaderTask newLoaderTask(BaseLauncherBinder binder, UserManagerState userState);
+ }
}
diff --git a/src/com/android/launcher3/model/ModelDbController.java b/src/com/android/launcher3/model/ModelDbController.java
index feae632bc5..64b9c1c9cd 100644
--- a/src/com/android/launcher3/model/ModelDbController.java
+++ b/src/com/android/launcher3/model/ModelDbController.java
@@ -73,6 +73,8 @@ import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.Utilities;
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger;
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger.RestoreError;
+import com.android.launcher3.dagger.ApplicationContext;
+import com.android.launcher3.dagger.LauncherAppSingleton;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.provider.LauncherDbUtils;
@@ -91,10 +93,13 @@ import java.io.StringReader;
import java.util.List;
import java.util.stream.Collectors;
+import javax.inject.Inject;
+
/**
* Utility class which maintains an instance of Launcher database and provides utility methods
* around it.
*/
+@LauncherAppSingleton
public class ModelDbController {
private static final String TAG = "ModelDbController";
@@ -105,17 +110,25 @@ public class ModelDbController {
protected DatabaseHelper mOpenHelper;
private final Context mContext;
-
- public ModelDbController(Context context) {
+ private final InvariantDeviceProfile mIdp;
+ private final LauncherPrefs mPrefs;
+ private final UserCache mUserCache;
+
+ @Inject
+ ModelDbController(
+ @ApplicationContext Context context,
+ InvariantDeviceProfile idp,
+ LauncherPrefs prefs,
+ UserCache userCache) {
mContext = context;
+ mIdp = idp;
+ mPrefs = prefs;
+ mUserCache = userCache;
}
private void printDBs(String prefix) {
try {
- File directory = new File(
- mContext.getDatabasePath(InvariantDeviceProfile.INSTANCE.get(mContext).dbFile)
- .getParent()
- );
+ File directory = new File(mContext.getDatabasePath(mIdp.dbFile).getParent());
if (directory.exists()) {
for (File file : directory.listFiles()) {
Log.d("b/353505773", prefix + "Database file: " + file.getName());
@@ -130,9 +143,9 @@ public class ModelDbController {
private synchronized void createDbIfNotExists() {
if (mOpenHelper == null) {
- String dbFile = LauncherPrefs.get(mContext).get(DB_FILE);
+ String dbFile = mPrefs.get(DB_FILE);
if (dbFile.isEmpty()) {
- dbFile = InvariantDeviceProfile.INSTANCE.get(mContext).dbFile;
+ dbFile = mIdp.dbFile;
}
mOpenHelper = createDatabaseHelper(false /* forMigration */, dbFile);
printDBs("before: ");
@@ -144,7 +157,7 @@ public class ModelDbController {
protected DatabaseHelper createDatabaseHelper(boolean forMigration, String dbFile) {
// Set the flag for empty DB
Runnable onEmptyDbCreateCallback = forMigration ? () -> { }
- : () -> LauncherPrefs.get(mContext).putSync(getEmptyDbCreatedKey(dbFile).to(true));
+ : () -> mPrefs.putSync(getEmptyDbCreatedKey(dbFile).to(true));
DatabaseHelper databaseHelper = new DatabaseHelper(mContext, dbFile,
this::getSerialNumberForUser, onEmptyDbCreateCallback);
@@ -169,12 +182,12 @@ public class ModelDbController {
* Refer {@link SQLiteDatabase#query}
*/
@WorkerThread
- public Cursor query(String table, String[] projection, String selection,
+ public Cursor query(String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
createDbIfNotExists();
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Cursor result = db.query(
- table, projection, selection, selectionArgs, null, null, sortOrder);
+ TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder);
final Bundle extra = new Bundle();
extra.putString(EXTRA_DB_NAME, mOpenHelper.getDatabaseName());
@@ -186,12 +199,12 @@ public class ModelDbController {
* Refer {@link SQLiteDatabase#insert(String, String, ContentValues)}
*/
@WorkerThread
- public int insert(String table, ContentValues initialValues) {
+ public int insert(ContentValues initialValues) {
createDbIfNotExists();
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
addModifiedTime(initialValues);
- int rowId = mOpenHelper.dbInsertAndCheck(db, table, initialValues);
+ int rowId = mOpenHelper.dbInsertAndCheck(db, TABLE_NAME, initialValues);
if (rowId >= 0) {
onAddOrDeleteOp(db);
}
@@ -202,11 +215,11 @@ public class ModelDbController {
* Refer {@link SQLiteDatabase#delete(String, String, String[])}
*/
@WorkerThread
- public int delete(String table, String selection, String[] selectionArgs) {
+ public int delete(String selection, String[] selectionArgs) {
createDbIfNotExists();
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count = db.delete(table, selection, selectionArgs);
+ int count = db.delete(TABLE_NAME, selection, selectionArgs);
if (count > 0) {
onAddOrDeleteOp(db);
}
@@ -217,14 +230,12 @@ public class ModelDbController {
* Refer {@link SQLiteDatabase#update(String, ContentValues, String, String[])}
*/
@WorkerThread
- public int update(String table, ContentValues values,
- String selection, String[] selectionArgs) {
+ public int update(ContentValues values, String selection, String[] selectionArgs) {
createDbIfNotExists();
addModifiedTime(values);
SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count = db.update(table, values, selection, selectionArgs);
- return count;
+ return db.update(TABLE_NAME, values, selection, selectionArgs);
}
/**
@@ -261,7 +272,7 @@ public class ModelDbController {
public void createEmptyDB() {
createDbIfNotExists();
mOpenHelper.createEmptyDB(mOpenHelper.getWritableDatabase());
- LauncherPrefs.get(mContext).putSync(getEmptyDbCreatedKey().to(true));
+ mPrefs.putSync(getEmptyDbCreatedKey().to(true));
}
/**
@@ -292,7 +303,6 @@ public class ModelDbController {
mOpenHelper.getReadableDatabase(), Favorites.HYBRID_HOTSEAT_BACKUP_TABLE);
}
-
/**
* Resets the launcher DB if we should reset it.
*/
@@ -302,11 +312,10 @@ public class ModelDbController {
}
FileLog.d(TAG, "resetLauncherDb: Migration failed: resetting launcher database");
createEmptyDB();
- LauncherPrefs.get(mContext).putSync(
- getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()).to(true));
+ mPrefs.putSync(getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()).to(true));
// Write the grid state to avoid another migration
- new DeviceGridState(LauncherAppState.getIDP(mContext)).writeToPrefs(mContext);
+ new DeviceGridState(mIdp).writeToPrefs(mContext);
}
/**
@@ -326,7 +335,7 @@ public class ModelDbController {
}
private boolean isThereExistingDb() {
- if (LauncherPrefs.get(mContext).get(getEmptyDbCreatedKey())) {
+ if (mPrefs.get(getEmptyDbCreatedKey())) {
// If we already have a new DB, ignore migration
FileLog.d(TAG, "isThereExistingDb: new DB already created, skipping migration");
return true;
@@ -335,8 +344,7 @@ public class ModelDbController {
}
private boolean isGridMigrationNecessary() {
- InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
- if (GridSizeMigrationDBController.needsToMigrate(mContext, idp)) {
+ if (GridSizeMigrationDBController.needsToMigrate(mContext, mIdp)) {
return true;
}
FileLog.d(TAG, "isGridMigrationNecessary: no grid migration needed");
@@ -344,8 +352,7 @@ public class ModelDbController {
}
private boolean isCurrentDbSameAsTarget() {
- InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
- String targetDbName = new DeviceGridState(idp).getDbFile();
+ String targetDbName = new DeviceGridState(mIdp).getDbFile();
if (TextUtils.equals(targetDbName, mOpenHelper.getDatabaseName())) {
FileLog.e(TAG, "isCurrentDbSameAsTarget: target db is same as current"
+ " current db: " + mOpenHelper.getDatabaseName()
@@ -367,7 +374,6 @@ public class ModelDbController {
return;
}
- InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
DatabaseHelper oldHelper = mOpenHelper;
// We save the existing db's before creating the destination db helper so we know what logic
@@ -376,12 +382,12 @@ public class ModelDbController {
.filter(dbName -> mContext.getDatabasePath(dbName).exists())
.collect(Collectors.toList());
- mOpenHelper = createDatabaseHelper(true, new DeviceGridState(idp).getDbFile());
+ mOpenHelper = createDatabaseHelper(true, new DeviceGridState(mIdp).getDbFile());
try {
// This is the current grid we have, given by the mContext
DeviceGridState srcDeviceState = new DeviceGridState(mContext);
// This is the state we want to migrate to that is given by the idp
- DeviceGridState destDeviceState = new DeviceGridState(idp);
+ DeviceGridState destDeviceState = new DeviceGridState(mIdp);
boolean isDestNewDb = !existingDBs.contains(destDeviceState.getDbFile());
GridSizeMigrationLogic gridSizeMigrationLogic = new GridSizeMigrationLogic();
@@ -404,10 +410,10 @@ public class ModelDbController {
ModelDelegate modelDelegate) {
if (!migrateGridIfNeeded(modelDelegate)) {
if (restoreEventLogger != null) {
- if (LauncherPrefs.get(mContext).get(NO_DB_FILES_RESTORED)) {
+ if (mPrefs.get(NO_DB_FILES_RESTORED)) {
restoreEventLogger.logLauncherItemsRestoreFailed(DATA_TYPE_DB_FILE, 1,
RestoreError.DATABASE_FILE_NOT_RESTORED);
- LauncherPrefs.get(mContext).put(NO_DB_FILES_RESTORED, false);
+ mPrefs.put(NO_DB_FILES_RESTORED, false);
FileLog.d(TAG, "There is no data to migrate: resetting launcher database");
} else {
restoreEventLogger.logLauncherItemsRestored(DATA_TYPE_DB_FILE, 1);
@@ -416,11 +422,10 @@ public class ModelDbController {
}
FileLog.d(TAG, "tryMigrateDB: Migration failed: resetting launcher database");
createEmptyDB();
- LauncherPrefs.get(mContext).putSync(
- getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()).to(true));
+ mPrefs.putSync(getEmptyDbCreatedKey(mOpenHelper.getDatabaseName()).to(true));
// Write the grid state to avoid another migration
- new DeviceGridState(LauncherAppState.getIDP(mContext)).writeToPrefs(mContext);
+ new DeviceGridState(mIdp).writeToPrefs(mContext);
} else if (restoreEventLogger != null) {
restoreEventLogger.logLauncherItemsRestored(DATA_TYPE_DB_FILE, 1);
}
@@ -434,17 +439,16 @@ public class ModelDbController {
*/
private boolean migrateGridIfNeeded(ModelDelegate modelDelegate) {
createDbIfNotExists();
- if (LauncherPrefs.get(mContext).get(getEmptyDbCreatedKey())) {
+ if (mPrefs.get(getEmptyDbCreatedKey())) {
// If we have already create a new DB, ignore migration
FileLog.d(TAG, "migrateGridIfNeeded: new DB already created, skipping migration");
return false;
}
- InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
- if (!GridSizeMigrationDBController.needsToMigrate(mContext, idp)) {
+ if (!GridSizeMigrationDBController.needsToMigrate(mContext, mIdp)) {
FileLog.d(TAG, "migrateGridIfNeeded: no grid migration needed");
return true;
}
- String targetDbName = new DeviceGridState(idp).getDbFile();
+ String targetDbName = new DeviceGridState(mIdp).getDbFile();
if (TextUtils.equals(targetDbName, mOpenHelper.getDatabaseName())) {
FileLog.e(TAG, "migrateGridIfNeeded: target db is same as current"
+ " current db: " + mOpenHelper.getDatabaseName()
@@ -462,7 +466,7 @@ public class ModelDbController {
// This is the current grid we have, given by the mContext
DeviceGridState srcDeviceState = new DeviceGridState(mContext);
// This is the state we want to migrate to that is given by the idp
- DeviceGridState destDeviceState = new DeviceGridState(idp);
+ DeviceGridState destDeviceState = new DeviceGridState(mIdp);
boolean isDestNewDb = !existingDBs.contains(destDeviceState.getDbFile());
return GridSizeMigrationDBController.migrateGridIfNeeded(mContext, srcDeviceState,
destDeviceState, mOpenHelper, oldHelper.getWritableDatabase(), isDestNewDb,
@@ -611,7 +615,7 @@ public class ModelDbController {
}
private void clearFlagEmptyDbCreated() {
- LauncherPrefs.get(mContext).removeSync(getEmptyDbCreatedKey());
+ mPrefs.removeSync(getEmptyDbCreatedKey());
}
/**
@@ -625,7 +629,7 @@ public class ModelDbController {
public synchronized void loadDefaultFavoritesIfNecessary() {
createDbIfNotExists();
- if (LauncherPrefs.get(mContext).get(getEmptyDbCreatedKey())) {
+ if (mPrefs.get(getEmptyDbCreatedKey())) {
Log.d(TAG, "loading default workspace");
LauncherWidgetHolder widgetHolder = mOpenHelper.newLauncherWidgetHolder();
@@ -737,10 +741,9 @@ public class ModelDbController {
}
private DefaultLayoutParser getDefaultLayoutParser(LauncherWidgetHolder widgetHolder) {
- InvariantDeviceProfile idp = LauncherAppState.getIDP(mContext);
- int defaultLayout = idp.demoModeLayoutId != 0
+ int defaultLayout = mIdp.demoModeLayoutId != 0
&& mContext.getSystemService(UserManager.class).isDemoUser()
- ? idp.demoModeLayoutId : idp.defaultLayoutId;
+ ? mIdp.demoModeLayoutId : mIdp.defaultLayoutId;
return new DefaultLayoutParser(mContext, widgetHolder,
mOpenHelper, mContext.getResources(), defaultLayout);
@@ -766,6 +769,6 @@ public class ModelDbController {
* Returns the serial number for the provided user
*/
public long getSerialNumberForUser(UserHandle user) {
- return UserCache.INSTANCE.get(mContext).getSerialNumberForUser(user);
+ return mUserCache.getSerialNumberForUser(user);
}
}
diff --git a/src/com/android/launcher3/model/ModelLauncherCallbacks.kt b/src/com/android/launcher3/model/ModelLauncherCallbacks.kt
index 7ba2dad553..8b6c369e66 100644
--- a/src/com/android/launcher3/model/ModelLauncherCallbacks.kt
+++ b/src/com/android/launcher3/model/ModelLauncherCallbacks.kt
@@ -114,7 +114,7 @@ class ModelLauncherCallbacks(private var taskExecutor: Consumer<ModelUpdateTask>
override fun onUpdateSessionDisplay(key: PackageUserKey, info: SessionInfo) {
/** Updates the icons and label of all pending icons for the provided package name. */
taskExecutor.accept { controller, _, _ ->
- controller.app.iconCache.updateSessionCache(key, info)
+ controller.iconCache.updateSessionCache(key, info)
}
taskExecutor.accept(
CacheDataUpdatedTask(
@@ -128,7 +128,7 @@ class ModelLauncherCallbacks(private var taskExecutor: Consumer<ModelUpdateTask>
override fun onInstallSessionCreated(sessionInfo: PackageInstallInfo) {
if (FeatureFlags.PROMISE_APPS_IN_ALL_APPS.get()) {
taskExecutor.accept { taskController, _, apps ->
- apps.addPromiseApp(taskController.app.context, sessionInfo)
+ apps.addPromiseApp(taskController.context, sessionInfo)
taskController.bindApplicationsIfNeeded()
}
}
diff --git a/src/com/android/launcher3/model/ModelTaskController.kt b/src/com/android/launcher3/model/ModelTaskController.kt
index 5566482738..f17ca32cce 100644
--- a/src/com/android/launcher3/model/ModelTaskController.kt
+++ b/src/com/android/launcher3/model/ModelTaskController.kt
@@ -16,27 +16,34 @@
package com.android.launcher3.model
-import com.android.launcher3.LauncherAppState
+import android.content.Context
import com.android.launcher3.LauncherModel
import com.android.launcher3.LauncherModel.CallbackTask
import com.android.launcher3.celllayout.CellPosMapper
+import com.android.launcher3.dagger.ApplicationContext
+import com.android.launcher3.icons.IconCache
import com.android.launcher3.model.BgDataModel.FixedContainerItems
import com.android.launcher3.model.data.ItemInfo
+import com.android.launcher3.util.Executors.MAIN_EXECUTOR
import com.android.launcher3.util.PackageUserKey
import com.android.launcher3.widget.model.WidgetsListBaseEntriesBuilder
import java.util.Objects
-import java.util.concurrent.Executor
import java.util.function.Predicate
+import javax.inject.Inject
/** Class with utility methods and properties for running a LauncherModel Task */
-class ModelTaskController(
- val app: LauncherAppState,
+class ModelTaskController
+@Inject
+constructor(
+ @ApplicationContext val context: Context,
+ val iconCache: IconCache,
val dataModel: BgDataModel,
val allAppsList: AllAppsList,
- private val model: LauncherModel,
- private val uiExecutor: Executor,
+ val model: LauncherModel,
) {
+ private val uiExecutor = MAIN_EXECUTOR
+
/** Schedules a {@param task} to be executed on the current callbacks. */
fun scheduleCallbackTask(task: CallbackTask) {
for (cb in model.callbacks) {
@@ -78,7 +85,7 @@ class ModelTaskController(
fun bindUpdatedWidgets(dataModel: BgDataModel) {
val allWidgets =
- WidgetsListBaseEntriesBuilder(app.context)
+ WidgetsListBaseEntriesBuilder(context)
.build(dataModel.widgetsModel.widgetsByPackageItemForPicker)
scheduleCallbackTask { it.bindAllWidgets(allWidgets) }
}
diff --git a/src/com/android/launcher3/model/ModelWriter.java b/src/com/android/launcher3/model/ModelWriter.java
index 0332775224..2650e03c63 100644
--- a/src/com/android/launcher3/model/ModelWriter.java
+++ b/src/com/android/launcher3/model/ModelWriter.java
@@ -16,7 +16,6 @@
package com.android.launcher3.model;
-import static com.android.launcher3.LauncherSettings.Favorites.TABLE_NAME;
import static com.android.launcher3.provider.LauncherDbUtils.itemIdMatch;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
@@ -229,7 +228,7 @@ public class ModelWriter {
}).executeOnModelThread();
}
- private void notifyItemModified(ItemInfo item) {
+ public void notifyItemModified(ItemInfo item) {
notifyOtherCallbacks(c -> c.bindItemsModified(Collections.singletonList(item)));
}
@@ -253,7 +252,7 @@ public class ModelWriter {
item.onAddToDatabase(writer);
writer.put(Favorites._ID, item.id);
- mModel.getModelDbController().insert(Favorites.TABLE_NAME, writer.getValues(mContext));
+ mModel.getModelDbController().insert(writer.getValues(mContext));
synchronized (mBgDataModel) {
checkItemInfoLocked(item.id, item, stackTrace);
mBgDataModel.addItem(mContext, item, true);
@@ -292,7 +291,7 @@ public class ModelWriter {
notifyDelete(items);
enqueueDeleteRunnable(newModelTask(() -> {
for (ItemInfo item : items) {
- mModel.getModelDbController().delete(TABLE_NAME, itemIdMatch(item.id), null);
+ mModel.getModelDbController().delete(itemIdMatch(item.id), null);
mBgDataModel.removeItem(mContext, item);
verifier.verifyModel();
}
@@ -307,12 +306,12 @@ public class ModelWriter {
notifyDelete(Collections.singleton(info));
enqueueDeleteRunnable(newModelTask(() -> {
- mModel.getModelDbController().delete(Favorites.TABLE_NAME,
+ mModel.getModelDbController().delete(
Favorites.CONTAINER + "=" + info.id, null);
mBgDataModel.removeItem(mContext, info.getContents());
info.getContents().clear();
- mModel.getModelDbController().delete(Favorites.TABLE_NAME,
+ mModel.getModelDbController().delete(
Favorites._ID + "=" + info.id, null);
mBgDataModel.removeItem(mContext, info);
verifier.verifyModel();
@@ -411,7 +410,7 @@ public class ModelWriter {
@Override
public void runImpl() {
mModel.getModelDbController().update(
- TABLE_NAME, mWriter.get().getValues(mContext), itemIdMatch(mItemId), null);
+ mWriter.get().getValues(mContext), itemIdMatch(mItemId), null);
updateItemArrays(mItem, mItemId);
}
}
@@ -433,7 +432,7 @@ public class ModelWriter {
ItemInfo item = mItems.get(i);
final int itemId = item.id;
mModel.getModelDbController().update(
- TABLE_NAME, mValues.get(i), itemIdMatch(itemId), null);
+ mValues.get(i), itemIdMatch(itemId), null);
updateItemArrays(item, itemId);
}
t.commit();
diff --git a/src/com/android/launcher3/model/PackageInstallStateChangedTask.java b/src/com/android/launcher3/model/PackageInstallStateChangedTask.java
index a2160422b2..a3561eda4d 100644
--- a/src/com/android/launcher3/model/PackageInstallStateChangedTask.java
+++ b/src/com/android/launcher3/model/PackageInstallStateChangedTask.java
@@ -52,11 +52,11 @@ public class PackageInstallStateChangedTask implements ModelUpdateTask {
try {
// For instant apps we do not get package-add. Use setting events to update
// any pinned icons.
- Context context = taskController.getApp().getContext();
+ Context context = taskController.getContext();
ApplicationInfo ai = context
.getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
if (InstantAppResolver.newInstance(context).isInstantApp(ai)) {
- taskController.getApp().getModel().newModelCallbacks()
+ taskController.getModel().newModelCallbacks()
.onPackageAdded(ai.packageName, mInstallInfo.user);
}
} catch (PackageManager.NameNotFoundException e) {
diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java
index 3cdb2500e1..04f3faa194 100644
--- a/src/com/android/launcher3/model/PackageUpdatedTask.java
+++ b/src/com/android/launcher3/model/PackageUpdatedTask.java
@@ -38,7 +38,6 @@ import android.util.Log;
import androidx.annotation.NonNull;
import com.android.launcher3.Flags;
-import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.ModelUpdateTask;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.config.FeatureFlags;
@@ -106,9 +105,8 @@ public class PackageUpdatedTask implements ModelUpdateTask {
@Override
public void execute(@NonNull ModelTaskController taskController, @NonNull BgDataModel dataModel,
@NonNull AllAppsList appsList) {
- final LauncherAppState app = taskController.getApp();
- final Context context = app.getContext();
- final IconCache iconCache = app.getIconCache();
+ final Context context = taskController.getContext();
+ final IconCache iconCache = taskController.getIconCache();
final String[] packages = mPackages;
final int packageCount = packages.length;
@@ -433,7 +431,7 @@ public class PackageUpdatedTask implements ModelUpdateTask {
// Load widgets for the new package. Changes due to app updates are handled through
// AppWidgetHost events, this is just to initialize the long-press options.
for (int i = 0; i < packageCount; i++) {
- dataModel.widgetsModel.update(app, new PackageUserKey(packages[i], mUser));
+ dataModel.widgetsModel.update(new PackageUserKey(packages[i], mUser));
}
taskController.bindUpdatedWidgets(dataModel);
}
diff --git a/src/com/android/launcher3/model/SdCardAvailableReceiver.java b/src/com/android/launcher3/model/SdCardAvailableReceiver.java
index 9e3f0e1aa2..9ae8092345 100644
--- a/src/com/android/launcher3/model/SdCardAvailableReceiver.java
+++ b/src/com/android/launcher3/model/SdCardAvailableReceiver.java
@@ -22,7 +22,6 @@ import android.content.Intent;
import android.content.pm.LauncherApps;
import android.os.UserHandle;
-import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.util.ApplicationInfoWrapper;
import com.android.launcher3.util.PackageUserKey;
@@ -43,9 +42,10 @@ public class SdCardAvailableReceiver extends BroadcastReceiver {
private final Context mContext;
private final Set<PackageUserKey> mPackages;
- public SdCardAvailableReceiver(LauncherAppState app, Set<PackageUserKey> packages) {
- mModel = app.getModel();
- mContext = app.getContext();
+ public SdCardAvailableReceiver(
+ Context context, LauncherModel model, Set<PackageUserKey> packages) {
+ mContext = context;
+ mModel = model;
mPackages = packages;
}
diff --git a/src/com/android/launcher3/model/SessionFailureTask.kt b/src/com/android/launcher3/model/SessionFailureTask.kt
index 8baf568ace..6ed5178ed7 100644
--- a/src/com/android/launcher3/model/SessionFailureTask.kt
+++ b/src/com/android/launcher3/model/SessionFailureTask.kt
@@ -33,9 +33,9 @@ class SessionFailureTask(val packageName: String, val user: UserHandle) : ModelU
dataModel: BgDataModel,
apps: AllAppsList,
) {
- val iconCache = taskController.app.iconCache
+ val iconCache = taskController.iconCache
val isAppArchived =
- ApplicationInfoWrapper(taskController.app.context, packageName, user).isArchived()
+ ApplicationInfoWrapper(taskController.context, packageName, user).isArchived()
synchronized(dataModel) {
if (isAppArchived) {
val updatedItems = mutableListOf<WorkspaceItemInfo>()
diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.kt b/src/com/android/launcher3/model/ShortcutsChangedTask.kt
index 56e9e43d3a..d6759e2d21 100644
--- a/src/com/android/launcher3/model/ShortcutsChangedTask.kt
+++ b/src/com/android/launcher3/model/ShortcutsChangedTask.kt
@@ -40,8 +40,7 @@ class ShortcutsChangedTask(
dataModel: BgDataModel,
apps: AllAppsList,
) {
- val app = taskController.app
- val context = app.context
+ val context = taskController.context
// Find WorkspaceItemInfo's that have changed on the workspace.
val matchingWorkspaceItems = ArrayList<WorkspaceItemInfo>()
@@ -88,7 +87,7 @@ class ShortcutsChangedTask(
.filter { itemInfo: WorkspaceItemInfo -> shortcutId == itemInfo.deepShortcutId }
.forEach { workspaceItemInfo: WorkspaceItemInfo ->
workspaceItemInfo.updateFromDeepShortcutInfo(fullDetails, context)
- app.iconCache.getShortcutIcon(
+ taskController.iconCache.getShortcutIcon(
workspaceItemInfo,
CacheableShortcutInfo(fullDetails, infoWrapper),
)
diff --git a/src/com/android/launcher3/model/UserLockStateChangedTask.java b/src/com/android/launcher3/model/UserLockStateChangedTask.java
index 3dc5ff3b57..4d28ccb42d 100644
--- a/src/com/android/launcher3/model/UserLockStateChangedTask.java
+++ b/src/com/android/launcher3/model/UserLockStateChangedTask.java
@@ -23,7 +23,6 @@ import android.os.UserHandle;
import androidx.annotation.NonNull;
-import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel.ModelUpdateTask;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -55,8 +54,7 @@ public class UserLockStateChangedTask implements ModelUpdateTask {
@Override
public void execute(@NonNull ModelTaskController taskController, @NonNull BgDataModel dataModel,
@NonNull AllAppsList apps) {
- LauncherAppState app = taskController.getApp();
- Context context = app.getContext();
+ Context context = taskController.getContext();
HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>();
if (mIsUserUnlocked) {
@@ -92,7 +90,7 @@ public class UserLockStateChangedTask implements ModelUpdateTask {
}
si.runtimeStatusFlags &= ~FLAG_DISABLED_LOCKED_USER;
si.updateFromDeepShortcutInfo(shortcut, context);
- app.getIconCache().getShortcutIcon(si, shortcut);
+ taskController.getIconCache().getShortcutIcon(si, shortcut);
} else {
si.runtimeStatusFlags |= FLAG_DISABLED_LOCKED_USER;
}
diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java
index 52b142db67..f2144c0e3a 100644
--- a/src/com/android/launcher3/model/WidgetsModel.java
+++ b/src/com/android/launcher3/model/WidgetsModel.java
@@ -27,6 +27,7 @@ import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.dagger.ApplicationContext;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.cache.CachedObject;
import com.android.launcher3.model.data.PackageItemInfo;
@@ -54,6 +55,8 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
+import javax.inject.Inject;
+
/**
* Widgets data model that is used by the adapters of the widget views and controllers.
*
@@ -68,6 +71,29 @@ public class WidgetsModel {
private final Map<PackageItemInfo, List<WidgetItem>> mWidgetsByPackageItem = new HashMap<>();
@Nullable private WidgetValidityCheckForPicker mWidgetValidityCheckForPicker = null;
+ private final Context mContext;
+ private final InvariantDeviceProfile mIdp;
+ private final IconCache mIconCache;
+ private final AppFilter mAppFilter;
+
+ @Inject
+ public WidgetsModel(
+ @ApplicationContext Context context,
+ InvariantDeviceProfile idp,
+ IconCache iconCache,
+ AppFilter appFilter) {
+ mContext = context;
+ mIdp = idp;
+ mIconCache = iconCache;
+ mAppFilter = appFilter;
+ }
+
+ public WidgetsModel(Context context) {
+ this(context,
+ LauncherAppState.getIDP(context),
+ LauncherAppState.getInstance(context).getIconCache(), new AppFilter(context));
+ }
+
/**
* Returns all widgets keyed by their component key.
*/
@@ -128,36 +154,33 @@ public class WidgetsModel {
* @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
* only widgets and shortcuts associated with the package/user are.
*/
- public List<CachedObject> update(
- LauncherAppState app, @Nullable PackageUserKey packageUser) {
+ public List<CachedObject> update(@Nullable PackageUserKey packageUser) {
if (!WIDGETS_ENABLED) {
return new ArrayList<>();
}
Preconditions.assertWorkerThread();
- Context context = app.getContext();
final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
List<CachedObject> updatedItems = new ArrayList<>();
try {
- InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
// Widgets
- WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
+ WidgetManagerHelper widgetManager = new WidgetManagerHelper(mContext);
for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
LauncherAppWidgetProviderInfo launcherWidgetInfo =
- LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
+ LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, widgetInfo);
widgetsAndShortcuts.add(new WidgetItem(
- launcherWidgetInfo, idp, app.getIconCache(), app.getContext()));
+ launcherWidgetInfo, mIdp, mIconCache, mContext));
updatedItems.add(launcherWidgetInfo);
}
// Shortcuts
for (ShortcutConfigActivityInfo info :
- queryList(context, packageUser)) {
- widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache()));
+ queryList(mContext, packageUser)) {
+ widgetsAndShortcuts.add(new WidgetItem(info, mIconCache));
updatedItems.add(info);
}
- setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
+ setWidgetsAndShortcuts(widgetsAndShortcuts, packageUser);
} catch (Exception e) {
if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
// the returned value may be incomplete and will not be refreshed until the next
@@ -172,14 +195,14 @@ public class WidgetsModel {
return updatedItems;
}
- private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts,
- LauncherAppState app, @Nullable PackageUserKey packageUser) {
+ private synchronized void setWidgetsAndShortcuts(
+ ArrayList<WidgetItem> rawWidgetsShortcuts, @Nullable PackageUserKey packageUser) {
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
}
// Refresh the validity checker with latest app state.
- mWidgetValidityCheckForPicker = new WidgetValidityCheckForPicker(app);
+ mWidgetValidityCheckForPicker = new WidgetValidityCheckForPicker(mIdp, mAppFilter);
// Temporary cache for {@link PackageItemInfos} to avoid having to go through
// {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
@@ -196,19 +219,17 @@ public class WidgetsModel {
// add and update.
mWidgetsByPackageItem.putAll(rawWidgetsShortcuts.stream()
.filter(new WidgetFlagCheck())
- .flatMap(widgetItem -> getPackageUserKeys(app.getContext(), widgetItem).stream()
+ .flatMap(widgetItem -> getPackageUserKeys(mContext, widgetItem).stream()
.map(key -> new Pair<>(packageItemInfoCache.getOrCreate(key), widgetItem)))
.collect(groupingBy(pair -> pair.first, mapping(pair -> pair.second, toList()))));
// Update each package entry
- IconCache iconCache = app.getIconCache();
for (PackageItemInfo p : packageItemInfoCache.values()) {
- iconCache.getTitleAndIconForApp(p, DEFAULT_LOOKUP_FLAG.withUseLowRes());
+ mIconCache.getTitleAndIconForApp(p, DEFAULT_LOOKUP_FLAG.withUseLowRes());
}
}
- public void onPackageIconsUpdated(Set<String> packageNames, UserHandle user,
- LauncherAppState app) {
+ public void onPackageIconsUpdated(Set<String> packageNames, UserHandle user) {
if (!WIDGETS_ENABLED) {
return;
}
@@ -220,11 +241,10 @@ public class WidgetsModel {
WidgetItem item = items.get(i);
if (item.user.equals(user)) {
if (item.activityInfo != null) {
- items.set(i, new WidgetItem(item.activityInfo, app.getIconCache()));
+ items.set(i, new WidgetItem(item.activityInfo, mIconCache));
} else {
- items.set(i, new WidgetItem(item.widgetInfo,
- app.getInvariantDeviceProfile(), app.getIconCache(),
- app.getContext()));
+ items.set(i, new WidgetItem(
+ item.widgetInfo, mIdp, mIconCache, mContext));
}
}
}
@@ -277,9 +297,9 @@ public class WidgetsModel {
private final InvariantDeviceProfile mIdp;
private final AppFilter mAppFilter;
- WidgetValidityCheckForPicker(LauncherAppState app) {
- mIdp = app.getInvariantDeviceProfile();
- mAppFilter = new AppFilter(app.getContext());
+ WidgetValidityCheckForPicker(InvariantDeviceProfile idp, AppFilter appFilter) {
+ mIdp = idp;
+ mAppFilter = appFilter;
}
@Override
diff --git a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
index 99f2837dd0..7b8f21866a 100644
--- a/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
+++ b/src/com/android/launcher3/model/WorkspaceItemProcessor.kt
@@ -18,6 +18,7 @@ package com.android.launcher3.model
import android.annotation.SuppressLint
import android.appwidget.AppWidgetProviderInfo
import android.content.ComponentName
+import android.content.Context
import android.content.Intent
import android.content.pm.LauncherApps
import android.content.pm.LauncherApps.ShortcutQuery
@@ -29,10 +30,10 @@ import android.util.Log
import android.util.LongSparseArray
import com.android.launcher3.Flags
import com.android.launcher3.InvariantDeviceProfile
-import com.android.launcher3.LauncherAppState
import com.android.launcher3.LauncherSettings.Favorites
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger.RestoreError
import com.android.launcher3.icons.CacheableShortcutInfo
+import com.android.launcher3.icons.IconCache
import com.android.launcher3.icons.cache.CacheLookupFlag.Companion.DEFAULT_LOOKUP_FLAG
import com.android.launcher3.logging.FileLog
import com.android.launcher3.model.data.AppInfo
@@ -70,7 +71,10 @@ class WorkspaceItemProcessor(
private val launcherApps: LauncherApps,
private val pendingPackages: MutableSet<PackageUserKey>,
private val shortcutKeyToPinnedShortcuts: Map<ShortcutKey, ShortcutInfo>,
- private val app: LauncherAppState,
+ private val context: Context,
+ private val idp: InvariantDeviceProfile,
+ private val iconCache: IconCache,
+ private val isSafeMode: Boolean,
private val bgDataModel: BgDataModel,
private val widgetProvidersMap: MutableMap<ComponentKey, AppWidgetProviderInfo?>,
private val installingPkgs: HashMap<PackageUserKey, PackageInstaller.SessionInfo>,
@@ -82,9 +86,7 @@ class WorkspaceItemProcessor(
private val allDeepShortcuts: MutableList<CacheableShortcutInfo>,
) {
- private val isSafeMode = app.isSafeModeEnabled
private val tempPackageKey = PackageUserKey(null, null)
- private val iconCache = app.iconCache
/**
* This is the entry point for processing 1 workspace item. This method is like the midfielder
@@ -159,7 +161,7 @@ class WorkspaceItemProcessor(
)
return
}
- val appInfoWrapper = ApplicationInfoWrapper(app.context, targetPkg, c.user)
+ val appInfoWrapper = ApplicationInfoWrapper(context, targetPkg, c.user)
var validTarget = launcherApps.isPackageEnabled(targetPkg, c.user)
// If it's a deep shortcut, we'll use pinned shortcuts to restore it
@@ -306,7 +308,7 @@ class WorkspaceItemProcessor(
)
return
}
- info = WorkspaceItemInfo(pinnedShortcut, app.context)
+ info = WorkspaceItemInfo(pinnedShortcut, context)
// If the pinned deep shortcut is no longer published,
// use the last saved icon instead of the default.
val csi = CacheableShortcutInfo(pinnedShortcut, appInfoWrapper)
@@ -369,7 +371,7 @@ class WorkspaceItemProcessor(
info,
activityInfo,
userCache.getUserInfo(c.user),
- ApiWrapper.INSTANCE[app.context],
+ ApiWrapper.INSTANCE[context],
pmHelper,
)
}
@@ -529,7 +531,7 @@ class WorkspaceItemProcessor(
(si == null) &&
(lapi == null) &&
!(Flags.enableSupportForArchiving() &&
- ApplicationInfoWrapper(app.context, component.packageName, c.user)
+ ApplicationInfoWrapper(context, component.packageName, c.user)
.isArchived())
) {
// Restore never started
@@ -553,7 +555,7 @@ class WorkspaceItemProcessor(
if (si == null) 0 else (si.getProgress() * 100).toInt()
appWidgetInfo.pendingItemInfo =
WidgetsModel.newPendingItemInfo(
- app.context,
+ context,
appWidgetInfo.providerName,
appWidgetInfo.user,
)
@@ -563,7 +565,7 @@ class WorkspaceItemProcessor(
WidgetSizes.updateWidgetSizeRangesAsync(
appWidgetInfo.appWidgetId,
lapi,
- app.context,
+ context,
appWidgetInfo.spanX,
appWidgetInfo.spanY,
)
@@ -586,7 +588,7 @@ class WorkspaceItemProcessor(
" appWidgetId: ${c.appWidgetId}," +
" component=${component}",
)
- logWidgetInfo(app.invariantDeviceProfile, lapi)
+ logWidgetInfo(idp, lapi)
}
}
c.checkAndAddItem(appWidgetInfo, bgDataModel, memoryLogger)
diff --git a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
index 1a6d1786e6..17f1615d8d 100644
--- a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
+++ b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
@@ -21,7 +21,7 @@ import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID;
import android.util.LongSparseArray;
import com.android.launcher3.InvariantDeviceProfile;
-import com.android.launcher3.LauncherAppState;
+import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.ItemInfo;
@@ -31,23 +31,37 @@ import com.android.launcher3.util.IntSet;
import java.util.ArrayList;
+import javax.inject.Inject;
+
/**
* Utility class to help find space for new workspace items
*/
public class WorkspaceItemSpaceFinder {
+ private BgDataModel mDataModel;
+ private InvariantDeviceProfile mIDP;
+ private LauncherModel mModel;
+
+ @Inject
+ WorkspaceItemSpaceFinder(
+ BgDataModel dataModel, InvariantDeviceProfile idp, LauncherModel model) {
+ mDataModel = dataModel;
+ mIDP = idp;
+ mModel = model;
+ }
+
/**
* Find a position on the screen for the given size or adds a new screen.
*
* @return screenId and the coordinates for the item in an int array of size 3.
*/
- public int[] findSpaceForItem(LauncherAppState app, BgDataModel dataModel,
+ public int[] findSpaceForItem(
IntArray workspaceScreens, IntArray addedWorkspaceScreensFinal, int spanX, int spanY) {
LongSparseArray<ArrayList<ItemInfo>> screenItems = new LongSparseArray<>();
// Use sBgItemsIdMap as all the items are already loaded.
- synchronized (dataModel) {
- for (ItemInfo info : dataModel.itemsIdMap) {
+ synchronized (mDataModel) {
+ for (ItemInfo info : mDataModel.itemsIdMap) {
if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
ArrayList<ItemInfo> items = screenItems.get(info.screenId);
if (items == null) {
@@ -75,7 +89,7 @@ public class WorkspaceItemSpaceFinder {
for (int screen = 0; screen < screenCount; screen++) {
screenId = workspaceScreens.get(screen);
if (!screensToExclude.contains(screenId) && findNextAvailableIconSpaceInScreen(
- app, screenItems.get(screenId), coordinates, spanX, spanY)) {
+ screenItems.get(screenId), coordinates, spanX, spanY)) {
// We found a space for it
found = true;
break;
@@ -84,7 +98,7 @@ public class WorkspaceItemSpaceFinder {
if (!found) {
// Still no position found. Add a new screen to the end.
- screenId = app.getModel().getModelDbController().getNewScreenId();
+ screenId = mModel.getModelDbController().getNewScreenId();
// Save the screen id for binding in the workspace
workspaceScreens.add(screenId);
@@ -92,7 +106,7 @@ public class WorkspaceItemSpaceFinder {
// If we still can't find an empty space, then God help us all!!!
if (!findNextAvailableIconSpaceInScreen(
- app, screenItems.get(screenId), coordinates, spanX, spanY)) {
+ screenItems.get(screenId), coordinates, spanX, spanY)) {
throw new RuntimeException("Can't find space to add the item");
}
}
@@ -100,11 +114,8 @@ public class WorkspaceItemSpaceFinder {
}
private boolean findNextAvailableIconSpaceInScreen(
- LauncherAppState app, ArrayList<ItemInfo> occupiedPos,
- int[] xy, int spanX, int spanY) {
- InvariantDeviceProfile profile = app.getInvariantDeviceProfile();
-
- GridOccupancy occupied = new GridOccupancy(profile.numColumns, profile.numRows);
+ ArrayList<ItemInfo> occupiedPos, int[] xy, int spanX, int spanY) {
+ GridOccupancy occupied = new GridOccupancy(mIDP.numColumns, mIDP.numRows);
if (occupiedPos != null) {
for (ItemInfo r : occupiedPos) {
occupied.markCells(r, true);
diff --git a/src/com/android/launcher3/model/data/FolderInfo.java b/src/com/android/launcher3/model/data/FolderInfo.java
index 9656ac10b2..4c792a7672 100644
--- a/src/com/android/launcher3/model/data/FolderInfo.java
+++ b/src/com/android/launcher3/model/data/FolderInfo.java
@@ -20,6 +20,9 @@ import static android.text.TextUtils.isEmpty;
import static androidx.core.util.Preconditions.checkNotNull;
+import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
+import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APP_PAIR;
+import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
import static com.android.launcher3.logger.LauncherAtom.Attribute.EMPTY_LABEL;
import static com.android.launcher3.logger.LauncherAtom.Attribute.MANUAL_LABEL;
import static com.android.launcher3.logger.LauncherAtom.Attribute.SUGGESTED_LABEL;
@@ -30,8 +33,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.Utilities;
-import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderNameInfos;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logger.LauncherAtom.Attribute;
@@ -42,8 +43,6 @@ import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.util.ContentWriter;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
import java.util.OptionalInt;
import java.util.stream.IntStream;
@@ -52,18 +51,6 @@ import java.util.stream.IntStream;
*/
public class FolderInfo extends CollectionInfo {
- public static final int NO_FLAGS = 0x00000000;
-
- /**
- * The folder is locked in sorted mode
- */
- public static final int FLAG_ITEMS_SORTED = 0x00000001;
-
- /**
- * It is a work folder
- */
- public static final int FLAG_WORK_FOLDER = 0x00000002;
-
/**
* The multi-page animation has run for this folder
*/
@@ -95,8 +82,6 @@ public class FolderInfo extends CollectionInfo {
}
}
- public static final String EXTRA_FOLDER_SUGGESTIONS = "suggest";
-
public int options;
public FolderNameInfos suggestedFolderNames;
@@ -106,61 +91,16 @@ public class FolderInfo extends CollectionInfo {
*/
private final ArrayList<ItemInfo> contents = new ArrayList<>();
- private ArrayList<FolderListener> mListeners = new ArrayList<>();
-
public FolderInfo() {
itemType = LauncherSettings.Favorites.ITEM_TYPE_FOLDER;
}
- /** Adds a app or shortcut to the contents ArrayList without animation. */
@Override
public void add(@NonNull ItemInfo item) {
- add(item, false /* animate */);
- }
-
- /**
- * Add an app or shortcut
- *
- * @param item
- */
- public void add(ItemInfo item, boolean animate) {
- add(item, getContents().size(), animate);
- }
-
- /**
- * Add an app or shortcut for a specified rank.
- */
- public void add(ItemInfo item, int rank, boolean animate) {
- if (!Folder.willAccept(item)) {
+ if (!willAcceptItemType(item.itemType)) {
throw new RuntimeException("tried to add an illegal type into a folder");
}
-
- rank = Utilities.boundToRange(rank, 0, getContents().size());
- getContents().add(rank, item);
- for (int i = 0; i < mListeners.size(); i++) {
- mListeners.get(i).onAdd(item, rank);
- }
- itemsChanged(animate);
- }
-
- /**
- * Remove an app or shortcut. Does not change the DB.
- *
- * @param item
- */
- public void remove(ItemInfo item, boolean animate) {
- removeAll(Collections.singletonList(item), animate);
- }
-
- /**
- * Remove all matching app or shortcut. Does not change the DB.
- */
- public void removeAll(List<ItemInfo> items, boolean animate) {
- contents.removeAll(items);
- for (int i = 0; i < mListeners.size(); i++) {
- mListeners.get(i).onRemove(items);
- }
- itemsChanged(animate);
+ getContents().add(item);
}
/**
@@ -197,28 +137,6 @@ public class FolderInfo extends CollectionInfo {
writer.put(LauncherSettings.Favorites.OPTIONS, options);
}
- public void addListener(FolderListener listener) {
- mListeners.add(listener);
- }
-
- public void removeListener(FolderListener listener) {
- mListeners.remove(listener);
- }
-
- public void itemsChanged(boolean animate) {
- for (int i = 0; i < mListeners.size(); i++) {
- mListeners.get(i).onItemsChanged(animate);
- }
- }
-
- public interface FolderListener {
- void onAdd(ItemInfo item, int rank);
- void onRemove(List<ItemInfo> item);
- void onItemsChanged(boolean animate);
- void onTitleChanged(CharSequence title);
-
- }
-
public boolean hasOption(int optionFlag) {
return (options & optionFlag) != 0;
}
@@ -261,7 +179,6 @@ public class FolderInfo extends CollectionInfo {
.build();
}
- @Override
public void setTitle(@Nullable CharSequence title, ModelWriter modelWriter) {
// Updating label from null to empty is considered as false touch.
// Retaining null title(ie., UNLABELED state) allows auto-labeling when new items added.
@@ -289,10 +206,6 @@ public class FolderInfo extends CollectionInfo {
if (modelWriter != null) {
modelWriter.updateItemInDatabase(this);
}
-
- for (int i = 0; i < mListeners.size(); i++) {
- mListeners.get(i).onTitleChanged(title);
- }
}
/**
@@ -401,4 +314,13 @@ public class FolderInfo extends CollectionInfo {
}
return LauncherAtom.ToState.TO_STATE_UNSPECIFIED;
}
+
+ /**
+ * Checks if {@code itemType} is a type that can be placed in folders.
+ */
+ public static boolean willAcceptItemType(int itemType) {
+ return itemType == ITEM_TYPE_APPLICATION
+ || itemType == ITEM_TYPE_DEEP_SHORTCUT
+ || itemType == ITEM_TYPE_APP_PAIR;
+ }
}
diff --git a/src/com/android/launcher3/model/data/ItemInfo.java b/src/com/android/launcher3/model/data/ItemInfo.java
index 588e75959e..ad7696cd15 100644
--- a/src/com/android/launcher3/model/data/ItemInfo.java
+++ b/src/com/android/launcher3/model/data/ItemInfo.java
@@ -61,7 +61,6 @@ import com.android.launcher3.logger.LauncherAtom.ShortcutsContainer;
import com.android.launcher3.logger.LauncherAtom.TaskSwitcherContainer;
import com.android.launcher3.logger.LauncherAtom.WallpapersContainer;
import com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers;
-import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.pm.UserCache;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ContentWriter;
@@ -536,14 +535,6 @@ public class ItemInfo {
}
/**
- * Sets the title of the item and writes to DB model if needed.
- */
- public void setTitle(@Nullable final CharSequence title,
- @Nullable final ModelWriter modelWriter) {
- this.title = title;
- }
-
- /**
* Returns a string ID that is stable for a user session, but may not be persisted
*/
@Nullable
diff --git a/src/com/android/launcher3/pageindicators/PageIndicator.java b/src/com/android/launcher3/pageindicators/PageIndicator.java
index 0640bf3672..a6f76c4d44 100644
--- a/src/com/android/launcher3/pageindicators/PageIndicator.java
+++ b/src/com/android/launcher3/pageindicators/PageIndicator.java
@@ -15,6 +15,8 @@
*/
package com.android.launcher3.pageindicators;
+import java.util.function.Consumer;
+
/**
* Base class for a page indicator.
*/
@@ -27,6 +29,14 @@ public interface PageIndicator {
void setMarkersCount(int numMarkers);
/**
+ * This is only going to be used by the FolderPagedView's PageIndicator. A refactor is planned
+ * to separate the two purposes of this class, but in the meantime, this indicator will serve to
+ * let the folder snap to the page of its click, and also tell the PageIndicator not to draw
+ * arrows if the click listener is null (at least until after this is refactored).
+ */
+ void setArrowClickListener(Consumer<Direction> listener);
+
+ /**
* Sets a flag indicating whether to pause scroll.
* <p>Should be set to {@code true} while the screen is binding or new data is being applied,
* and to {@code false} once done. This prevents animation conflicts due to scrolling during
diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorArrowClickListener.kt b/src/com/android/launcher3/pageindicators/PageIndicatorArrowClickListener.kt
new file mode 100644
index 0000000000..970d210ad9
--- /dev/null
+++ b/src/com/android/launcher3/pageindicators/PageIndicatorArrowClickListener.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2025 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.pageindicators
+
+interface PageIndicatorArrowClickListener {
+ fun onArrowClick(direction: Direction)
+}
+
+enum class Direction {
+ END,
+ START,
+}
diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
index 37f51899aa..384f87623a 100644
--- a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
+++ b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java
@@ -32,11 +32,13 @@ import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.graphics.drawable.VectorDrawable;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.IntProperty;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewOutlineProvider;
@@ -51,9 +53,14 @@ import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.Themes;
+import java.util.function.Consumer;
+
/**
* {@link PageIndicator} which shows dots per page. The active page is shown with the current
* accent color.
+ * <p>
+ * TODO(b/402258632): Split PageIndicatorDots into 2 different classes: FolderPageIndicator &
+ * WorkspacePageIndicator. A lot of the functionality in this class is only used by one UI purpose.
*/
public class PageIndicatorDots extends View implements Insettable, PageIndicator {
@@ -68,6 +75,12 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
private static final int ENTER_ANIMATION_STAGGERED_DELAY = 150;
private static final int ENTER_ANIMATION_DURATION = 400;
+ private static final int LARGE_HEIGHT_MULTIPLIER = 12;
+ private static final int SMALL_HEIGHT_MULTIPLIER = 4;
+ private static final int LARGE_WIDTH_MULTIPLIER = 5;
+ private static final int SMALL_WIDTH_MULTIPLIER = 3;
+ private static final float ARROW_TOUCH_BOX_FACTOR = 5f;
+
private static final int PAGE_INDICATOR_ALPHA = 255;
private static final int DOT_ALPHA = 128;
private static final float DOT_ALPHA_FRACTION = 0.5f;
@@ -75,12 +88,14 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
private static final int VISIBLE_ALPHA = 255;
private static final int INVISIBLE_ALPHA = 0;
private Paint mPaginationPaint;
+ private Consumer<Direction> mOnArrowClickListener;
// This value approximately overshoots to 1.5 times the original size.
private static final float ENTER_ANIMATION_OVERSHOOT_TENSION = 4.9f;
// This is used to optimize the onDraw method by not constructing a new RectF each draw.
private static final RectF sTempRect = new RectF();
+ private static final RectF sLastActiveRect = new RectF();
private static final FloatProperty<PageIndicatorDots> CURRENT_POSITION =
new FloatProperty<PageIndicatorDots>("current_position") {
@@ -99,23 +114,27 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
private static final IntProperty<PageIndicatorDots> PAGINATION_ALPHA =
new IntProperty<PageIndicatorDots>("pagination_alpha") {
- @Override
- public Integer get(PageIndicatorDots obj) {
- return obj.mPaginationPaint.getAlpha();
- }
+ @Override
+ public Integer get(PageIndicatorDots obj) {
+ return obj.mPaginationPaint.getAlpha();
+ }
- @Override
- public void setValue(PageIndicatorDots obj, int alpha) {
- obj.mPaginationPaint.setAlpha(alpha);
- obj.invalidate();
- }
- };
+ @Override
+ public void setValue(PageIndicatorDots obj, int alpha) {
+ obj.mPaginationPaint.setAlpha(alpha);
+ obj.invalidate();
+ }
+ };
private final Handler mDelayedPaginationFadeHandler = new Handler(Looper.getMainLooper());
private final float mDotRadius;
private final float mGapWidth;
private final float mCircleGap;
private final boolean mIsRtl;
+ private final VectorDrawable mArrowRight;
+ private final VectorDrawable mArrowLeft;
+ private final Rect mArrowRightBounds = new Rect();
+ private final Rect mArrowLeftBounds = new Rect();
private int mNumPages;
private int mActivePage;
@@ -167,6 +186,8 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
: DOT_GAP_FACTOR * mDotRadius;
setOutlineProvider(new MyOutlineProver());
mIsRtl = Utilities.isRtl(getResources());
+ mArrowRight = (VectorDrawable) getResources().getDrawable(R.drawable.ic_chevron_end);
+ mArrowLeft = (VectorDrawable) getResources().getDrawable(R.drawable.ic_chevron_start);
}
@Override
@@ -405,6 +426,11 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
}
@Override
+ public void setArrowClickListener(Consumer<Direction> listener) {
+ mOnArrowClickListener = listener;
+ }
+
+ @Override
public void setPauseScroll(boolean pause, boolean isTwoPanels) {
mIsTwoPanels = isTwoPanels;
@@ -419,11 +445,16 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO(b/394355070): Verify Folder Entry Animation works correctly with visual updates
- // Add extra spacing of mDotRadius on all sides so than entry animation could be run.
+ // Add extra spacing of mDotRadius on all sides so than entry animation could be run
+ // and so the hitboxes of arrows can be clicked easier.
int width = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ?
- MeasureSpec.getSize(widthMeasureSpec) : (int) ((mNumPages * 3 + 2) * mDotRadius);
+ MeasureSpec.getSize(widthMeasureSpec)
+ : (int) ((mNumPages * ((enableLauncherVisualRefresh())
+ ? LARGE_WIDTH_MULTIPLIER : SMALL_WIDTH_MULTIPLIER) + 2) * mDotRadius);
int height = MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY
- ? MeasureSpec.getSize(heightMeasureSpec) : (int) (4 * mDotRadius);
+ ? MeasureSpec.getSize(heightMeasureSpec)
+ : (int) (((enableLauncherVisualRefresh())
+ ? LARGE_HEIGHT_MULTIPLIER : SMALL_HEIGHT_MULTIPLIER) * mDotRadius);
setMeasuredDimension(width, height);
}
@@ -443,18 +474,51 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
float y = getHeight() / 2;
if (mEntryAnimationRadiusFactors != null) {
- // During entry animation, only draw the circles
- // TODO(b/394355070): Verify Folder Entry Animation works correctly - visual updates
+ if (enableLauncherVisualRefresh()) {
+ x -= mDotRadius;
+ if (mIsRtl) {
+ x = getWidth() - x;
+ circleGap = -circleGap;
+ }
+ sTempRect.top = y - mDotRadius;
+ sTempRect.bottom = y + mDotRadius;
- if (mIsRtl) {
- x = getWidth() - x;
- circleGap = -circleGap;
- }
- for (int i = 0; i < mEntryAnimationRadiusFactors.length; i++) {
- mPaginationPaint.setAlpha(i == mActivePage ? PAGE_INDICATOR_ALPHA : DOT_ALPHA);
- canvas.drawCircle(x, y, mDotRadius * mEntryAnimationRadiusFactors[i],
- mPaginationPaint);
- x += circleGap;
+ for (int i = 0; i < mEntryAnimationRadiusFactors.length; i++) {
+ if (i == mActivePage) {
+ if (mIsRtl) {
+ sTempRect.left = x - (mDotRadius * 3);
+ sTempRect.right = x + mDotRadius;
+ x += circleGap - (mDotRadius * 2);
+ } else {
+ sTempRect.left = x - mDotRadius;
+ sTempRect.right = x + (mDotRadius * 3);
+ x += circleGap + (mDotRadius * 2);
+ }
+ scale(sTempRect, mEntryAnimationRadiusFactors[i]);
+ float scaledRadius = mDotRadius * mEntryAnimationRadiusFactors[i];
+ mPaginationPaint.setAlpha(PAGE_INDICATOR_ALPHA);
+ canvas.drawRoundRect(sTempRect, scaledRadius, scaledRadius,
+ mPaginationPaint);
+ } else {
+ mPaginationPaint.setAlpha(DOT_ALPHA);
+ canvas.drawCircle(x, y, mDotRadius * mEntryAnimationRadiusFactors[i],
+ mPaginationPaint);
+ x += circleGap;
+ }
+ }
+ } else {
+ // During entry animation, only draw the circles
+
+ if (mIsRtl) {
+ x = getWidth() - x;
+ circleGap = -circleGap;
+ }
+ for (int i = 0; i < mEntryAnimationRadiusFactors.length; i++) {
+ mPaginationPaint.setAlpha(i == mActivePage ? PAGE_INDICATOR_ALPHA : DOT_ALPHA);
+ canvas.drawCircle(x, y, mDotRadius * mEntryAnimationRadiusFactors[i],
+ mPaginationPaint);
+ x += circleGap;
+ }
}
} else {
// Save the current alpha value, so we can reset to it again after drawing the dots
@@ -468,12 +532,31 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
sTempRect.bottom = y + mDotRadius;
sTempRect.left = x - diameter;
- float posDif = Math.abs(mLastPosition - mCurrentPosition);
+ float currentPosition = mCurrentPosition;
+ float lastPosition = mLastPosition;
+
+ if (mIsRtl) {
+ currentPosition = mNumPages - currentPosition - 1;
+ lastPosition = mNumPages - lastPosition - 1;
+ }
+ float posDif = Math.abs(lastPosition - currentPosition);
float boundedPosition = (posDif > 1)
- ? Math.round(mCurrentPosition)
- : mCurrentPosition;
+ ? Math.round(currentPosition)
+ : currentPosition;
float bounceProgress = (posDif > 1) ? posDif - 1 : 0;
- float bounceAdjustment = Math.abs(mCurrentPosition - boundedPosition) * diameter;
+ float bounceAdjustment = Math.abs(currentPosition - boundedPosition) * diameter;
+
+ if (mOnArrowClickListener != null && boundedPosition >= 1) {
+ // Here we draw the Left Arrow
+ mArrowLeft.setAlpha(alpha);
+ int size = (int) (mGapWidth * 4);
+ mArrowLeftBounds.left = (int) (sTempRect.left - mGapWidth - size);
+ mArrowLeftBounds.top = (int) (y - size / 2);
+ mArrowLeftBounds.right = (int) (sTempRect.left - mGapWidth);
+ mArrowLeftBounds.bottom = (int) (y + size / 2);
+ mArrowLeft.setBounds(mArrowLeftBounds);
+ mArrowLeft.draw(canvas);
+ }
// Here we draw the dots, one at a time from the left-most dot to the right-most dot
// 1.0 => 000000 000000111111 000000
@@ -495,10 +578,10 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
// While the animation is shifting the active pagination dots size from
// the previously active one, to the newly active dot, there is no bounce
// adjustment. The bounce happens in the "Overshoot" phase of the animation.
- // mLastPosition is used to determine when the currentPosition is just
+ // lastPosition is used to determine when the currentPosition is just
// leaving the page, or if it is in the overshoot phase.
if (boundedPosition == i && bounceProgress != 0) {
- if (mLastPosition < mCurrentPosition) {
+ if (lastPosition < currentPosition) {
sTempRect.left -= bounceAdjustment;
} else {
sTempRect.right += bounceAdjustment;
@@ -507,19 +590,34 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
} else {
sTempRect.right = sTempRect.left + diameter;
- if (mLastPosition == i && bounceProgress != 0) {
- if (mLastPosition > mCurrentPosition) {
+ if (lastPosition == i && bounceProgress != 0) {
+ if (lastPosition > currentPosition) {
sTempRect.left += bounceAdjustment;
} else {
sTempRect.right -= bounceAdjustment;
}
}
}
+ if (Math.round(mCurrentPosition) == i) {
+ sLastActiveRect.set(sTempRect);
+ }
canvas.drawRoundRect(sTempRect, mDotRadius, mDotRadius, mPaginationPaint);
// TODO(b/394355070) Verify RTL experience works correctly with visual updates
sTempRect.left = sTempRect.right + mGapWidth;
}
+
+ if (mOnArrowClickListener != null && boundedPosition <= mNumPages - 2) {
+ // Here we draw the Right Arrow
+ mArrowRight.setAlpha(alpha);
+ int size = (int) (mGapWidth * 4);
+ mArrowRightBounds.left = (int) sTempRect.left;
+ mArrowRightBounds.top = (int) (y - size / 2);
+ mArrowRightBounds.right = (int) (int) (sTempRect.left + size);
+ mArrowRightBounds.bottom = (int) (y + size / 2);
+ mArrowRight.setBounds(mArrowRightBounds);
+ mArrowRight.draw(canvas);
+ }
} else {
// Here we draw the dots
mPaginationPaint.setAlpha((int) (alpha * DOT_ALPHA_FRACTION));
@@ -538,6 +636,38 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
}
}
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (mOnArrowClickListener == null) {
+ // No - Op. Don't care about touch events
+ } else if ((mIsRtl && withinExpandedBounds(mArrowRightBounds, ev))
+ || (!mIsRtl && withinExpandedBounds(mArrowLeftBounds, ev))) {
+ mOnArrowClickListener.accept(Direction.START);
+ } else if ((mIsRtl && withinExpandedBounds(mArrowLeftBounds, ev))
+ || (!mIsRtl && withinExpandedBounds(mArrowRightBounds, ev))) {
+ mOnArrowClickListener.accept(Direction.END);
+ }
+ return super.onTouchEvent(ev);
+ }
+
+ // For larger Touch box
+ private boolean withinExpandedBounds(Rect rect, MotionEvent ev) {
+ RectF scaledRect = new RectF(rect);
+ scale(scaledRect, ARROW_TOUCH_BOX_FACTOR);
+ return scaledRect.contains(ev.getX(), ev.getY());
+ }
+
+ private static void scale(RectF rect, float factor) {
+ float horizontalAdjustment = rect.width() * (factor - 1) / 2;
+ float verticalAdjustment = rect.height() * (factor - 1) / 2;
+
+ rect.top -= verticalAdjustment;
+ rect.bottom += verticalAdjustment;
+
+ rect.left -= horizontalAdjustment;
+ rect.right += horizontalAdjustment;
+ }
+
private RectF getActiveRect() {
float startCircle = (int) mCurrentPosition;
float delta = mCurrentPosition - startCircle;
@@ -590,8 +720,8 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
@Override
public void getOutline(View view, Outline outline) {
if (mEntryAnimationRadiusFactors == null) {
- // TODO(b/394355070): Verify Outline works correctly with visual updates
- RectF activeRect = getActiveRect();
+ RectF activeRect = enableLauncherVisualRefresh()
+ ? sLastActiveRect : getActiveRect();
outline.setRoundRect(
(int) activeRect.left,
(int) activeRect.top,
diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
index aad1400865..39f68bfe70 100644
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -16,9 +16,12 @@
package com.android.launcher3.popup;
+import static android.multiuser.Flags.enableMovingContentIntoPrivateSpace;
+
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS;
import static com.android.launcher3.Utilities.squaredHypot;
import static com.android.launcher3.Utilities.squaredTouchSlop;
+import static com.android.launcher3.allapps.AlphabeticalAppsList.PRIVATE_SPACE_PACKAGE;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_NOT_PINNABLE;
import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
@@ -65,6 +68,7 @@ import com.android.launcher3.views.ActivityContext;
import com.android.launcher3.views.BaseDragLayer;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -207,7 +211,10 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
R.layout.popup_container, launcher.getDragLayer(), false);
container.configureForLauncher(launcher, item);
- container.populateAndShowRows(icon, deepShortcutCount, systemShortcuts);
+ boolean shouldHideSystemShortcuts = enableMovingContentIntoPrivateSpace()
+ && Objects.equals(item.getTargetPackage(), PRIVATE_SPACE_PACKAGE);
+ container.populateAndShowRows(icon, deepShortcutCount,
+ shouldHideSystemShortcuts ? Collections.emptyList() : systemShortcuts);
launcher.refreshAndBindWidgetsForPackageUser(PackageUserKey.fromItemInfo(item));
container.requestFocus();
return container;
diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java
index 5c1a7553a5..95110329d3 100644
--- a/src/com/android/launcher3/popup/PopupDataProvider.java
+++ b/src/com/android/launcher3/popup/PopupDataProvider.java
@@ -26,7 +26,6 @@ import androidx.annotation.Nullable;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
import com.android.launcher3.dot.DotInfo;
-import com.android.launcher3.dot.FolderDotInfo;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.model.data.FolderInfo;
@@ -76,11 +75,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan
((BubbleTextView) v).applyDotState(info, true /* animate */);
} else if (v instanceof FolderIcon icon
&& info instanceof FolderInfo fi && fi.anyMatch(matcher)) {
- FolderDotInfo folderDotInfo = new FolderDotInfo();
- for (ItemInfo si : fi.getContents()) {
- folderDotInfo.addDotInfo(getDotInfoForItem(si));
- }
- icon.setDotInfo(folderDotInfo);
+ icon.updateDotInfo();
}
// process all the shortcuts
diff --git a/src/com/android/launcher3/provider/LauncherDbUtils.kt b/src/com/android/launcher3/provider/LauncherDbUtils.kt
index c92328d8a3..36413715e0 100644
--- a/src/com/android/launcher3/provider/LauncherDbUtils.kt
+++ b/src/com/android/launcher3/provider/LauncherDbUtils.kt
@@ -26,19 +26,17 @@ import android.os.PersistableBundle
import android.os.Process
import android.os.UserManager
import android.text.TextUtils
-import com.android.launcher3.LauncherAppState
import com.android.launcher3.LauncherSettings
import com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP
import com.android.launcher3.Utilities
+import com.android.launcher3.dagger.LauncherComponentProvider.appComponent
import com.android.launcher3.icons.IconCache
-import com.android.launcher3.model.LoaderCursor
import com.android.launcher3.model.UserManagerState
import com.android.launcher3.pm.PinRequestHelper
import com.android.launcher3.pm.UserCache
import com.android.launcher3.shortcuts.ShortcutKey
import com.android.launcher3.util.IntArray
import com.android.launcher3.util.IntSet
-import com.android.launcher3.util.PackageManagerHelper
/** A set of utility methods for Launcher DB used for DB updates and migration. */
object LauncherDbUtils {
@@ -155,12 +153,11 @@ object LauncherDbUtils {
null,
null,
)
- val pmHelper = PackageManagerHelper.INSTANCE[context]
val ums = UserManagerState()
ums.run {
init(UserCache.INSTANCE[context], context.getSystemService(UserManager::class.java))
}
- val lc = LoaderCursor(c, LauncherAppState.getInstance(context), ums, pmHelper, null)
+ val lc = context.appComponent.loaderCursorFactory.createLoaderCursor(c, ums, null)
val deletedShortcuts = IntSet()
while (lc.moveToNext()) {
diff --git a/src/com/android/launcher3/provider/RestoreDbTask.java b/src/com/android/launcher3/provider/RestoreDbTask.java
index 23941bb1e6..f6ee26baa6 100644
--- a/src/com/android/launcher3/provider/RestoreDbTask.java
+++ b/src/com/android/launcher3/provider/RestoreDbTask.java
@@ -80,6 +80,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
@@ -206,7 +207,8 @@ public class RestoreDbTask {
LauncherRestoreEventLogger restoreEventLogger =
LauncherRestoreEventLogger.Companion.newInstance(context);
task.sanitizeDB(context, controller, db, backupManager, restoreEventLogger);
- task.restoreAppWidgetIdsIfExists(context, controller, restoreEventLogger);
+ task.restoreAppWidgetIdsIfExists(context, controller, restoreEventLogger,
+ () -> new AppWidgetHost(context, APPWIDGET_HOST_ID));
t.commit();
return true;
} catch (Exception e) {
@@ -438,14 +440,13 @@ public class RestoreDbTask {
@WorkerThread
@VisibleForTesting
void restoreAppWidgetIdsIfExists(Context context, ModelDbController controller,
- LauncherRestoreEventLogger restoreEventLogger) {
+ LauncherRestoreEventLogger restoreEventLogger, Supplier<AppWidgetHost> hostSupplier) {
LauncherPrefs lp = LauncherPrefs.get(context);
if (lp.has(APP_WIDGET_IDS, OLD_APP_WIDGET_IDS)) {
- AppWidgetHost host = new AppWidgetHost(context, APPWIDGET_HOST_ID);
restoreAppWidgetIds(context, controller, restoreEventLogger,
IntArray.fromConcatString(lp.get(OLD_APP_WIDGET_IDS)).toArray(),
IntArray.fromConcatString(lp.get(APP_WIDGET_IDS)).toArray(),
- host);
+ hostSupplier.get());
} else {
FileLog.d(TAG, "Did not receive new app widget id map during Launcher restore");
}
diff --git a/src/com/android/launcher3/touch/AllAppsSwipeController.java b/src/com/android/launcher3/touch/AllAppsSwipeController.java
index 2cc4909712..f86fd6ac33 100644
--- a/src/com/android/launcher3/touch/AllAppsSwipeController.java
+++ b/src/com/android/launcher3/touch/AllAppsSwipeController.java
@@ -22,6 +22,7 @@ import static com.android.app.animation.Interpolators.EMPHASIZED_DECELERATE;
import static com.android.app.animation.Interpolators.FINAL_FRAME;
import static com.android.app.animation.Interpolators.INSTANT;
import static com.android.app.animation.Interpolators.LINEAR;
+import static com.android.app.animation.Interpolators.clampToProgress;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_ALL_APPS_FADE;
@@ -39,6 +40,7 @@ import android.view.animation.Interpolator;
import com.android.app.animation.Interpolators;
import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.Flags;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.states.StateAnimationConfig;
@@ -53,10 +55,10 @@ public class AllAppsSwipeController extends AbstractStateChangeTouchController {
private static final float ALL_APPS_SCRIM_VISIBLE_THRESHOLD = 0.1f;
private static final float ALL_APPS_STAGGERED_FADE_THRESHOLD = 0.5f;
- public static final Interpolator ALL_APPS_SCRIM_RESPONDER =
+ private static final Interpolator ALL_APPS_SCRIM_RESPONDER =
Interpolators.clampToProgress(
LINEAR, ALL_APPS_SCRIM_VISIBLE_THRESHOLD, ALL_APPS_STAGGERED_FADE_THRESHOLD);
- public static final Interpolator ALL_APPS_CLAMPING_RESPONDER =
+ private static final Interpolator ALL_APPS_CLAMPING_RESPONDER =
Interpolators.clampToProgress(
LINEAR,
1 - ALL_APPS_CONTENT_FADE_MAX_CLAMPING_THRESHOLD,
@@ -207,7 +209,16 @@ public class AllAppsSwipeController extends AbstractStateChangeTouchController {
}
config.setInterpolator(ANIM_WORKSPACE_SCALE, DECELERATED_EASE);
config.setInterpolator(ANIM_DEPTH, DECELERATED_EASE);
- if (launcher.getDeviceProfile().isPhone) {
+ if (Flags.allAppsBlur()) {
+ if (!config.isUserControlled()) {
+ config.setInterpolator(ANIM_DEPTH, EMPHASIZED_DECELERATE);
+ }
+ config.setInterpolator(ANIM_WORKSPACE_FADE,
+ clampToProgress(LINEAR, 1 - ALL_APPS_SCRIM_VISIBLE_THRESHOLD, 1));
+ config.setInterpolator(ANIM_HOTSEAT_FADE,
+ clampToProgress(LINEAR, 1 - ALL_APPS_SCRIM_VISIBLE_THRESHOLD, 1));
+ } else if (launcher.getDeviceProfile().isPhone) {
+ // On phones without blur, reveal the workspace and hotseat when leaving All Apps.
config.setInterpolator(ANIM_WORKSPACE_FADE, INSTANT);
config.setInterpolator(ANIM_HOTSEAT_FADE, INSTANT);
config.animFlags |= StateAnimationConfig.SKIP_DEPTH_CONTROLLER;
@@ -253,7 +264,14 @@ public class AllAppsSwipeController extends AbstractStateChangeTouchController {
}
config.setInterpolator(ANIM_WORKSPACE_SCALE, DECELERATED_EASE);
config.setInterpolator(ANIM_DEPTH, DECELERATED_EASE);
- if (launcher.getDeviceProfile().isPhone) {
+ if (Flags.allAppsBlur()) {
+ config.setInterpolator(ANIM_DEPTH, LINEAR);
+ config.setInterpolator(ANIM_WORKSPACE_FADE,
+ clampToProgress(LINEAR, 0, ALL_APPS_SCRIM_VISIBLE_THRESHOLD));
+ config.setInterpolator(ANIM_HOTSEAT_FADE,
+ clampToProgress(LINEAR, 0, ALL_APPS_SCRIM_VISIBLE_THRESHOLD));
+ } else if (launcher.getDeviceProfile().isPhone) {
+ // On phones without blur, hide the workspace and hotseat when entering All Apps.
config.setInterpolator(ANIM_WORKSPACE_FADE, FINAL_FRAME);
config.setInterpolator(ANIM_HOTSEAT_FADE, FINAL_FRAME);
config.animFlags |= StateAnimationConfig.SKIP_DEPTH_CONTROLLER;
diff --git a/src/com/android/launcher3/touch/WorkspaceTouchListener.java b/src/com/android/launcher3/touch/WorkspaceTouchListener.java
index d72e6f9e39..576f17616b 100644
--- a/src/com/android/launcher3/touch/WorkspaceTouchListener.java
+++ b/src/com/android/launcher3/touch/WorkspaceTouchListener.java
@@ -131,7 +131,7 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe
}
boolean isInAllAppsBottomSheet = mLauncher.isInState(ALL_APPS)
- && mLauncher.getDeviceProfile().isTablet;
+ && mLauncher.getDeviceProfile().shouldShowAllAppsOnSheet();
final boolean result;
if (mLongPressState == STATE_COMPLETED) {
diff --git a/src/com/android/launcher3/util/ContentWriter.java b/src/com/android/launcher3/util/ContentWriter.java
index 9910dc2e70..c2c1fee561 100644
--- a/src/com/android/launcher3/util/ContentWriter.java
+++ b/src/com/android/launcher3/util/ContentWriter.java
@@ -23,7 +23,6 @@ import android.os.UserHandle;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.GraphicsUtils;
import com.android.launcher3.model.ModelDbController;
@@ -107,7 +106,7 @@ public class ContentWriter {
public int commit() {
if (mCommitParams != null) {
return mCommitParams.mDbController.update(
- Favorites.TABLE_NAME, getValues(mContext),
+ getValues(mContext),
mCommitParams.mWhere, mCommitParams.mSelectionArgs);
}
return 0;
diff --git a/src/com/android/launcher3/util/ItemInflater.kt b/src/com/android/launcher3/util/ItemInflater.kt
index ebf4656c61..acb3c4ee12 100644
--- a/src/com/android/launcher3/util/ItemInflater.kt
+++ b/src/com/android/launcher3/util/ItemInflater.kt
@@ -24,6 +24,7 @@ import android.view.View.OnClickListener
import android.view.View.OnFocusChangeListener
import android.view.ViewGroup
import com.android.launcher3.BubbleTextView
+import com.android.launcher3.LauncherAppState
import com.android.launcher3.LauncherSettings.Favorites
import com.android.launcher3.R
import com.android.launcher3.apppairs.AppPairIcon
@@ -46,10 +47,11 @@ class ItemInflater<T>(
private val widgetHolder: LauncherWidgetHolder,
private val clickListener: OnClickListener,
private val focusListener: OnFocusChangeListener,
- private val defaultParent: ViewGroup
+ private val defaultParent: ViewGroup,
) where T : Context, T : ActivityContext {
- private val widgetInflater = WidgetInflater(context)
+ private val widgetInflater =
+ WidgetInflater(context, LauncherAppState.getInstance(context).isSafeModeEnabled)
@JvmOverloads
fun inflateItem(item: ItemInfo, writer: ModelWriter, nullableParent: ViewGroup? = null): View? {
@@ -75,7 +77,7 @@ class ItemInflater<T>(
R.layout.folder_icon,
context,
parent,
- item as FolderInfo
+ item as FolderInfo,
)
Favorites.ITEM_TYPE_APP_PAIR ->
return AppPairIcon.inflateIcon(
@@ -83,7 +85,7 @@ class ItemInflater<T>(
context,
parent,
item as AppPairInfo,
- BubbleTextView.DISPLAY_WORKSPACE
+ BubbleTextView.DISPLAY_WORKSPACE,
)
Favorites.ITEM_TYPE_APPWIDGET,
Favorites.ITEM_TYPE_CUSTOM_APPWIDGET ->
diff --git a/src/com/android/launcher3/util/SimpleBroadcastReceiver.java b/src/com/android/launcher3/util/SimpleBroadcastReceiver.java
index 7a40abe62b..53e0bce182 100644
--- a/src/com/android/launcher3/util/SimpleBroadcastReceiver.java
+++ b/src/com/android/launcher3/util/SimpleBroadcastReceiver.java
@@ -123,6 +123,32 @@ public class SimpleBroadcastReceiver extends BroadcastReceiver {
}
}
+ /**
+ * Same as {@link #register(Runnable, int, String...)} above but with additional permission
+ * params utilizine the original {@link Context}.
+ */
+ @AnyThread
+ public void register(@Nullable Runnable completionCallback,
+ String broadcastPermission, int flags, String... actions) {
+ if (Looper.myLooper() == mHandler.getLooper()) {
+ registerInternal(mContext, completionCallback, broadcastPermission, flags, actions);
+ } else {
+ mHandler.post(() -> registerInternal(mContext, completionCallback, broadcastPermission,
+ flags, actions));
+ }
+ }
+
+ /** Register broadcast receiver with permission and run completion callback if passed. */
+ @AnyThread
+ private void registerInternal(
+ @NonNull Context context, @Nullable Runnable completionCallback,
+ String broadcastPermission, int flags, String... actions) {
+ context.registerReceiver(this, getFilter(actions), broadcastPermission, null, flags);
+ if (completionCallback != null) {
+ completionCallback.run();
+ }
+ }
+
/** Same as {@link #register(Runnable, String...)} above but with pkg name. */
@AnyThread
public void registerPkgActions(@Nullable String pkg, String... actions) {
diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java
index 82cc40d93b..8c01c5999f 100644
--- a/src/com/android/launcher3/views/OptionsPopupView.java
+++ b/src/com/android/launcher3/views/OptionsPopupView.java
@@ -19,6 +19,7 @@ import static com.android.launcher3.BuildConfig.WIDGETS_ENABLED;
import static com.android.launcher3.LauncherState.EDIT_MODE;
import static com.android.launcher3.config.FeatureFlags.MULTI_SELECT_EDIT_MODE;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.IGNORE;
+import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALL_APPS_TAP_OR_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS;
@@ -219,6 +220,11 @@ public class OptionsPopupView<T extends Context & ActivityContext> extends Arrow
OptionsPopupView::enterHomeGardening));
}
options.add(new OptionItem(launcher,
+ R.string.all_apps_home_screen,
+ R.drawable.ic_apps,
+ LAUNCHER_ALL_APPS_TAP_OR_LONGPRESS,
+ OptionsPopupView::enterAllApps));
+ options.add(new OptionItem(launcher,
R.string.settings_button_text,
R.drawable.ic_setting,
LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS,
@@ -226,6 +232,20 @@ public class OptionsPopupView<T extends Context & ActivityContext> extends Arrow
return options;
}
+ /**
+ * Used by the options to open All Apps, uses an intent as to not tie the implementation of
+ * opening All Apps with OptionsPopup, instead it uses the public API to open All Apps.
+ */
+ public static boolean enterAllApps(View view) {
+ Launcher launcher = Launcher.getLauncher(view.getContext());
+ launcher.startActivity(
+ new Intent(Intent.ACTION_ALL_APPS)
+ .setComponent(launcher.getComponentName())
+ .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
+ );
+ return true;
+ }
+
private static boolean enterHomeGardening(View view) {
Launcher launcher = Launcher.getLauncher(view.getContext());
launcher.getStateManager().goToState(EDIT_MODE);
diff --git a/src/com/android/launcher3/views/ScrimView.java b/src/com/android/launcher3/views/ScrimView.java
index ce58de1ee5..ec71f3118a 100644
--- a/src/com/android/launcher3/views/ScrimView.java
+++ b/src/com/android/launcher3/views/ScrimView.java
@@ -54,8 +54,7 @@ public class ScrimView extends View implements Insettable {
}
@Override
- public void setInsets(Rect insets) {
- }
+ public void setInsets(Rect insets) {}
@Override
public boolean hasOverlappingRendering() {
diff --git a/src/com/android/launcher3/widget/WidgetInflater.kt b/src/com/android/launcher3/widget/WidgetInflater.kt
index d6cadc73a8..03f680abb4 100644
--- a/src/com/android/launcher3/widget/WidgetInflater.kt
+++ b/src/com/android/launcher3/widget/WidgetInflater.kt
@@ -19,14 +19,21 @@ package com.android.launcher3.widget
import android.content.Context
import com.android.launcher3.BuildConfig
import com.android.launcher3.Launcher
-import com.android.launcher3.LauncherAppState
import com.android.launcher3.backuprestore.LauncherRestoreEventLogger.RestoreError
+import com.android.launcher3.dagger.ApplicationContext
import com.android.launcher3.logging.FileLog
import com.android.launcher3.model.data.LauncherAppWidgetInfo
import com.android.launcher3.qsb.QsbContainerView
+import javax.inject.Inject
+import javax.inject.Named
/** Utility class for handling widget inflation taking into account all the restore state updates */
-class WidgetInflater(private val context: Context) {
+class WidgetInflater
+@Inject
+constructor(
+ @ApplicationContext private val context: Context,
+ @Named("SAFE_MODE") private val isSafeModeEnabled: Boolean,
+) {
private val widgetHelper = WidgetManagerHelper(context)
@@ -41,9 +48,8 @@ class WidgetInflater(private val context: Context) {
)
}
}
- if (LauncherAppState.INSTANCE.get(context).isSafeModeEnabled) {
- return InflationResult(TYPE_PENDING)
- }
+ if (isSafeModeEnabled) return InflationResult(TYPE_PENDING)
+
val appWidgetInfo: LauncherAppWidgetProviderInfo?
var removalReason = ""
@RestoreError var logReason = RestoreError.OTHER_WIDGET_INFLATION_FAIL
diff --git a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
index e94f3a065d..185c3ee9ed 100644
--- a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
+++ b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java
@@ -26,9 +26,12 @@ import androidx.annotation.Nullable;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
+import com.android.launcher3.pageindicators.Direction;
import com.android.launcher3.pageindicators.PageIndicator;
import com.android.launcher3.views.ActivityContext;
+import java.util.function.Consumer;
+
/**
* Supports two indicator colors, dedicated for personal and work tabs.
*/
@@ -78,6 +81,11 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd
}
@Override
+ public void setArrowClickListener(Consumer<Direction> listener) {
+ // No-Op. All Apps doesn't need accessibility arrows for single click navigation.
+ }
+
+ @Override
public boolean hasOverlappingRendering() {
return false;
}