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

Commit 04072114 authored by kecinzer's avatar kecinzer Committed by Steve Kondik
Browse files

Battery text mode (1/2)



PS2: Make battery level more fit current solution
PS3: Fix displaing battery level inside the icon
PS6: Show battery level in status bar header when charging and percentage
     mode set to inside icon (it's replaced by charging icon)

Change-Id: I537c99827e78c796b4980ec7751e5f9b58a88251
Signed-off-by: default avatarkecinzer <kecinzer@gmail.com>
parent a8909012
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3108,6 +3108,9 @@ public final class Settings {

        /**
         * Status bar battery %
         * 0: Hide the battery percentage
         * 1: Display the battery percentage inside the icon
         * 2: Display the battery percentage next to the icon
         * @hide
         */
        public static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
+9 −0
Original line number Diff line number Diff line
@@ -85,6 +85,15 @@

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

            <com.android.systemui.BatteryLevelTextView android:id="@+id/battery_level_text"
                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="#ffffff"
                android:visibility="gone"
                android:textSize="@dimen/battery_level_text_size" />

            <com.android.systemui.statusbar.policy.Clock
                android:id="@+id/clock"
                android:textAppearance="@style/TextAppearance.StatusBar.Clock"
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import com.android.systemui.statusbar.policy.BatteryController;

public class BatteryLevelTextView extends TextView implements
        BatteryController.BatteryStateChangeCallback{
    private BatteryController mBatteryController;
    private boolean mShow;

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
            loadShowBatteryTextSetting();
            setVisibility(mShow ? View.VISIBLE : View.GONE);
        }
    };

    public BatteryLevelTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        loadShowBatteryTextSetting();
        setVisibility(mShow ? View.VISIBLE : View.GONE);
    }

    private void loadShowBatteryTextSetting() {
        mShow = 2 == Settings.System.getInt(getContext().getContentResolver(),
                Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
    }

    @Override
    public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
        setText(getResources().getString(R.string.battery_level_template, level));
    }

    public void setBatteryController(BatteryController batteryController) {
        mBatteryController = batteryController;
        mBatteryController.addStateChangedCallback(this);
    }

    @Override
    public void onPowerSaveChanged() {
        // Not used
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                "status_bar_show_battery_percent"), false, mObserver);
    }

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

        if (mBatteryController != null) {
            mBatteryController.removeStateChangedCallback(this);
        }
    }
}
+6 −5
Original line number Diff line number Diff line
@@ -157,8 +157,9 @@ public class BatteryMeterView extends View implements DemoMode,

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
            mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
                getContext().getContentResolver(), Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
            mShowPercent = ENABLE_PERCENT && 1 == Settings.System.getInt(
                    getContext().getContentResolver(),
                    Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
            postInvalidate();
        }
    };
@@ -216,7 +217,7 @@ public class BatteryMeterView extends View implements DemoMode,
        levels.recycle();
        colors.recycle();
        atts.recycle();
        mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
        mShowPercent = ENABLE_PERCENT && 1 == Settings.System.getInt(
                context.getContentResolver(), "status_bar_show_battery_percent", 0);
        mWarningString = context.getString(R.string.battery_meter_very_low_overlay_symbol);
        mCriticalLevel = mContext.getResources().getInteger(
+38 −1
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ package com.android.systemui.statusbar.phone;

import android.animation.LayoutTransition;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
@@ -57,8 +61,23 @@ public class KeyguardStatusBarView extends RelativeLayout
    private int mSystemIconsSwitcherHiddenExpandedMargin;
    private Interpolator mFastOutSlowInInterpolator;

    private boolean mShowBatteryText;

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
            loadShowBatteryTextSetting();
            updateVisibilities();
        }
    };

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

    private void loadShowBatteryTextSetting() {
        mShowBatteryText = 2 == Settings.System.getInt(getContext().getContentResolver(),
                Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
    }

    @Override
@@ -72,6 +91,7 @@ public class KeyguardStatusBarView extends RelativeLayout
        mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(),
                android.R.interpolator.fast_out_slow_in);
        updateUserSwitcher();
        updateVisibilities();
    }

    @Override
@@ -97,7 +117,8 @@ public class KeyguardStatusBarView extends RelativeLayout
        } else if (mMultiUserSwitch.getParent() == this && mKeyguardUserSwitcherShowing) {
            removeView(mMultiUserSwitch);
        }
        mBatteryLevel.setVisibility(mBatteryCharging ? View.VISIBLE : View.GONE);
        mBatteryLevel.setVisibility(
                (mBatteryCharging || mShowBatteryText) ? View.VISIBLE : View.GONE);
    }

    private void updateSystemIconsLayoutParams() {
@@ -233,4 +254,20 @@ public class KeyguardStatusBarView extends RelativeLayout
    public boolean hasOverlappingRendering() {
        return false;
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                "status_bar_show_battery_percent"), false, mObserver);
    }

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

        if (mBatteryController != null) {
            mBatteryController.removeStateChangedCallback(this);
        }
    }
}
Loading