diff options
Diffstat (limited to 'src/com/android/launcher3/Launcher.java')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 179 |
1 files changed, 102 insertions, 77 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 257f0dfcf..491e5de85 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -16,10 +16,11 @@ package com.android.launcher3; -import static android.content.pm.ActivityInfo.CONFIG_LOCALE; import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION; import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; +import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; +import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR; import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY; import static com.android.launcher3.LauncherState.ALL_APPS; @@ -77,6 +78,9 @@ import android.view.accessibility.AccessibilityEvent; import android.view.animation.OvershootInterpolator; import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; + import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; import com.android.launcher3.allapps.AllAppsContainerView; @@ -91,9 +95,9 @@ import com.android.launcher3.dot.DotInfo; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.dragndrop.DragView; -import com.android.launcher3.folder.Folder; +import com.android.launcher3.folder.FolderGridOrganizer; import com.android.launcher3.folder.FolderIcon; -import com.android.launcher3.folder.FolderIconPreviewVerifier; +import com.android.launcher3.folder.FolderNameProvider; import com.android.launcher3.graphics.RotationMode; import com.android.launcher3.icons.IconCache; import com.android.launcher3.keyboard.CustomActionsPopup; @@ -103,14 +107,14 @@ import com.android.launcher3.logging.StatsLogUtils; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate; import com.android.launcher3.model.AppLaunchTracker; +import com.android.launcher3.model.BgDataModel.Callbacks; import com.android.launcher3.model.ModelWriter; import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.popup.PopupDataProvider; -import com.android.launcher3.shortcuts.DeepShortcutManager; +import com.android.launcher3.qsb.QsbContainerView; import com.android.launcher3.states.InternalStateHandler; import com.android.launcher3.states.RotationHelper; -import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.uioverrides.UiFactory; import com.android.launcher3.userevent.nano.LauncherLogProto; @@ -145,7 +149,7 @@ import com.android.launcher3.widget.WidgetAddFlowHandler; import com.android.launcher3.widget.WidgetHostViewLoader; import com.android.launcher3.widget.WidgetListRowEntry; import com.android.launcher3.widget.WidgetsFullSheet; -import com.android.launcher3.widget.custom.CustomWidgetParser; +import com.android.launcher3.widget.custom.CustomWidgetManager; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -156,14 +160,11 @@ import java.util.HashSet; import java.util.List; import java.util.function.Predicate; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; - /** * Default launcher application. */ public class Launcher extends BaseDraggingActivity implements LauncherExterns, - LauncherModel.Callbacks, LauncherProviderChangeListener, UserEventDelegate, + Callbacks, LauncherProviderChangeListener, UserEventDelegate, InvariantDeviceProfile.OnIDPChangeListener { public static final String TAG = "Launcher"; static final boolean LOGD = false; @@ -220,9 +221,11 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, private LauncherAppTransitionManager mAppTransitionManager; private Configuration mOldConfig; - @Thunk Workspace mWorkspace; + @Thunk + Workspace mWorkspace; private View mLauncherView; - @Thunk DragLayer mDragLayer; + @Thunk + DragLayer mDragLayer; private DragController mDragController; private AppWidgetManagerCompat mAppWidgetManager; @@ -230,21 +233,25 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, private final int[] mTmpAddItemCellCoordinates = new int[2]; - @Thunk Hotseat mHotseat; + @Thunk + Hotseat mHotseat; private DropTargetBar mDropTargetBar; // Main container view for the all apps screen. - @Thunk AllAppsContainerView mAppsView; + @Thunk + AllAppsContainerView mAppsView; AllAppsTransitionController mAllAppsController; // Scrim view for the all apps and overview state. - @Thunk ScrimView mScrimView; + @Thunk + ScrimView mScrimView; // UI and state for the overview panel private View mOverviewPanel; - @Thunk boolean mWorkspaceLoading = true; + @Thunk + boolean mWorkspaceLoading = true; private ArrayList<OnResumeCallback> mOnResumeCallbacks = new ArrayList<>(); @@ -326,8 +333,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, UiFactory.onCreate(this); mAppWidgetManager = AppWidgetManagerCompat.getInstance(this); - - mAppWidgetHost = new LauncherAppWidgetHost(this); + mAppWidgetHost = new LauncherAppWidgetHost(this, + appWidgetId -> getWorkspace().removeWidget(appWidgetId)); mAppWidgetHost.startListening(); mLauncherView = LayoutInflater.from(this).inflate(R.layout.launcher, null); @@ -389,7 +396,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, RaceConditionTracker.onEvent(ON_CREATE_EVT, EXIT); mStateManager.addStateListener(new LauncherStateManager.StateListener() { @Override - public void onStateTransitionStart(LauncherState toState) {} + public void onStateTransitionStart(LauncherState toState) { + } @Override public void onStateTransitionComplete(LauncherState finalState) { @@ -419,10 +427,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, public void onConfigurationChanged(Configuration newConfig) { int diff = newConfig.diff(mOldConfig); - if ((diff & CONFIG_LOCALE) != 0) { - Folder.setLocaleDependentFields(getResources(), true /* force */); - } - if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) { onIdpChanged(mDeviceProfile.inv); } @@ -497,6 +501,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, // Load configuration-specific DeviceProfile mDeviceProfile = idp.getDeviceProfile(this); if (isInMultiWindowMode()) { + // Note: Calls to getSize() can't rely on our cached DefaultDisplay since it can return + // the app window size Display display = getWindowManager().getDefaultDisplay(); Point mwSize = new Point(); display.getSize(mwSize); @@ -548,6 +554,10 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, return mStateManager; } + public FolderNameProvider getFolderNameProvider() { + return new FolderNameProvider(); + } + @Override public <T extends View> T findViewById(int id) { return mLauncherView.findViewById(id); @@ -604,10 +614,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, if (info.container >= 0) { View folderIcon = getWorkspace().getHomescreenIconByItemId(info.container); if (folderIcon instanceof FolderIcon && folderIcon.getTag() instanceof FolderInfo) { - FolderIconPreviewVerifier verifier = - new FolderIconPreviewVerifier(getDeviceProfile().inv); - verifier.setFolderInfo((FolderInfo) folderIcon.getTag()); - if (verifier.isItemInPreview(info.rank)) { + if (new FolderGridOrganizer(getDeviceProfile().inv) + .setFolderInfo((FolderInfo) folderIcon.getTag()) + .isItemInPreview(info.rank)) { folderIcon.invalidate(); } } @@ -647,7 +656,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, .getLauncherAppWidgetInfo(widgetId); if (provider != null) { new WidgetAddFlowHandler(provider) - .startConfigActivity(this, widgetInfo, REQUEST_RECONFIGURE_APPWIDGET); + .startConfigActivity(this, widgetInfo, + REQUEST_RECONFIGURE_APPWIDGET); } } break; @@ -835,7 +845,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } } - @Thunk void completeTwoStageWidgetDrop( + @Thunk + void completeTwoStageWidgetDrop( final int resultCode, final int appWidgetId, final PendingRequestArgs requestArgs) { CellLayout cellLayout = mWorkspace.getScreenWithId(requestArgs.screenId); Runnable onCompleteRunnable = null; @@ -932,15 +943,14 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, int containerType = mStateManager.getState().containerType; if (containerType == ContainerType.WORKSPACE && mWorkspace != null) { getUserEventDispatcher().logActionCommand(command, - containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0); + containerType, -1, mWorkspace.isOverlayShown() ? -1 : 0); } else { getUserEventDispatcher().logActionCommand(command, containerType, -1); } } - protected void onStateSet(LauncherState state) { - getAppWidgetHost().setResumed(state == LauncherState.NORMAL); + public void onStateSetStart(LauncherState state) { if (mDeferredResumePending) { handleDeferredResume(); } @@ -949,6 +959,12 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } } + public void onStateSetEnd(LauncherState state) { + getAppWidgetHost().setResumed(state == LauncherState.NORMAL); + getWorkspace().setClipChildren(!state.disablePageClipping); + finishAutoCancelActionMode(); + } + @Override protected void onResume() { RaceConditionTracker.onEvent(ON_RESUME_EVT, ENTER); @@ -1061,7 +1077,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, mStateManager.goToState(state, false /* animated */); } - PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS); + PendingRequestArgs requestArgs = savedState.getParcelable( + RUNTIME_STATE_PENDING_REQUEST_ARGS); if (requestArgs != null) { setWaitingForResult(requestArgs); } @@ -1131,8 +1148,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, * Creates a view representing a shortcut inflated from the specified resource. * * @param parent The group the shortcut belongs to. - * @param info The data structure describing the shortcut. - * + * @param info The data structure describing the shortcut. * @return A View inflated from layoutResId. */ public View createShortcut(ViewGroup parent, WorkspaceItemInfo info) { @@ -1234,7 +1250,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, * * @param appWidgetId The app widget id */ - @Thunk void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, + @Thunk + void completeAddAppWidget(int appWidgetId, ItemInfo itemInfo, AppWidgetHostView hostView, LauncherAppWidgetProviderInfo appWidgetInfo) { if (appWidgetInfo == null) { @@ -1352,7 +1369,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, return mSharedPrefs; } - public int getOrientation() { return mOldConfig.orientation; } + public int getOrientation() { + return mOldConfig.orientation; + } @Override protected void onNewIntent(Intent intent) { @@ -1436,9 +1455,10 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, outState.remove(RUNTIME_STATE_WIDGET_PANEL); } - // We close any open folders and shortcut containers since they will not be re-opened, + // We close any open folders and shortcut containers that are not safe for rebind, // and we need to make sure this state is reflected. - AbstractFloatingView.closeAllOpenViews(this, false); + AbstractFloatingView.closeOpenViews(this, false, TYPE_ALL & ~TYPE_REBIND_SAFE); + finishAutoCancelActionMode(); if (mPendingRequestArgs != null) { outState.putParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS, mPendingRequestArgs); @@ -1575,7 +1595,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, void addAppWidgetImpl(int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget, WidgetAddFlowHandler addFlowHandler, int delay) { - if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, REQUEST_CREATE_APPWIDGET)) { + if (!addFlowHandler.startConfigActivity(this, appWidgetId, info, + REQUEST_CREATE_APPWIDGET)) { // If the configuration flow was not started, add the widget Runnable onComplete = new Runnable() { @@ -1585,7 +1606,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, mStateManager.goToState(NORMAL, SPRING_LOADED_EXIT_DELAY); } }; - completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this)); + completeAddAppWidget(appWidgetId, info, boundWidget, + addFlowHandler.getProviderInfo(this)); mWorkspace.removeExtraEmptyScreenDelayed(true, onComplete, delay, false); } } @@ -1611,7 +1633,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, break; default: throw new IllegalStateException("Unknown item type: " + info.itemType); - } + } } /** @@ -1647,10 +1669,9 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } else { // In this case, we either need to start an activity to get permission to bind // the widget, or we need to start an activity to configure the widget, or both. - if (FeatureFlags.ENABLE_CUSTOM_WIDGETS && - info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) { - appWidgetId = CustomWidgetParser.getWidgetIdForCustomProvider( - this, info.componentName); + if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET) { + appWidgetId = CustomWidgetManager.INSTANCE.get(this).getWidgetIdForCustomProvider( + info.componentName); } else { appWidgetId = getAppWidgetHost().allocateAppWidgetId(); } @@ -1669,7 +1690,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, FolderIcon addFolder(CellLayout layout, int container, final int screenId, int cellX, int cellY) { final FolderInfo folderInfo = new FolderInfo(); - folderInfo.title = getText(R.string.folder_name); + folderInfo.title = ""; // Update the model getModelWriter().addItemToDatabase(folderInfo, container, screenId, cellX, cellY); @@ -1723,8 +1744,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, return true; } - - @Override public boolean dispatchKeyEvent(KeyEvent event) { return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event); @@ -1788,7 +1807,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, @Override public int getCurrentState() { - if(mStateManager.getState() == LauncherState.ALL_APPS) { + if (mStateManager.getState() == LauncherState.ALL_APPS) { return StatsLogUtils.LAUNCHER_STATE_ALLAPPS; } else if (mStateManager.getState() == OVERVIEW) { return StatsLogUtils.LAUNCHER_STATE_OVERVIEW; @@ -1923,8 +1942,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, // Floating panels (except the full widget sheet) are associated with individual icons. If // we are starting a fresh bind, close all such panels as all the icons are about // to go away. - AbstractFloatingView.closeOpenViews(this, true, - AbstractFloatingView.TYPE_ALL & ~AbstractFloatingView.TYPE_REBIND_SAFE); + AbstractFloatingView.closeOpenViews(this, true, TYPE_ALL & ~TYPE_REBIND_SAFE); setWorkspaceLoading(true); @@ -2052,7 +2070,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, throw new RuntimeException("Invalid Item Type"); } - /* + /* * Remove colliding items. */ if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { @@ -2124,6 +2142,14 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } private View inflateAppWidget(LauncherAppWidgetInfo item) { + if (item.hasOptionFlag(LauncherAppWidgetInfo.OPTION_SEARCH_WIDGET)) { + item.providerName = QsbContainerView.getSearchComponentName(this); + if (item.providerName == null) { + getModelWriter().deleteItemFromDatabase(item); + return null; + } + } + if (mIsSafeModeEnabled) { PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, mIconCache, true); @@ -2170,7 +2196,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, pendingInfo.spanY = item.spanY; pendingInfo.minSpanX = item.minSpanX; pendingInfo.minSpanY = item.minSpanY; - Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, pendingInfo); + Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(this, + pendingInfo); boolean isDirectConfig = item.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG); @@ -2324,6 +2351,11 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, // override the previous page so we don't log the page switch. mWorkspace.setCurrentPage(pageBoundFirst, pageBoundFirst /* overridePrevPage */); + // Cache one page worth of icons + getViewCache().setCacheSize(R.layout.folder_application, + mDeviceProfile.inv.numFolderColumns * mDeviceProfile.inv.numFolderRows); + getViewCache().setCacheSize(R.layout.folder_page, 2); + TraceHelper.endSection("finishBindingItems"); } @@ -2345,7 +2377,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindAllApplications(ArrayList<AppInfo> apps) { + public void bindAllApplications(AppInfo[] apps) { mAppsView.getAppsStore().setApps(apps); } @@ -2358,16 +2390,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); } - /** - * A package was updated. - * - * Implementation of the method from LauncherModel.Callbacks. - */ - @Override - public void bindAppsAddedOrUpdated(ArrayList<AppInfo> apps) { - mAppsView.getAppsStore().addOrUpdateApps(apps); - } - @Override public void bindPromiseAppProgressUpdated(PromiseAppInfo app) { mAppsView.getAppsStore().updatePromiseAppProgress(app); @@ -2415,11 +2437,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } @Override - public void bindAppInfosRemoved(final ArrayList<AppInfo> appInfos) { - mAppsView.getAppsStore().removeApps(appInfos); - } - - @Override public void bindAllWidgets(final ArrayList<WidgetListRowEntry> allWidgets) { mPopupDataProvider.setAllWidgets(allWidgets); } @@ -2464,14 +2481,16 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, } writer.println(prefix + "Misc:"); - writer.print(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading); - writer.print(" mPendingRequestArgs=" + mPendingRequestArgs); - writer.println(" mPendingActivityResult=" + mPendingActivityResult); - writer.println(" mRotationHelper: " + mRotationHelper); + dumpMisc(prefix + "\t", writer); + writer.println(prefix + "\tmWorkspaceLoading=" + mWorkspaceLoading); + writer.println(prefix + "\tmPendingRequestArgs=" + mPendingRequestArgs + + " mPendingActivityResult=" + mPendingActivityResult); + writer.println(prefix + "\tmRotationHelper: " + mRotationHelper); + writer.println(prefix + "\tmAppWidgetHost.isListening: " + mAppWidgetHost.isListening()); + // Extra logging for b/116853349 mDragLayer.dump(prefix, writer); mStateManager.dump(prefix, writer); - dumpMisc(writer); try { FileLog.flushAll(writer); @@ -2532,8 +2551,8 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, if (focusedView instanceof BubbleTextView && focusedView.getTag() instanceof ItemInfo && mAccessibilityDelegate.performAction(focusedView, - (ItemInfo) focusedView.getTag(), - LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) { + (ItemInfo) focusedView.getTag(), + LauncherAccessibilityDelegate.DEEP_SHORTCUTS)) { PopupContainerWithArrow.getOpen(this).requestFocus(); return true; } @@ -2578,6 +2597,12 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, return (Launcher) fromContext(context); } + @Override + public void returnToHomescreen() { + super.returnToHomescreen(); + getStateManager().goToState(LauncherState.NORMAL); + } + /** * Just a wrapper around the type cast to allow easier tracking of calls. */ |