QuickSettings: Icon updates + BT connecting state.
Bug:15186962
Change-Id: I56de6f3cabcb36b13617d4027323a078cceb9587
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java
index 5a19881..117bf61 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothControllerImpl.java
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.policy;
import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothAdapter.BluetoothStateChangeCallback;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -31,14 +30,13 @@
public class BluetoothControllerImpl extends BroadcastReceiver implements BluetoothController {
private static final String TAG = "StatusBar.BluetoothController";
+ private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
+ private final Set<BluetoothDevice> mBondedDevices = new HashSet<BluetoothDevice>();
private final BluetoothAdapter mAdapter;
- private boolean mEnabled = false;
-
- private Set<BluetoothDevice> mBondedDevices = new HashSet<BluetoothDevice>();
-
- private ArrayList<BluetoothStateChangeCallback> mChangeCallbacks =
- new ArrayList<BluetoothStateChangeCallback>();
+ private boolean mEnabled;
+ private boolean mConnecting;
+ private BluetoothDevice mLastDevice;
public BluetoothControllerImpl(Context context) {
mAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -57,14 +55,14 @@
updateBondedBluetoothDevices();
}
- public void addStateChangedCallback(BluetoothStateChangeCallback cb) {
- mChangeCallbacks.add(cb);
+ public void addStateChangedCallback(Callback cb) {
+ mCallbacks.add(cb);
fireCallback(cb);
}
@Override
- public void removeStateChangedCallback(BluetoothStateChangeCallback cb) {
- mChangeCallbacks.remove(cb);
+ public void removeStateChangedCallback(Callback cb) {
+ mCallbacks.remove(cb);
}
@Override
@@ -79,6 +77,12 @@
}
@Override
+ public boolean isBluetoothConnecting() {
+ return mAdapter != null
+ && mAdapter.getConnectionState() == BluetoothAdapter.STATE_CONNECTING;
+ }
+
+ @Override
public void setBluetoothEnabled(boolean enabled) {
if (mAdapter != null) {
if (enabled) {
@@ -99,6 +103,13 @@
}
@Override
+ public String getLastDeviceName() {
+ return mLastDevice != null ? mLastDevice.getName()
+ : mBondedDevices.size() == 1 ? mBondedDevices.iterator().next().getName()
+ : null;
+ }
+
+ @Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
@@ -106,6 +117,11 @@
handleAdapterStateChange(
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR));
}
+ if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
+ mConnecting = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, -1)
+ == BluetoothAdapter.STATE_CONNECTING;
+ mLastDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ }
fireCallbacks();
updateBondedBluetoothDevices();
}
@@ -131,12 +147,12 @@
}
private void fireCallbacks() {
- for (BluetoothStateChangeCallback cb : mChangeCallbacks) {
+ for (Callback cb : mCallbacks) {
fireCallback(cb);
}
}
- private void fireCallback(BluetoothStateChangeCallback cb) {
- cb.onBluetoothStateChange(mEnabled);
+ private void fireCallback(Callback cb) {
+ cb.onBluetoothStateChange(mEnabled, mConnecting);
}
}