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

Commit bdf67f63 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix battery icon showing in QQS when it shouldn't"

parents 7796107b 698839be
Loading
Loading
Loading
Loading
+43 −3
Original line number Diff line number Diff line
@@ -88,6 +88,9 @@ public class BatteryMeterView extends LinearLayout implements
    private int mShowPercentMode = MODE_DEFAULT;
    private boolean mForceShowPercent;
    private boolean mShowPercentAvailable;
    // Some places may need to show the battery conditionally, and not obey the tuner
    private boolean mIgnoreTunerUpdates;
    private boolean mIsSubscribedForTunerUpdates;

    private int mDarkModeBackgroundColor;
    private int mDarkModeFillColor;
@@ -182,6 +185,44 @@ public class BatteryMeterView extends LinearLayout implements
        updateShowPercent();
    }

    /**
     * Set {@code true} to turn off BatteryMeterView's subscribing to the tuner for updates, and
     * thus avoid it controlling its own visibility
     *
     * @param ignore whether to ignore the tuner or not
     */
    public void setIgnoreTunerUpdates(boolean ignore) {
        mIgnoreTunerUpdates = ignore;
        updateTunerSubscription();
    }

    private void updateTunerSubscription() {
        if (mIgnoreTunerUpdates) {
            unsubscribeFromTunerUpdates();
        } else {
            subscribeForTunerUpdates();
        }
    }

    private void subscribeForTunerUpdates() {
        if (mIsSubscribedForTunerUpdates || mIgnoreTunerUpdates) {
            return;
        }

        Dependency.get(TunerService.class)
                .addTunable(this, StatusBarIconController.ICON_BLACKLIST);
        mIsSubscribedForTunerUpdates = true;
    }

    private void unsubscribeFromTunerUpdates() {
        if (!mIsSubscribedForTunerUpdates) {
            return;
        }

        Dependency.get(TunerService.class).removeTunable(this);
        mIsSubscribedForTunerUpdates = false;
    }

    /**
     * Sets whether the battery meter view uses the wallpaperTextColor. If we're not using it, we'll
     * revert back to dark-mode-based/tinted colors.
@@ -247,8 +288,7 @@ public class BatteryMeterView extends LinearLayout implements
        getContext().getContentResolver().registerContentObserver(
                Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser);
        updateShowPercent();
        Dependency.get(TunerService.class)
                .addTunable(this, StatusBarIconController.ICON_BLACKLIST);
        subscribeForTunerUpdates();
        Dependency.get(ConfigurationController.class).addCallback(this);
        mUserTracker.startTracking();
    }
@@ -259,7 +299,7 @@ public class BatteryMeterView extends LinearLayout implements
        mUserTracker.stopTracking();
        mBatteryController.removeCallback(this);
        getContext().getContentResolver().unregisterContentObserver(mSettingObserver);
        Dependency.get(TunerService.class).removeTunable(this);
        unsubscribeFromTunerUpdates();
        Dependency.get(ConfigurationController.class).removeCallback(this);
    }

+2 −0
Original line number Diff line number Diff line
@@ -232,6 +232,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements
        // Tint for the battery icons are handled in setupHost()
        mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon);
        mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_OFF);
        // Don't need to worry about tuner settings for this icon
        mBatteryRemainingIcon.setIgnoreTunerUpdates(true);

        mBatteryRemainingText = findViewById(R.id.batteryRemainingText);
        mBatteryRemainingText.setTextColor(fillColor);