Merge "Support defining X column layout for all apps as a display option." into ub-launcher3-qt-future-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
315732e524
+1
-1
@@ -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;
|
||||
|
||||
+3
-2
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -541,6 +557,13 @@ public class DeviceProfile {
|
||||
return isLandscape && transposeLayoutWithOrientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user