Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fa7f4259 authored by Evan Laird's avatar Evan Laird Committed by android-build-merger
Browse files

Merge "Use QS context when creating the bluetooth battery indicator" into oc-mr1-dev

am: 69e95006

Change-Id: I55ca66f2cfc3ae91b39548f61825f3647fd88219
parents 83827fc4 69e95006
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.text.TextUtils;
@@ -34,10 +35,8 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settingslib.Utils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.graph.BluetoothDeviceLayerDrawable;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.R.drawable;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.qs.DetailAdapter;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
@@ -135,11 +134,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
                if (lastDevice != null) {
                    int batteryLevel = lastDevice.getBatteryLevel();
                    if (batteryLevel != BluetoothDevice.BATTERY_LEVEL_UNKNOWN) {
                        BluetoothDeviceLayerDrawable drawable = createLayerDrawable(mContext,
                                R.drawable.ic_qs_bluetooth_connected, batteryLevel,
                                mContext.getResources().getFraction(
                                        R.fraction.bt_battery_scale_fraction, 1, 1));
                        state.icon = new DrawableIcon(drawable);
                        state.icon = new BluetoothBatteryDrawable(batteryLevel);
                    }
                }
                state.contentDescription = mContext.getString(
@@ -215,6 +210,22 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
        return new BluetoothDetailAdapter();
    }

    private class BluetoothBatteryDrawable extends Icon {
        private int mLevel;

        BluetoothBatteryDrawable(int level) {
            mLevel = level;
        }

        @Override
        public Drawable getDrawable(Context context) {
            return createLayerDrawable(context,
                    R.drawable.ic_qs_bluetooth_connected, mLevel,
                    context.getResources().getFraction(
                            R.fraction.bt_battery_scale_fraction, 1, 1));
        }
    }

    protected class BluetoothDetailAdapter implements DetailAdapter, QSDetailItems.Callback {
        // We probably won't ever have space in the UI for more than 20 devices, so don't
        // get info for them.