diff options
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher3/ButtonDropTarget.java | 29 | ||||
-rw-r--r-- | src/com/android/launcher3/DeleteDropTarget.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/DropTargetBar.java | 52 |
3 files changed, 85 insertions, 2 deletions
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index e4a322622..632e49059 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -29,6 +29,7 @@ import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.view.View.OnClickListener; @@ -69,6 +70,7 @@ public abstract class ButtonDropTarget extends TextView /** The paint applied to the drag view on hover */ protected int mHoverColor = 0; + protected CharSequence mText; protected ColorStateList mOriginalTextColor; protected Drawable mDrawable; @@ -96,6 +98,7 @@ public abstract class ButtonDropTarget extends TextView @Override protected void onFinishInflate() { super.onFinishInflate(); + mText = getText(); mOriginalTextColor = getTextColors(); } @@ -297,4 +300,30 @@ public abstract class ButtonDropTarget extends TextView public int getTextColor() { return getTextColors().getDefaultColor(); } + + /** + * Returns True if any update was made. + */ + public boolean updateText(boolean hide) { + if ((hide && getText().toString().isEmpty()) || (!hide && mText.equals(getText()))) { + return false; + } + + setText(hide ? "" : mText); + return true; + } + + public boolean isTextTruncated() { + int availableWidth = getMeasuredWidth(); + if (mHideParentOnDisable) { + ViewGroup parent = (ViewGroup) getParent(); + availableWidth = parent.getMeasuredWidth() - parent.getPaddingLeft() + - parent.getPaddingRight(); + } + availableWidth -= (getPaddingLeft() + getPaddingRight() + mDrawable.getIntrinsicWidth() + + getCompoundDrawablePadding()); + CharSequence displayedText = TextUtils.ellipsize(mText, getPaint(), availableWidth, + TextUtils.TruncateAt.END); + return !mText.equals(displayedText); + } } diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java index 975675a6f..4dcb64f01 100644 --- a/src/com/android/launcher3/DeleteDropTarget.java +++ b/src/com/android/launcher3/DeleteDropTarget.java @@ -65,9 +65,11 @@ public class DeleteDropTarget extends ButtonDropTarget { * Set the drop target's text to either "Remove" or "Cancel" depending on the drag source. */ public void setTextBasedOnDragSource(DragSource dragSource) { - if (!TextUtils.isEmpty(getText())) { - setText(dragSource.supportsDeleteDropTarget() ? R.string.remove_drop_target_label + if (!TextUtils.isEmpty(mText)) { + mText = getResources().getString(dragSource.supportsDeleteDropTarget() + ? R.string.remove_drop_target_label : android.R.string.cancel); + requestLayout(); } } 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; |