Merge "Enforce a maximum size for action button icons." into jb-mr1-dev
This commit is contained in:
@@ -48,6 +48,9 @@ public class ActionMenuItemView extends TextView
|
|||||||
private int mMinWidth;
|
private int mMinWidth;
|
||||||
private int mSavedPaddingLeft;
|
private int mSavedPaddingLeft;
|
||||||
|
|
||||||
|
private static final int MAX_ICON_SIZE = 32; // dp
|
||||||
|
private int mMaxIconSize;
|
||||||
|
|
||||||
public ActionMenuItemView(Context context) {
|
public ActionMenuItemView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
@@ -67,6 +70,9 @@ public class ActionMenuItemView extends TextView
|
|||||||
com.android.internal.R.styleable.ActionMenuItemView_minWidth, 0);
|
com.android.internal.R.styleable.ActionMenuItemView_minWidth, 0);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
|
final float density = res.getDisplayMetrics().density;
|
||||||
|
mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f);
|
||||||
|
|
||||||
setOnClickListener(this);
|
setOnClickListener(this);
|
||||||
setOnLongClickListener(this);
|
setOnLongClickListener(this);
|
||||||
|
|
||||||
@@ -135,7 +141,20 @@ public class ActionMenuItemView extends TextView
|
|||||||
|
|
||||||
public void setIcon(Drawable icon) {
|
public void setIcon(Drawable icon) {
|
||||||
mIcon = icon;
|
mIcon = icon;
|
||||||
setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
int width = icon.getIntrinsicWidth();
|
||||||
|
int height = icon.getIntrinsicHeight();
|
||||||
|
if (width > mMaxIconSize) {
|
||||||
|
final float scale = (float) mMaxIconSize / width;
|
||||||
|
width = mMaxIconSize;
|
||||||
|
height *= scale;
|
||||||
|
}
|
||||||
|
if (height > mMaxIconSize) {
|
||||||
|
final float scale = (float) mMaxIconSize / height;
|
||||||
|
height = mMaxIconSize;
|
||||||
|
width *= scale;
|
||||||
|
}
|
||||||
|
icon.setBounds(0, 0, width, height);
|
||||||
|
setCompoundDrawables(icon, null, null, null);
|
||||||
|
|
||||||
updateTextButtonVisibility();
|
updateTextButtonVisibility();
|
||||||
}
|
}
|
||||||
@@ -245,7 +264,7 @@ public class ActionMenuItemView extends TextView
|
|||||||
// TextView won't center compound drawables in both dimensions without
|
// TextView won't center compound drawables in both dimensions without
|
||||||
// a little coercion. Pad in to center the icon after we've measured.
|
// a little coercion. Pad in to center the icon after we've measured.
|
||||||
final int w = getMeasuredWidth();
|
final int w = getMeasuredWidth();
|
||||||
final int dw = mIcon.getIntrinsicWidth();
|
final int dw = mIcon.getBounds().width();
|
||||||
super.setPadding((w - dw) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
|
super.setPadding((w - dw) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user