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

Commit 7d30ec36 authored by Zhao Wei Liew's avatar Zhao Wei Liew
Browse files

SystemUI: Implement battery level text customisations

3 options - hidden, show beside, or show inside.

Forward port the battery text-related changes from CM 13.0:
2e0a11bb Forward port battery icon options
738f5a87 SystemUI: Expose values in status bar expanded header
9500061a Themes: Expose hard code for themes in SystemUI

Change-Id: Idec48a3536a3dd529f7dd6076bf33a20cd8020c1
parent e6c5b404
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@
            android:layout_gravity="center_vertical"
            android:layout_marginStart="@dimen/header_battery_margin_keyguard"
            android:paddingEnd="@dimen/battery_level_padding_end"
            android:textColor="#ffffff"
            android:textColor="@color/status_bar_battery_level_text_color"
            android:visibility="gone"
            android:textSize="@dimen/battery_level_text_size"
            android:importantForAccessibility="noHideDescendants"/>
+8 −0
Original line number Diff line number Diff line
@@ -64,6 +64,14 @@

            <include layout="@layout/system_icons" />

            <com.android.systemui.BatteryLevelTextView android:id="@+id/battery_level"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="@dimen/header_battery_margin_keyguard"
                android:textColor="@color/status_bar_battery_level_text_color"
                android:textSize="@dimen/battery_level_text_size" />

            <com.android.systemui.statusbar.policy.Clock
                android:id="@+id/clock"
                android:textAppearance="@style/TextAppearance.StatusBar.Clock"
+2 −0
Original line number Diff line number Diff line
@@ -20,4 +20,6 @@
    <color name="status_bar_temperature_text_color">#FFFFFFFF</color>
    <color name="status_bar_temperature_location_text_color">#FFFFFFFF</color>

    <!-- Status bar battery level text color -->
    <color name="status_bar_battery_level_text_color">#ffffff</color>
</resources>
+79 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014-2016 The CyanogenMod 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.
 */

package com.android.systemui;

import android.content.Context;
import android.icu.text.NumberFormat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.tuner.TunerService;

import cyanogenmod.providers.CMSettings;

public class BatteryLevelTextView extends TextView implements
        BatteryController.BatteryStateChangeCallback, TunerService.Tunable {

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

    private BatteryController mBatteryController;

    public BatteryLevelTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
        setText(NumberFormat.getPercentInstance().format((double) level / 100.0));
    }

    public void setBatteryController(BatteryController batteryController) {
        mBatteryController = batteryController;
        mBatteryController.addStateChangedCallback(this);
        TunerService.get(getContext()).addTunable(this, STATUS_BAR_SHOW_BATTERY_PERCENT);
    }

    @Override
    public void onPowerSaveChanged(boolean isPowerSave) {
        // Unused
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        TunerService.get(getContext()).removeTunable(this);
        if (mBatteryController != null) {
            mBatteryController.removeStateChangedCallback(this);
        }
    }

    @Override
    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);
                break;
            default:
                break;
        }
    }
}
+6 −3
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import android.provider.Settings;

import com.android.systemui.statusbar.policy.BatteryController;

import cyanogenmod.providers.CMSettings;

public class BatteryMeterDrawable extends Drawable implements
        BatteryController.BatteryStateChangeCallback {

@@ -182,7 +184,8 @@ public class BatteryMeterDrawable extends Drawable implements
    public void startListening() {
        mListening = true;
        mContext.getContentResolver().registerContentObserver(
                Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
                CMSettings.System.getUriFor(CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT),
                false, mSettingObserver);
        updateShowPercent();
        mBatteryController.addStateChangedCallback(this);
    }
@@ -266,8 +269,8 @@ public class BatteryMeterDrawable extends Drawable implements
    }

    private void updateShowPercent() {
        mShowPercent = 0 != Settings.System.getInt(mContext.getContentResolver(),
                SHOW_PERCENT_SETTING, 0);
        mShowPercent = CMSettings.System.getInt(mContext.getContentResolver(),
                CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0) == 1;
    }

    private int getColorForLevel(int percent) {
Loading