summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Miranda <jonmiranda@google.com>2019-09-16 14:44:14 -0700
committerJon Miranda <jonmiranda@google.com>2019-09-16 16:24:59 -0700
commit6f7e9702e3124680b7eb0640898cca0a8855fbb7 (patch)
treebb94ea2dd961e5e380c21896518265dfe6612dfc
parent3463d1c5f9e9b5b5014a5326fbbc812a834aadb8 (diff)
downloadandroid_packages_apps_Trebuchet-6f7e9702e3124680b7eb0640898cca0a8855fbb7.tar.gz
android_packages_apps_Trebuchet-6f7e9702e3124680b7eb0640898cca0a8855fbb7.tar.bz2
android_packages_apps_Trebuchet-6f7e9702e3124680b7eb0640898cca0a8855fbb7.zip
Support defining X column layout for all apps as a display option.
Bug: 124967099 Change-Id: I7bf576759b3fa4f6ca617fbbd660541c12fd09ac
-rw-r--r--quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java2
-rw-r--r--quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java5
-rw-r--r--res/values/attrs.xml9
-rw-r--r--src/com/android/launcher3/DeviceProfile.java41
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java51
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java1
-rw-r--r--src/com/android/launcher3/allapps/AllAppsGridAdapter.java8
7 files changed, 97 insertions, 20 deletions
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java
index a12917f29..cc276d8ce 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionAppTracker.java
@@ -128,7 +128,7 @@ public class PredictionAppTracker extends AppLaunchTracker {
destroy();
// Initialize the clients
- int count = InvariantDeviceProfile.INSTANCE.get(mContext).numColumns;
+ int count = InvariantDeviceProfile.INSTANCE.get(mContext).numAllAppsColumns;
mHomeAppPredictor = createPredictor(Client.HOME, count);
mRecentsOverviewPredictor = createPredictor(Client.OVERVIEW, count);
return true;
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java
index 95f63cea1..23db5df2e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/appprediction/PredictionRowView.java
@@ -93,7 +93,7 @@ public class PredictionRowView extends LinearLayout implements
private final Launcher mLauncher;
private final PredictionUiStateManager mPredictionUiStateManager;
- private final int mNumPredictedAppsPerRow;
+ private int mNumPredictedAppsPerRow;
// The set of predicted app component names
private final List<ComponentKeyMapper> mPredictedAppComponents = new ArrayList<>();
@@ -129,7 +129,7 @@ public class PredictionRowView extends LinearLayout implements
mFocusHelper = new SimpleFocusIndicatorHelper(this);
- mNumPredictedAppsPerRow = LauncherAppState.getIDP(context).numColumns;
+ mNumPredictedAppsPerRow = LauncherAppState.getIDP(context).numAllAppsColumns;
mLauncher = Launcher.getLauncher(context);
mLauncher.addOnDeviceProfileChangeListener(this);
@@ -227,6 +227,7 @@ public class PredictionRowView extends LinearLayout implements
@Override
public void onDeviceProfileChanged(DeviceProfile dp) {
+ mNumPredictedAppsPerRow = dp.inv.numAllAppsColumns;
removeAllViews();
applyPredictionApps();
}
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 69b8c8a22..e76b89826 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -115,7 +115,8 @@
<attr name="numFolderColumns" format="integer" />
<!-- numHotseatIcons defaults to numColumns, if not specified -->
<attr name="numHotseatIcons" format="integer" />
-
+ <!-- numAllAppsColumns defaults to numColumns, if not specified -->
+ <attr name="numAllAppsColumns" format="integer" />
<attr name="defaultLayoutId" format="reference" />
<attr name="demoModeLayoutId" format="reference" />
</declare-styleable>
@@ -131,6 +132,12 @@
<attr name="iconTextSize" format="float" />
<!-- If true, this display option is used to determine the default grid -->
<attr name="canBeDefault" format="boolean" />
+
+ <!-- The following values are only enabled if grid is supported. -->
+ <!-- allAppsIconSize defaults to iconSize, if not specified -->
+ <attr name="allAppsIconSize" format="float" />
+ <!-- allAppsIconTextSize defaults to iconTextSize, if not specified -->
+ <attr name="allAppsIconTextSize" format="float" />
</declare-styleable>
<declare-styleable name="CellLayout">
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 61f247c39..44c307058 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -307,11 +307,16 @@ public class DeviceProfile {
updateAvailableFolderCellDimensions(dm, res);
}
+ /**
+ * Updating the iconSize affects many aspects of the launcher layout, such as: iconSizePx,
+ * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants,
+ * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx.
+ */
private void updateIconSize(float scale, Resources res, DisplayMetrics dm) {
// Workspace
final boolean isVerticalLayout = isVerticalBarLayout();
- float invIconSizePx = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
- iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizePx, dm) * scale));
+ float invIconSizeDp = isVerticalLayout ? inv.landscapeIconSize : inv.iconSize;
+ iconSizePx = Math.max(1, (int) (ResourceUtils.pxFromDp(invIconSizeDp, dm) * scale));
iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
iconDrawablePaddingPx = (int) (iconDrawablePaddingOriginalPx * scale);
@@ -329,12 +334,19 @@ public class DeviceProfile {
cellWidthPx = iconSizePx + iconDrawablePaddingPx;
// All apps
- allAppsIconTextSizePx = iconTextSizePx;
- allAppsIconSizePx = iconSizePx;
- allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
- allAppsCellHeightPx = getCellSize().y;
+ if (allAppsHasDifferentNumColumns()) {
+ allAppsIconSizePx = ResourceUtils.pxFromDp(inv.allAppsIconSize, dm);
+ allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, dm);
+ allAppsCellHeightPx = getCellSize(inv.numAllAppsColumns, inv.numAllAppsColumns).y;
+ allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx;
+ } else {
+ allAppsIconSizePx = iconSizePx;
+ allAppsIconTextSizePx = iconTextSizePx;
+ allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
+ allAppsCellHeightPx = getCellSize().y;
+ }
- if (isVerticalLayout) {
+ if (isVerticalBarLayout()) {
// Always hide the Workspace text with vertical bar layout.
adjustToHideWorkspaceLabels();
}
@@ -419,14 +431,18 @@ public class DeviceProfile {
}
public Point getCellSize() {
+ return getCellSize(inv.numColumns, inv.numRows);
+ }
+
+ private Point getCellSize(int numColumns, int numRows) {
Point result = new Point();
// Since we are only concerned with the overall padding, layout direction does
// not matter.
Point padding = getTotalWorkspacePadding();
result.x = calculateCellWidth(availableWidthPx - padding.x
- - cellLayoutPaddingLeftRightPx * 2, inv.numColumns);
+ - cellLayoutPaddingLeftRightPx * 2, numColumns);
result.y = calculateCellHeight(availableHeightPx - padding.y
- - cellLayoutBottomPaddingPx, inv.numRows);
+ - cellLayoutBottomPaddingPx, numRows);
return result;
}
@@ -542,6 +558,13 @@ public class DeviceProfile {
}
/**
+ * Returns true when the number of workspace columns and all apps columns differs.
+ */
+ private boolean allAppsHasDifferentNumColumns() {
+ return inv.numAllAppsColumns != inv.numColumns;
+ }
+
+ /**
* Updates orientation information and returns true if it has changed from the previous value.
*/
public boolean updateIsSeascape(Context context) {
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 208a822eb..310a9e92f 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -19,6 +19,7 @@ package com.android.launcher3;
import static com.android.launcher3.Utilities.getDevicePrefs;
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
+import static com.android.launcher3.settings.SettingsActivity.GRID_OPTIONS_PREFERENCE_KEY;
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
import android.annotation.TargetApi;
@@ -102,6 +103,8 @@ public class InvariantDeviceProfile {
public int iconBitmapSize;
public int fillResIconDpi;
public float iconTextSize;
+ public float allAppsIconSize;
+ public float allAppsIconTextSize;
private SparseArray<TypedValue> mExtraAttrs;
@@ -110,6 +113,11 @@ public class InvariantDeviceProfile {
*/
public int numHotseatIcons;
+ /**
+ * Number of columns in the all apps list.
+ */
+ public int numAllAppsColumns;
+
public int defaultLayoutId;
int demoModeLayoutId;
@@ -136,6 +144,9 @@ public class InvariantDeviceProfile {
landscapeIconSize = p.landscapeIconSize;
iconTextSize = p.iconTextSize;
numHotseatIcons = p.numHotseatIcons;
+ numAllAppsColumns = p.numAllAppsColumns;
+ allAppsIconSize = p.allAppsIconSize;
+ allAppsIconTextSize = p.allAppsIconTextSize;
defaultLayoutId = p.defaultLayoutId;
demoModeLayoutId = p.demoModeLayoutId;
mExtraAttrs = p.mExtraAttrs;
@@ -144,7 +155,10 @@ public class InvariantDeviceProfile {
@TargetApi(23)
private InvariantDeviceProfile(Context context) {
- initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null));
+ String gridName = Utilities.getPrefs(context).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)
+ ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)
+ : null;
+ initGrid(context, gridName);
mConfigMonitor = new ConfigMonitor(context,
APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess);
mOverlayMonitor = new OverlayMonitor(context);
@@ -198,6 +212,8 @@ public class InvariantDeviceProfile {
demoModeLayoutId = closestProfile.demoModeLayoutId;
numFolderRows = closestProfile.numFolderRows;
numFolderColumns = closestProfile.numFolderColumns;
+ numAllAppsColumns = closestProfile.numAllAppsColumns;
+
mExtraAttrs = closestProfile.extraAttrs;
if (!closestProfile.name.equals(gridName)) {
@@ -212,6 +228,14 @@ public class InvariantDeviceProfile {
iconTextSize = interpolatedDisplayOption.iconTextSize;
fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
+ if (Utilities.getPrefs(context).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)) {
+ allAppsIconSize = interpolatedDisplayOption.allAppsIconSize;
+ allAppsIconTextSize = interpolatedDisplayOption.allAppsIconTextSize;
+ } else {
+ allAppsIconSize = iconSize;
+ allAppsIconTextSize = iconTextSize;
+ }
+
// If the partner customization apk contains any grid overrides, apply them
// Supported overrides: numRows, numColumns, iconSize
applyPartnerDeviceProfileOverrides(context, displayInfo.metrics);
@@ -285,9 +309,10 @@ public class InvariantDeviceProfile {
InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this);
// Re-init grid
- // TODO(b/131867841): We pass in null here so that we can calculate the closest profile
- // without the bias of the grid name.
- initGrid(context, null);
+ String gridName = Utilities.getPrefs(context).getBoolean(GRID_OPTIONS_PREFERENCE_KEY, false)
+ ? Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null)
+ : null;
+ initGrid(context, gridName);
int changeFlags = 0;
if (numRows != oldProfile.numRows ||
@@ -489,6 +514,8 @@ public class InvariantDeviceProfile {
private final int numHotseatIcons;
+ private final int numAllAppsColumns;
+
private final int defaultLayoutId;
private final int demoModeLayoutId;
@@ -511,6 +538,9 @@ public class InvariantDeviceProfile {
R.styleable.GridDisplayOption_numFolderRows, numRows);
numFolderColumns = a.getInt(
R.styleable.GridDisplayOption_numFolderColumns, numColumns);
+ numAllAppsColumns = a.getInt(
+ R.styleable.GridDisplayOption_numAllAppsColumns, numColumns);
+
a.recycle();
extraAttrs = Themes.createValueMap(context, attrs,
@@ -527,8 +557,10 @@ public class InvariantDeviceProfile {
private final boolean canBeDefault;
private float iconSize;
- private float landscapeIconSize;
private float iconTextSize;
+ private float landscapeIconSize;
+ private float allAppsIconSize;
+ private float allAppsIconTextSize;
DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
this.grid = grid;
@@ -546,6 +578,11 @@ public class InvariantDeviceProfile {
landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
iconSize);
iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
+
+ allAppsIconSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconSize,
+ iconSize);
+ allAppsIconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_allAppsIconTextSize,
+ iconTextSize);
a.recycle();
}
@@ -560,14 +597,18 @@ public class InvariantDeviceProfile {
private DisplayOption multiply(float w) {
iconSize *= w;
landscapeIconSize *= w;
+ allAppsIconSize *= w;
iconTextSize *= w;
+ allAppsIconTextSize *= w;
return this;
}
private DisplayOption add(DisplayOption p) {
iconSize += p.iconSize;
landscapeIconSize += p.landscapeIconSize;
+ allAppsIconSize += p.allAppsIconSize;
iconTextSize += p.iconTextSize;
+ allAppsIconTextSize += p.allAppsIconTextSize;
return this;
}
}
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 293b86722..37ee24850 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -312,6 +312,7 @@ public class AllAppsContainerView extends SpringRelativeLayout implements DragSo
+ grid.cellLayoutPaddingLeftRightPx;
for (int i = 0; i < mAH.length; i++) {
+ mAH[i].adapter.setAppsPerRow(grid.inv.numAllAppsColumns);
mAH[i].padding.bottom = insets.bottom;
mAH[i].padding.left = mAH[i].padding.right = leftRightPadding;
mAH[i].applyPadding();
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 3cfa0b1ec..bb212686e 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -180,7 +180,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
private final GridLayoutManager mGridLayoutMgr;
private final GridSpanSizer mGridSizer;
- private final int mAppsPerRow;
+ private int mAppsPerRow;
private BindViewCallback mBindViewCallback;
private OnFocusChangeListener mIconFocusListener;
@@ -200,7 +200,11 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter<AllAppsGridAdapter.
mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
mLayoutInflater = LayoutInflater.from(launcher);
- mAppsPerRow = mLauncher.getDeviceProfile().inv.numColumns;
+ setAppsPerRow(mLauncher.getDeviceProfile().inv.numAllAppsColumns);
+ }
+
+ public void setAppsPerRow(int appsPerRow) {
+ mAppsPerRow = appsPerRow;
mGridLayoutMgr.setSpanCount(mAppsPerRow);
}