Merge "Center drop target button alignment across devices" into tm-dev

This commit is contained in:
Alex Chau
2022-05-25 12:38:11 +00:00
committed by Android (Google) Code Review
4 changed files with 40 additions and 11 deletions

View File

@@ -31,6 +31,7 @@
<dimen name="drop_target_button_drawable_horizontal_padding">24dp</dimen>
<dimen name="drop_target_button_drawable_vertical_padding">20dp</dimen>
<dimen name="drop_target_button_gap">32dp</dimen>
<dimen name="drop_target_button_workspace_edge_gap">32dp</dimen>
<dimen name="drop_target_top_margin">110dp</dimen>
<dimen name="drop_target_bottom_margin">48dp</dimen>

View File

@@ -241,6 +241,7 @@
<dimen name="drop_target_button_drawable_horizontal_padding">16dp</dimen>
<dimen name="drop_target_button_drawable_vertical_padding">8dp</dimen>
<dimen name="drop_target_button_gap">28dp</dimen>
<dimen name="drop_target_button_workspace_edge_gap">0dp</dimen>
<!-- the distance an icon must be dragged before button drop targets accept it -->
<dimen name="drag_distanceThreshold">30dp</dimen>

View File

@@ -215,6 +215,7 @@ public class DeviceProfile {
public int dropTargetHorizontalPaddingPx;
public int dropTargetVerticalPaddingPx;
public int dropTargetGapPx;
public int dropTargetButtonWorkspaceEdgeGapPx;
// Insets
private final Rect mInsets = new Rect();
@@ -342,6 +343,8 @@ public class DeviceProfile {
dropTargetVerticalPaddingPx = res.getDimensionPixelSize(
R.dimen.drop_target_button_drawable_vertical_padding);
dropTargetGapPx = res.getDimensionPixelSize(R.dimen.drop_target_button_gap);
dropTargetButtonWorkspaceEdgeGapPx = res.getDimensionPixelSize(
R.dimen.drop_target_button_workspace_edge_gap);
workspaceSpringLoadedBottomSpace =
res.getDimensionPixelSize(R.dimen.dynamic_grid_min_spring_loaded_space);

View File

@@ -186,14 +186,13 @@ public class DropTargetBar extends FrameLayout
availableWidth = scaledPanelWidth - halfButtonGap / 2;
} else {
// Both buttons plus the button gap do not display past the edge of the scaled
// workspace.
availableWidth = (scaledPanelWidth - dp.dropTargetGapPx) / 2;
// workspace, less a pre-defined gap from the edge of the workspace.
availableWidth = scaledPanelWidth - dp.dropTargetGapPx
- 2 * dp.dropTargetButtonWorkspaceEdgeGapPx;
}
int widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
firstButton.measure(widthSpec, heightSpec);
secondButton.measure(widthSpec, heightSpec);
if (!mIsVertical) {
// Remove icons and put the button's text on two lines if text is truncated.
if (firstButton.isTextTruncated(availableWidth)) {
@@ -202,6 +201,14 @@ public class DropTargetBar extends FrameLayout
firstButton.setPadding(horizontalPadding, verticalPadding / 2,
horizontalPadding, verticalPadding / 2);
}
}
if (!dp.isTwoPanels) {
availableWidth -= firstButton.getMeasuredWidth() + dp.dropTargetGapPx;
widthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
}
secondButton.measure(widthSpec, heightSpec);
if (!mIsVertical) {
if (secondButton.isTextTruncated(availableWidth)) {
secondButton.setIconVisible(false);
secondButton.setTextMultiLine(true);
@@ -243,13 +250,30 @@ public class DropTargetBar extends FrameLayout
int buttonGap = dp.dropTargetGapPx;
ButtonDropTarget leftButton = mTempTargets[0];
leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0,
barCenter - (buttonGap / 2), leftButton.getMeasuredHeight());
ButtonDropTarget rightButton = mTempTargets[1];
rightButton.layout(barCenter + (buttonGap / 2), 0,
barCenter + (buttonGap / 2) + rightButton.getMeasuredWidth(),
rightButton.getMeasuredHeight());
if (dp.isTwoPanels) {
leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0,
barCenter - (buttonGap / 2), leftButton.getMeasuredHeight());
rightButton.layout(barCenter + (buttonGap / 2), 0,
barCenter + (buttonGap / 2) + rightButton.getMeasuredWidth(),
rightButton.getMeasuredHeight());
} else {
int scaledPanelWidth = (int) (dp.getCellLayoutWidth() * scale);
int leftButtonWidth = leftButton.getMeasuredWidth();
int rightButtonWidth = rightButton.getMeasuredWidth();
int extraSpace = scaledPanelWidth - leftButtonWidth - rightButtonWidth - buttonGap;
int leftButtonStart = barCenter - (scaledPanelWidth / 2) + extraSpace / 2;
int leftButtonEnd = leftButtonStart + leftButtonWidth;
int rightButtonStart = leftButtonEnd + buttonGap;
int rightButtonEnd = rightButtonStart + rightButtonWidth;
leftButton.layout(leftButtonStart, 0, leftButtonEnd,
leftButton.getMeasuredHeight());
rightButton.layout(rightButtonStart, 0, rightButtonEnd,
rightButton.getMeasuredHeight());
}
}
}
@@ -318,7 +342,7 @@ public class DropTargetBar extends FrameLayout
}
public ButtonDropTarget[] getDropTargets() {
return mDropTargets;
return getVisibility() == View.VISIBLE ? mDropTargets : new ButtonDropTarget[0];
}
@Override