diff options
author | Doris Liu <tianliu@google.com> | 2014-01-28 18:22:51 -0800 |
---|---|---|
committer | Doris Liu <tianliu@google.com> | 2014-01-28 18:22:51 -0800 |
commit | 58ac7e042e0718e860f9aea6dca3697e1c3d9bb8 (patch) | |
tree | b8dda17a1fcc4466ec98b19e1a35dd41b47e7d2c | |
parent | 5e6c3e7840b41685ebd27c40ee243a7ae75e7229 (diff) | |
download | android_packages_apps_Camera2-58ac7e042e0718e860f9aea6dca3697e1c3d9bb8.tar.gz android_packages_apps_Camera2-58ac7e042e0718e860f9aea6dca3697e1c3d9bb8.tar.bz2 android_packages_apps_Camera2-58ac7e042e0718e860f9aea6dca3697e1c3d9bb8.zip |
Use mutable drawable to avoid sharing drawable states
Bug: 12594617
Change-Id: I798b67ed42a5593c346643d42ebf1143d54551e6
-rw-r--r-- | src/com/android/camera/ui/BottomBar.java | 13 | ||||
-rw-r--r-- | src/com/android/camera/ui/ModeSelectorItem.java | 14 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/com/android/camera/ui/BottomBar.java b/src/com/android/camera/ui/BottomBar.java index 3ee8b73b1..35b514231 100644 --- a/src/com/android/camera/ui/BottomBar.java +++ b/src/com/android/camera/ui/BottomBar.java @@ -511,10 +511,19 @@ public class BottomBar extends FrameLayout } /** - * Set the shutter button's icon resource + * Sets the shutter button's icon resource. By default, all drawables instances + * loaded from the same resource share a common state; if you modify the state + * of one instance, all the other instances will receive the same modification. + * In order to modify properties of this icon drawable without affecting other + * drawables, here we use a mutable drawable which is guaranteed to not share + * states with other drawables. */ public void setShutterButtonIcon(int resId) { - mShutterButton.setImageResource(resId); + Drawable iconDrawable = getResources().getDrawable(resId); + if (iconDrawable != null) { + iconDrawable = iconDrawable.mutate(); + } + mShutterButton.setImageDrawable(iconDrawable); } /** diff --git a/src/com/android/camera/ui/ModeSelectorItem.java b/src/com/android/camera/ui/ModeSelectorItem.java index bf89f2b09..44c567cbd 100644 --- a/src/com/android/camera/ui/ModeSelectorItem.java +++ b/src/com/android/camera/ui/ModeSelectorItem.java @@ -20,6 +20,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.util.AttributeSet; import android.widget.FrameLayout; @@ -147,12 +148,21 @@ class ModeSelectorItem extends FrameLayout { } /** - * Sets image resource as the icon for the mode. + * Sets image resource as the icon for the mode. By default, all drawables instances + * loaded from the same resource share a common state; if you modify the state + * of one instance, all the other instances will receive the same modification. + * In order to modify properties of this icon drawable without affecting other + * drawables, here we use a mutable drawable which is guaranteed to not share + * states with other drawables. * * @param resource resource id of the asset to be used as icon */ public void setImageResource(int resource) { - mIcon.setImageResource(resource); + Drawable drawableIcon = getResources().getDrawable(resource); + if (drawableIcon != null) { + drawableIcon = drawableIcon.mutate(); + } + mIcon.setImageDrawable(drawableIcon); } /** |