summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2012-07-30 12:18:15 -0700
committerAdam Powell <adamp@google.com>2012-07-30 14:30:51 -0700
commitc0047d4e111b8cfbffdbebb55f846c7ae935e53e (patch)
tree1ad4417812e93482a854d236ec9715f2ae98a6ba /core
parentfa14d824d235c33b137a429c3eb6818f273407ab (diff)
downloadframeworks_base-c0047d4e111b8cfbffdbebb55f846c7ae935e53e.zip
frameworks_base-c0047d4e111b8cfbffdbebb55f846c7ae935e53e.tar.gz
frameworks_base-c0047d4e111b8cfbffdbebb55f846c7ae935e53e.tar.bz2
Enforce a maximum size for action button icons.
Change-Id: Id9b5c1573cd40012229921fa8497cbe5ce340b1e
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/view/menu/ActionMenuItemView.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/core/java/com/android/internal/view/menu/ActionMenuItemView.java b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
index 671badb..96d486b 100644
--- a/core/java/com/android/internal/view/menu/ActionMenuItemView.java
+++ b/core/java/com/android/internal/view/menu/ActionMenuItemView.java
@@ -48,6 +48,9 @@ public class ActionMenuItemView extends TextView
private int mMinWidth;
private int mSavedPaddingLeft;
+ private static final int MAX_ICON_SIZE = 32; // dp
+ private int mMaxIconSize;
+
public ActionMenuItemView(Context context) {
this(context, null);
}
@@ -67,6 +70,9 @@ public class ActionMenuItemView extends TextView
com.android.internal.R.styleable.ActionMenuItemView_minWidth, 0);
a.recycle();
+ final float density = res.getDisplayMetrics().density;
+ mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f);
+
setOnClickListener(this);
setOnLongClickListener(this);
@@ -135,7 +141,20 @@ public class ActionMenuItemView extends TextView
public void setIcon(Drawable 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();
}
@@ -245,7 +264,7 @@ public class ActionMenuItemView extends TextView
// TextView won't center compound drawables in both dimensions without
// a little coercion. Pad in to center the icon after we've measured.
final int w = getMeasuredWidth();
- final int dw = mIcon.getIntrinsicWidth();
+ final int dw = mIcon.getBounds().width();
super.setPadding((w - dw) / 2, getPaddingTop(), getPaddingRight(), getPaddingBottom());
}
}