diff options
author | d34d <clark@cyngn.com> | 2016-02-19 13:09:07 -0800 |
---|---|---|
committer | Clark Scheff <clark@cyngn.com> | 2016-02-22 09:06:50 -0800 |
commit | 28585cd4e5901acf59fe9c150cddf87bbfe34a58 (patch) | |
tree | 9b7b365df516f3e2ecf1a467aff9f499cf9a0499 /packages/SystemUI | |
parent | fadfc45d2348e126df95ff4643f057ccc9c3f453 (diff) | |
download | frameworks_base-28585cd4e5901acf59fe9c150cddf87bbfe34a58.zip frameworks_base-28585cd4e5901acf59fe9c150cddf87bbfe34a58.tar.gz frameworks_base-28585cd4e5901acf59fe9c150cddf87bbfe34a58.tar.bz2 |
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
Diffstat (limited to 'packages/SystemUI')
-rw-r--r-- | packages/SystemUI/res/values/cm_strings.xml | 6 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/qs/tiles/HotspotTile.java | 29 |
2 files changed, 34 insertions, 1 deletions
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 @@ <!-- Notification which notifies user flashlight is enabled --> <string name="quick_settings_tile_flashlight_not_title">Flashlight is on</string> <string name="quick_settings_tile_flashlight_not_summary">Tap to turn off</string> + + <!-- Wi-Fi hotspot label when enabled --> + <plurals name="wifi_hotspot_connected_clients_label"> + <item quantity="one">%1$d client</item> + <item quantity="other">%1$d clients</item> + </plurals> </resources> 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<QSTile.BooleanState> { @@ -44,12 +49,15 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> { 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<QSTile.BooleanState> { @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<QSTile.BooleanState> { @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<WifiDevice> 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<QSTile.BooleanState> { 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) { |