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

Commit 4673c381 authored by Evan Laird's avatar Evan Laird
Browse files

Use QS context when creating the bluetooth battery indicator

SysUI context doesn't know about the dark theme change when trying to
set the tint on the BluetoothDeviceLayerDrawable, so change the icon to
one that isn't cached so it can use the QS context and use the right
tint when in dark mode.

Test: set dark background, visual
Change-Id: If9255e2d2155ebcd355ddf26f06385e73aab68d6
Fixes: 66497162
parent a120e6b6
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.