diff options
| author | 2016-01-21 05:34:13 +0000 | |
|---|---|---|
| committer | 2016-01-21 05:34:13 +0000 | |
| commit | 7a1c6562694faaee4bf30a3b06573e96e93034ff (patch) | |
| tree | 695a6f2de5741e71e069c3a21131c760df29b993 | |
| parent | bf9a587ca8528219e46fc35746d6ec8a8e6568d1 (diff) | |
| parent | 3c988197fac989e4cca7fd1a96f6489e8ed4a05b (diff) | |
Fix SystemUI animator leak
am: 3c988197fa
* commit '3c988197fac989e4cca7fd1a96f6489e8ed4a05b':
  Fix SystemUI animator leak
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java | 54 | 
1 files changed, 38 insertions, 16 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java index cc30882a7089..68e483c3a669 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/SignalClusterView.java @@ -351,10 +351,13 @@ public class SignalClusterView          for (PhoneState state : mPhoneStates) {              if (state.mMobile != null) { +                state.maybeStopAnimatableDrawable(state.mMobile);                  state.mMobile.setImageDrawable(null); +                state.mLastMobileStrengthId = -1;              }              if (state.mMobileType != null) {                  state.mMobileType.setImageDrawable(null); +                state.mLastMobileTypeId = -1;              }          } @@ -486,6 +489,8 @@ public class SignalClusterView          private final int mSubId;          private boolean mMobileVisible = false;          private int mMobileStrengthId = 0, mMobileTypeId = 0; +        private int mLastMobileStrengthId = -1; +        private int mLastMobileTypeId = -1;          private boolean mIsMobileTypeIconWide;          private String mMobileDescription, mMobileTypeDescription; @@ -508,25 +513,16 @@ public class SignalClusterView          public boolean apply(boolean isSecondaryIcon) {              if (mMobileVisible && !mIsAirplaneMode) { -                mMobile.setImageResource(mMobileStrengthId); -                Drawable mobileDrawable = mMobile.getDrawable(); -                if (mobileDrawable instanceof Animatable) { -                    Animatable ad = (Animatable) mobileDrawable; -                    if (!ad.isRunning()) { -                        ad.start(); -                    } +                if (mLastMobileStrengthId != mMobileStrengthId) { +                    updateAnimatableIcon(mMobile, mMobileStrengthId); +                    updateAnimatableIcon(mMobileDark, mMobileStrengthId); +                    mLastMobileStrengthId = mMobileStrengthId;                  } -                mMobileDark.setImageResource(mMobileStrengthId); -                Drawable mobileDarkDrawable = mMobileDark.getDrawable(); -                if (mobileDarkDrawable instanceof Animatable) { -                    Animatable ad = (Animatable) mobileDarkDrawable; -                    if (!ad.isRunning()) { -                        ad.start(); -                    } +                if (mLastMobileTypeId != mMobileTypeId) { +                    mMobileType.setImageResource(mMobileTypeId); +                    mLastMobileTypeId = mMobileTypeId;                  } - -                mMobileType.setImageResource(mMobileTypeId);                  mMobileGroup.setContentDescription(mMobileTypeDescription                          + " " + mMobileDescription);                  mMobileGroup.setVisibility(View.VISIBLE); @@ -550,6 +546,32 @@ public class SignalClusterView              return mMobileVisible;          } +        private void updateAnimatableIcon(ImageView view, int resId) { +            maybeStopAnimatableDrawable(view); +            view.setImageResource(resId); +            maybeStartAnimatableDrawable(view); +        } + +        private void maybeStopAnimatableDrawable(ImageView view) { +            Drawable drawable = view.getDrawable(); +            if (drawable instanceof Animatable) { +                Animatable ad = (Animatable) drawable; +                if (ad.isRunning()) { +                    ad.stop(); +                } +            } +        } + +        private void maybeStartAnimatableDrawable(ImageView view) { +            Drawable drawable = view.getDrawable(); +            if (drawable instanceof Animatable) { +                Animatable ad = (Animatable) drawable; +                if (!ad.isRunning()) { +                    ad.start(); +                } +            } +        } +          public void populateAccessibilityEvent(AccessibilityEvent event) {              if (mMobileVisible && mMobileGroup != null                      && mMobileGroup.getContentDescription() != null) {  |