diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-20 07:45:27 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-09-20 07:45:27 +0000 |
commit | 1b60530b9272671b6bddda223aea9dfd95f5d469 (patch) | |
tree | b755c5b64eb096681181d4ddb36c313988309141 /src/com/android/launcher3/DropTargetBar.java | |
parent | f78db7fa5c485433b362b68a497a80cd728faf19 (diff) | |
parent | fb46415e803a7f20a7d48bf42106f3f40cd769dd (diff) | |
download | android_packages_apps_Trebuchet-1b60530b9272671b6bddda223aea9dfd95f5d469.tar.gz android_packages_apps_Trebuchet-1b60530b9272671b6bddda223aea9dfd95f5d469.tar.bz2 android_packages_apps_Trebuchet-1b60530b9272671b6bddda223aea9dfd95f5d469.zip |
release-request-42a2a3ad-8c90-4c84-a0ad-5d067beb8e30-for-git_oc-mr1-release-4349323 snap-temp-L16100000104414353
Change-Id: I98e6266bf9b4b187c6ad6f24d06b1f02e8beef97
Diffstat (limited to 'src/com/android/launcher3/DropTargetBar.java')
-rw-r--r-- | src/com/android/launcher3/DropTargetBar.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java index 0840b7015..29a1349d5 100644 --- a/src/com/android/launcher3/DropTargetBar.java +++ b/src/com/android/launcher3/DropTargetBar.java @@ -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; |