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;
}
}
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;
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);
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) {