Launcher3: add support for hotseat qsb
and fix styles to support ListPreference
Change-Id: I571dfacf67a63872a8f7351ad9c6106397f79505
Launcher3: fix crash on taskbar usage
we use search_container_hotseat.xml for phone when using
qsb in hotseat. So add a new empty one for taskbar
Change-Id: I3df2c9ad432c51e06102b65282bcbc9c4848e6fa
Launcher3: fixup hardocded usages of QSB_ON_FIRST_SCREEN
Change-Id: Id8f6ca9c332f0c53bdf96c944f8daa361adeab1c
Launcher3: fix hotseat qsb widget width
we are not going beyond isScalableGrid in
recalculateHotseatWidthAndBorderSpace so hotseatQsbWidth is 0
in that case. To prevent any unwanted side effects add
a separate API for the width to use if not isQsbInline
Change-Id: I2d49127aa6ea3e10eab043f3f9a102154f1d8458
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 00db3a3..a403544 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -71,6 +71,7 @@
import com.android.launcher3.util.ResourceHelper;
import com.android.launcher3.util.WindowBounds;
import com.android.launcher3.util.window.WindowManagerProxy;
+import com.android.launcher3.Utilities;
import java.io.PrintWriter;
import java.util.Locale;
@@ -540,7 +541,7 @@
workspaceCellPaddingXPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_padding_x);
- hotseatQsbHeight = res.getDimensionPixelSize(R.dimen.qsb_widget_height);
+ hotseatQsbHeight = Utilities.showHotseatQsbWidget(context) ? res.getDimensionPixelSize(R.dimen.qsb_widget_height) : 0;
hotseatQsbShadowHeight = res.getDimensionPixelSize(R.dimen.qsb_shadow_height);
hotseatQsbVisualHeight = hotseatQsbHeight - 2 * hotseatQsbShadowHeight;
@@ -887,6 +888,13 @@
}
/**
+ * used in Hotseat only for !isQsbInline
+ */
+ public int getHostseatQsbWidth() {
+ return calculateQsbWidth(0);
+ }
+
+ /**
* Calculates the width of the hotseat, changing spaces between the icons and removing icons if
* necessary.
*/
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 8546454..117c281 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -33,6 +33,7 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;
+import com.android.launcher3.Utilities;
import com.android.launcher3.util.HorizontalInsettableView;
import com.android.launcher3.util.MultiTranslateDelegate;
import com.android.launcher3.views.ActivityContext;
@@ -64,7 +65,11 @@
public Hotseat(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false);
+ if (Utilities.showHotseatQsbWidget(context)) {
+ mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false);
+ } else {
+ mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat_empty, this, false);
+ }
addView(mQsb);
}
@@ -248,7 +253,8 @@
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
DeviceProfile dp = mActivity.getDeviceProfile();
- mQsb.measure(MeasureSpec.makeMeasureSpec(dp.hotseatQsbWidth, MeasureSpec.EXACTLY),
+ int hotseatQsbWidth = dp.isQsbInline ? dp.hotseatQsbWidth : dp.getHostseatQsbWidth();
+ mQsb.measure(MeasureSpec.makeMeasureSpec(hotseatQsbWidth, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(dp.hotseatQsbHeight, MeasureSpec.EXACTLY));
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index c1ef4b4..b38db5d 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -24,6 +24,7 @@
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_BOTTOM_OR_RIGHT;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_POSITION_TOP_OR_LEFT;
import static com.android.launcher3.util.SplitConfigurationOptions.STAGE_TYPE_MAIN;
+import static com.android.launcher3.settings.SettingsActivity.QSB_LOCATION_PREFERENCE_KEY;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
@@ -195,6 +196,19 @@
context.getResources().getBoolean(R.bool.qsb_show_default));
}
+ public static String qsbWidgtLocation(Context context) {
+ return LauncherPrefs.getPrefs(context).getString(QSB_LOCATION_PREFERENCE_KEY,
+ context.getResources().getString(R.string.pref_qsb_location_workspace_value));
+ }
+
+ public static boolean showHotseatQsbWidget(Context context) {
+ return showQsbWidget(context) && qsbWidgtLocation(context).equals(context.getResources().getString(R.string.pref_qsb_location_hotseat_value));
+ }
+
+ public static boolean showWorkspaceQsbWidget(Context context) {
+ return showQsbWidget(context) && qsbWidgtLocation(context).equals(context.getResources().getString(R.string.pref_qsb_location_workspace_value));
+ }
+
/**
* Given a coordinate relative to the descendant, find the coordinate in a parent view's
* coordinates.
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 0676c05..460d175 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -597,7 +597,7 @@
* Initializes and binds the first page
*/
public void bindAndInitFirstWorkspaceScreen() {
- if ((!Utilities.showQsbWidget(mContext)
+ if ((!Utilities.showWorkspaceQsbWidget(mContext)
|| !mLauncher.getIsFirstPagePinnedItemEnabled())
|| SHOULD_SHOW_FIRST_PAGE_WIDGET) {
mFirstPagePinnedItem = null;
@@ -1038,7 +1038,7 @@
int id = mWorkspaceScreens.keyAt(i);
CellLayout cl = mWorkspaceScreens.valueAt(i);
// FIRST_SCREEN_ID can never be removed.
- if (((!Utilities.showQsbWidget(getContext())
+ if (((!Utilities.showWorkspaceQsbWidget(getContext())
|| SHOULD_SHOW_FIRST_PAGE_WIDGET)
|| id > FIRST_SCREEN_ID)
&& cl.getShortcutsAndWidgets().getChildCount() == 0) {
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 82bf1ba..3117085 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -50,7 +50,7 @@
*/
@Deprecated
// NOTE: replaced by resource qsb_show_default
- public static final boolean QSB_ON_FIRST_SCREEN = true;
+ public static final boolean QSB_ON_FIRST_SCREEN = BuildConfig.QSB_ON_FIRST_SCREEN;
/**
* Feature flag to handle define config changes dynamically instead of killing the process.
diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
index 91deef1..9b51d74 100644
--- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
+++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java
@@ -504,7 +504,7 @@
}
// Add first page QSB
- if (Utilities.showQsbWidget(mContext) && dataModel.isFirstPagePinnedItemEnabled
+ if (Utilities.showWorkspaceQsbWidget(mContext) && dataModel.isFirstPagePinnedItemEnabled
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET) {
CellLayout firstScreen = mWorkspaceScreens.get(FIRST_SCREEN_ID);
View qsb = mHomeElementInflater.inflate(R.layout.qsb_preview, firstScreen, false);
diff --git a/src/com/android/launcher3/model/DatabaseHelper.java b/src/com/android/launcher3/model/DatabaseHelper.java
index 8368256..8d20fb0 100644
--- a/src/com/android/launcher3/model/DatabaseHelper.java
+++ b/src/com/android/launcher3/model/DatabaseHelper.java
@@ -258,7 +258,7 @@
Favorites.SCREEN, IntArray.wrap(-777, -778)), null);
}
case 30: {
- if (FeatureFlags.QSB_ON_FIRST_SCREEN
+ if (Utilities.showWorkspaceQsbWidget(mContext)
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET) {
// Clean up first row in screen 0 as it might contain junk data.
Log.d(TAG, "Cleaning up first row");
diff --git a/src/com/android/launcher3/model/GridSizeMigrationUtil.java b/src/com/android/launcher3/model/GridSizeMigrationUtil.java
index ad32fc2..b3a1544 100644
--- a/src/com/android/launcher3/model/GridSizeMigrationUtil.java
+++ b/src/com/android/launcher3/model/GridSizeMigrationUtil.java
@@ -347,7 +347,7 @@
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
+ && (Utilities.showWorkspaceQsbWidget(destReader.mContext)
&& (!enableSmartspaceRemovalToggle() || LauncherPrefs.getPrefs(destReader.mContext)
.getBoolean(SMARTSPACE_ON_HOME_SCREEN, true))
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET)
diff --git a/src/com/android/launcher3/model/LoaderCursor.java b/src/com/android/launcher3/model/LoaderCursor.java
index b668b84..179cf3b 100644
--- a/src/com/android/launcher3/model/LoaderCursor.java
+++ b/src/com/android/launcher3/model/LoaderCursor.java
@@ -553,7 +553,7 @@
if (!mOccupied.containsKey(item.screenId)) {
GridOccupancy screen = new GridOccupancy(countX + 1, countY + 1);
- if (item.screenId == Workspace.FIRST_SCREEN_ID && (FeatureFlags.QSB_ON_FIRST_SCREEN
+ if (item.screenId == Workspace.FIRST_SCREEN_ID && (Utilities.showWorkspaceQsbWidget(mContext)
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET
&& isFirstPagePinnedItemEnabled)) {
// Mark the first X columns (X is width of the search container) in the first row as
@@ -561,7 +561,7 @@
// container.
int spanX = mIDP.numSearchContainerColumns;
int spanY = 1;
- screen.markCells(0, 0, spanX, spanY, Utilities.showQsbWidget(mContext));
+ screen.markCells(0, 0, spanX, spanY, Utilities.showWorkspaceQsbWidget(mContext));
}
mOccupied.put(item.screenId, screen);
}
diff --git a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
index 1a6d178..7e025ac 100644
--- a/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
+++ b/src/com/android/launcher3/model/WorkspaceItemSpaceFinder.java
@@ -25,6 +25,7 @@
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.ItemInfo;
+import com.android.launcher3.Utilities;
import com.android.launcher3.util.GridOccupancy;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.IntSet;
@@ -67,7 +68,7 @@
int screenCount = workspaceScreens.size();
// First check the preferred screen.
IntSet screensToExclude = new IntSet();
- if (FeatureFlags.QSB_ON_FIRST_SCREEN
+ if (Utilities.showWorkspaceQsbWidget(app.getContext())
&& !SHOULD_SHOW_FIRST_PAGE_WIDGET) {
screensToExclude.add(FIRST_SCREEN_ID);
}
diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java
index 6379469..46995b2 100644
--- a/src/com/android/launcher3/settings/SettingsActivity.java
+++ b/src/com/android/launcher3/settings/SettingsActivity.java
@@ -83,6 +83,7 @@
private static final String NOTIFICATION_DOTS_PREFERENCE_KEY = "pref_icon_badging";
private static final String GRID_SIZE_PREFERENCE_KEY = "pref_grid";
+ public static final String QSB_LOCATION_PREFERENCE_KEY = "pref_qsb_location";
public static final String EXTRA_FRAGMENT_ARGS = ":settings:fragment_args";
@@ -269,6 +270,16 @@
return true;
}
});
+
+ final ListPreference qsbLocation = (ListPreference) findPreference(QSB_LOCATION_PREFERENCE_KEY);
+ valueIndex = qsbLocation.findIndexOfValue(qsbLocation.getValue());
+ qsbLocation.setSummary(qsbLocation.getEntries()[valueIndex]);
+ qsbLocation.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ new Handler().postDelayed(() -> Utilities.restart(getActivity()), Utilities.WAIT_BEFORE_RESTART);
+ return true;
+ }
+ });
}
@Override