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

Unverified Commit a4f56010 authored by Zhao Wei Liew's avatar Zhao Wei Liew Committed by Michael Bestas
Browse files

SystemUI: Implement hidden and text battery styles

Forward port the hidden and text battery styles from CM 13.0:
2e0a11bb Forward port battery icon options

Change-Id: I30d95edf9c6fe6afb343aff5effe132f94c49eeb
parent 8ae9c686
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@
    android:layout_width="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:paddingEnd="@dimen/signal_cluster_battery_padding"
    >
    <ImageView
        android:id="@+id/vpn"
+23 −3
Original line number Diff line number Diff line
@@ -32,9 +32,13 @@ public class BatteryLevelTextView extends TextView implements

    private static final String STATUS_BAR_SHOW_BATTERY_PERCENT =
            "cmsystem:" + CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT;
    private static final String STATUS_BAR_BATTERY_STYLE =
            "cmsystem:" + CMSettings.System.STATUS_BAR_BATTERY_STYLE;

    private BatteryController mBatteryController;

    private boolean mRequestedVisibility;

    public BatteryLevelTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
@@ -47,7 +51,8 @@ public class BatteryLevelTextView extends TextView implements
    public void setBatteryController(BatteryController batteryController) {
        mBatteryController = batteryController;
        mBatteryController.addStateChangedCallback(this);
        TunerService.get(getContext()).addTunable(this, STATUS_BAR_SHOW_BATTERY_PERCENT);
        TunerService.get(getContext()).addTunable(this,
                STATUS_BAR_SHOW_BATTERY_PERCENT, STATUS_BAR_BATTERY_STYLE);
    }

    @Override
@@ -69,8 +74,23 @@ public class BatteryLevelTextView extends TextView implements
    public void onTuningChanged(String key, String newValue) {
        switch (key) {
            case STATUS_BAR_SHOW_BATTERY_PERCENT:
                setVisibility(newValue != null && Integer.parseInt(newValue) == 2 ?
                        View.VISIBLE : View.GONE);
                mRequestedVisibility = newValue != null && Integer.parseInt(newValue) == 2;
                setVisibility(mRequestedVisibility ? View.VISIBLE : View.GONE);
                break;
            case STATUS_BAR_BATTERY_STYLE:
                final int value = newValue == null ?
                        BatteryMeterDrawable.BATTERY_STYLE_PORTRAIT : Integer.parseInt(newValue);
                switch (value) {
                    case BatteryMeterDrawable.BATTERY_STYLE_TEXT:
                        setVisibility(View.VISIBLE);
                        break;
                    case BatteryMeterDrawable.BATTERY_STYLE_HIDDEN:
                        setVisibility(View.GONE);
                        break;
                    default:
                        setVisibility(mRequestedVisibility ? View.VISIBLE : View.GONE);
                        break;
                }
                break;
            default:
                break;
+7 −0
Original line number Diff line number Diff line
@@ -52,6 +52,13 @@ public class BatteryMeterDrawable extends Drawable implements

    private static final float BOLT_LEVEL_THRESHOLD = 0.3f;  // opaque bolt below this fraction

    // Values for the different battery styles
    public static final int BATTERY_STYLE_PORTRAIT  = 0;
    public static final int BATTERY_STYLE_CIRCLE    = 2;
    public static final int BATTERY_STYLE_HIDDEN    = 4;
    public static final int BATTERY_STYLE_LANDSCAPE = 5;
    public static final int BATTERY_STYLE_TEXT      = 6;

    private final int[] mColors;
    private final int mIntrinsicWidth;
    private final int mIntrinsicHeight;
+41 −2
Original line number Diff line number Diff line
@@ -29,13 +29,21 @@ import com.android.systemui.statusbar.phone.StatusBarIconController;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;

import cyanogenmod.providers.CMSettings;

public class BatteryMeterView extends ImageView implements
        BatteryController.BatteryStateChangeCallback, TunerService.Tunable {

    private final BatteryMeterDrawable mDrawable;
    private static final String STATUS_BAR_BATTERY_STYLE =
            "cmsystem:" + CMSettings.System.STATUS_BAR_BATTERY_STYLE;

    private BatteryMeterDrawable mDrawable;
    private final String mSlotBattery;
    private BatteryController mBatteryController;

    private final Context mContext;
    private final int mFrameColor;

    public BatteryMeterView(Context context) {
        this(context, null, 0);
    }
@@ -57,6 +65,9 @@ public class BatteryMeterView extends ImageView implements
        mSlotBattery = context.getString(
                com.android.internal.R.string.status_bar_battery);
        setImageDrawable(mDrawable);

        mContext = context;
        mFrameColor = frameColor;
    }

    @Override
@@ -69,6 +80,8 @@ public class BatteryMeterView extends ImageView implements
        if (StatusBarIconController.ICON_BLACKLIST.equals(key)) {
            ArraySet<String> icons = StatusBarIconController.getIconBlacklist(newValue);
            setVisibility(icons.contains(mSlotBattery) ? View.GONE : View.VISIBLE);
        } else if (STATUS_BAR_BATTERY_STYLE.equals(key)) {
            updateBatteryStyle(newValue);
        }
    }

@@ -77,7 +90,8 @@ public class BatteryMeterView extends ImageView implements
        super.onAttachedToWindow();
        mBatteryController.addStateChangedCallback(this);
        mDrawable.startListening();
        TunerService.get(getContext()).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
        TunerService.get(getContext()).addTunable(this, StatusBarIconController.ICON_BLACKLIST,
                STATUS_BAR_BATTERY_STYLE);
    }

    @Override
@@ -108,4 +122,29 @@ public class BatteryMeterView extends ImageView implements
    public void setDarkIntensity(float f) {
        mDrawable.setDarkIntensity(f);
    }

    private void updateBatteryStyle(String styleStr) {
        final int style = styleStr == null ?
                BatteryMeterDrawable.BATTERY_STYLE_PORTRAIT : Integer.parseInt(styleStr);

        switch (style) {
            case BatteryMeterDrawable.BATTERY_STYLE_TEXT:
            case BatteryMeterDrawable.BATTERY_STYLE_HIDDEN:
                setVisibility(View.GONE);
                setImageDrawable(null);
                break;
            default:
                mDrawable = new BatteryMeterDrawable(mContext, new Handler(), mFrameColor);
                setImageDrawable(mDrawable);
                setVisibility(View.VISIBLE);
                break;
        }
        restoreDrawableAttributes();
        requestLayout();
    }

    private void restoreDrawableAttributes() {
        mDrawable.setBatteryController(mBatteryController);
        mDrawable.startListening();
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -635,10 +635,6 @@ public class SignalClusterView
            }
        }
        mNoSimsCombo.setVisibility(mNoSimsVisible ? View.VISIBLE : View.GONE);

        boolean anythingVisible = mNoSimsVisible || mWifiVisible || mIsAirplaneMode
                || anyMobileVisible || mVpnVisible || mEthernetVisible;
        setPaddingRelative(0, 0, anythingVisible ? mEndPadding : mEndPaddingNothingVisible, 0);
    }

    /**
Loading