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

Commit 3a5f2e4b authored by Steve Kondik's avatar Steve Kondik
Browse files

Battery percentage patch from canadiancow.

parent 845d5337
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -13,6 +13,11 @@ public class IconData {
     */
    public static final int ICON = 2;

    /**
       * Indicates ths item represents an integer displayed on top of an icon.
       */
    public static final int ICON_NUMBER = 3;

    /**
     * The type of this item. One of TEXT, ICON, or LEVEL_ICON.
     */
@@ -72,6 +77,18 @@ public class IconData {
        return data;
    }

    public static IconData makeIconNumber(String slot,
            String iconPackage, int iconId, int iconLevel, int number) {
        IconData data = new IconData();
        data.type = ICON_NUMBER;
        data.slot = slot;
        data.iconPackage = iconPackage;
        data.iconId = iconId;
        data.iconLevel = iconLevel;
        data.number = number;
        return data;
    }

    public void copyFrom(IconData that) {
        this.type = that.type;
        this.slot = that.slot;
@@ -99,6 +116,13 @@ public class IconData {
                    + " iconId=" + Integer.toHexString(this.iconId)
                    + " iconLevel=" + this.iconLevel + ")"; 
        }
        else if (this.type == ICON_NUMBER) {
            return "IconData(slot=" + (this.slot != null ? "'" + this.slot + "'" : "null")
                    + " package=" + this.iconPackage
                    + " iconId=" + Integer.toHexString(this.iconId)
                    + " iconLevel=" + this.iconLevel
                    + " number='" + this.number + "')"; 
        }
        else {
            return "IconData(type=" + type + ")";
        }
+35 −0
Original line number Diff line number Diff line
@@ -77,6 +77,40 @@ class StatusBarIcon {
                }
                break;
            }

            case IconData.ICON_NUMBER: {
                // container
                LayoutInflater inflater = (LayoutInflater)context.getSystemService(
                                                Context.LAYOUT_INFLATER_SERVICE);
                View v = inflater.inflate(com.android.internal.R.layout.status_bar_icon, parent, false);
                this.view = v;

                // icon
                AnimatedImageView im = (AnimatedImageView)v.findViewById(com.android.internal.R.id.image);
                im.setImageDrawable(getIcon(context, data));
                im.setImageLevel(data.iconLevel);
                mImageView = im;

                // number
                TextView nv = (TextView)v.findViewById(com.android.internal.R.id.number);
                mNumberView = nv;

                //remove background, center, and change gravity of text
                mNumberView.setLayoutParams(
                    new FrameLayout.LayoutParams(
                        FrameLayout.LayoutParams.WRAP_CONTENT,
                        FrameLayout.LayoutParams.WRAP_CONTENT,
                        Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL));
                mNumberView.setBackgroundDrawable(null);
                mNumberView.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

                if (data.number > 0) {
                    nv.setText("" + data.number);
                } else {
                    nv.setText("");
                }
                break;
            }
        }
    }

@@ -92,6 +126,7 @@ class StatusBarIcon {
            }
            break;
        case IconData.ICON:
        case IconData.ICON_NUMBER:
            if (((mData.iconPackage != null && data.iconPackage != null)
                        && !mData.iconPackage.equals(data.iconPackage))
                    || mData.iconId != data.iconId
+11 −2
Original line number Diff line number Diff line
@@ -402,7 +402,7 @@ public class StatusBarPolicy {
        updateClock();

        // battery
        mBatteryData = IconData.makeIcon("battery",
        mBatteryData = IconData.makeIconNumber("battery",
                null, com.android.internal.R.drawable.stat_sys_battery_unknown, 0, 0);
        mBatteryIcon = service.addIcon(mBatteryData, null);

@@ -555,10 +555,19 @@ public class StatusBarPolicy {
    private final void updateBattery(Intent intent) {
        mBatteryData.iconId = intent.getIntExtra("icon-small", 0);
        mBatteryData.iconLevel = intent.getIntExtra("level", 0);
        mService.updateIcon(mBatteryIcon, mBatteryData, null);

        boolean plugged = intent.getIntExtra("plugged", 0) != 0;
        int level = intent.getIntExtra("level", -1);

        //show battery percentage if not plugged in
        if (plugged) {
            mBatteryData.number = -1;
        } else {
            mBatteryData.number = level;
        }

        mService.updateIcon(mBatteryIcon, mBatteryData, null);

        if (false) {
            Log.d(TAG, "updateBattery level=" + level
                    + " plugged=" + plugged