Merge "QS: Make hotspot go unavailable in airplane mode" into nyc-dev am: 72f19ff6f0
am: 628c714f3e
* commit '628c714f3e3414155f4e477bfa8d76b520ced01b':
QS: Make hotspot go unavailable in airplane mode
Change-Id: I1db7a4e27b0e518509ac0e51e44c2f3fd781b38b
This commit is contained in:
62
packages/SystemUI/res/drawable/ic_hotspot_unavailable.xml
Normal file
62
packages/SystemUI/res/drawable/ic_hotspot_unavailable.xml
Normal file
File diff suppressed because one or more lines are too long
@@ -16,15 +16,22 @@
|
|||||||
|
|
||||||
package com.android.systemui.qs.tiles;
|
package com.android.systemui.qs.tiles;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.provider.Settings.Global;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
|
|
||||||
import com.android.internal.logging.MetricsLogger;
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
|
import com.android.systemui.qs.GlobalSetting;
|
||||||
import com.android.systemui.qs.QSTile;
|
import com.android.systemui.qs.QSTile;
|
||||||
import com.android.systemui.statusbar.policy.HotspotController;
|
import com.android.systemui.statusbar.policy.HotspotController;
|
||||||
|
|
||||||
@@ -36,12 +43,22 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
|||||||
private final AnimationIcon mDisable =
|
private final AnimationIcon mDisable =
|
||||||
new AnimationIcon(R.drawable.ic_hotspot_disable_animation,
|
new AnimationIcon(R.drawable.ic_hotspot_disable_animation,
|
||||||
R.drawable.ic_hotspot_enable);
|
R.drawable.ic_hotspot_enable);
|
||||||
|
private final Icon mUnavailable =
|
||||||
|
ResourceIcon.get(R.drawable.ic_hotspot_unavailable);
|
||||||
private final HotspotController mController;
|
private final HotspotController mController;
|
||||||
private final Callback mCallback = new Callback();
|
private final Callback mCallback = new Callback();
|
||||||
|
private final GlobalSetting mAirplaneMode;
|
||||||
|
private boolean mListening;
|
||||||
|
|
||||||
public HotspotTile(Host host) {
|
public HotspotTile(Host host) {
|
||||||
super(host);
|
super(host);
|
||||||
mController = host.getHotspotController();
|
mController = host.getHotspotController();
|
||||||
|
mAirplaneMode = new GlobalSetting(mContext, mHandler, Global.AIRPLANE_MODE_ON) {
|
||||||
|
@Override
|
||||||
|
protected void handleValueChanged(int value) {
|
||||||
|
refreshState();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,11 +78,18 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setListening(boolean listening) {
|
public void setListening(boolean listening) {
|
||||||
|
if (mListening == listening) return;
|
||||||
|
mListening = listening;
|
||||||
if (listening) {
|
if (listening) {
|
||||||
mController.addCallback(mCallback);
|
mController.addCallback(mCallback);
|
||||||
|
final IntentFilter filter = new IntentFilter();
|
||||||
|
filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||||
|
mContext.registerReceiver(mReceiver, filter);
|
||||||
} else {
|
} else {
|
||||||
mController.removeCallback(mCallback);
|
mController.removeCallback(mCallback);
|
||||||
|
mContext.unregisterReceiver(mReceiver);
|
||||||
}
|
}
|
||||||
|
mAirplaneMode.setListening(listening);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -76,6 +100,9 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
|||||||
@Override
|
@Override
|
||||||
protected void handleClick() {
|
protected void handleClick() {
|
||||||
final boolean isEnabled = (Boolean) mState.value;
|
final boolean isEnabled = (Boolean) mState.value;
|
||||||
|
if (!isEnabled && mAirplaneMode.getValue() != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
MetricsLogger.action(mContext, getMetricsCategory(), !isEnabled);
|
MetricsLogger.action(mContext, getMetricsCategory(), !isEnabled);
|
||||||
mController.setHotspotEnabled(!isEnabled);
|
mController.setHotspotEnabled(!isEnabled);
|
||||||
}
|
}
|
||||||
@@ -96,6 +123,13 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
|||||||
state.value = mController.isHotspotEnabled();
|
state.value = mController.isHotspotEnabled();
|
||||||
}
|
}
|
||||||
state.icon = state.value ? mEnable : mDisable;
|
state.icon = state.value ? mEnable : mDisable;
|
||||||
|
if (mAirplaneMode.getValue() != 0) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
state.minimalAccessibilityClassName = state.expandedAccessibilityClassName
|
state.minimalAccessibilityClassName = state.expandedAccessibilityClassName
|
||||||
= Switch.class.getName();
|
= Switch.class.getName();
|
||||||
state.contentDescription = state.label;
|
state.contentDescription = state.label;
|
||||||
@@ -121,4 +155,13 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
|||||||
refreshState(enabled);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user