Merge "Fix the remove button icon not centered when the home screen is in landscape." into sc-v2-dev am: 8935b22cd7 am: 763405dfca
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/16087348
Change-Id: I29b9912fdf63a922b5cf8904be768c1e481b5e6c
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index 7d0f858..69150c5 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -108,8 +108,8 @@
// We do not set the drawable in the xml as that inflates two drawables corresponding to
// drawableLeft and drawableStart.
mDrawable = getContext().getDrawable(resId).mutate();
- mDrawable.setBounds(0, 0, mDrawableSize, mDrawableSize);
mDrawable.setTintList(getTextColors());
+ centerIcon();
setCompoundDrawablesRelative(mDrawable, null, null, null);
}
@@ -278,7 +278,7 @@
}
final int top = to.top + (getMeasuredHeight() - height) / 2;
- final int bottom = top + height;
+ final int bottom = top + height;
to.set(left, top, right, bottom);
@@ -290,6 +290,12 @@
return to;
}
+ private void centerIcon() {
+ int x = mTextVisible ? 0
+ : (getWidth() - getPaddingLeft() - getPaddingRight()) / 2 - mDrawableSize / 2;
+ mDrawable.setBounds(x, 0, x + mDrawableSize, mDrawableSize);
+ }
+
@Override
public void onClick(View v) {
mLauncher.getAccessibilityDelegate().handleAccessibleDrop(this, null, null);
@@ -300,12 +306,19 @@
if (mTextVisible != isVisible || !TextUtils.equals(newText, getText())) {
mTextVisible = isVisible;
setText(newText);
+ centerIcon();
setCompoundDrawablesRelative(mDrawable, null, null, null);
int drawablePadding = mTextVisible ? mDrawablePadding : 0;
setCompoundDrawablePadding(drawablePadding);
}
}
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ centerIcon();
+ }
+
public void setToolTipLocation(int location) {
mToolTipLocation = location;
hideTooltip();