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

Unverified Commit e608868d authored by tsubus's avatar tsubus Committed by Michael Bestas
Browse files

KeyguardStatusBarView: Fix battery text visibility issues

Change-Id: I8f517ad38f9c225b69eeadffa71efd811a523f78
parent 2dc051f3
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.systemui.BatteryMeterDrawable;
import com.android.systemui.BatteryMeterView;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
@@ -50,6 +51,8 @@ public class KeyguardStatusBarView extends RelativeLayout

    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 boolean mBatteryCharging;
    private boolean mKeyguardUserSwitcherShowing;
@@ -70,6 +73,7 @@ public class KeyguardStatusBarView extends RelativeLayout
    private View mSystemIconsContainer;

    private boolean mShowBatteryText;
    private Boolean mForceBatteryText;

    public KeyguardStatusBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -175,9 +179,13 @@ public class KeyguardStatusBarView extends RelativeLayout
            }
        }

        if (mForceBatteryText != null) {
            mBatteryLevel.setVisibility(mForceBatteryText ? View.VISIBLE : View.GONE);
        } else {
            mBatteryLevel.setVisibility(
                    mBatteryCharging || mShowBatteryText ? View.VISIBLE : View.GONE);
        }
    }

    private void updateSystemIconsLayoutParams() {
        RelativeLayout.LayoutParams lp =
@@ -201,7 +209,8 @@ public class KeyguardStatusBarView extends RelativeLayout
        }
        mBatteryListening = listening;
        if (mBatteryListening) {
            TunerService.get(getContext()).addTunable(this, STATUS_BAR_SHOW_BATTERY_PERCENT);
            TunerService.get(getContext()).addTunable(this,
                    STATUS_BAR_SHOW_BATTERY_PERCENT, STATUS_BAR_BATTERY_STYLE);
            mBatteryController.addStateChangedCallback(this);
        } else {
            mBatteryController.removeStateChangedCallback(this);
@@ -337,9 +346,23 @@ public class KeyguardStatusBarView extends RelativeLayout

    @Override
    public void onTuningChanged(String key, String newValue) {
        if (key.equals(STATUS_BAR_SHOW_BATTERY_PERCENT)) {
            mShowBatteryText = newValue == null ? false : Integer.parseInt(newValue) == 2;
            updateVisibilities();
        switch (key) {
            case STATUS_BAR_SHOW_BATTERY_PERCENT:
                mShowBatteryText = newValue != null && Integer.parseInt(newValue) == 2;
                break;
            case STATUS_BAR_BATTERY_STYLE:
                if (newValue != null) {
                    final int value = Integer.parseInt(newValue);
                    if (value == BatteryMeterDrawable.BATTERY_STYLE_TEXT) {
                        mForceBatteryText = true;
                    } else if (value == BatteryMeterDrawable.BATTERY_STYLE_HIDDEN) {
                        mForceBatteryText = false;
                    } else {
                        mForceBatteryText = null;
                    }
                }
                break;
        }
        updateVisibilities();
    }
}