diff options
author | Gavin Ni <gisngy@gmail.com> | 2016-07-16 15:26:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-08-04 23:41:56 -0700 |
commit | 88e7a6c7fcaf71d6dae2b9067db19aaeba7de39b (patch) | |
tree | bc395e7e02954dc008dba5497ccc45ff98c10c02 /packages | |
parent | d59f3670cf1979008532d8e8fa299f18954141e2 (diff) | |
download | frameworks_base-88e7a6c7fcaf71d6dae2b9067db19aaeba7de39b.zip frameworks_base-88e7a6c7fcaf71d6dae2b9067db19aaeba7de39b.tar.gz frameworks_base-88e7a6c7fcaf71d6dae2b9067db19aaeba7de39b.tar.bz2 |
SystemUI: Display bluetooth battery status when available
Change-Id: I659e6270058d02fdd894b8242a6375b1a13237df
Diffstat (limited to 'packages')
6 files changed, 199 insertions, 1 deletions
diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml new file mode 100644 index 0000000..3a4ee98 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_1.xml @@ -0,0 +1,28 @@ +<!-- +Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="17dp" + android:viewportWidth="56.0" + android:viewportHeight="48.0"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M14.0,24.0l-4.0,-4.0l-4.0,4.0l4.0,4.0L14.0,24.0zM35.4,15.4L24.0,4.0l-2.0,0.0l0.0,15.2L12.8,10.0L10.0,12.8L21.2,24.0L10.0,35.2l2.8,2.8l9.2,-9.2L22.0,44.0l2.0,0.0l11.4,-11.4L26.8,24.0L35.4,15.4zM26.0,11.7l3.8,3.8L26.0,19.2L26.0,11.7zM29.8,32.6L26.0,36.3l0.0,-7.5L29.8,32.6zM38.0,20.0l-4.0,4.0l4.0,4.0l4.0,-4.0L38.0,20.0z"/> + <path + android:fillColor="#4DFFFFFF" + android:pathData="M44,4V44h8V4h-8z"/> +</vector> diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml new file mode 100644 index 0000000..3a01881 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_2.xml @@ -0,0 +1,31 @@ +<!-- +Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="17dp" + android:viewportWidth="56.0" + android:viewportHeight="48.0"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M14.0,24.0l-4.0,-4.0l-4.0,4.0l4.0,4.0L14.0,24.0zM35.4,15.4L24.0,4.0l-2.0,0.0l0.0,15.2L12.8,10.0L10.0,12.8L21.2,24.0L10.0,35.2l2.8,2.8l9.2,-9.2L22.0,44.0l2.0,0.0l11.4,-11.4L26.8,24.0L35.4,15.4zM26.0,11.7l3.8,3.8L26.0,19.2L26.0,11.7zM29.8,32.6L26.0,36.3l0.0,-7.5L29.8,32.6zM38.0,20.0l-4.0,4.0l4.0,4.0l4.0,-4.0L38.0,20.0z"/> + <path + android:fillColor="#4DFFFFFF" + android:pathData="M44,4V44h8V4h-8z"/> + <path + android:fillColor="#FFFFFF" + android:pathData="M44,34V44h8V34h-8z"/> +</vector> diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml new file mode 100644 index 0000000..9639d28 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_3.xml @@ -0,0 +1,31 @@ +<!-- +Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="17dp" + android:viewportWidth="56.0" + android:viewportHeight="48.0"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M14.0,24.0l-4.0,-4.0l-4.0,4.0l4.0,4.0L14.0,24.0zM35.4,15.4L24.0,4.0l-2.0,0.0l0.0,15.2L12.8,10.0L10.0,12.8L21.2,24.0L10.0,35.2l2.8,2.8l9.2,-9.2L22.0,44.0l2.0,0.0l11.4,-11.4L26.8,24.0L35.4,15.4zM26.0,11.7l3.8,3.8L26.0,19.2L26.0,11.7zM29.8,32.6L26.0,36.3l0.0,-7.5L29.8,32.6zM38.0,20.0l-4.0,4.0l4.0,4.0l4.0,-4.0L38.0,20.0z"/> + <path + android:fillColor="#4DFFFFFF" + android:pathData="M44,4V44h8V4h-8z"/> + <path + android:fillColor="#FFFFFF" + android:pathData="M44,24V44h8V24h-8z"/> +</vector> diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml new file mode 100644 index 0000000..1e8ac10 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_4.xml @@ -0,0 +1,31 @@ +<!-- +Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="17dp" + android:viewportWidth="56.0" + android:viewportHeight="48.0"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M14.0,24.0l-4.0,-4.0l-4.0,4.0l4.0,4.0L14.0,24.0zM35.4,15.4L24.0,4.0l-2.0,0.0l0.0,15.2L12.8,10.0L10.0,12.8L21.2,24.0L10.0,35.2l2.8,2.8l9.2,-9.2L22.0,44.0l2.0,0.0l11.4,-11.4L26.8,24.0L35.4,15.4zM26.0,11.7l3.8,3.8L26.0,19.2L26.0,11.7zM29.8,32.6L26.0,36.3l0.0,-7.5L29.8,32.6zM38.0,20.0l-4.0,4.0l4.0,4.0l4.0,-4.0L38.0,20.0z"/> + <path + android:fillColor="#4DFFFFFF" + android:pathData="M44,4V44h8V4h-8z"/> + <path + android:fillColor="#FFFFFF" + android:pathData="M44,14V44h8V14h-8z"/> +</vector> diff --git a/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml new file mode 100644 index 0000000..7464bec --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_data_bluetooth_connected_battery_5.xml @@ -0,0 +1,31 @@ +<!-- +Copyright (C) 2014 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="17dp" + android:viewportWidth="56.0" + android:viewportHeight="48.0"> + + <path + android:fillColor="#FFFFFF" + android:pathData="M14.0,24.0l-4.0,-4.0l-4.0,4.0l4.0,4.0L14.0,24.0zM35.4,15.4L24.0,4.0l-2.0,0.0l0.0,15.2L12.8,10.0L10.0,12.8L21.2,24.0L10.0,35.2l2.8,2.8l9.2,-9.2L22.0,44.0l2.0,0.0l11.4,-11.4L26.8,24.0L35.4,15.4zM26.0,11.7l3.8,3.8L26.0,19.2L26.0,11.7zM29.8,32.6L26.0,36.3l0.0,-7.5L29.8,32.6zM38.0,20.0l-4.0,4.0l4.0,4.0l4.0,-4.0L38.0,20.0z"/> + <path + android:fillColor="#4DFFFFFF" + android:pathData="M44,4V44h8V4h-8z"/> + <path + android:fillColor="#FFFFFF" + android:pathData="M44,4V44h8V4h-8z"/> +</vector> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index 0e71bee..1395ff6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -22,6 +22,8 @@ import android.app.AlarmManager.AlarmClockInfo; import android.app.IUserSwitchObserver; import android.app.PendingIntent; import android.app.StatusBarManager; +import android.bluetooth.BluetoothAssignedNumbers; +import android.bluetooth.BluetoothHeadset; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -103,6 +105,7 @@ public class PhoneStatusBarPolicy implements Callback { private boolean mZenVisible; private boolean mVolumeVisible; private boolean mCurrentUserSetup; + private Float mBluetoothBatteryLevel = null; private int mZen; @@ -129,6 +132,9 @@ public class PhoneStatusBarPolicy implements Callback { else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { updateTTY(intent); } + else if (action.equals(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT)) { + updateBluetoothBattery(intent); + } } }; @@ -166,6 +172,9 @@ public class PhoneStatusBarPolicy implements Callback { filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); + filter.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT); + filter.addCategory(BluetoothHeadset.VENDOR_SPECIFIC_HEADSET_EVENT_COMPANY_ID_CATEGORY + + "." + Integer.toString(BluetoothAssignedNumbers.APPLE)); mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); // listen for user / profile change. @@ -357,6 +366,27 @@ public class PhoneStatusBarPolicy implements Callback { updateBluetooth(); } + private void updateBluetoothBattery(Intent intent) { + if (intent.hasExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD)) { + String command = intent.getStringExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD); + if ("+IPHONEACCEV".equals(command)) { + Object[] args = (Object[]) intent.getSerializableExtra(BluetoothHeadset.EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS); + if (args.length >= 3 && args[0] instanceof Integer && ((Integer)args[0])*2+1<=args.length) { + for (int i=0;i<((Integer)args[0]);i++) { + if (!(args[i*2+1] instanceof Integer) || !(args[i*2+2] instanceof Integer)) { + continue; + } + if (args[i*2+1].equals(1)) { + mBluetoothBatteryLevel = (((Integer)args[i*2+2])+1)/10.0f; + updateBluetooth(); + break; + } + } + } + } + } + } + private final void updateBluetooth() { int iconId = R.drawable.stat_sys_data_bluetooth; String contentDescription = @@ -365,8 +395,24 @@ public class PhoneStatusBarPolicy implements Callback { if (mBluetooth != null) { bluetoothEnabled = mBluetooth.isBluetoothEnabled(); if (mBluetooth.isBluetoothConnected()) { - iconId = R.drawable.stat_sys_data_bluetooth_connected; + if (mBluetoothBatteryLevel == null) { + iconId = R.drawable.stat_sys_data_bluetooth_connected; + } else { + if (mBluetoothBatteryLevel<=0.15f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_1; + } else if (mBluetoothBatteryLevel<=0.375f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_2; + } else if (mBluetoothBatteryLevel<=0.625f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_3; + } else if (mBluetoothBatteryLevel<=0.85f) { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_4; + } else { + iconId = R.drawable.stat_sys_data_bluetooth_connected_battery_5; + } + } contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected); + } else { + mBluetoothBatteryLevel = null; } } |