diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java index 8a7a7fb7273eb..27b079a06c99f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSTile.java @@ -634,6 +634,18 @@ public abstract class QSTile { } } + public static class AirplaneBooleanState extends BooleanState { + public boolean isAirplaneMode; + + @Override + public boolean copyTo(State other) { + final AirplaneBooleanState o = (AirplaneBooleanState) other; + final boolean changed = super.copyTo(other) || o.isAirplaneMode != isAirplaneMode; + o.isAirplaneMode = isAirplaneMode; + return changed; + } + } + public static final class SignalState extends BooleanState { public boolean connected; public boolean activityIn; diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java index 1c134c1e1424e..d3434e5aa8120 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java @@ -36,15 +36,16 @@ import com.android.systemui.qs.QSTile; import com.android.systemui.statusbar.policy.HotspotController; /** Quick settings tile: Hotspot **/ -public class HotspotTile extends QSTile { +public class HotspotTile extends QSTile { private final AnimationIcon mEnable = new AnimationIcon(R.drawable.ic_hotspot_enable_animation, R.drawable.ic_hotspot_disable); private final AnimationIcon mDisable = new AnimationIcon(R.drawable.ic_hotspot_disable_animation, R.drawable.ic_hotspot_enable); - private final Icon mUnavailable = - ResourceIcon.get(R.drawable.ic_hotspot_unavailable); + private final Icon mDisableNoAnimation = ResourceIcon.get(R.drawable.ic_hotspot_enable); + private final Icon mUnavailable = ResourceIcon.get(R.drawable.ic_hotspot_unavailable); + private final HotspotController mController; private final Callback mCallback = new Callback(); private final GlobalSetting mAirplaneMode; @@ -72,8 +73,8 @@ public class HotspotTile extends QSTile { } @Override - public BooleanState newTileState() { - return new BooleanState(); + public AirplaneBooleanState newTileState() { + return new AirplaneBooleanState(); } @Override @@ -84,10 +85,8 @@ public class HotspotTile extends QSTile { mController.addCallback(mCallback); final IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); - mContext.registerReceiver(mReceiver, filter); } else { mController.removeCallback(mCallback); - mContext.unregisterReceiver(mReceiver); } mAirplaneMode.setListening(listening); } @@ -113,7 +112,7 @@ public class HotspotTile extends QSTile { } @Override - protected void handleUpdateState(BooleanState state, Object arg) { + protected void handleUpdateState(AirplaneBooleanState state, Object arg) { state.label = mContext.getString(R.string.quick_settings_hotspot_label); checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_TETHERING); @@ -123,12 +122,16 @@ public class HotspotTile extends QSTile { state.value = mController.isHotspotEnabled(); } state.icon = state.value ? mEnable : mDisable; - if (mAirplaneMode.getValue() != 0) { + boolean wasAirplane = state.isAirplaneMode; + state.isAirplaneMode = mAirplaneMode.getValue() != 0; + if (state.isAirplaneMode) { final int disabledColor = mHost.getContext().getColor(R.color.qs_tile_tint_unavailable); state.label = new SpannableStringBuilder().append(state.label, new ForegroundColorSpan(disabledColor), SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE); state.icon = mUnavailable; + } else if (wasAirplane) { + state.icon = mDisableNoAnimation; } state.minimalAccessibilityClassName = state.expandedAccessibilityClassName = Switch.class.getName(); @@ -155,13 +158,4 @@ public class HotspotTile extends QSTile { refreshState(enabled); } }; - - private final BroadcastReceiver mReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) { - refreshState(); - } - } - }; }