Skip to content

Commit

Permalink
DerpLauncher: Add a toggle for smartspace
Browse files Browse the repository at this point in the history
Change-Id: I3b2681d51197642ba0957111db455937c0c376e8
  • Loading branch information
adithya2306 authored and NurKeinNeid committed Apr 13, 2024
1 parent 3a075dc commit 2ae454e
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 30 deletions.
4 changes: 4 additions & 0 deletions res/values-de/derp_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,8 @@
<!-- Force monocrome icons -->
<string name="pref_force_mono_icons_title">Thematische Symbole erzwingen</string>
<string name="pref_force_mono_icons_summary">Thematische Symbole für Apps erzwingen, die diese nicht nativ unterstützen (erfordert ein erneutes Umschalten der thematischen Symbole)</string>

<!-- Smartspace -->
<string name="smartspace_pref_title">Live-Anzeige</string>
<string name="smartspace_pref_summary">Live-Anzeige oben auf dem Startbildschirm anzeigen</string>
</resources>
5 changes: 5 additions & 0 deletions res/values/derp_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<string name="interface_category_title">Interface</string>
<string name="search_bar_category_title">Search bar</string>
<string name="actions_category_title">Quick actions</string>
<string name="quickspace_category_title">At A Glance</string>

<!-- Developer options -->
<string name="dev_options_title">Developer options</string>
Expand Down Expand Up @@ -195,4 +196,8 @@
<!-- Force monocrome icons -->
<string name="pref_force_mono_icons_title">Force monochrome icons</string>
<string name="pref_force_mono_icons_summary">Force monochrome icons for apps that don\'t support them natively (requires re-toggling of themed icons)</string>

<!-- Smartspace -->
<string name="smartspace_pref_title">At a Glance</string>
<string name="smartspace_pref_summary">Show smartspace at the top of home screen</string>
</resources>
14 changes: 13 additions & 1 deletion res/xml/launcher_home_screen_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@
</PreferenceCategory>

<PreferenceCategory
android:title="@string/interface_category_title">
android:title="@string/quickspace_category_title">

<SwitchPreferenceCompat
android:key="pref_smartspace"
android:title="@string/smartspace_pref_title"
android:summary="@string/smartspace_pref_summary"
android:defaultValue="true"
launcher:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:key="pref_enable_minus_one"
Expand All @@ -89,6 +96,11 @@
android:defaultValue="true"
launcher:iconSpaceReserved="false" />

</PreferenceCategory>

<PreferenceCategory
android:title="@string/interface_category_title">

<SwitchPreferenceCompat
android:key="pref_show_statusbar"
android:title="@string/show_statusbar_title"
Expand Down
12 changes: 12 additions & 0 deletions src/com/android/launcher3/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public class Launcher extends StatefulActivity<LauncherState>
private final CannedAnimationCoordinator mAnimationCoordinator =
new CannedAnimationCoordinator(this);

private boolean mSmartspaceEnabled;
private final List<BackPressHandler> mBackPressedHandlers = new ArrayList<>();
private boolean mIsColdStartupAfterReboot;

Expand Down Expand Up @@ -514,6 +515,8 @@ protected void onCreate(Bundle savedInstanceState) {

setupViews();

mSmartspaceEnabled = Utilities.showSmartspace(this);

mAppWidgetManager = new WidgetManagerHelper(this);
mAppWidgetHolder = createAppWidgetHolder();
mAppWidgetHolder.startListening();
Expand Down Expand Up @@ -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);
}

Expand Down
10 changes: 10 additions & 0 deletions src/com/android/launcher3/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions src/com/android/launcher3/Workspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/com/android/launcher3/model/AddWorkspaceItemsTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemInfo> filteredItems = new ArrayList<>();
for (Pair<ItemInfo, Object> entry : mItemList) {
Expand Down
4 changes: 2 additions & 2 deletions src/com/android/launcher3/model/BaseLauncherBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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++;
Expand Down
7 changes: 3 additions & 4 deletions src/com/android/launcher3/model/BgDataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 5 additions & 3 deletions src/com/android/launcher3/model/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -531,4 +529,8 @@ private static int getMaxId(SQLiteDatabase db, String query, Object... args) {
}
return max;
}

public boolean isQsbOnFirstScreen() {
return Utilities.showSmartspace(mContext);
}
}
6 changes: 1 addition & 5 deletions src/com/android/launcher3/model/GridSizeMigrationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,7 @@ private static void solveGridPlacement(@NonNull final DatabaseHelper helper,
@NonNull final List<DbEntry> 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<DbEntry> existedEntries = destReader.mWorkspaceEntriesByScreenId.get(screenId);
if (existedEntries != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/launcher3/model/LoaderCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/android/launcher3/model/LoaderTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void sendFirstScreenActiveInstallsBroadcast() {
ArrayList<ItemInfo> 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);

Expand Down
4 changes: 2 additions & 2 deletions src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/android/launcher3/qsb/QsbContainerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void rebindFragment() {
}

public boolean isQsbEnabled() {
return FeatureFlags.QSB_ON_FIRST_SCREEN && !shouldShowFirstPageWidget();
return Utilities.showSmartspace(getContext());
}

protected Bundle createBindOptions() {
Expand Down
16 changes: 15 additions & 1 deletion src/com/android/launcher3/settings/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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";

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2ae454e

Please sign in to comment.