From 28585cd4e5901acf59fe9c150cddf87bbfe34a58 Mon Sep 17 00:00:00 2001 From: d34d Date: Fri, 19 Feb 2016 13:09:07 -0800 Subject: QS: Show # of clients connected to hotspot Since we no longer post a notification showing that the wifi hotspot is on and the # of connected clients, we now show the # of clients connected in the label of the hotspot QS tile. Change-Id: I9ed37b96db9b5b4320a7260524f69733ea70d030 --- packages/SystemUI/res/values/cm_strings.xml | 6 +++++ .../com/android/systemui/qs/tiles/HotspotTile.java | 29 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'packages/SystemUI') diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml index cd76ef7..30547f6 100644 --- a/packages/SystemUI/res/values/cm_strings.xml +++ b/packages/SystemUI/res/values/cm_strings.xml @@ -252,4 +252,10 @@ Flashlight is on Tap to turn off + + + + %1$d client + %1$d clients + 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 d1b167e..71a3f95 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java @@ -21,6 +21,9 @@ import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; +import android.net.ConnectivityManager; +import android.net.wifi.WifiDevice; import android.provider.Settings; import com.android.internal.logging.MetricsLogger; @@ -31,6 +34,8 @@ import com.android.systemui.qs.UsageTracker; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.HotspotController; +import java.util.List; + /** Quick settings tile: Hotspot **/ public class HotspotTile extends QSTile { @@ -44,12 +49,15 @@ public class HotspotTile extends QSTile { private final HotspotController mController; private final Callback mCallback = new Callback(); private final UsageTracker mUsageTracker; + private final ConnectivityManager mConnectivityManager; + private boolean mListening; public HotspotTile(Host host) { super(host); mController = host.getHotspotController(); mUsageTracker = newUsageTracker(host.getContext()); mUsageTracker.setListening(true); + mConnectivityManager = host.getContext().getSystemService(ConnectivityManager.class); } @Override @@ -65,11 +73,16 @@ public class HotspotTile extends QSTile { @Override public void setListening(boolean listening) { + if (mListening == listening) return; if (listening) { mController.addCallback(mCallback); + mContext.registerReceiver(mTetherConnectStateChangedReceiver, + new IntentFilter(ConnectivityManager.TETHER_CONNECT_STATE_CHANGED)); } else { mController.removeCallback(mCallback); + mContext.unregisterReceiver(mTetherConnectStateChangedReceiver); } + mListening = listening; } @Override @@ -111,13 +124,20 @@ public class HotspotTile extends QSTile { @Override protected void handleUpdateState(BooleanState state, Object arg) { state.visible = mController.isHotspotSupported() && mUsageTracker.isRecentlyUsed(); - state.label = mContext.getString(R.string.quick_settings_hotspot_label); if (arg instanceof Boolean) { state.value = (boolean) arg; } else { state.value = mController.isHotspotEnabled(); } + if (state.visible && state.value) { + final List clients = mConnectivityManager.getTetherConnectedSta(); + final int count = clients != null ? clients.size() : 0; + state.label = mContext.getResources().getQuantityString( + R.plurals.wifi_hotspot_connected_clients_label, count, count); + } else { + state.label = mContext.getString(R.string.quick_settings_hotspot_label); + } state.icon = state.visible && state.value ? mEnable : mDisable; } @@ -140,6 +160,13 @@ public class HotspotTile extends QSTile { R.integer.days_to_show_hotspot_tile); } + private BroadcastReceiver mTetherConnectStateChangedReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + refreshState(); + } + }; + private final class Callback implements HotspotController.Callback { @Override public void onHotspotChanged(boolean enabled) { -- cgit v1.1