Hides text on ButtonDropTargets if any of them are ellipsized.

This can happen on small devices or on devices where Font/Display size
is enlarged and when Developer Options is turned on when all three
options {Uninstall, Delete, App Info} are shown at once.

Bug: 64391860
Change-Id: If355d28087d53148114eb586efb3c26f158b3713
This commit is contained in:
Jon Miranda
2017-08-21 15:31:51 -07:00
parent 9b745a82bf
commit bfaa4a4edc
3 changed files with 85 additions and 2 deletions

View File

@@ -78,6 +78,58 @@ public class DropTargetBar extends LinearLayout implements DragController.DragLi
setupButtonDropTarget(this, dragController);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
boolean hideText = hideTextHelper(false /* shouldUpdateText */, false /* no-op */);
if (hideTextHelper(true /* shouldUpdateText */, hideText)) {
// Text has changed, so we need to re-measure.
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
/**
* Helper method that iterates through the children and returns whether any of the visible
* {@link ButtonDropTarget} has truncated text.
*
* @param shouldUpdateText If True, updates the text of all children.
* @param hideText If True and {@param shouldUpdateText} is True, clears the text of all
* children; otherwise it sets the original text value.
*
*
* @return If shouldUpdateText is True, returns whether any of the children updated their text.
* Else, returns whether any of the children have truncated their text.
*/
private boolean hideTextHelper(boolean shouldUpdateText, boolean hideText) {
boolean result = false;
View visibleView;
ButtonDropTarget dropTarget;
for (int i = getChildCount() - 1; i >= 0; --i) {
if (getChildAt(i) instanceof ButtonDropTarget) {
visibleView = dropTarget = (ButtonDropTarget) getChildAt(i);
} else if (getChildAt(i) instanceof ViewGroup) {
// The Drop Target is wrapped in a FrameLayout.
visibleView = getChildAt(i);
dropTarget = (ButtonDropTarget) ((ViewGroup) visibleView).getChildAt(0);
} else {
// Ignore other views.
continue;
}
if (visibleView.getVisibility() == View.VISIBLE) {
if (shouldUpdateText) {
result |= dropTarget.updateText(hideText);
} else if (dropTarget.isTextTruncated()) {
result = true;
break;
}
}
}
return result;
}
private void setupButtonDropTarget(View view, DragController dragController) {
if (view instanceof ButtonDropTarget) {
ButtonDropTarget bdt = (ButtonDropTarget) view;