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

Commit 62d3af8b authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Gerrit Code Review
Browse files

Merge "Framework: Add option to always show battery status on lockscreen (1/2)" into jellybean

parents 4f6bc910 4d4a1224
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -2642,6 +2642,12 @@ public final class Settings {
         */
        public static final String LOCKSCREEN_CALENDAR_REMINDERS_ONLY = "lockscreen_calendar_reminders_only";

        /**
         * Always show the battery status on the lockscreen
         * @hide
         */
        public static final String LOCKSCREEN_ALWAYS_SHOW_BATTERY = "lockscreen_always_show_battery";

        /**
         * Show the pending notification counts as overlays on the status bar
         * @hide
@@ -2733,6 +2739,7 @@ public final class Settings {
            QUIET_HOURS_MUTE,
            QUIET_HOURS_STILL,
            QUIET_HOURS_DIM,
            LOCKSCREEN_ALWAYS_SHOW_BATTERY,
        };

        // Settings moved to Settings.Secure
+3 −0
Original line number Diff line number Diff line
@@ -3834,4 +3834,7 @@
  <java-symbol type="string" name="second" />
  <java-symbol type="string" name="seconds" />

  <!-- Lock screen always show battery -->
  <java-symbol type="string" name="lockscreen_discharging" />

</resources>
+4 −3
Original line number Diff line number Diff line
@@ -1979,15 +1979,16 @@
    <!-- When the lock screen is showing and the phone plugged in, and the battery
         is not fully charged, show the current charge %.  -->
    <string name="lockscreen_plugged_in">Charging, <xliff:g id="number">%d</xliff:g><xliff:g id="percent">%%</xliff:g></string>
    <string name="lockscreen_discharging">Discharging, <xliff:g id="number">%d</xliff:g><xliff:g id="percent">%%</xliff:g></string>
    <!-- When the lock screen is showing, the phone is plugged in and the battery is fully
         charged, say that it is charged. -->
    <string name="lockscreen_charged">Charged.</string>
    <string name="lockscreen_charged">Charged</string>
    <!-- A short representation of charging information, e.g "34%" -->
    <string name="lockscreen_battery_short"><xliff:g id="number">%d</xliff:g><xliff:g id="percent">%%</xliff:g></string>

    <!-- When the lock screen is showing and the battery is low, warn user to plug
         in the phone soon. -->
    <string name="lockscreen_low_battery">Connect your charger.</string>
         in the phone soon and show current percentage. -->
    <string name="lockscreen_low_battery">Connect your charger, <xliff:g id="number">%d</xliff:g><xliff:g id="percent">%%</xliff:g></string>

    <!-- Shown in the lock screen when there is no SIM card. -->
    <string name="lockscreen_missing_sim_message_short">No SIM card.</string>
+15 −2
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ class KeyguardStatusViewManager implements OnClickListener {
    public static final int LOCK_ICON = 0; // R.drawable.ic_lock_idle_lock;
    public static final int ALARM_ICON = R.drawable.ic_lock_idle_alarm;
    public static final int CHARGING_ICON = 0; //R.drawable.ic_lock_idle_charging;
    public static final int DISCHARGING_ICON = 0; // no icon used in ics+ currently
    public static final int BATTERY_LOW_ICON = 0; //R.drawable.ic_lock_idle_low_battery;
    private static final long INSTRUCTION_RESET_DELAY = 2000; // time until instruction text resets

@@ -121,6 +122,9 @@ class KeyguardStatusViewManager implements OnClickListener {
    // last known battery level
    private int mBatteryLevel = 100;

    // always show battery status?
    private boolean mAlwaysShowBattery = false;

    // last known SIM state
    protected State mSimState;

@@ -675,6 +679,7 @@ class KeyguardStatusViewManager implements OnClickListener {
        mShowingBatteryInfo = mUpdateMonitor.shouldShowBatteryInfo();
        mPluggedIn = mUpdateMonitor.isDevicePluggedIn();
        mBatteryLevel = mUpdateMonitor.getBatteryLevel();
        mAlwaysShowBattery = KeyguardUpdateMonitor.shouldAlwaysShowBatteryInfo(getContext());
        updateStatusLines(true);
    }

@@ -748,8 +753,12 @@ class KeyguardStatusViewManager implements OnClickListener {
                icon.value = CHARGING_ICON;
            } else if (mBatteryLevel < KeyguardUpdateMonitor.LOW_BATTERY_THRESHOLD) {
                // Battery is low
                string = getContext().getString(R.string.lockscreen_low_battery);
                string = getContext().getString(R.string.lockscreen_low_battery, mBatteryLevel);
                icon.value = BATTERY_LOW_ICON;
            } else if (mAlwaysShowBattery) {
                // Discharging
                string = getContext().getString(R.string.lockscreen_discharging, mBatteryLevel);
                icon.value = DISCHARGING_ICON;
            }
        } else {
            string = mCarrierText;
@@ -775,8 +784,12 @@ class KeyguardStatusViewManager implements OnClickListener {
                icon.value = CHARGING_ICON;
            } else if (mBatteryLevel < KeyguardUpdateMonitor.LOW_BATTERY_THRESHOLD) {
                // Battery is low
                string = getContext().getString(R.string.lockscreen_low_battery);
                string = getContext().getString(R.string.lockscreen_low_battery, mBatteryLevel);
                icon.value = BATTERY_LOW_ICON;
            } else if (mAlwaysShowBattery) {
                // Discharging
                string = getContext().getString(R.string.lockscreen_discharging, mBatteryLevel);
                icon.value = DISCHARGING_ICON;
            }
        } else if (!inWidgetMode() && mOwnerInfoView == null && mOwnerInfoText != null) {
            // OwnerInfo shows in status if we don't have a dedicated widget
+11 −5
Original line number Diff line number Diff line
@@ -378,7 +378,7 @@ public class KeyguardUpdateMonitor {
    private void handleBatteryUpdate(BatteryStatus batteryStatus) {
        if (DEBUG) Log.d(TAG, "handleBatteryUpdate");
        final boolean batteryUpdateInteresting =
                isBatteryUpdateInteresting(mBatteryStatus, batteryStatus);
                isBatteryUpdateInteresting(mBatteryStatus, batteryStatus, mContext);
        mBatteryStatus = batteryStatus;
        if (batteryUpdateInteresting) {
            for (int i = 0; i < mInfoCallbacks.size(); i++) {
@@ -437,7 +437,7 @@ public class KeyguardUpdateMonitor {
                || status.plugged == BatteryManager.BATTERY_PLUGGED_USB;
    }

    private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) {
    private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current, Context context) {
        final boolean nowPluggedIn = isPluggedIn(current);
        final boolean wasPluggedIn = isPluggedIn(old);
        final boolean stateChangedWhilePluggedIn =
@@ -449,8 +449,8 @@ public class KeyguardUpdateMonitor {
            return true;
        }

        // change in battery level while plugged in
        if (nowPluggedIn && old.level != current.level) {
        // change in battery level while plugged in or always interested
        if ((nowPluggedIn || shouldAlwaysShowBatteryInfo(context)) && old.level != current.level) {
            return true;
        }

@@ -676,7 +676,13 @@ public class KeyguardUpdateMonitor {
    }

    public boolean shouldShowBatteryInfo() {
        return isPluggedIn(mBatteryStatus) || isBatteryLow(mBatteryStatus);
        return isPluggedIn(mBatteryStatus) || isBatteryLow(mBatteryStatus)
                       || shouldAlwaysShowBatteryInfo(mContext);
    }

    public static boolean shouldAlwaysShowBatteryInfo(Context context) {
        return Settings.System.getInt(context.getContentResolver(),
                       Settings.System.LOCKSCREEN_ALWAYS_SHOW_BATTERY, 0) == 1;
    }

    public CharSequence getTelephonyPlmn() {