From 2ae454ebc0c679774b0e01b91b2af49420ef9409 Mon Sep 17 00:00:00 2001 From: Adithya R Date: Sun, 31 Jul 2022 23:43:51 +0530 Subject: [PATCH] DerpLauncher: Add a toggle for smartspace Change-Id: I3b2681d51197642ba0957111db455937c0c376e8 --- res/values-de/derp_strings.xml | 4 ++++ res/values/derp_strings.xml | 5 +++++ res/xml/launcher_home_screen_preferences.xml | 14 +++++++++++++- src/com/android/launcher3/Launcher.java | 12 ++++++++++++ src/com/android/launcher3/Utilities.java | 10 ++++++++++ src/com/android/launcher3/Workspace.java | 8 ++------ .../graphics/LauncherPreviewRenderer.java | 3 +-- .../launcher3/model/AddWorkspaceItemsTask.java | 3 ++- .../launcher3/model/BaseLauncherBinder.java | 4 ++-- src/com/android/launcher3/model/BgDataModel.java | 7 +++---- .../android/launcher3/model/DatabaseHelper.java | 8 +++++--- .../launcher3/model/GridSizeMigrationUtil.java | 6 +----- .../android/launcher3/model/LoaderCursor.java | 2 +- src/com/android/launcher3/model/LoaderTask.java | 2 +- .../model/WorkspaceItemSpaceFinder.java | 4 ++-- .../android/launcher3/qsb/QsbContainerView.java | 2 +- .../launcher3/settings/SettingsActivity.java | 16 +++++++++++++++- 17 files changed, 80 insertions(+), 30 deletions(-) diff --git a/res/values-de/derp_strings.xml b/res/values-de/derp_strings.xml index f9c08077951..ee839f30ee3 100644 --- a/res/values-de/derp_strings.xml +++ b/res/values-de/derp_strings.xml @@ -183,4 +183,8 @@ Thematische Symbole erzwingen Thematische Symbole für Apps erzwingen, die diese nicht nativ unterstützen (erfordert ein erneutes Umschalten der thematischen Symbole) + + + Live-Anzeige + Live-Anzeige oben auf dem Startbildschirm anzeigen diff --git a/res/values/derp_strings.xml b/res/values/derp_strings.xml index cb78a8b7cdb..d87ab215ae0 100644 --- a/res/values/derp_strings.xml +++ b/res/values/derp_strings.xml @@ -29,6 +29,7 @@ Interface Search bar Quick actions + At A Glance Developer options @@ -195,4 +196,8 @@ Force monochrome icons Force monochrome icons for apps that don\'t support them natively (requires re-toggling of themed icons) + + + At a Glance + Show smartspace at the top of home screen diff --git a/res/xml/launcher_home_screen_preferences.xml b/res/xml/launcher_home_screen_preferences.xml index cd51754d498..c762b244598 100644 --- a/res/xml/launcher_home_screen_preferences.xml +++ b/res/xml/launcher_home_screen_preferences.xml @@ -80,7 +80,14 @@ + android:title="@string/quickspace_category_title"> + + + + + + private final CannedAnimationCoordinator mAnimationCoordinator = new CannedAnimationCoordinator(this); + private boolean mSmartspaceEnabled; private final List mBackPressedHandlers = new ArrayList<>(); private boolean mIsColdStartupAfterReboot; @@ -514,6 +515,8 @@ protected void onCreate(Bundle savedInstanceState) { setupViews(); + mSmartspaceEnabled = Utilities.showSmartspace(this); + mAppWidgetManager = new WidgetManagerHelper(this); mAppWidgetHolder = createAppWidgetHolder(); mAppWidgetHolder.startListening(); @@ -2122,6 +2125,15 @@ public void setIsFirstPagePinnedItemEnabled(boolean isFirstPagePinnedItemEnabled @Override public void bindScreens(IntArray orderedScreenIds) { + int firstScreenPosition = 0; + if (mSmartspaceEnabled && + orderedScreenIds.indexOf(Workspace.FIRST_SCREEN_ID) != firstScreenPosition) { + orderedScreenIds.removeValue(Workspace.FIRST_SCREEN_ID); + orderedScreenIds.add(firstScreenPosition, Workspace.FIRST_SCREEN_ID); + } else if (!mSmartspaceEnabled && orderedScreenIds.isEmpty()) { + // If there are no screens, we need to have an empty screen + mWorkspace.addExtraEmptyScreens(); + } mModelCallbacks.bindScreens(orderedScreenIds); } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 7a4a6cc0779..9c3f098818c 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -195,6 +195,7 @@ public final class Utilities { public static final String KEY_APP_DRAWER_OPACITY = "pref_app_drawer_opacity"; public static final String KEY_RECENTS_MEMINFO = "pref_recents_meminfo"; public static final String KEY_DRAWER_SEARCH = "pref_drawer_search"; + public static final String KEY_SMARTSPACE = "pref_smartspace"; public static final String KEY_HOTSEAT_OPACITY = "pref_hotseat_opacity"; public static final String KEY_LENS = "pref_recents_lens"; public static final String KEY_SHORT_PARALLAX = "pref_short_parallax"; @@ -1014,6 +1015,15 @@ public static boolean showSearch(Context context) { return prefs.getBoolean(KEY_DRAWER_SEARCH, true); } + public static boolean showSmartspace(Context context) { + return isGSAEnabled(context) && isSmartspaceEnabled(context); + } + + private static boolean isSmartspaceEnabled(Context context) { + SharedPreferences prefs = LauncherPrefs.getPrefs(context.getApplicationContext()); + return prefs.getBoolean(KEY_SMARTSPACE, true); + } + public static int getHotseatOpacity(Context context) { SharedPreferences prefs = LauncherPrefs.getPrefs(context.getApplicationContext()); return prefs.getInt(KEY_HOTSEAT_OPACITY, 40); diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 3fbc584f084..f240e20ac14 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -600,9 +600,7 @@ public void onViewAdded(View child) { * Initializes and binds the first page */ public void bindAndInitFirstWorkspaceScreen() { - if ((!FeatureFlags.QSB_ON_FIRST_SCREEN - || !mLauncher.getIsFirstPagePinnedItemEnabled()) - || shouldShowFirstPageWidget()) { + if (!Utilities.showSmartspace(getContext())) { mFirstPagePinnedItem = null; return; } @@ -1029,9 +1027,7 @@ public void stripEmptyScreens() { int id = mWorkspaceScreens.keyAt(i); CellLayout cl = mWorkspaceScreens.valueAt(i); // FIRST_SCREEN_ID can never be removed. - if (((!FeatureFlags.QSB_ON_FIRST_SCREEN - || shouldShowFirstPageWidget()) - || id > FIRST_SCREEN_ID) + if ((!Utilities.showSmartspace(getContext()) || id > FIRST_SCREEN_ID) && cl.getShortcutsAndWidgets().getChildCount() == 0) { removeScreens.add(id); } diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index 33304489196..1a599db1476 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -527,8 +527,7 @@ private void populate(BgDataModel dataModel, } // Add first page QSB - if (FeatureFlags.QSB_ON_FIRST_SCREEN && dataModel.isFirstPagePinnedItemEnabled - && !shouldShowFirstPageWidget()) { + if (Utilities.showSmartspace(mContext)) { CellLayout firstScreen = mWorkspaceScreens.get(FIRST_SCREEN_ID); View qsb = mHomeElementInflater.inflate(R.layout.qsb_preview, firstScreen, false); CellLayoutLayoutParams lp = new CellLayoutLayoutParams( diff --git a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java index 5e86bd6b8ae..8c937b1af8d 100644 --- a/src/com/android/launcher3/model/AddWorkspaceItemsTask.java +++ b/src/com/android/launcher3/model/AddWorkspaceItemsTask.java @@ -28,6 +28,7 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherModel.CallbackTask; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.Utilities; import com.android.launcher3.logging.FileLog; import com.android.launcher3.model.BgDataModel.Callbacks; import com.android.launcher3.model.data.AppInfo; @@ -86,7 +87,7 @@ public void execute(@NonNull final LauncherAppState app, @NonNull final BgDataMo final IntArray addedWorkspaceScreensFinal = new IntArray(); synchronized (dataModel) { - IntArray workspaceScreens = dataModel.collectWorkspaceScreens(); + IntArray workspaceScreens = dataModel.collectWorkspaceScreens(app.getContext()); List filteredItems = new ArrayList<>(); for (Pair entry : mItemList) { diff --git a/src/com/android/launcher3/model/BaseLauncherBinder.java b/src/com/android/launcher3/model/BaseLauncherBinder.java index 9b2344d2ad8..3a2aae4de50 100644 --- a/src/com/android/launcher3/model/BaseLauncherBinder.java +++ b/src/com/android/launcher3/model/BaseLauncherBinder.java @@ -89,7 +89,7 @@ public void bindWorkspace(boolean incrementBindId, boolean isBindSync) { try { if (FeatureFlags.ENABLE_WORKSPACE_LOADING_OPTIMIZATION.get()) { DisjointWorkspaceBinder workspaceBinder = - initWorkspaceBinder(incrementBindId, mBgDataModel.collectWorkspaceScreens()); + initWorkspaceBinder(incrementBindId, mBgDataModel.collectWorkspaceScreens(mApp.getContext())); workspaceBinder.bindCurrentWorkspacePages(isBindSync); workspaceBinder.bindOtherWorkspacePages(); } else { @@ -130,7 +130,7 @@ private void bindWorkspaceAllAtOnce(boolean incrementBindId, boolean isBindSync) synchronized (mBgDataModel) { workspaceItems.addAll(mBgDataModel.workspaceItems); appWidgets.addAll(mBgDataModel.appWidgets); - orderedScreenIds.addAll(mBgDataModel.collectWorkspaceScreens()); + orderedScreenIds.addAll(mBgDataModel.collectWorkspaceScreens(mApp.getContext())); mBgDataModel.extraItems.forEach(extraItems::add); if (incrementBindId) { mBgDataModel.lastBindId++; diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index 7f0f683091e..d24c205ca08 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -39,6 +39,7 @@ import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherSettings.Favorites; +import com.android.launcher3.Utilities; import com.android.launcher3.Workspace; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.AppInfo; @@ -150,16 +151,14 @@ public synchronized void clear() { /** * Creates an array of valid workspace screens based on current items in the model. */ - public synchronized IntArray collectWorkspaceScreens() { + public synchronized IntArray collectWorkspaceScreens(Context context) { IntSet screenSet = new IntSet(); for (ItemInfo item: itemsIdMap) { if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { screenSet.add(item.screenId); } } - if ((FeatureFlags.QSB_ON_FIRST_SCREEN - && !shouldShowFirstPageWidget()) - || screenSet.isEmpty()) { + if (Utilities.showSmartspace(context) || screenSet.isEmpty()) { screenSet.add(Workspace.FIRST_SCREEN_ID); } return screenSet.getArray(); diff --git a/src/com/android/launcher3/model/DatabaseHelper.java b/src/com/android/launcher3/model/DatabaseHelper.java index 13605101e75..f5fc9663a84 100644 --- a/src/com/android/launcher3/model/DatabaseHelper.java +++ b/src/com/android/launcher3/model/DatabaseHelper.java @@ -40,7 +40,6 @@ import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.Utilities; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.logging.FileLog; import com.android.launcher3.pm.UserCache; import com.android.launcher3.provider.LauncherDbUtils; @@ -258,8 +257,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Favorites.SCREEN, IntArray.wrap(-777, -778)), null); } case 30: { - if (FeatureFlags.QSB_ON_FIRST_SCREEN - && !shouldShowFirstPageWidget()) { + if (isQsbOnFirstScreen()) { // Clean up first row in screen 0 as it might contain junk data. Log.d(TAG, "Cleaning up first row"); db.delete(Favorites.TABLE_NAME, @@ -531,4 +529,8 @@ private static int getMaxId(SQLiteDatabase db, String query, Object... args) { } return max; } + + public boolean isQsbOnFirstScreen() { + return Utilities.showSmartspace(mContext); + } } diff --git a/src/com/android/launcher3/model/GridSizeMigrationUtil.java b/src/com/android/launcher3/model/GridSizeMigrationUtil.java index efd55745196..4a030b9c8d2 100644 --- a/src/com/android/launcher3/model/GridSizeMigrationUtil.java +++ b/src/com/android/launcher3/model/GridSizeMigrationUtil.java @@ -331,11 +331,7 @@ private static void solveGridPlacement(@NonNull final DatabaseHelper helper, @NonNull final List sortedItemsToPlace, final boolean matchingScreenIdOnly) { final GridOccupancy occupied = new GridOccupancy(trgX, trgY); final Point trg = new Point(trgX, trgY); - final Point next = new Point(0, screenId == 0 - && (FeatureFlags.QSB_ON_FIRST_SCREEN - && (!ENABLE_SMARTSPACE_REMOVAL.get() || LauncherPrefs.getPrefs(destReader.mContext) - .getBoolean(SMARTSPACE_ON_HOME_SCREEN, true)) - && !shouldShowFirstPageWidget()) + final Point next = new Point(0, screenId == 0 && helper.isQsbOnFirstScreen() ? 1 /* smartspace */ : 0); List existedEntries = destReader.mWorkspaceEntriesByScreenId.get(screenId); if (existedEntries != null) { diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java index 43700435694..1066681a8d8 100644 --- a/src/com/android/launcher3/model/LoaderCursor.java +++ b/src/com/android/launcher3/model/LoaderCursor.java @@ -536,7 +536,7 @@ protected boolean checkItemPlacement(ItemInfo item, boolean isFirstPagePinnedIte // container. int spanX = mIDP.numSearchContainerColumns; int spanY = 1; - screen.markCells(0, 0, spanX, spanY, true); + screen.markCells(0, 0, spanX, spanY, Utilities.showSmartspace(mContext)); } mOccupied.put(item.screenId, screen); } diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index 10ae171f9a3..60e8222b032 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -202,7 +202,7 @@ private void sendFirstScreenActiveInstallsBroadcast() { ArrayList allItems = mBgDataModel.getAllWorkspaceItems(); // Screen set is never empty - IntArray allScreens = mBgDataModel.collectWorkspaceScreens(); + IntArray allScreens = mBgDataModel.collectWorkspaceScreens(mApp.getContext()); final int firstScreen = allScreens.get(0); IntSet firstScreens = IntSet.wrap(firstScreen); diff --git a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java index 929f698236e..a3987b36406 100644 --- a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java +++ b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java @@ -23,6 +23,7 @@ import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.util.GridOccupancy; @@ -67,8 +68,7 @@ public int[] findSpaceForItem(LauncherAppState app, BgDataModel dataModel, int screenCount = workspaceScreens.size(); // First check the preferred screen. IntSet screensToExclude = new IntSet(); - if (FeatureFlags.QSB_ON_FIRST_SCREEN - && !shouldShowFirstPageWidget()) { + if (Utilities.showSmartspace(app.getContext())) { screensToExclude.add(FIRST_SCREEN_ID); } diff --git a/src/com/android/launcher3/qsb/QsbContainerView.java b/src/com/android/launcher3/qsb/QsbContainerView.java index 69591df3102..b9a6229920c 100644 --- a/src/com/android/launcher3/qsb/QsbContainerView.java +++ b/src/com/android/launcher3/qsb/QsbContainerView.java @@ -296,7 +296,7 @@ private void rebindFragment() { } public boolean isQsbEnabled() { - return FeatureFlags.QSB_ON_FIRST_SCREEN && !shouldShowFirstPageWidget(); + return Utilities.showSmartspace(getContext()); } protected Bundle createBindOptions() { diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 0e51adc3f53..04442b6cecc 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -20,6 +20,7 @@ import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; import android.view.MenuItem; @@ -37,6 +38,7 @@ import androidx.preference.PreferenceScreen; import androidx.recyclerview.widget.RecyclerView; +import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherFiles; import com.android.launcher3.R; import com.android.launcher3.Utilities; @@ -47,7 +49,8 @@ * Settings activity for Launcher. */ public class SettingsActivity extends CollapsingToolbarBaseActivity - implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback { + implements OnPreferenceStartFragmentCallback, OnPreferenceStartScreenCallback, + SharedPreferences.OnSharedPreferenceChangeListener { public static final String EXTRA_FRAGMENT_ARGS = ":settings:fragment_args"; @@ -92,6 +95,17 @@ protected void onCreate(Bundle savedInstanceState) { } } + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + switch (key) { + case Utilities.KEY_SMARTSPACE: + LauncherAppState.getInstanceNoCreate().setNeedsRestart(); + break; + default: + break; + } + } + private boolean startPreference(String fragment, Bundle args, String key) { if (Utilities.ATLEAST_P && getSupportFragmentManager().isStateSaved()) { // Sometimes onClick can come after onPause because of being posted on the handler.