Revert "Revert "Moving DeviceProfile properties into DevicePrope..."

Revert submission 33716851-revert-33672643-DataDeviceProfile1-XHYRAPLEBK

Reason for revert: Error is fixed

Reverted changes: /q/submissionid:33716851-revert-33672643-DataDeviceProfile1-XHYRAPLEBK

Change-Id: Ib86824134955903c11e51e52dbfd6368aba1cd50
This commit is contained in:
Sebastián Franco
2025-05-23 14:05:01 -07:00
committed by Sebastian Franco
parent 1bec329180
commit e1d31e5406
128 changed files with 727 additions and 597 deletions
+1 -1
View File
@@ -1052,7 +1052,7 @@ public class CellLayout extends ViewGroup {
/**
* Returns the amount of space left over after subtracting padding and cells. This space will be
* very small, a few pixels at most, and is a result of rounding down when calculating the cell
* width in {@link DeviceProfile#calculateCellWidth(int, int, int)}.
* width in {@link deviceprofile#calculateCellWidth(int, int, int)}.
*/
public int getUnusedHorizontalSpace() {
return getMeasuredWidth() - getPaddingLeft() - getPaddingRight() - (mCountX * mCellWidth)
+118 -134
View File
@@ -56,6 +56,7 @@ import androidx.core.content.res.ResourcesCompat;
import com.android.launcher3.CellLayout.ContainerType;
import com.android.launcher3.DevicePaddings.DevicePadding;
import com.android.launcher3.InvariantDeviceProfile.DisplayOptionSpec;
import com.android.launcher3.deviceprofile.DeviceProperties;
import com.android.launcher3.graphics.ThemeManager;
import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.model.data.ItemInfo;
@@ -102,31 +103,15 @@ public class DeviceProfile {
private final IconSizeSteps mIconSizeSteps;
// Device properties
public final boolean isTablet;
public final boolean isPhone;
public final boolean transposeLayoutWithOrientation;
public final boolean isMultiDisplay;
public final boolean isTwoPanels;
private final DeviceProperties mDeviceProperties;
public boolean isPredictiveBackSwipe;
public final boolean isQsbInline;
// Device properties in current orientation
public final boolean isLandscape;
public final boolean isMultiWindowMode;
public final boolean isGestureMode;
public final boolean isLeftRightSplit;
public final int windowX;
public final int windowY;
public final int widthPx;
public final int heightPx;
public final int availableWidthPx;
public final int availableHeightPx;
public final int rotationHint;
public final float aspectRatio;
private final boolean mIsScalableGrid;
private final int mTypeIndex;
@@ -327,30 +312,29 @@ public class DeviceProfile {
/** Used only as an alternative to mocking when null values cannot be used. */
@VisibleForTesting
public DeviceProfile() {
mDeviceProperties = new DeviceProperties(
0,0,
0,
0,0,
0,0,
0.0f,
false,
false,
false,
false,
false,
false,
false,
false
);
inv = null;
mDisplayOptionSpec = null;
mInfo = null;
mMetrics = null;
mIconSizeSteps = null;
isTablet = false;
isPhone = false;
transposeLayoutWithOrientation = false;
isMultiDisplay = false;
isTwoPanels = false;
isPredictiveBackSwipe = false;
isQsbInline = false;
isLandscape = false;
isMultiWindowMode = false;
isGestureMode = false;
isLeftRightSplit = false;
windowX = 0;
windowY = 0;
widthPx = 0;
heightPx = 0;
availableWidthPx = 0;
availableHeightPx = 0;
rotationHint = 0;
aspectRatio = 1;
mIsScalableGrid = false;
mTypeIndex = 0;
mIsResponsiveGrid = false;
@@ -402,14 +386,15 @@ public class DeviceProfile {
boolean isTransientTaskbar, DisplayOptionSpec displayOptionSpec) {
this.inv = inv;
this.isLandscape = windowBounds.isLandscape();
this.isMultiWindowMode = isMultiWindowMode;
this.transposeLayoutWithOrientation = transposeLayoutWithOrientation;
this.isMultiDisplay = isMultiDisplay;
this.isGestureMode = isGestureMode;
windowX = windowBounds.bounds.left;
windowY = windowBounds.bounds.top;
this.rotationHint = windowBounds.rotationHint;
mDeviceProperties = DeviceProperties.Factory.createDeviceProperties(
info,
windowBounds,
transposeLayoutWithOrientation,
isMultiDisplay,
isMultiWindowMode,
isGestureMode
);
mInsets.set(windowBounds.insets);
this.mDisplayOptionSpec = displayOptionSpec;
@@ -424,18 +409,15 @@ public class DeviceProfile {
mIsScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
// Determine device posture.
mInfo = info;
isTablet = info.isTablet(windowBounds);
isPhone = !isTablet;
isTwoPanels = isTablet && isMultiDisplay;
boolean taskbarOrBubbleBarOnPhones = enableTinyTaskbar()
|| (enableBubbleBar() && enableBubbleBarOnPhones());
isTaskbarPresent = (isTablet || (taskbarOrBubbleBarOnPhones && isGestureMode))
isTaskbarPresent = (mDeviceProperties.isTablet() || (taskbarOrBubbleBarOnPhones && isGestureMode))
&& wmProxy.isTaskbarDrawnInProcess();
// Some more constants.
context = getContext(context, info, inv.isFixedLandscape
|| isVerticalBarLayout()
|| (isTablet && isLandscape)
|| (mDeviceProperties.isTablet() && mDeviceProperties.isLandscape())
? Configuration.ORIENTATION_LANDSCAPE
: Configuration.ORIENTATION_PORTRAIT,
windowBounds);
@@ -444,13 +426,6 @@ public class DeviceProfile {
mIconSizeSteps = new IconSizeSteps(res);
// Determine sizes.
widthPx = windowBounds.bounds.width();
heightPx = windowBounds.bounds.height();
availableWidthPx = windowBounds.availableSize.x;
availableHeightPx = windowBounds.availableSize.y;
aspectRatio = ((float) Math.max(widthPx, heightPx)) / Math.min(widthPx, heightPx);
mTypeIndex = displayOptionSpec.typeIndex;
this.isTransientTaskbar = isTransientTaskbar;
@@ -492,13 +467,13 @@ public class DeviceProfile {
{
// In large screens, in portrait mode, a bottom sheet can appear too elongated, so, we
// apply additional padding.
final boolean applyExtraTopPadding = isTablet
&& !isLandscape
&& (aspectRatio > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING);
final int derivedTopPadding = heightPx / 6;
final boolean applyExtraTopPadding = mDeviceProperties.isTablet()
&& !mDeviceProperties.isLandscape()
&& (mDeviceProperties.getAspectRatio() > MIN_ASPECT_RATIO_FOR_EXTRA_TOP_PADDING);
final int derivedTopPadding = mDeviceProperties.getHeightPx() / 6;
bottomSheetTopPadding = mInsets.top // statusbar height
+ (applyExtraTopPadding ? derivedTopPadding : 0)
+ (isTablet ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
+ (mDeviceProperties.isTablet() ? 0 : edgeMarginPx); // phones need edgeMarginPx additional padding
}
bottomSheetOpenDuration = res.getInteger(R.integer.config_bottomSheetOpenDuration);
@@ -582,9 +557,9 @@ public class DeviceProfile {
dropTargetBarSizePx = res.getDimensionPixelSize(R.dimen.dynamic_grid_drop_target_size);
// Some foldable portrait modes are too wide in terms of aspect ratio so we need to tweak
// the dimensions for edit state.
final boolean shouldApplyWidePortraitDimens = isTablet
&& !isLandscape
&& aspectRatio < MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE;
final boolean shouldApplyWidePortraitDimens = mDeviceProperties.isTablet()
&& !mDeviceProperties.isLandscape()
&& mDeviceProperties.getAspectRatio() < MAX_ASPECT_RATIO_FOR_ALTERNATE_EDIT_STATE;
dropTargetBarTopMarginPx = shouldApplyWidePortraitDimens
? 0
: res.getDimensionPixelSize(R.dimen.drop_target_top_margin);
@@ -623,15 +598,15 @@ public class DeviceProfile {
int minQsbMargin = res.getDimensionPixelSize(R.dimen.min_qsb_margin);
if (mIsResponsiveGrid) {
float responsiveAspectRatio = (float) widthPx / heightPx;
float responsiveAspectRatio = (float) mDeviceProperties.getWidthPx() / mDeviceProperties.getHeightPx();
HotseatSpecsProvider hotseatSpecsProvider =
HotseatSpecsProvider.create(new ResourceHelper(context,
displayOptionSpec.hotseatSpecsId));
mResponsiveHotseatSpec =
isVerticalBarLayout() ? hotseatSpecsProvider.getCalculatedSpec(
responsiveAspectRatio, DimensionType.WIDTH, widthPx)
responsiveAspectRatio, DimensionType.WIDTH, mDeviceProperties.getWidthPx())
: hotseatSpecsProvider.getCalculatedSpec(responsiveAspectRatio,
DimensionType.HEIGHT, heightPx);
DimensionType.HEIGHT, mDeviceProperties.getHeightPx());
hotseatQsbSpace = mResponsiveHotseatSpec.getHotseatQsbSpace();
hotseatBarBottomSpace =
isVerticalBarLayout() ? 0 : mResponsiveHotseatSpec.getEdgePadding();
@@ -642,7 +617,7 @@ public class DeviceProfile {
ResponsiveCellSpecsProvider workspaceCellSpecs = ResponsiveCellSpecsProvider.create(
new ResourceHelper(context, displayOptionSpec.workspaceCellSpecsId));
mResponsiveWorkspaceCellSpec = workspaceCellSpecs.getCalculatedSpec(
responsiveAspectRatio, heightPx);
responsiveAspectRatio, mDeviceProperties.getHeightPx());
} else {
hotseatQsbSpace = pxFromDp(inv.hotseatQsbSpace[mTypeIndex], mMetrics);
hotseatBarBottomSpace = pxFromDp(inv.hotseatBarBottomSpace[mTypeIndex], mMetrics);
@@ -684,7 +659,7 @@ public class DeviceProfile {
updateHotseatSizes(pxFromDp(inv.iconSize[mTypeIndex], mMetrics));
}
if (areNavButtonsInline && !isPhone) {
if (areNavButtonsInline && !mDeviceProperties.isPhone()) {
inlineNavButtonsEndSpacingPx =
res.getDimensionPixelSize(inv.inlineNavButtonsEndSpacing);
/* 3 nav buttons + Spacing between nav buttons */
@@ -704,12 +679,12 @@ public class DeviceProfile {
// for the available height to be correct
if (mIsResponsiveGrid) {
int availableResponsiveWidth =
availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
mDeviceProperties.getAvailableWidthPx() - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
int numWorkspaceColumns = getPanelCount() * inv.numColumns;
// don't use availableHeightPx because it subtracts mInsets.bottom
int availableResponsiveHeight = heightPx - mInsets.top
int availableResponsiveHeight = mDeviceProperties.getHeightPx() - mInsets.top
- (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
float responsiveAspectRatio = (float) widthPx / heightPx;
float responsiveAspectRatio = (float) mDeviceProperties.getWidthPx() / mDeviceProperties.getHeightPx();
ResponsiveSpecsProvider workspaceSpecs = ResponsiveSpecsProvider.create(
new ResourceHelper(context, displayOptionSpec.workspaceSpecsId),
@@ -723,7 +698,7 @@ public class DeviceProfile {
new ResourceHelper(context, displayOptionSpec.allAppsSpecsId),
ResponsiveSpecType.AllApps);
mResponsiveAllAppsWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
DimensionType.WIDTH, numShownAllAppsColumns, mDeviceProperties.getAvailableWidthPx(),
mResponsiveWorkspaceWidthSpec);
if (inv.appListAlignedWithWorkspaceRow >= 0) {
allAppsTopPadding += mResponsiveWorkspaceHeightSpec.getStartPaddingPx()
@@ -733,7 +708,7 @@ public class DeviceProfile {
}
mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
heightPx - allAppsTopPadding, mResponsiveWorkspaceHeightSpec);
mDeviceProperties.getHeightPx() - allAppsTopPadding, mResponsiveWorkspaceHeightSpec);
ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
new ResourceHelper(context, displayOptionSpec.folderSpecsId),
@@ -785,10 +760,10 @@ public class DeviceProfile {
boolean allowLeftRightSplitInPortrait =
leftRightSplitPortraitResId > 0
&& res.getBoolean(leftRightSplitPortraitResId);
if (allowLeftRightSplitInPortrait && isTablet) {
isLeftRightSplit = !isLandscape;
if (allowLeftRightSplitInPortrait && mDeviceProperties.isTablet()) {
isLeftRightSplit = !mDeviceProperties.isLandscape();
} else {
isLeftRightSplit = isLandscape;
isLeftRightSplit = mDeviceProperties.isLandscape();
}
// Calculate all of the remaining variables.
@@ -797,7 +772,7 @@ public class DeviceProfile {
calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace);
int cellLayoutPadding =
isTwoPanels ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
mDeviceProperties.isTwoPanels() ? cellLayoutBorderSpacePx.x / 2 : res.getDimensionPixelSize(
R.dimen.cell_layout_padding);
cellLayoutPaddingPx = new Rect(cellLayoutPadding, cellLayoutPadding, cellLayoutPadding,
cellLayoutPadding);
@@ -820,7 +795,7 @@ public class DeviceProfile {
if (shouldShowAllAppsOnSheet()) {
allAppsPadding.top = allAppsTopPadding;
allAppsShiftRange = heightPx - allAppsTopPadding + mInsets.top;
allAppsShiftRange = mDeviceProperties.getHeightPx() - allAppsTopPadding + mInsets.top;
} else {
allAppsPadding.top = 0;
allAppsShiftRange =
@@ -841,6 +816,10 @@ public class DeviceProfile {
mDotRendererAllApps = createDotRenderer(themeManager, allAppsIconSizePx, dotRendererCache);
}
public DeviceProperties getDeviceProperties() {
return mDeviceProperties;
}
/**
* Takes care of the logic that determines if we show a the QSB inline or not.
*/
@@ -852,7 +831,7 @@ public class DeviceProfile {
// In tablets we inline in both orientations but only if we have enough space in the QSB
boolean tabletInlineQsb = inv.inlineQsb[INDEX_DEFAULT] || inv.inlineQsb[INDEX_LANDSCAPE];
boolean canQsbInline = isTwoPanels ? twoPanelCanInline : tabletInlineQsb;
boolean canQsbInline = mDeviceProperties.isTwoPanels() ? twoPanelCanInline : tabletInlineQsb;
canQsbInline = canQsbInline && hotseatQsbHeight > 0;
return (mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline)
@@ -879,7 +858,7 @@ public class DeviceProfile {
* reasonable over estimation is fine.
*/
public int getMaxAllAppsRowCount() {
return (int) (Math.ceil((availableHeightPx - allAppsPadding.top)
return (int) (Math.ceil((mDeviceProperties.getAvailableHeightPx() - allAppsPadding.top)
/ (float) allAppsCellHeightPx));
}
@@ -969,7 +948,7 @@ public class DeviceProfile {
updateHotseatWidthAndBorderSpace(inv.numColumns);
int numWorkspaceColumns = getPanelCount() * inv.numColumns;
if (isTwoPanels) {
if (mDeviceProperties.isTwoPanels()) {
updateHotseatWidthAndBorderSpace(inv.numDatabaseHotseatIcons);
// If hotseat doesn't fit with current width, increase column span to fit by multiple
// of 2.
@@ -999,7 +978,7 @@ public class DeviceProfile {
// The side space with inline buttons should be what is defined in InvariantDeviceProfile
int sideSpacePx = inlineNavButtonsEndSpacingPx;
int maxHotseatWidthPx = availableWidthPx - sideSpacePx - hotseatBarEndOffset;
int maxHotseatWidthPx = mDeviceProperties.getAvailableWidthPx() - sideSpacePx - hotseatBarEndOffset;
int maxHotseatIconsWidthPx = maxHotseatWidthPx - (isQsbInline ? hotseatQsbWidth : 0);
hotseatBorderSpace = calculateHotseatBorderSpace(maxHotseatIconsWidthPx,
(isQsbInline ? 1 : 0) + /* border between nav buttons and first icon */ 1);
@@ -1074,8 +1053,13 @@ public class DeviceProfile {
public Builder toBuilder(Context context) {
WindowBounds bounds = new WindowBounds(
widthPx, heightPx, availableWidthPx, availableHeightPx, rotationHint);
bounds.bounds.offsetTo(windowX, windowY);
mDeviceProperties.getWidthPx(),
mDeviceProperties.getHeightPx(),
mDeviceProperties.getAvailableWidthPx(),
mDeviceProperties.getAvailableHeightPx(),
mDeviceProperties.getRotationHint()
);
bounds.bounds.offsetTo(mDeviceProperties.getWindowX(), mDeviceProperties.getWindowY());
bounds.insets.set(mInsets);
SparseArray<DotRenderer> dotRendererCache = new SparseArray<>();
@@ -1084,10 +1068,10 @@ public class DeviceProfile {
return inv.newDPBuilder(context, mInfo)
.setWindowBounds(bounds)
.setIsMultiDisplay(isMultiDisplay)
.setMultiWindowMode(isMultiWindowMode)
.setIsMultiDisplay(mDeviceProperties.isMultiDisplay())
.setMultiWindowMode(mDeviceProperties.isMultiWindowMode())
.setDotRendererCache(dotRendererCache)
.setGestureMode(isGestureMode)
.setGestureMode(mDeviceProperties.isGestureMode())
.setDisplayOptionSpec(mDisplayOptionSpec);
}
@@ -1179,7 +1163,7 @@ public class DeviceProfile {
float usedWidth =
getCellLayoutWidthSpecification() + (desiredWorkspaceHorizontalMarginPx * 2);
// We do not subtract padding here, as we also scale the workspace padding if needed.
scaleX = availableWidthPx / usedWidth;
scaleX = mDeviceProperties.getAvailableWidthPx() / usedWidth;
shouldScale = true;
}
@@ -1344,7 +1328,7 @@ public class DeviceProfile {
maxIconTextLineCount = 1;
int cellPaddingY = (getCellSize().y - cellHeightPx) / 2;
if (iconDrawablePaddingPx > cellPaddingY && !isVerticalLayout
&& !isMultiWindowMode) {
&& !mDeviceProperties.isMultiWindowMode()) {
// Ensures that the label is closer to its corresponding icon. This is not an issue
// with vertical bar layout or multi-window mode since the issue is handled
// separately with their calls to {@link #adjustToHideWorkspaceLabels}.
@@ -1522,11 +1506,11 @@ public class DeviceProfile {
private void updateAllAppsContainerWidth() {
int cellLayoutHorizontalPadding =
(cellLayoutPaddingPx.left + cellLayoutPaddingPx.right) / 2;
if (isTablet) {
if (mDeviceProperties.isTablet()) {
int usedWidth = (allAppsCellWidthPx * numShownAllAppsColumns)
+ (allAppsBorderSpacePx.x * (numShownAllAppsColumns - 1))
+ allAppsPadding.left + allAppsPadding.right;
allAppsLeftRightMargin = Math.max(1, (availableWidthPx - usedWidth) / 2);
allAppsLeftRightMargin = Math.max(1, (mDeviceProperties.getAvailableWidthPx() - usedWidth) / 2);
} else if (!mIsResponsiveGrid) {
allAppsPadding.left = allAppsPadding.right =
Math.max(0, desiredWorkspaceHorizontalMarginPx + cellLayoutHorizontalPadding
@@ -1536,7 +1520,7 @@ public class DeviceProfile {
/** Whether All Apps should be presented on a bottom sheet. */
public boolean shouldShowAllAppsOnSheet() {
return isTablet || Flags.allAppsSheetForHandheld();
return mDeviceProperties.isTablet() || Flags.allAppsSheetForHandheld();
}
private void setupAllAppsStyle(Context context) {
@@ -1563,14 +1547,14 @@ public class DeviceProfile {
+ ((numFolderRows - 1) * folderCellLayoutBorderSpacePx.y)
+ folderFooterHeightPx
+ folderContentPaddingTop;
int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
int contentMaxHeight = mDeviceProperties.getAvailableHeightPx() - totalWorkspacePadding.y;
float scaleY = contentMaxHeight / contentUsedHeight;
// Check if the folder fit within the available width.
float contentUsedWidth = folderCellWidthPx * numFolderColumns
+ ((numFolderColumns - 1) * folderCellLayoutBorderSpacePx.x)
+ folderContentPaddingLeftRight * 2;
int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
int contentMaxWidth = mDeviceProperties.getAvailableWidthPx() - totalWorkspacePadding.x;
float scaleX = contentMaxWidth / contentUsedWidth;
float scale = Math.min(scaleX, scaleY);
@@ -1722,7 +1706,7 @@ public class DeviceProfile {
* Gets the number of panels within the workspace.
*/
public int getPanelCount() {
return isTwoPanels ? 2 : 1;
return mDeviceProperties.isTwoPanels() ? 2 : 1;
}
/**
@@ -1732,7 +1716,7 @@ public class DeviceProfile {
private int getVerticalHotseatLastItemBottomOffset(Context context) {
Rect hotseatBarPadding = getHotseatLayoutPadding(context);
int cellHeight = calculateCellHeight(
heightPx - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
mDeviceProperties.getHeightPx() - hotseatBarPadding.top - hotseatBarPadding.bottom, hotseatBorderSpace,
numShownHotseatIcons);
int extraIconEndSpacing = (cellHeight - iconSizePx) / 2;
return extraIconEndSpacing + hotseatBarPadding.bottom;
@@ -1751,7 +1735,7 @@ public class DeviceProfile {
*/
public float getCellLayoutSpringLoadShrunkBottom(Context context) {
int topOfHotseat = hotseatBarSizePx + springLoadedHotseatBarTopMarginPx;
return heightPx - (isVerticalBarLayout()
return mDeviceProperties.getHeightPx() - (isVerticalBarLayout()
? getVerticalHotseatLastItemBottomOffset(context) : topOfHotseat);
}
@@ -1765,7 +1749,7 @@ public class DeviceProfile {
scale = Math.min(scale, 1f);
// Reduce scale if next pages would not be visible after scaling the workspace.
int workspaceWidth = availableWidthPx;
int workspaceWidth = mDeviceProperties.getAvailableWidthPx();
float scaledWorkspaceWidth = workspaceWidth * scale;
float maxAvailableWidth = workspaceWidth - (2 * workspaceSpringLoadedMinNextPageVisiblePx);
if (scaledWorkspaceWidth > maxAvailableWidth) {
@@ -1781,7 +1765,7 @@ public class DeviceProfile {
* layouts have two Cell Layouts per workspace.
*/
public int getCellLayoutWidth() {
return (availableWidthPx - getTotalWorkspacePadding().x) / getPanelCount();
return (mDeviceProperties.getAvailableWidthPx() - getTotalWorkspacePadding().x) / getPanelCount();
}
/**
@@ -1790,7 +1774,7 @@ public class DeviceProfile {
* <p>This is the height of a Workspace, less its vertical padding.
*/
public int getCellLayoutHeight() {
return availableHeightPx - getTotalWorkspacePadding().y;
return mDeviceProperties.getAvailableHeightPx() - getTotalWorkspacePadding().y;
}
public Point getTotalWorkspacePadding() {
@@ -1955,7 +1939,7 @@ public class DeviceProfile {
int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
int qsbWidth = getAdditionalQsbSpace() + iconExtraSpacePx / 2;
int availableWidthPxForHotseat = availableWidthPx - Math.abs(workspacePadding.width())
int availableWidthPxForHotseat = mDeviceProperties.getAvailableWidthPx() - Math.abs(workspacePadding.width())
- Math.abs(cellLayoutPaddingPx.width());
int remainingSpaceOnSide = (availableWidthPxForHotseat - hotseatPlusQSBWidth) / 2;
@@ -1984,9 +1968,9 @@ public class DeviceProfile {
// Hotseat aligns to the left with nav buttons
if (hotseatBarEndOffset > 0) {
startSpacing = inlineNavButtonsEndSpacingPx;
endSpacing = availableWidthPx - hotseatWidth - startSpacing + hotseatBorderSpace;
endSpacing = mDeviceProperties.getAvailableWidthPx() - hotseatWidth - startSpacing + hotseatBorderSpace;
} else {
startSpacing = (availableWidthPx - hotseatWidth) / 2;
startSpacing = (mDeviceProperties.getAvailableWidthPx() - hotseatWidth) / 2;
endSpacing = startSpacing;
}
startSpacing += getAdditionalQsbSpace();
@@ -2004,7 +1988,7 @@ public class DeviceProfile {
} else if (mIsScalableGrid) {
int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx);
int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
int sideSpacing = (mDeviceProperties.getAvailableWidthPx() - (hotseatQsbWidth + iconExtraSpacePx)) / 2;
hotseatBarPadding.set(sideSpacing,
0,
sideSpacing,
@@ -2014,8 +1998,8 @@ public class DeviceProfile {
// icons in the hotseat are a different size, and so don't line up perfectly. To account
// for this, we pad the left and right of the hotseat with half of the difference of a
// workspace cell vs a hotseat cell.
float workspaceCellWidth = (float) widthPx / inv.numColumns;
float hotseatCellWidth = (float) widthPx / numShownHotseatIcons;
float workspaceCellWidth = (float) mDeviceProperties.getWidthPx() / inv.numColumns;
float hotseatCellWidth = (float) mDeviceProperties.getWidthPx() / numShownHotseatIcons;
int hotseatAdjustment = Math.round((workspaceCellWidth - hotseatCellWidth) / 2);
hotseatBarPadding.set(
hotseatAdjustment + workspacePadding.left + cellLayoutPaddingPx.left
@@ -2040,7 +2024,7 @@ public class DeviceProfile {
}
int cellWidth = DeviceProfile.calculateCellWidth(
availableWidthPx - allAppsSpacing,
mDeviceProperties.getAvailableWidthPx() - allAppsSpacing,
0 /* borderSpace */,
numShownAllAppsColumns);
int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2;
@@ -2122,7 +2106,7 @@ public class DeviceProfile {
/** Returns whether bubble bar should be aligned with the hotseat. */
public boolean shouldAlignBubbleBarWithHotseat() {
return isQsbInline || isGestureMode;
return isQsbInline || mDeviceProperties.isGestureMode();
}
/**
@@ -2142,7 +2126,7 @@ public class DeviceProfile {
/** Gets the space that the overview actions will take, including bottom margin. */
public int getOverviewActionsClaimedSpace() {
int overviewActionsSpace = isTablet && enableGridOnlyOverview()
int overviewActionsSpace = mDeviceProperties.isTablet() && enableGridOnlyOverview()
? 0
: (overviewActionsTopMarginPx + overviewActionsHeight);
return overviewActionsSpace + getOverviewActionsClaimedSpaceBelow();
@@ -2169,15 +2153,15 @@ public class DeviceProfile {
// Folders should only appear right of the drop target bar and left of the hotseat
return new Rect(mInsets.left + dropTargetBarSizePx + edgeMarginPx,
mInsets.top,
mInsets.left + availableWidthPx - hotseatBarSizePx - edgeMarginPx,
mInsets.top + availableHeightPx);
mInsets.left + mDeviceProperties.getAvailableWidthPx() - hotseatBarSizePx - edgeMarginPx,
mInsets.top + mDeviceProperties.getAvailableHeightPx());
} else {
// Folders should only appear below the drop target bar and above the hotseat
int hotseatTop = isTaskbarPresent ? taskbarHeight : hotseatBarSizePx;
return new Rect(mInsets.left + edgeMarginPx,
mInsets.top + dropTargetBarSizePx + edgeMarginPx,
mInsets.left + availableWidthPx - edgeMarginPx,
mInsets.top + availableHeightPx - hotseatTop
mInsets.left + mDeviceProperties.getAvailableWidthPx() - edgeMarginPx,
mInsets.top + mDeviceProperties.getAvailableHeightPx() - hotseatTop
- workspacePageIndicatorHeight - edgeMarginPx);
}
}
@@ -2196,11 +2180,11 @@ public class DeviceProfile {
* the hotseat is on the bottom row.
*/
public boolean isVerticalBarLayout() {
return isLandscape && transposeLayoutWithOrientation;
return mDeviceProperties.isLandscape() && mDeviceProperties.getTransposeLayoutWithOrientation();
}
public boolean isSeascape() {
return rotationHint == Surface.ROTATION_270
return mDeviceProperties.getRotationHint() == Surface.ROTATION_270
&& (isVerticalBarLayout() || inv.isFixedLandscape);
}
@@ -2237,29 +2221,29 @@ public class DeviceProfile {
writer.println(prefix + "DeviceProfile:");
writer.println(prefix + "\t1 dp = " + mMetrics.density + " px");
writer.println(prefix + "\tisTablet:" + isTablet);
writer.println(prefix + "\tisPhone:" + isPhone);
writer.println(prefix + "\tisTablet:" + mDeviceProperties.isTablet());
writer.println(prefix + "\tisPhone:" + mDeviceProperties.isPhone());
writer.println(prefix + "\ttransposeLayoutWithOrientation:"
+ transposeLayoutWithOrientation);
writer.println(prefix + "\tisGestureMode:" + isGestureMode);
+ mDeviceProperties.getTransposeLayoutWithOrientation());
writer.println(prefix + "\tisGestureMode:" + mDeviceProperties.isGestureMode());
writer.println(prefix + "\tisLandscape:" + isLandscape);
writer.println(prefix + "\tisMultiWindowMode:" + isMultiWindowMode);
writer.println(prefix + "\tisTwoPanels:" + isTwoPanels);
writer.println(prefix + "\tisLandscape:" + mDeviceProperties.isLandscape());
writer.println(prefix + "\tisMultiWindowMode:" + mDeviceProperties.isMultiWindowMode());
writer.println(prefix + "\tisTwoPanels:" + mDeviceProperties.isTwoPanels());
writer.println(prefix + "\tisLeftRightSplit:" + isLeftRightSplit);
writer.println(prefix + pxToDpStr("windowX", windowX));
writer.println(prefix + pxToDpStr("windowY", windowY));
writer.println(prefix + pxToDpStr("widthPx", widthPx));
writer.println(prefix + pxToDpStr("heightPx", heightPx));
writer.println(prefix + pxToDpStr("availableWidthPx", availableWidthPx));
writer.println(prefix + pxToDpStr("availableHeightPx", availableHeightPx));
writer.println(prefix + pxToDpStr("windowX", mDeviceProperties.getWindowX()));
writer.println(prefix + pxToDpStr("windowY", mDeviceProperties.getWindowY()));
writer.println(prefix + pxToDpStr("widthPx", mDeviceProperties.getWidthPx()));
writer.println(prefix + pxToDpStr("heightPx", mDeviceProperties.getHeightPx()));
writer.println(prefix + pxToDpStr("availableWidthPx", mDeviceProperties.getAvailableWidthPx()));
writer.println(prefix + pxToDpStr("availableHeightPx", mDeviceProperties.getAvailableHeightPx()));
writer.println(prefix + pxToDpStr("mInsets.left", mInsets.left));
writer.println(prefix + pxToDpStr("mInsets.top", mInsets.top));
writer.println(prefix + pxToDpStr("mInsets.right", mInsets.right));
writer.println(prefix + pxToDpStr("mInsets.bottom", mInsets.bottom));
writer.println(prefix + "\taspectRatio:" + aspectRatio);
writer.println(prefix + "\taspectRatio:" + mDeviceProperties.getAspectRatio());
writer.println(prefix + "\tisResponsiveGrid:" + mIsResponsiveGrid);
writer.println(prefix + "\tisScalableGrid:" + mIsScalableGrid);
@@ -2442,12 +2426,12 @@ public class DeviceProfile {
/** Returns a reduced representation of this DeviceProfile. */
public String toSmallString() {
return "isTablet:" + isTablet + ", "
+ "isMultiDisplay:" + isMultiDisplay + ", "
+ "widthPx:" + widthPx + ", "
+ "heightPx:" + heightPx + ", "
return "isTablet:" + mDeviceProperties.isTablet() + ", "
+ "mDeviceProperties.isMultiDisplay():" + mDeviceProperties.isMultiDisplay() + ", "
+ "widthPx:" + mDeviceProperties.getWidthPx() + ", "
+ "heightPx:" + mDeviceProperties.getHeightPx() + ", "
+ "insets:" + mInsets + ", "
+ "rotationHint:" + rotationHint;
+ "rotationHint:" + mDeviceProperties.getRotationHint();
}
private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) {
+23 -22
View File
@@ -85,8 +85,9 @@ public class DropTargetBar extends FrameLayout
@Override
public void setInsets(Rect insets) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
DeviceProfile grid = mLauncher.getDeviceProfile();
mIsVertical = grid.isVerticalBarLayout();
DeviceProfile deviceProfile = mLauncher.getDeviceProfile();
mIsVertical = deviceProfile.isVerticalBarLayout();
int widthPx = deviceProfile.getDeviceProperties().getWidthPx();
lp.leftMargin = insets.left;
lp.topMargin = insets.top;
@@ -95,25 +96,25 @@ public class DropTargetBar extends FrameLayout
int tooltipLocation = TOOLTIP_DEFAULT;
int horizontalMargin;
if (grid.isTablet) {
if (deviceProfile.getDeviceProperties().isTablet()) {
// XXX: If the icon size changes across orientations, we will have to take
// that into account here too.
horizontalMargin = ((grid.widthPx - 2 * grid.edgeMarginPx
- (grid.inv.numColumns * grid.cellWidthPx))
/ (2 * (grid.inv.numColumns + 1)))
+ grid.edgeMarginPx;
horizontalMargin = ((widthPx - 2 * deviceProfile.edgeMarginPx
- (deviceProfile.inv.numColumns * deviceProfile.cellWidthPx))
/ (2 * (deviceProfile.inv.numColumns + 1)))
+ deviceProfile.edgeMarginPx;
} else {
horizontalMargin = getContext().getResources()
.getDimensionPixelSize(R.dimen.drop_target_bar_margin_horizontal);
}
lp.topMargin += grid.dropTargetBarTopMarginPx;
lp.bottomMargin += grid.dropTargetBarBottomMarginPx;
lp.width = grid.availableWidthPx - 2 * horizontalMargin;
lp.topMargin += deviceProfile.dropTargetBarTopMarginPx;
lp.bottomMargin += deviceProfile.dropTargetBarBottomMarginPx;
lp.width = deviceProfile.getDeviceProperties().getAvailableWidthPx() - 2 * horizontalMargin;
if (mIsVertical) {
lp.leftMargin = (grid.widthPx - lp.width) / 2;
lp.rightMargin = (grid.widthPx - lp.width) / 2;
lp.leftMargin = (widthPx - lp.width) / 2;
lp.rightMargin = (widthPx - lp.width) / 2;
}
lp.height = grid.dropTargetBarSizePx;
lp.height = deviceProfile.dropTargetBarSizePx;
lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
DeviceProfile dp = mLauncher.getDeviceProfile();
@@ -121,7 +122,7 @@ public class DropTargetBar extends FrameLayout
int verticalPadding = dp.dropTargetVerticalPaddingPx;
setLayoutParams(lp);
for (ButtonDropTarget button : mDropTargets) {
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.dropTargetTextSizePx);
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, deviceProfile.dropTargetTextSizePx);
button.setToolTipLocation(tooltipLocation);
button.setPadding(horizontalPadding, verticalPadding, horizontalPadding,
verticalPadding);
@@ -175,15 +176,15 @@ public class DropTargetBar extends FrameLayout
// Reset second button padding in case it was previously changed to multi-line text.
secondButton.setPadding(horizontalPadding, verticalPadding, horizontalPadding,
verticalPadding);
int availableWidth;
if (dp.isTwoPanels) {
if (dp.getDeviceProperties().isTwoPanels()) {
// Each button for two panel fits to half the width of the screen excluding the
// center gap between the buttons.
availableWidth = (dp.availableWidthPx - dp.dropTargetGapPx) / 2;
availableWidth = (dp.getDeviceProperties().getAvailableWidthPx() - dp.dropTargetGapPx) / 2;
} else {
// Both buttons plus the button gap do not display past the edge of the screen.
availableWidth = dp.availableWidthPx - dp.dropTargetGapPx;
availableWidth = dp.getDeviceProperties().getAvailableWidthPx() - dp.dropTargetGapPx;
}
int widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
@@ -199,7 +200,7 @@ public class DropTargetBar extends FrameLayout
}
}
if (!dp.isTwoPanels) {
if (!dp.getDeviceProperties().isTwoPanels()) {
availableWidth -= firstButton.getMeasuredWidth() + dp.dropTargetGapPx;
widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
}
@@ -239,11 +240,11 @@ public class DropTargetBar extends FrameLayout
float scale = dp.getWorkspaceSpringLoadScale(mLauncher);
Workspace<?> ws = mLauncher.getWorkspace();
int barCenter;
if (dp.isTwoPanels) {
if (dp.getDeviceProperties().isTwoPanels()) {
barCenter = (right - left) / 2;
} else {
int workspaceCenter = (ws.getLeft() + ws.getRight()) / 2;
int cellLayoutCenter = ((dp.getInsets().left + dp.workspacePadding.left) + (dp.widthPx
int cellLayoutCenter = ((dp.getInsets().left + dp.workspacePadding.left) + (dp.getDeviceProperties().getWidthPx()
- dp.getInsets().right - dp.workspacePadding.right)) / 2;
int cellLayoutCenterOffset = (int) ((cellLayoutCenter - workspaceCenter) * scale);
barCenter = workspaceCenter + cellLayoutCenterOffset - left;
@@ -258,7 +259,7 @@ public class DropTargetBar extends FrameLayout
ButtonDropTarget leftButton = mTempTargets[0];
ButtonDropTarget rightButton = mTempTargets[1];
if (dp.isTwoPanels) {
if (dp.getDeviceProperties().isTwoPanels()) {
leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0,
barCenter - (buttonGap / 2), leftButton.getMeasuredHeight());
rightButton.layout(barCenter + (buttonGap / 2), 0,
@@ -207,7 +207,7 @@ public class InvariantDeviceProfile {
public @StyleRes int allAppsStyle;
/**
* Do not query directly. see {@link DeviceProfile#isScalableGrid}.
* Do not query directly. see {@link deviceprofile#isScalableGrid}.
*/
protected boolean isScalable;
@XmlRes
@@ -488,14 +488,14 @@ public class InvariantDeviceProfile {
int numMinShownHotseatIconsForTablet = supportedProfiles
.stream()
.filter(deviceProfile -> deviceProfile.isTablet)
.filter(deviceProfile -> deviceProfile.getDeviceProperties().isTablet())
.mapToInt(deviceProfile -> deviceProfile.numShownHotseatIcons)
.min()
.orElse(0);
supportedProfiles
.stream()
.filter(deviceProfile -> deviceProfile.isTablet)
.filter(deviceProfile -> deviceProfile.getDeviceProperties().isTablet())
.forEach(deviceProfile -> {
deviceProfile.numShownHotseatIcons = numMinShownHotseatIconsForTablet;
deviceProfile.recalculateHotseatWidthAndBorderSpace();
@@ -924,12 +924,12 @@ public class InvariantDeviceProfile {
float minDiff = Float.MAX_VALUE;
for (DeviceProfile profile : supportedProfiles) {
float diff = Math.abs(profile.widthPx - screenWidth)
+ Math.abs(profile.heightPx - screenHeight);
float diff = Math.abs(profile.getDeviceProperties().getWidthPx() - screenWidth)
+ Math.abs(profile.getDeviceProperties().getHeightPx() - screenHeight);
if (diff < minDiff) {
minDiff = diff;
bestMatch = profile;
} else if (diff == minDiff && profile.rotationHint == rotation) {
} else if (diff == minDiff && profile.getDeviceProperties().getRotationHint() == rotation) {
bestMatch = profile;
}
}
@@ -995,7 +995,7 @@ public class InvariantDeviceProfile {
displayInfo.getDeviceType()), isLandscape);
}
/** Class to expose properties required for external displays to {@link DeviceProfile} */
/** Class to expose properties required for external displays to {@link deviceprofile} */
public static final class DisplayOptionSpec {
public final int typeIndex;
public final int numShownHotseatIcons;
+10 -8
View File
@@ -677,9 +677,9 @@ public class Launcher extends StatefulActivity<LauncherState>
// When the flag oneGridSpecs is on we want to disable ALLOW_ROTATION which is replaced
// by FIXED_LANDSCAPE_MODE, ALLOW_ROTATION will only be used on Tablets and foldables
// afterwards.
if (getDeviceProfile().isPhone) {
if (getDeviceProfile().getDeviceProperties().isPhone()) {
LauncherPrefs.get(this).put(LauncherPrefs.ALLOW_ROTATION, false);
} else if (getDeviceProfile().isTablet) {
} else if (getDeviceProfile().getDeviceProperties().isTablet()) {
// Tablet do not use fixed landscape mode, make sure it can't be activated by mistake
LauncherPrefs.get(this).put(FIXED_LANDSCAPE_MODE, false);
}
@@ -708,7 +708,7 @@ public class Launcher extends StatefulActivity<LauncherState>
this, getMultiWindowDisplaySize());
}
if (FOLDABLE_SINGLE_PAGE.get() && mDeviceProfile.isTwoPanels) {
if (FOLDABLE_SINGLE_PAGE.get() && mDeviceProfile.getDeviceProperties().isTwoPanels()) {
mCellPosMapper = new TwoPanelCellPosMapper(mDeviceProfile.inv.numColumns);
} else {
mCellPosMapper = new CellPosMapper(mDeviceProfile.isVerticalBarLayout(),
@@ -1883,13 +1883,15 @@ public class Launcher extends StatefulActivity<LauncherState>
public void updateOpenFolderPosition(int[] inOutPosition, Rect bounds, int width, int height) {
int left = inOutPosition[0];
int top = inOutPosition[1];
DeviceProfile grid = getDeviceProfile();
DeviceProfile deviceProfile = getDeviceProfile();
int distFromEdgeOfScreen = getWorkspace().getPaddingLeft();
if (grid.isPhone && (grid.availableWidthPx - width) < 4 * distFromEdgeOfScreen) {
final int availableWidth = deviceProfile.getDeviceProperties().getAvailableWidthPx();
if (deviceProfile.getDeviceProperties().isPhone()
&& (availableWidth - width) < 4 * distFromEdgeOfScreen) {
// Center the folder if it is very close to being centered anyway, by virtue of
// filling the majority of the viewport. ie. remove it from the uncanny valley
// of centeredness.
left = (grid.availableWidthPx - width) / 2;
left = (availableWidth - width) / 2;
} else if (width >= bounds.width()) {
// If the folder doesn't fit within the bounds, center it about the desired bounds
left = bounds.left + (bounds.width() - width) / 2;
@@ -1900,7 +1902,7 @@ public class Launcher extends StatefulActivity<LauncherState>
} else {
// Folder height is less than page height, so bound it to the absolute open folder
// bounds if necessary
Rect folderBounds = grid.getAbsoluteOpenFolderBounds();
Rect folderBounds = deviceProfile.getAbsoluteOpenFolderBounds();
left = Math.max(folderBounds.left, Math.min(left, folderBounds.right - width));
top = Math.max(folderBounds.top, Math.min(top, folderBounds.bottom - height));
}
@@ -2540,7 +2542,7 @@ public class Launcher extends StatefulActivity<LauncherState>
if (BuildCompat.isAtLeastV()
&& Flags.enableDesktopWindowingMode()
&& !Flags.enableDesktopWindowingWallpaperActivity()
&& mDeviceProfile.isTablet) {
&& mDeviceProfile.getDeviceProperties().isTablet()) {
// TODO(b/333533253): Clean up after desktop wallpaper activity flag is rolled out
return;
}
+5 -5
View File
@@ -242,7 +242,7 @@ public abstract class LauncherState implements BaseState<LauncherState> {
DeviceProfile dp = launcher.getDeviceProfile();
if (dp.isQsbInline) {
int marginStart = getFloatingSearchBarRestingMarginStart(launcher);
return dp.widthPx - marginStart - dp.hotseatQsbWidth;
return dp.getDeviceProperties().getWidthPx() - marginStart - dp.hotseatQsbWidth;
}
boolean isRtl = Utilities.isRtl(launcher.getResources());
@@ -258,7 +258,7 @@ public abstract class LauncherState implements BaseState<LauncherState> {
public int getVisibleElements(Launcher launcher) {
int elements = HOTSEAT_ICONS | WORKSPACE_PAGE_INDICATOR | VERTICAL_SWIPE_INDICATOR;
// Floating search bar is visible in normal state except in landscape on phones.
if (!(launcher.getDeviceProfile().isPhone && launcher.getDeviceProfile().isLandscape)) {
if (!(launcher.getDeviceProfile().getDeviceProperties().isPhone() && launcher.getDeviceProfile().getDeviceProperties().isLandscape())) {
elements |= FLOATING_SEARCH_BAR;
}
return elements;
@@ -346,7 +346,7 @@ public abstract class LauncherState implements BaseState<LauncherState> {
public final <DEVICE_PROFILE_CONTEXT extends Context & ActivityContext>
float getDepth(DEVICE_PROFILE_CONTEXT context) {
return getDepth(context,
ActivityContext.lookupContext(context).getDeviceProfile().isMultiWindowMode);
ActivityContext.lookupContext(context).getDeviceProfile().getDeviceProperties().isMultiWindowMode());
}
/**
@@ -390,7 +390,7 @@ public abstract class LauncherState implements BaseState<LauncherState> {
boolean shouldFadeAdjacentScreens = (this == NORMAL || this == HINT_STATE)
&& dp.shouldFadeAdjacentWorkspaceScreens();
// Avoid showing adjacent screens behind handheld All Apps sheet.
if (Flags.allAppsSheetForHandheld() && dp.isPhone && this == ALL_APPS) {
if (Flags.allAppsSheetForHandheld() && dp.getDeviceProperties().isPhone() && this == ALL_APPS) {
shouldFadeAdjacentScreens = true;
}
if (!shouldFadeAdjacentScreens) {
@@ -410,7 +410,7 @@ public abstract class LauncherState implements BaseState<LauncherState> {
*/
public PageTranslationProvider getWorkspacePageTranslationProvider(Launcher launcher) {
if (!(this == SPRING_LOADED || this == EDIT_MODE)
|| !launcher.getDeviceProfile().isTwoPanels) {
|| !launcher.getDeviceProfile().getDeviceProperties().isTwoPanels()) {
return DEFAULT_PAGE_TRANSLATION_PROVIDER;
}
final float quarterPageSpacing = launcher.getWorkspace().getPageSpacing() / 4f;
+7 -6
View File
@@ -158,7 +158,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
launcher.workspace.removeExtraEmptyScreen(/* stripEmptyScreens= */ true)
launcher.workspace.pageIndicator.setPauseScroll(
/*pause=*/ false,
deviceProfile.isTwoPanels,
deviceProfile.deviceProperties.isTwoPanels,
)
launcher.finishBindingItems(pagesBoundFirst)
}
@@ -270,12 +270,13 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
// in single panel.
if (actualIds.contains(firstId)) {
result.add(firstId)
if (launcher.deviceProfile.isTwoPanels && actualIds.contains(pairId)) {
if (launcher.deviceProfile.deviceProperties.isTwoPanels && actualIds.contains(pairId)) {
result.add(pairId)
}
} else if (
LauncherAppState.getIDP(launcher).supportedProfiles.any(DeviceProfile::isTwoPanels) &&
actualIds.contains(pairId)
LauncherAppState.getIDP(launcher).supportedProfiles.any {
it.deviceProperties.isTwoPanels
} && actualIds.contains(pairId)
) {
// Add the right panel if left panel is hidden when switching display, due to empty
// pages being hidden in single panel.
@@ -287,7 +288,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
private fun bindScreens(orderedScreenIds: LIntArray) {
launcher.workspace.pageIndicator.setPauseScroll(
/*pause=*/ true,
launcher.deviceProfile.isTwoPanels,
launcher.deviceProfile.deviceProperties.isTwoPanels,
)
val firstScreenPosition = 0
if (orderedScreenIds.indexOf(FIRST_SCREEN_ID) != firstScreenPosition) {
@@ -345,7 +346,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
private fun bindAddScreens(orderedScreenIdsArg: LIntArray) {
var orderedScreenIds = orderedScreenIdsArg
if (launcher.deviceProfile.isTwoPanels) {
if (launcher.deviceProfile.deviceProperties.isTwoPanels) {
if (FeatureFlags.FOLDABLE_SINGLE_PAGE.get()) {
orderedScreenIds = filterTwoPanelScreenIds(orderedScreenIds)
} else {
+6 -6
View File
@@ -534,7 +534,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
}
private boolean isTwoPanelEnabled() {
return !FOLDABLE_SINGLE_PAGE.get() && mLauncher.mDeviceProfile.isTwoPanels;
return !FOLDABLE_SINGLE_PAGE.get() && mLauncher.mDeviceProfile.getDeviceProperties().isTwoPanels();
}
public void deferRemoveExtraEmptyScreen() {
@@ -692,7 +692,7 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
// created CellLayout.
DeviceProfile dp = mLauncher.getDeviceProfile();
CellLayout newScreen;
if (FOLDABLE_SINGLE_PAGE.get() && dp.isTwoPanels) {
if (FOLDABLE_SINGLE_PAGE.get() && dp.getDeviceProperties().isTwoPanels()) {
newScreen = (CellLayout) LayoutInflater.from(getContext()).inflate(
R.layout.workspace_screen_foldable, this, false /* attachToRoot */);
} else {
@@ -3443,13 +3443,13 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
@Override
public int getExpectedHeight() {
return getMeasuredHeight() <= 0 || !mIsLayoutValid
? mLauncher.getDeviceProfile().heightPx : getMeasuredHeight();
? mLauncher.getDeviceProfile().getDeviceProperties().getHeightPx() : getMeasuredHeight();
}
@Override
public int getExpectedWidth() {
return getMeasuredWidth() <= 0 || !mIsLayoutValid
? mLauncher.getDeviceProfile().widthPx : getMeasuredWidth();
? mLauncher.getDeviceProfile().getDeviceProperties().getWidthPx() : getMeasuredWidth();
}
@Override
@@ -3515,12 +3515,12 @@ public class Workspace<T extends View & PageIndicator> extends PagedView<T>
@Override
protected boolean isSignificantMove(float absoluteDelta, int pageOrientedSize) {
DeviceProfile deviceProfile = mLauncher.getDeviceProfile();
if (!deviceProfile.isTablet) {
if (!deviceProfile.getDeviceProperties().isTablet()) {
return super.isSignificantMove(absoluteDelta, pageOrientedSize);
}
return absoluteDelta
> deviceProfile.availableWidthPx * SIGNIFICANT_MOVE_SCREEN_WIDTH_PERCENTAGE;
> deviceProfile.getDeviceProperties().getAvailableWidthPx() * SIGNIFICANT_MOVE_SCREEN_WIDTH_PERCENTAGE;
}
@Override
@@ -1211,7 +1211,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
MarginLayoutParams mlp = (MarginLayoutParams) getLayoutParams();
// Ignore left/right insets on tablet because we are already centered in-screen.
if (grid.isTablet) {
if (grid.getDeviceProperties().isTablet()) {
mlp.leftMargin = mlp.rightMargin = 0;
} else {
mlp.leftMargin = insets.left;
@@ -235,7 +235,7 @@ public class AllAppsTransitionController
boolean fromBackground =
mLauncher.getStateManager().getCurrentStableState() == BACKGROUND_APP;
// Allow apps panel to shift the full screen if coming from another app.
float shiftRange = fromBackground ? mLauncher.getDeviceProfile().heightPx : mShiftRange;
float shiftRange = fromBackground ? mLauncher.getDeviceProfile().getDeviceProperties().getHeightPx() : mShiftRange;
getAppsViewProgressTranslationY().setValue(mProgress * shiftRange);
mLauncher.onAllAppsTransition(1 - progress);
@@ -99,7 +99,7 @@ public class LauncherAllAppsContainerView extends ActivityAllAppsContainerView<L
// Special case to not expand the search bar when exiting All Apps on phones.
if (stateManager.getCurrentStableState() == LauncherState.ALL_APPS
&& mActivityContext.getDeviceProfile().isPhone) {
&& mActivityContext.getDeviceProfile().getDeviceProperties().isPhone()) {
return LauncherState.ALL_APPS.getFloatingSearchBarRestingMarginStart(mActivityContext);
}
@@ -121,7 +121,7 @@ public class LauncherAllAppsContainerView extends ActivityAllAppsContainerView<L
// Special case to not expand the search bar when exiting All Apps on phones.
if (stateManager.getCurrentStableState() == LauncherState.ALL_APPS
&& mActivityContext.getDeviceProfile().isPhone) {
&& mActivityContext.getDeviceProfile().getDeviceProperties().isPhone()) {
return LauncherState.ALL_APPS.getFloatingSearchBarRestingMarginEnd(mActivityContext);
}
@@ -165,7 +165,7 @@ public class WorkUtilityView extends LinearLayout implements Insettable,
bottomMargin += dp.hotseatQsbHeight;
}
if (!dp.isGestureMode && dp.isTaskbarPresent) {
if (!dp.getDeviceProperties().isGestureMode() && dp.isTaskbarPresent) {
bottomMargin += dp.taskbarHeight;
}
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3.deviceprofile
import com.android.launcher3.util.DisplayController
import com.android.launcher3.util.WindowBounds
import kotlin.math.max
import kotlin.math.min
data class DeviceProperties(
val windowX: Int,
val windowY: Int,
val rotationHint: Int,
val widthPx: Int,
val heightPx: Int,
val availableWidthPx: Int,
val availableHeightPx: Int,
val aspectRatio: Float,
val isTablet: Boolean,
val isPhone: Boolean,
val transposeLayoutWithOrientation: Boolean,
val isMultiDisplay: Boolean,
val isTwoPanels: Boolean,
val isLandscape: Boolean,
val isMultiWindowMode: Boolean,
val isGestureMode: Boolean,
) {
companion object Factory {
// b/419264328 adding here all the improvements/cleanup for this class
fun createDeviceProperties(
info: DisplayController.Info,
windowBounds: WindowBounds,
transposeLayoutWithOrientation: Boolean,
isMultiDisplay: Boolean,
isMultiWindowMode: Boolean,
isGestureMode: Boolean,
): DeviceProperties {
val isTablet = info.isTablet(windowBounds)
val windowX = windowBounds.bounds.left
val windowY = windowBounds.bounds.top
val rotationHint = windowBounds.rotationHint
val widthPx = windowBounds.bounds.width()
val heightPx = windowBounds.bounds.height()
val availableWidthPx = windowBounds.availableSize.x
val availableHeightPx = windowBounds.availableSize.y
return DeviceProperties(
windowX = windowX,
windowY = windowY,
rotationHint = rotationHint,
widthPx = widthPx,
heightPx = heightPx,
availableWidthPx = availableWidthPx,
availableHeightPx = availableHeightPx,
aspectRatio = max(widthPx, heightPx).toFloat() / min(widthPx, heightPx).toFloat(),
isTablet = isTablet,
isPhone = !isTablet,
transposeLayoutWithOrientation = transposeLayoutWithOrientation,
isMultiDisplay = isMultiDisplay,
isTwoPanels = isTablet && isMultiDisplay,
isLandscape = windowBounds.isLandscape,
isMultiWindowMode = isMultiWindowMode,
isGestureMode = isGestureMode,
)
}
}
}
+2 -2
View File
@@ -1315,7 +1315,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
@VisibleForTesting
int getMaxContentAreaHeight() {
DeviceProfile grid = mActivityContext.getDeviceProfile();
return grid.availableHeightPx - grid.getTotalWorkspacePadding().y
return grid.getDeviceProperties().getAvailableHeightPx() - grid.getTotalWorkspacePadding().y
- getFooterHeight();
}
@@ -1963,7 +1963,7 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
private int getHeightFromBottom() {
BaseDragLayer.LayoutParams layoutParams = (BaseDragLayer.LayoutParams) getLayoutParams();
int folderBottomPx = layoutParams.y + layoutParams.height;
int windowBottomPx = mActivityContext.getDeviceProfile().heightPx;
int windowBottomPx = mActivityContext.getDeviceProfile().getDeviceProperties().getHeightPx();
return windowBottomPx - folderBottomPx;
}
@@ -247,12 +247,12 @@ public class LauncherPreviewRenderer extends BaseContext
new ContextThemeWrapper(this, R.style.HomeScreenElementTheme));
mHomeElementInflater.setFactory2(this);
int layoutRes = mDp.isTwoPanels ? R.layout.launcher_preview_two_panel_layout
int layoutRes = mDp.getDeviceProperties().isTwoPanels() ? R.layout.launcher_preview_two_panel_layout
: R.layout.launcher_preview_layout;
mRootView = (InsettableFrameLayout) mHomeElementInflater.inflate(
layoutRes, null, false);
mRootView.setInsets(mInsets);
measureView(mRootView, mDp.widthPx, mDp.heightPx);
measureView(mRootView, mDp.getDeviceProperties().getWidthPx(), mDp.getDeviceProperties().getHeightPx());
mHotseat = mRootView.findViewById(R.id.hotseat);
mHotseat.resetLayout(false);
@@ -264,12 +264,12 @@ public class LauncherPreviewRenderer extends BaseContext
firstScreen.setPadding(
mDp.workspacePadding.left + mDp.cellLayoutPaddingPx.left,
mDp.workspacePadding.top + mDp.cellLayoutPaddingPx.top,
mDp.isTwoPanels ? (mDp.cellLayoutBorderSpacePx.x / 2)
mDp.getDeviceProperties().isTwoPanels() ? (mDp.cellLayoutBorderSpacePx.x / 2)
: (mDp.workspacePadding.right + mDp.cellLayoutPaddingPx.right),
mDp.workspacePadding.bottom + mDp.cellLayoutPaddingPx.bottom
);
if (mDp.isTwoPanels) {
if (mDp.getDeviceProperties().isTwoPanels()) {
CellLayout rightPanel = mRootView.findViewById(R.id.workspace_right);
rightPanel.setPadding(
mDp.cellLayoutBorderSpacePx.x / 2,
@@ -483,11 +483,11 @@ public class LauncherPreviewRenderer extends BaseContext
}
}
measureView(mRootView, mDp.widthPx, mDp.heightPx);
measureView(mRootView, mDp.getDeviceProperties().getWidthPx(), mDp.getDeviceProperties().getHeightPx());
dispatchVisibilityAggregated(mRootView, true);
measureView(mRootView, mDp.widthPx, mDp.heightPx);
measureView(mRootView, mDp.getDeviceProperties().getWidthPx(), mDp.getDeviceProperties().getHeightPx());
// Additional measure for views which use auto text size API
measureView(mRootView, mDp.widthPx, mDp.heightPx);
measureView(mRootView, mDp.getDeviceProperties().getWidthPx(), mDp.getDeviceProperties().getHeightPx());
}
private void populateHotseatPredictions(BgDataModel dataModel) {
@@ -421,7 +421,7 @@ public class PreviewSurfaceRenderer {
DeviceProfile deviceProfile = idp.getDeviceProfile(previewContext);
int closestEvenPageId = mWorkspacePageId - (mWorkspacePageId % 2);
String query = deviceProfile.isTwoPanels
String query = deviceProfile.getDeviceProperties().isTwoPanels()
? selectionForWorkspaceScreen(closestEvenPageId, closestEvenPageId + 1)
: selectionForWorkspaceScreen(mWorkspacePageId);
task.loadWorkspaceForPreview(query);
@@ -169,7 +169,7 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
public void onInsetsChanged(Rect insets) {
DeviceProfile dp = mContainer.getDeviceProfile();
mDrawTopScrim = insets.top > 0;
mDrawBottomScrim = !dp.isVerticalBarLayout() && !dp.isGestureMode && !dp.isTaskbarPresent;
mDrawBottomScrim = !dp.isVerticalBarLayout() && !dp.getDeviceProperties().isGestureMode() && !dp.isTaskbarPresent;
}
@Override
@@ -689,8 +689,8 @@ class WorkspaceItemProcessor(
deviceProfile.getCellSize(cellSize)
FileLog.d(
TAG,
"DeviceProfile available width: ${deviceProfile.availableWidthPx}," +
" available height: ${deviceProfile.availableHeightPx}," +
"DeviceProfile available width: ${deviceProfile.deviceProperties.availableWidthPx}," +
" available height: ${deviceProfile.deviceProperties.availableHeightPx}," +
" cellLayoutBorderSpacePx Horizontal: ${deviceProfile.cellLayoutBorderSpacePx.x}," +
" cellLayoutBorderSpacePx Vertical: ${deviceProfile.cellLayoutBorderSpacePx.y}," +
" cellSize: $cellSize",
@@ -70,7 +70,10 @@ class AppPairInfo() : CollectionInfo() {
/** Checks if member apps are launchable at the current screen size. */
fun isLaunchable(context: Context): Pair<Boolean, Boolean> {
val isTablet =
(ActivityContext.lookupContext(context) as ActivityContext).getDeviceProfile().isTablet
(ActivityContext.lookupContext(context) as ActivityContext)
.getDeviceProfile()
.deviceProperties
.isTablet
return Pair(
isTablet || !getFirstApp().isNonResizeable,
isTablet || !getSecondApp().isNonResizeable,
@@ -413,7 +413,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext>
for (int i = deepShortcutCount; i > 0; i--) {
currentHeight += mShortcutHeight;
// when there is limited vertical screen space, limit total popup rows to fit
if (currentHeight >= mActivityContext.getDeviceProfile().availableHeightPx) break;
if (currentHeight >= mActivityContext.getDeviceProfile().getDeviceProperties().getAvailableHeightPx()) break;
DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut,
mDeepShortcutContainer);
v.getLayoutParams().width = mContainerWidth;
@@ -432,7 +432,8 @@ public abstract class SystemShortcut<T extends ActivityContext> extends ItemInfo
// basically is a check for small screens including Foldables when folded.
// However, the name is a bit misleading, so considering renaming.
WorkspaceItemInfo wsItemInfo = (WorkspaceItemInfo) itemInfo;
if (wsItemInfo.isNonResizeable() && activity.getDeviceProfile().isPhone) {
if (wsItemInfo.isNonResizeable()
&& activity.getDeviceProfile().getDeviceProperties().isPhone()) {
return null;
}
}
@@ -138,7 +138,7 @@ public class RotationHelper implements LauncherPrefChangeListener,
@Override
public void onDeviceProfileChanged(DeviceProfile dp) {
onIgnoreAutoRotateChanged(dp.isTablet);
onIgnoreAutoRotateChanged(dp.getDeviceProperties().isTablet());
}
private void onIgnoreAutoRotateChanged(boolean ignoreAutoRotateSettings) {
@@ -203,7 +203,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
return response;
case TestProtocol.REQUEST_IS_TABLET:
response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, mDeviceProfile.isTablet);
response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, mDeviceProfile.getDeviceProperties().isTablet());
return response;
case TestProtocol.REQUEST_IS_PREDICTIVE_BACK_SWIPE_ENABLED:
response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD,
@@ -230,7 +230,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
case TestProtocol.REQUEST_IS_TWO_PANELS:
response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD,
FOLDABLE_SINGLE_PAGE.get() ? false : mDeviceProfile.isTwoPanels);
FOLDABLE_SINGLE_PAGE.get() ? false : mDeviceProfile.getDeviceProperties().isTwoPanels());
return response;
case TestProtocol.REQUEST_GET_HAD_NONTEST_EVENTS:
@@ -312,13 +312,13 @@ public abstract class AbstractStateChangeTouchController
// snap to top or bottom using the release velocity
} else {
float successTransitionProgress = SUCCESS_TRANSITION_PROGRESS;
if (mLauncher.getDeviceProfile().isTablet
if (mLauncher.getDeviceProfile().getDeviceProperties().isTablet()
&& (mToState == ALL_APPS || mFromState == ALL_APPS)) {
successTransitionProgress = TABLET_BOTTOM_SHEET_SUCCESS_TRANSITION_PROGRESS;
} else if (!mLauncher.getDeviceProfile().isTablet
} else if (!mLauncher.getDeviceProfile().getDeviceProperties().isTablet()
&& mToState == ALL_APPS && mFromState == NORMAL) {
successTransitionProgress = AllAppsSwipeController.ALL_APPS_STATE_TRANSITION_MANUAL;
} else if (!mLauncher.getDeviceProfile().isTablet
} else if (!mLauncher.getDeviceProfile().getDeviceProperties().isTablet()
&& mToState == NORMAL && mFromState == ALL_APPS) {
successTransitionProgress =
1 - AllAppsSwipeController.ALL_APPS_STATE_TRANSITION_MANUAL;
@@ -209,11 +209,10 @@ public class AllAppsSwipeController extends AbstractStateChangeTouchController {
if (!config.isUserControlled()) {
config.setInterpolator(ANIM_VERTICAL_PROGRESS, EMPHASIZED);
}
config.setInterpolator(ANIM_WORKSPACE_SCALE,
Interpolators.reverse(ALL_APPS_SHEET_DEPTH));
config.setInterpolator(ANIM_HOTSEAT_SCALE, Interpolators.reverse(ALL_APPS_SHEET_DEPTH));
config.setInterpolator(ANIM_DEPTH, Interpolators.reverse(ALL_APPS_SHEET_DEPTH));
if (!Flags.allAppsBlur() && launcher.getDeviceProfile().isPhone) {
config.setInterpolator(ANIM_WORKSPACE_SCALE, ALL_APPS_SHEET_DEPTH);
config.setInterpolator(ANIM_HOTSEAT_SCALE, ALL_APPS_SHEET_DEPTH);
config.setInterpolator(ANIM_DEPTH, ALL_APPS_SHEET_DEPTH);
if (!Flags.allAppsBlur() && launcher.getDeviceProfile().getDeviceProperties().isPhone()) {
// On phones without blur, reveal the workspace and hotseat when leaving All Apps.
config.setInterpolator(ANIM_WORKSPACE_FADE, INSTANT);
config.setInterpolator(ANIM_HOTSEAT_FADE, INSTANT);
@@ -261,7 +260,7 @@ public class AllAppsSwipeController extends AbstractStateChangeTouchController {
config.setInterpolator(ANIM_WORKSPACE_SCALE, ALL_APPS_SHEET_DEPTH);
config.setInterpolator(ANIM_HOTSEAT_SCALE, ALL_APPS_SHEET_DEPTH);
config.setInterpolator(ANIM_DEPTH, ALL_APPS_SHEET_DEPTH);
if (!Flags.allAppsBlur() && launcher.getDeviceProfile().isPhone) {
if (!Flags.allAppsBlur() && launcher.getDeviceProfile().getDeviceProperties().isPhone()) {
// On phones without blur, hide the workspace and hotseat when entering All Apps.
config.setInterpolator(ANIM_WORKSPACE_FADE, FINAL_FRAME);
config.setInterpolator(ANIM_HOTSEAT_FADE, FINAL_FRAME);
@@ -160,7 +160,7 @@ public class ItemClickHandler {
if (!isApp1Launchable || !isApp2Launchable) {
// App pair is unlaunchable due to screen size.
boolean isFoldable = InvariantDeviceProfile.INSTANCE.get(launcher)
.supportedProfiles.stream().anyMatch(dp -> dp.isTwoPanels);
.supportedProfiles.stream().anyMatch(dp -> dp.getDeviceProperties().isTwoPanels());
Toast.makeText(launcher, isFoldable
? R.string.app_pair_needs_unfold
: R.string.app_pair_unlaunchable_at_screen_size,
@@ -29,10 +29,10 @@ object DimensionUtils {
*/
@JvmStatic
fun getTaskbarPhoneDimensions(
deviceProfile: DeviceProfile,
res: Resources,
isPhoneMode: Boolean,
isGestureNav: Boolean,
deviceProfile: DeviceProfile,
res: Resources,
isPhoneMode: Boolean,
isGestureNav: Boolean,
): Point {
val p = Point()
// Taskbar for large screen
@@ -50,7 +50,7 @@ object DimensionUtils {
}
// Taskbar on phone, portrait
if (!deviceProfile.isLandscape) {
if (!deviceProfile.deviceProperties.isLandscape) {
p.x = ViewGroup.LayoutParams.MATCH_PARENT
p.y = res.getDimensionPixelSize(R.dimen.taskbar_phone_size)
return p
@@ -435,7 +435,7 @@ public abstract class AbstractSlideInView<T extends Context & ActivityContext>
@Override
public void onDragEnd(float velocity) {
float successfulShiftThreshold = mActivityContext.getDeviceProfile().isTablet
float successfulShiftThreshold = mActivityContext.getDeviceProfile().getDeviceProperties().isTablet()
? TABLET_BOTTOM_SHEET_SUCCESS_TRANSITION_PROGRESS : SUCCESS_TRANSITION_PROGRESS;
if ((mSwipeDetector.isFling(velocity) && velocity > 0)
|| mTranslationShift > successfulShiftThreshold) {
@@ -240,7 +240,7 @@ public interface ActivityContext extends SavedStateRegistryOwner {
/** Registered {@link OnDeviceProfileChangeListener} instances. */
List<OnDeviceProfileChangeListener> getOnDeviceProfileChangeListeners();
/** Notifies listeners of a {@link DeviceProfile} change. */
/** Notifies listeners of a {@link deviceprofile} change. */
default void dispatchDeviceProfileChanged() {
DeviceProfile deviceProfile = getDeviceProfile();
List<OnDeviceProfileChangeListener> listeners = getOnDeviceProfileChangeListeners();
@@ -249,12 +249,12 @@ public interface ActivityContext extends SavedStateRegistryOwner {
}
}
/** Register listener for {@link DeviceProfile} changes. */
/** Register listener for {@link deviceprofile} changes. */
default void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
getOnDeviceProfileChangeListeners().add(listener);
}
/** Unregister listener for {@link DeviceProfile} changes. */
/** Unregister listener for {@link deviceprofile} changes. */
default void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
getOnDeviceProfileChangeListeners().remove(listener);
}
@@ -122,7 +122,7 @@ public class ClipIconView extends View implements ClipPathView {
MarginLayoutParams lp = (MarginLayoutParams) container.getLayoutParams();
float dX = mIsRtl
? rect.left - (dp.widthPx - lp.getMarginStart() - lp.width)
? rect.left - (dp.getDeviceProperties().getWidthPx() - lp.getMarginStart() - lp.width)
: rect.left - lp.getMarginStart();
float dY = rect.top - lp.topMargin;
container.setTranslationX(dX);
@@ -164,7 +164,7 @@ public class ClipIconView extends View implements ClipPathView {
float shapeRevealProgress = boundToRange(mapToRange(max(shapeProgressStart, progress),
shapeProgressStart, 1f, 0, toMax, LINEAR), 0, 1);
if (dp.isLandscape) {
if (dp.getDeviceProperties().isLandscape()) {
mOutline.right = (int) (rect.width() / scale);
} else {
mOutline.bottom = (int) (rect.height() / scale);
@@ -188,16 +188,16 @@ public class ClipIconView extends View implements ClipPathView {
mRevealAnimator.setCurrentFraction(shapeRevealProgress);
}
float drawableScale = (dp.isLandscape ? mOutline.width() : mOutline.height())
float drawableScale = (dp.getDeviceProperties().isLandscape() ? mOutline.width() : mOutline.height())
/ minSize;
setBackgroundDrawableBounds(drawableScale, dp.isLandscape);
setBackgroundDrawableBounds(drawableScale, dp.getDeviceProperties().isLandscape());
// Center align foreground
int height = mFinalDrawableBounds.height();
int width = mFinalDrawableBounds.width();
int diffY = dp.isLandscape ? 0
int diffY = dp.getDeviceProperties().isLandscape() ? 0
: (int) (((height * drawableScale) - height) / 2);
int diffX = dp.isLandscape ? (int) (((width * drawableScale) - width) / 2)
int diffX = dp.getDeviceProperties().isLandscape() ? (int) (((width * drawableScale) - width) / 2)
: 0;
sTmpRect.set(mFinalDrawableBounds);
sTmpRect.offset(diffX, diffY);
@@ -264,14 +264,14 @@ public class ClipIconView extends View implements ClipPathView {
Utilities.scaleRectAboutCenter(mStartRevealRect, ICON_VISIBLE_AREA_FACTOR);
}
if (dp.isLandscape) {
lp.width = (int) Math.max(lp.width, lp.height * dp.aspectRatio);
if (dp.getDeviceProperties().isLandscape()) {
lp.width = (int) Math.max(lp.width, lp.height * dp.getDeviceProperties().getAspectRatio());
} else {
lp.height = (int) Math.max(lp.height, lp.width * dp.aspectRatio);
lp.height = (int) Math.max(lp.height, lp.width * dp.getDeviceProperties().getAspectRatio());
}
int left = mIsRtl
? dp.widthPx - lp.getMarginStart() - lp.width
? dp.getDeviceProperties().getWidthPx() - lp.getMarginStart() - lp.width
: lp.leftMargin;
layout(left, lp.topMargin, left + lp.width, lp.topMargin + lp.height);
@@ -285,7 +285,7 @@ public class ClipIconView extends View implements ClipPathView {
bgDrawableStartScale = scale;
mOutline.set(0, 0, lp.width, lp.height);
}
setBackgroundDrawableBounds(bgDrawableStartScale, dp.isLandscape);
setBackgroundDrawableBounds(bgDrawableStartScale, dp.getDeviceProperties().isLandscape());
mEndRevealRect.set(0, 0, lp.width, lp.height);
setOutlineProvider(new ViewOutlineProvider() {
@Override
@@ -226,14 +226,14 @@ public class FloatingIconView extends FrameLayout implements
// Position the floating view exactly on top of the original
lp.topMargin = Math.round(pos.top);
if (mIsRtl) {
lp.setMarginStart(Math.round(mLauncher.getDeviceProfile().widthPx - pos.right));
lp.setMarginStart(Math.round(mLauncher.getDeviceProfile().getDeviceProperties().getWidthPx() - pos.right));
} else {
lp.setMarginStart(Math.round(pos.left));
}
// Set the properties here already to make sure they are available when running the first
// animation frame.
int left = mIsRtl
? mLauncher.getDeviceProfile().widthPx - lp.getMarginStart() - lp.width
? mLauncher.getDeviceProfile().getDeviceProperties().getWidthPx() - lp.getMarginStart() - lp.width
: lp.leftMargin;
layout(left, lp.topMargin, left + lp.width, lp.topMargin + lp.height);
}
@@ -370,8 +370,8 @@ public class FloatingIconView extends FrameLayout implements
mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
float aspectRatio = mLauncher.getDeviceProfile().aspectRatio;
if (dp.isLandscape) {
float aspectRatio = mLauncher.getDeviceProfile().getDeviceProperties().getAspectRatio();
if (dp.getDeviceProperties().isLandscape()) {
lp.width = (int) Math.max(lp.width, lp.height * aspectRatio);
} else {
lp.height = (int) Math.max(lp.height, lp.width * aspectRatio);
@@ -101,7 +101,7 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int widthUsed;
if (deviceProfile.isTablet) {
if (deviceProfile.getDeviceProperties().isTablet()) {
int margin = deviceProfile.allAppsLeftRightMargin;
widthUsed = Math.max(2 * margin, 2 * (mInsets.left + mInsets.right));
} else if (mInsets.bottom > 0) {
@@ -355,7 +355,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
protected int getInsetsWidth() {
int widthUsed;
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
if (deviceProfile.isTablet) {
if (deviceProfile.getDeviceProperties().isTablet()) {
widthUsed = Math.max(2 * getTabletHorizontalMargin(deviceProfile),
2 * (mInsets.left + mInsets.right));
} else if (mInsets.bottom > 0) {
@@ -375,7 +375,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
@Override
protected Interpolator getIdleInterpolator() {
return mActivityContext.getDeviceProfile().isTablet
return mActivityContext.getDeviceProfile().getDeviceProperties().isTablet()
? EMPHASIZED : super.getIdleInterpolator();
}
@@ -394,7 +394,7 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
// In light mode, landscape reverses navbar background color.
boolean isPhoneLandscape =
!mActivityContext.getDeviceProfile().isTablet && mInsets.bottom == 0;
!mActivityContext.getDeviceProfile().getDeviceProperties().isTablet() && mInsets.bottom == 0;
if (!isNavBarDark && isPhoneLandscape) {
isNavBarDark = true;
}
@@ -114,7 +114,7 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo impleme
// On phones we no longer support regular landscape, only fixed landscape for this
// reason we don't need to take regular landscape into account in phones
if (Flags.oneGridSpecs() && dp.inv.deviceType == TYPE_PHONE
&& dp.inv.isFixedLandscape != dp.isLandscape) {
&& dp.inv.isFixedLandscape != dp.getDeviceProperties().isLandscape()) {
continue;
}
@@ -174,7 +174,7 @@ public final class WidgetRecommendationsView extends PagedView<PageIndicatorDots
* <p>In case of a single category, no title is displayed for it.</p>
*
* @param recommendations a map of widget items per recommendation category
* @param deviceProfile the current {@link DeviceProfile}
* @param deviceProfile the current {@link deviceprofile}
* @param availableHeight height in px that can be used to display the recommendations;
* recommendations that don't fit in this height won't be shown
* @param availableWidth width in px that the recommendations should display in
@@ -653,11 +653,11 @@ public class WidgetsFullSheet extends BaseWidgetSheet
protected float getMaxAvailableHeightForRecommendations() {
// There isn't enough space to show recommendations in landscape orientation on phones with
// a full sheet design. Tablets use a two pane picker.
if (mDeviceProfile.isLandscape) {
if (mDeviceProfile.getDeviceProperties().isLandscape()) {
return 0f;
}
return (mDeviceProfile.heightPx - mDeviceProfile.bottomSheetTopPadding)
return (mDeviceProfile.getDeviceProperties().getHeightPx() - mDeviceProfile.bottomSheetTopPadding)
* RECOMMENDATION_TABLE_HEIGHT_RATIO;
}
@@ -775,7 +775,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
}
private static int getWidgetSheetId(BaseActivity activity) {
boolean isTwoPane = activity.getDeviceProfile().isTablet;
boolean isTwoPane = activity.getDeviceProfile().getDeviceProperties().isTablet();
return isTwoPane ? R.layout.widgets_two_pane_sheet : R.layout.widgets_full_sheet;
}
@@ -922,7 +922,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
private static boolean shouldRecreateLayout(DeviceProfile oldDp, DeviceProfile newDp) {
// When folding/unfolding the foldables, we need to switch between the regular widget picker
// and the two pane picker, so we rebuild the picker with the correct layout.
return oldDp.isTwoPanels != newDp.isTwoPanels;
return oldDp.getDeviceProperties().isTwoPanels() != newDp.getDeviceProperties().isTwoPanels();
}
/**
@@ -136,7 +136,7 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
mWidgetRecommendationsView.initParentViews(mWidgetRecommendationsContainer);
mWidgetRecommendationsView.setWidgetCellLongClickListener(this);
mWidgetRecommendationsView.setWidgetCellOnClickListener(this);
if (!mDeviceProfile.isTwoPanels) {
if (!mDeviceProfile.getDeviceProperties().isTwoPanels()) {
mWidgetRecommendationsView.enableFullPageViewIfLowDensity();
}
// To save the currently displayed page, so that, it can be requested when rebinding
@@ -242,7 +242,7 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
if (changed && mDeviceProfile.isTwoPanels) {
if (changed && mDeviceProfile.getDeviceProperties().isTwoPanels()) {
LinearLayout layout = mContent.findViewById(R.id.linear_layout_container);
FrameLayout leftPane = layout.findViewById(R.id.recycler_view_container);
LinearLayout.LayoutParams layoutParams = (LayoutParams) leftPane.getLayoutParams();
@@ -403,7 +403,7 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
return Float.MAX_VALUE;
}
return (mDeviceProfile.heightPx - mDeviceProfile.bottomSheetTopPadding)
return (mDeviceProfile.getDeviceProperties().getHeightPx() - mDeviceProfile.bottomSheetTopPadding)
* RECOMMENDATION_SECTION_HEIGHT_RATIO_TWO_PANE;
}
@@ -412,7 +412,7 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet {
protected int getAvailableWidthForSuggestions(int pickerAvailableWidth) {
int rightPaneWidth = (int) Math.ceil(0.67 * pickerAvailableWidth);
if (mDeviceProfile.isTwoPanels) {
if (mDeviceProfile.getDeviceProperties().isTwoPanels()) {
// See onLayout
int leftPaneWidth = (int) (0.33 * pickerAvailableWidth);
@Px int minLeftPaneWidthPx = Utilities.dpToPx(MINIMUM_WIDTH_LEFT_PANE_FOLDABLE_DP);
@@ -29,7 +29,7 @@ data class WidgetPreviewContainerSize(@JvmField val spanX: Int, @JvmField val sp
*/
fun forItem(item: WidgetItem, dp: DeviceProfile): WidgetPreviewContainerSize {
val sizes =
if (dp.isTablet && !dp.isTwoPanels) {
if (dp.deviceProperties.isTablet && !dp.deviceProperties.isTwoPanels) {
TABLET_WIDGET_PREVIEW_SIZES
} else {
HANDHELD_WIDGET_PREVIEW_SIZES
@@ -43,7 +43,7 @@ data class WidgetPreviewContainerSize(@JvmField val spanX: Int, @JvmField val sp
return findClosestFittingContainer(
containerSizes = sizes.toList(),
startIndex = index,
item = item
item = item,
)
}
}
@@ -54,7 +54,7 @@ data class WidgetPreviewContainerSize(@JvmField val spanX: Int, @JvmField val sp
private fun findClosestFittingContainer(
containerSizes: List<WidgetPreviewContainerSize>,
startIndex: Int,
item: WidgetItem
item: WidgetItem,
): WidgetPreviewContainerSize {
// Checks if it's a smaller container, but close enough to keep the down-scale minimal.
fun hasAcceptableSize(currentIndex: Int): Boolean {