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

Commit 2e0a11bb authored by Danesh M's avatar Danesh M
Browse files

Forward port battery icon options



Squash of following patches from cm-12.1 :

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>

Forward port battery icon options [1/2]

Bring forward the various battery icon options.
Portrait, Landscape, Circle, Text.

Still retains new options for where to display battery percentage text.

Change-Id: Icfc14d989eebde9014538291c24aa76d328df234

Cleanup battery style code

* Cleanup commented out code
* Fix landscape battery icon padding
* Fix landscape battery icon charging indicator
* Fix landscape battery icon percentage indicator
* Fix circle battery frame color on some black backgrounds
* Fix circle battery artifact on low percentage
* Fix percentage not shown while charging
* Fix percentage always showing on expanded status bar
* Fix battery icon showing after reboot on text/hidden modes

Change-Id: Ic56878c26e9a3416149eaaa8a9325d56d664e22e

SystemUI : Make BatteryMeterView multi-user compatible

Change-Id: Ib9a266dc74732b7ad328a6503898a8fbc46af58e

Clean up battery handling.

Use a single observer for all battery meter and level views, and remove
no-longer used callback registrations.

Change-Id: I8f9db5e484628d7fbc74fe892d64bef5f08cea24

SystemUI: Fix blinking when reported battery level is 0

Canvas::drawArc has a bug where, if the sweepAngle is 0,
depending on the startAngle it will draw an empty or full
circle. In the rare cases where the battery reports 0%
this would cause the circular meter to blink furiously
as it animates through several values of startAngle.

As a workaround, let's avoid drawing the percentage bar
if the reported battery level is zero.

Change-Id: I4c1c767f3616c9d2f8a60df63d64ec1f4e266583

SystemUI: improve circle battery

While plugged in, the circle animation would cause the statusbar to
keep redrawing itself repeatedly, using up unnecessary cpu cycles,
even when idle.

- Removed circle animation in status bar
- Left animations on keyguard/notificaiton header
- Set layer type to hardware when animating for optimized quick drawing
- Cleaned up some logic and unnecessary locking
- Removed extra work done in each draw
- override onDraw instead of draw to let the View system decide when we
  should draw

Change-Id: If0624ab6e3723f4522ebbd9ce583b142c1cb4606
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 7af5d09d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@
            >
            <include layout="@layout/system_icons" />
        </FrameLayout>
        <TextView android:id="@+id/battery_level"
        <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"
+8 −0
Original line number Diff line number Diff line
@@ -95,6 +95,14 @@

            <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:textSize="@dimen/battery_level_text_size" />

            <com.android.systemui.statusbar.policy.Clock
                android:id="@+id/clock"
                android:textAppearance="@style/TextAppearance.StatusBar.Clock"
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@
            >
            <include layout="@layout/system_icons" />
        </FrameLayout>
        <TextView android:id="@+id/battery_level"
        <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"
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2012-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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <array name="batterymeter_inverted_bolt_points" translatable="false">
        <item>743</item><item>73</item>
        <item>743</item><item>292</item>
        <item>442</item><item>201</item>
        <item>442</item><item>400</item>
        <item>0</item><item>20</item>
        <item>369</item><item>157</item>
        <item>369</item><item>0</item>
    </array>
</resources>
+129 −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 com.android.systemui.statusbar.policy.BatteryController;

import android.content.Context;
import android.content.res.Configuration;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;

import java.text.NumberFormat;

public class BatteryLevelTextView extends TextView implements
        BatteryController.BatteryStateChangeCallback{
    private BatteryController mBatteryController;
    private boolean mBatteryCharging;
    private boolean mForceShow;
    private boolean mAttached;
    private int mRequestedVisibility;
    private int mStyle;
    private int mPercentMode;

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

    public void setForceShown(boolean forceShow) {
        mForceShow = forceShow;
        updateVisibility();
    }

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

    @Override
    public void setVisibility(int visibility) {
        mRequestedVisibility = visibility;
        updateVisibility();
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Respect font size setting.
        setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(R.dimen.battery_level_text_size));
    }

    @Override
    public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
        String percentage = NumberFormat.getPercentInstance().format((double) level / 100.0);
        setText(percentage);
        if (mBatteryCharging != charging) {
            mBatteryCharging = charging;
            updateVisibility();
        }
    }

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

    @Override
    public void onBatteryStyleChanged(int style, int percentMode) {
        mStyle = style;
        mPercentMode = percentMode;
        updateVisibility();
    }

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

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

        mAttached = true;
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mAttached = false;

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

    private void updateVisibility() {
        boolean showNextPercent = mPercentMode == BatteryController.PERCENTAGE_MODE_OUTSIDE
                || (mBatteryCharging && mPercentMode == BatteryController.PERCENTAGE_MODE_INSIDE);
        if (mStyle == BatteryController.STYLE_GONE) {
            showNextPercent = false;
        } else if (mStyle == BatteryController.STYLE_TEXT) {
            showNextPercent = true;
        }

        if (showNextPercent || mForceShow) {
            super.setVisibility(mRequestedVisibility);
        } else {
            super.setVisibility(GONE);
        }
    }
}
Loading