Use full screen width for drop target buttons to support higher screen densities from truncating text.

Scale oversized text down if after all computations it will still be truncated at higher densities.

Fix: 239401464
Test: manual. To follow up with screenshot test: b/241386128
Change-Id: Ie088d0631b0d13beb2d9f9d5396a56f7b971dee1
This commit is contained in:
Pat Manning
2022-08-02 16:15:29 +01:00
parent 831f5ee748
commit e63dd25a54
4 changed files with 78 additions and 18 deletions

View File

@@ -151,6 +151,8 @@ public class DropTargetBar extends FrameLayout
int widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
ButtonDropTarget firstButton = mTempTargets[0];
firstButton.setTextSize(TypedValue.COMPLEX_UNIT_PX,
mLauncher.getDeviceProfile().dropTargetTextSizePx);
firstButton.setTextVisible(true);
firstButton.setIconVisible(true);
firstButton.measure(widthSpec, heightSpec);
@@ -160,14 +162,16 @@ public class DropTargetBar extends FrameLayout
int horizontalPadding = dp.dropTargetHorizontalPaddingPx;
ButtonDropTarget firstButton = mTempTargets[0];
firstButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp.dropTargetTextSizePx);
firstButton.setTextVisible(true);
firstButton.setIconVisible(true);
firstButton.setTextMultiLine(false);
// Reset second button padding in case it was previously changed to multi-line text.
// Reset first button padding in case it was previously changed to multi-line text.
firstButton.setPadding(horizontalPadding, verticalPadding, horizontalPadding,
verticalPadding);
ButtonDropTarget secondButton = mTempTargets[1];
secondButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, dp.dropTargetTextSizePx);
secondButton.setTextVisible(true);
secondButton.setIconVisible(true);
secondButton.setTextMultiLine(false);
@@ -175,20 +179,14 @@ public class DropTargetBar extends FrameLayout
secondButton.setPadding(horizontalPadding, verticalPadding, horizontalPadding,
verticalPadding);
float scale = dp.getWorkspaceSpringLoadScale(mLauncher);
int scaledPanelWidth = (int) (dp.getCellLayoutWidth() * scale);
int availableWidth;
if (dp.isTwoPanels) {
// Both buttons for two panel fit to the width of one Cell Layout (less
// half of the center gap between the buttons).
int halfButtonGap = dp.dropTargetGapPx / 2;
availableWidth = scaledPanelWidth - halfButtonGap / 2;
// 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;
} else {
// Both buttons plus the button gap do not display past the edge of the scaled
// workspace, less a pre-defined gap from the edge of the workspace.
availableWidth = scaledPanelWidth - dp.dropTargetGapPx
- 2 * dp.dropTargetButtonWorkspaceEdgeGapPx;
// Both buttons plus the button gap do not display past the edge of the screen.
availableWidth = dp.availableWidthPx - dp.dropTargetGapPx;
}
int widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
@@ -219,6 +217,15 @@ public class DropTargetBar extends FrameLayout
horizontalPadding, verticalPadding / 2);
}
}
// If text is still truncated, shrink to fit in measured width and resize both targets.
float minTextSize =
Math.min(firstButton.resizeTextToFit(), secondButton.resizeTextToFit());
if (firstButton.getTextSize() != minTextSize
|| secondButton.getTextSize() != minTextSize) {
firstButton.setTextSize(minTextSize);
secondButton.setTextSize(minTextSize);
}
}
setMeasuredDimension(width, height);
}