diff options
author | Adam Powell <adamp@google.com> | 2012-07-30 15:10:12 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-07-30 15:10:12 -0700 |
commit | 7dd2157ec2864815f4fb7a9e194843b2fb0d2f2d (patch) | |
tree | 2ef144f7230b4b65e15d6f91cdb02591184cbe39 /core | |
parent | fdfb676df6e5ed4f923bca5d38bf6c41bf237944 (diff) | |
parent | 2ebfee16402e9a9ae631fca00806bef9233a6ac0 (diff) | |
download | frameworks_base-7dd2157ec2864815f4fb7a9e194843b2fb0d2f2d.zip frameworks_base-7dd2157ec2864815f4fb7a9e194843b2fb0d2f2d.tar.gz frameworks_base-7dd2157ec2864815f4fb7a9e194843b2fb0d2f2d.tar.bz2 |
am 2ebfee16: am 859a62ce: Merge "Enforce a maximum size for action button icons." into jb-mr1-dev
* commit '2ebfee16402e9a9ae631fca00806bef9233a6ac0':
Enforce a maximum size for action button icons.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/com/android/internal/view/menu/ActionMenuItemView.java | 23 |
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()); } } |