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

Commit e38e104a authored by blunden's avatar blunden Committed by DvTonder
Browse files

Settings: Add option to always show battery status on lockscreen (2/2)

Based on the feature by burnsra in CM7
Authored by blunden
Tweaked by dvtonder
Change-Id: I1c8c8eef3d0c913c621f735e7d5e395c8768fe76

lockscreen battery status: add off option (1/2)
Change-Id: I06dd1b81826bdb1c1e35b72d99970f97dcad1a34
parent 45a662d0
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -105,6 +105,18 @@
        <item>1800000</item>
    </string-array>

    <string-array name="lockscreen_battery_status_entries" translatable="false">
        <item>@string/lockscreen_battery_status_charging</item>
        <item>@string/lockscreen_battery_status_alwayson</item>
        <item>@string/lockscreen_battery_status_alwaysoff</item>
    </string-array>

    <string-array name="lockscreen_battery_status_values" translatable="false">
        <item>0</item>
        <item>1</item>
        <item>2</item>
    </string-array>

    <string-array name="lockscreen_icon_picker_labels" translatable="false">
        <item>@string/icon_picker_alarm</item>
        <item>@string/icon_picker_browser</item>
+6 −0
Original line number Diff line number Diff line
@@ -734,6 +734,12 @@ two in order to insert additional control points. \'Remove\' deletes the selecte
    <!-- Sound settings, charging sounds label for ringtone == none -->
    <string name="power_notifications_ringtone_silent">Silent</string>

    <!-- Lock screen misc. settings -->
    <string name="lockscreen_battery_status_title">Battery status</string>
    <string name="lockscreen_battery_status_charging">Only when charging</string>
    <string name="lockscreen_battery_status_alwayson">Always on</string>
    <string name="lockscreen_battery_status_alwaysoff">Always off</string>

    <!-- Lock Screen Shortcuts -->
    <string name="lockscreen_target_info">Drag the slider to targets to assign shortcuts</string>
    <string name="lockscreen_target_title">Slider shortcuts</string>
+10 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2012-2013 The CyanogenMod Project
     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.
@@ -30,6 +30,15 @@
            <extra android:name="cm_security" android:value="true" />
        </PreferenceScreen>

        <ListPreference
            android:key="lockscreen_battery_status"
            android:persistent="false"
            android:dialogTitle="@string/lockscreen_battery_status_title"
            android:title="@string/lockscreen_battery_status_title"
            android:entries="@array/lockscreen_battery_status_entries"
            android:entryValues="@array/lockscreen_battery_status_values"
            android:defaultValue="0" />

        <Preference
            android:fragment="com.android.settings.cyanogenmod.LockscreenTargets"
            android:key="lockscreen_targets"
+36 −2
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The CyanogenMod Project
 * 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.
@@ -18,12 +18,14 @@ package com.android.settings.cyanogenmod;

import android.app.ActivityManager;
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.UserHandle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
@@ -35,15 +37,18 @@ import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;

public class LockscreenInterface extends SettingsPreferenceFragment {
public class LockscreenInterface extends SettingsPreferenceFragment implements
        Preference.OnPreferenceChangeListener {

    private static final String LOCKSCREEN_GENERAL_CATEGORY = "lockscreen_general_category";
    private static final String LOCKSCREEN_WIDGETS_CATEGORY = "lockscreen_widgets_category";
    private static final String KEY_BATTERY_STATUS = "lockscreen_battery_status";
    private static final String KEY_LOCKSCREEN_BUTTONS = "lockscreen_buttons";
    private static final String KEY_ENABLE_WIDGETS = "keyguard_enable_widgets";
    private static final String KEY_LOCK_CLOCK = "lock_clock";
    private static final String KEY_ENABLE_CAMERA = "keyguard_enable_camera";

    private ListPreference mBatteryStatus;
    private CheckBoxPreference mEnableKeyguardWidgets;
    private CheckBoxPreference mEnableCameraWidget;

@@ -70,6 +75,11 @@ public class LockscreenInterface extends SettingsPreferenceFragment {
        mEnableKeyguardWidgets = (CheckBoxPreference) findPreference(KEY_ENABLE_WIDGETS);
        mEnableCameraWidget = (CheckBoxPreference) findPreference(KEY_ENABLE_CAMERA);

        mBatteryStatus = (ListPreference) findPreference(KEY_BATTERY_STATUS);
        if (mBatteryStatus != null) {
            mBatteryStatus.setOnPreferenceChangeListener(this);
        }

        // Remove lockscreen button actions if device doesn't have hardware keys
        if (!hasButtons()) {
            generalCategory.removePreference(findPreference(KEY_LOCKSCREEN_BUTTONS));
@@ -119,6 +129,15 @@ public class LockscreenInterface extends SettingsPreferenceFragment {
        if (mEnableCameraWidget != null) {
            mEnableCameraWidget.setChecked(mLockUtils.getCameraEnabled());
        }

        // Update battery status
        if (mBatteryStatus != null) {
            ContentResolver cr = getActivity().getContentResolver();
            int batteryStatus = Settings.System.getInt(cr,
                    Settings.System.LOCKSCREEN_BATTERY_VISIBILITY, 0);
            mBatteryStatus.setValueIndex(batteryStatus);
            mBatteryStatus.setSummary(mBatteryStatus.getEntries()[batteryStatus]);
        }
    }

    @Override
@@ -136,6 +155,21 @@ public class LockscreenInterface extends SettingsPreferenceFragment {
        return super.onPreferenceTreeClick(preferenceScreen, preference);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object objValue) {
        ContentResolver cr = getActivity().getContentResolver();

        if (preference == mBatteryStatus) {
            int value = Integer.valueOf((String) objValue);
            int index = mBatteryStatus.findIndexOfValue((String) objValue);
            Settings.System.putInt(cr, Settings.System.LOCKSCREEN_BATTERY_VISIBILITY, value);
            mBatteryStatus.setSummary(mBatteryStatus.getEntries()[index]);
            return true;
        }

        return false;
    }

    /**
     * Checks if the device has hardware buttons.
     * @return has Buttons