From 0f27a3f0d7048140fac2329c714af2bfcf4218d6 Mon Sep 17 00:00:00 2001 From: Andrew Flynn Date: Wed, 10 Jun 2015 14:12:23 -0400 Subject: [PATCH] SysUI: Status bar ImageViews - Switch AlphaOptimizedImageView to have the boolean hasOverLappingRendering() return be a custom value. This allows us to have AnimatedImageView extend AlphaOptimizedImageView and support both types of ImageViews w/o having to create 2x subclasses. - Add drawable ID tracking to AnimatedImageView so that we don't interrupt animations with an update of the exact same drawable. - Switch mobile signal icon to use AnimatedImageView so that animations aren't interrupted. Bug: 21504588 Change-Id: Ic2275f1bf607449c191ae0d08bc7756c7d694bc1 --- .../res/layout/mobile_signal_group.xml | 7 +++-- .../res/layout/signal_cluster_view.xml | 7 +++++ .../res/layout/status_bar_expanded_header.xml | 1 + packages/SystemUI/res/values/attrs.xml | 4 +++ .../statusbar/AlphaOptimizedImageView.java | 31 ++++++++++++++----- .../systemui/statusbar/AnimatedImageView.java | 19 ++++++++++-- 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/res/layout/mobile_signal_group.xml b/packages/SystemUI/res/layout/mobile_signal_group.xml index 6a4ac2c220799..6ae5cf3ee3c8b 100644 --- a/packages/SystemUI/res/layout/mobile_signal_group.xml +++ b/packages/SystemUI/res/layout/mobile_signal_group.xml @@ -19,22 +19,25 @@ --> - - + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AlphaOptimizedImageView.java b/packages/SystemUI/src/com/android/systemui/statusbar/AlphaOptimizedImageView.java index 858c1183334ff..700ea346e3271 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/AlphaOptimizedImageView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/AlphaOptimizedImageView.java @@ -17,34 +17,49 @@ package com.android.systemui.statusbar; import android.content.Context; +import android.content.res.TypedArray; import android.util.AttributeSet; import android.widget.ImageView; +import com.android.systemui.R; + /** - * An ImageView which does not have overlapping rendering commands and therefore does not need a - * layer when alpha is changed. + * An ImageView which supports an attribute specifying whether it has overlapping rendering + * commands and therefore does not need a layer when alpha is changed. */ -public class AlphaOptimizedImageView extends ImageView -{ +public class AlphaOptimizedImageView extends ImageView { + private final boolean mHasOverlappingRendering; + public AlphaOptimizedImageView(Context context) { - super(context); + this(context, null /* attrs */); } public AlphaOptimizedImageView(Context context, AttributeSet attrs) { - super(context, attrs); + this(context, attrs, 0 /* defStyleAttr */); } public AlphaOptimizedImageView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); + this(context, attrs, defStyleAttr, 0 /* defStyleRes */); } public AlphaOptimizedImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + + TypedArray a = context.getTheme().obtainStyledAttributes(attrs, + R.styleable.AlphaOptimizedImageView, 0, 0); + + try { + // Default to true, which is what View.java defaults to + mHasOverlappingRendering = a.getBoolean( + R.styleable.AlphaOptimizedImageView_hasOverlappingRendering, true); + } finally { + a.recycle(); + } } @Override public boolean hasOverlappingRendering() { - return false; + return mHasOverlappingRendering; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java b/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java index 9839fe9e6f4d6..90f7c08e4ed79 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/AnimatedImageView.java @@ -25,10 +25,15 @@ import android.widget.ImageView; import android.widget.RemoteViews.RemoteView; @RemoteView -public class AnimatedImageView extends ImageView { +public class AnimatedImageView extends AlphaOptimizedImageView { AnimationDrawable mAnim; boolean mAttached; + // Tracks the last image that was set, so that we don't refresh the image if it is exactly + // the same as the previous one. If this is a resid, we track that. If it's a drawable, we + // track the hashcode of the drawable. + int mDrawableId; + public AnimatedImageView(Context context) { super(context); } @@ -43,7 +48,7 @@ public class AnimatedImageView extends ImageView { mAnim.stop(); } if (drawable instanceof AnimationDrawable) { - mAnim = (AnimationDrawable)drawable; + mAnim = (AnimationDrawable) drawable; if (isShown()) { mAnim.start(); } @@ -54,6 +59,13 @@ public class AnimatedImageView extends ImageView { @Override public void setImageDrawable(Drawable drawable) { + if (drawable != null) { + if (mDrawableId == drawable.hashCode()) return; + + mDrawableId = drawable.hashCode(); + } else { + mDrawableId = 0; + } super.setImageDrawable(drawable); updateAnim(); } @@ -61,6 +73,9 @@ public class AnimatedImageView extends ImageView { @Override @android.view.RemotableViewMethod public void setImageResource(int resid) { + if (mDrawableId == resid) return; + + mDrawableId = resid; super.setImageResource(resid); updateAnim(); }