Settings: Battery saver updates.
- Fewer trigger level options, new default of 0 (never) - Use new shared feature description text (in framework) - Remove "always on", add new top-level switch bar. Depends on the framework changes in I3d1ded1eec9e63e7d97469486f6a320e1bebbccd Bug:16214395 Change-Id: Ia01186cfeb19d00672f62cc84787584b4dcc1143
This commit is contained in:
@@ -1240,9 +1240,7 @@
|
||||
<integer-array name="battery_saver_trigger_values" translatable="false" >
|
||||
<item>0</item>
|
||||
<item>5</item>
|
||||
<item>10</item>
|
||||
<item>15</item>
|
||||
<item>20</item>
|
||||
</integer-array>
|
||||
|
||||
<!-- Process stats memory use details: labels for memory states -->
|
||||
|
@@ -3986,9 +3986,6 @@
|
||||
<!-- [CHAR_LIMIT=40] Battery saver: Label for feature, title + menu item -->
|
||||
<string name="battery_saver">Battery saver</string>
|
||||
|
||||
<!-- [CHAR_LIMIT=40] Battery saver: Title for always on option -->
|
||||
<string name="battery_saver_always_on_title">Always on</string>
|
||||
|
||||
<!-- [CHAR_LIMIT=40] Battery saver: Title for automatic entry option -->
|
||||
<string name="battery_saver_turn_on_automatically_title">Turn on automatically</string>
|
||||
|
||||
@@ -3998,9 +3995,6 @@
|
||||
<!-- [CHAR_LIMIT=40] Battery saver: Value for automatic entry option: pct% battery -->
|
||||
<string name="battery_saver_turn_on_automatically_pct">at %1$d%% battery</string>
|
||||
|
||||
<!-- [CHAR_LIMIT=NONE] Battery saver: Feature description -->
|
||||
<string name="battery_saver_description">To help improve battery life, Battery saver will reduce your device’s performance.\n\nBattery saver will be disabled when your device is plugged in.</string>
|
||||
|
||||
<!-- Process Stats strings -->
|
||||
<skip />
|
||||
|
||||
|
@@ -18,14 +18,6 @@
|
||||
android:title="@string/battery_saver"
|
||||
android:key="battery_saver">
|
||||
|
||||
<!-- Always on -->
|
||||
<SwitchPreference
|
||||
android:key="always_on"
|
||||
android:title="@string/battery_saver_always_on_title"
|
||||
android:switchTextOff=""
|
||||
android:switchTextOn=""
|
||||
android:persistent="false" />
|
||||
|
||||
<!-- Turn on automatically -->
|
||||
<com.android.settings.notification.DropDownPreference
|
||||
android:key="turn_on_automatically"
|
||||
@@ -35,7 +27,7 @@
|
||||
<!-- Feature description text -->
|
||||
<Preference
|
||||
android:key="description"
|
||||
android:summary="@string/battery_saver_description"
|
||||
android:summary="@*android:string/battery_saver_description"
|
||||
android:persistent="false"
|
||||
android:selectable="false" />
|
||||
|
||||
|
@@ -26,14 +26,18 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings.Global;
|
||||
import android.util.Log;
|
||||
import android.widget.Switch;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.notification.SettingPref;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
|
||||
public class BatterySaverSettings extends SettingsPreferenceFragment {
|
||||
public class BatterySaverSettings extends SettingsPreferenceFragment
|
||||
implements SwitchBar.OnSwitchChangeListener {
|
||||
private static final String TAG = "BatterySaverSettings";
|
||||
private static final String KEY_ALWAYS_ON = "always_on";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
private static final String KEY_TURN_ON_AUTOMATICALLY = "turn_on_automatically";
|
||||
private static final long WAIT_FOR_SWITCH_ANIM = 500;
|
||||
|
||||
@@ -42,8 +46,10 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private Context mContext;
|
||||
private boolean mCreated;
|
||||
private SettingPref mAlwaysOnPref;
|
||||
private SettingPref mTriggerPref;
|
||||
private SwitchBar mSwitchBar;
|
||||
private Switch mSwitch;
|
||||
private boolean mValidListener;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
@@ -53,25 +59,13 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
|
||||
addPreferencesFromResource(R.xml.battery_saver_settings);
|
||||
|
||||
mContext = getActivity();
|
||||
mAlwaysOnPref = new SettingPref(SettingPref.TYPE_GLOBAL, KEY_ALWAYS_ON,
|
||||
Global.LOW_POWER_MODE, 0) {
|
||||
@Override
|
||||
protected boolean setSetting(Context context, int value) {
|
||||
mHandler.removeCallbacks(mStartMode);
|
||||
if (value == 0) {
|
||||
return super.setSetting(context, value);
|
||||
} else {
|
||||
// about lose animations, make sure we don't turn the mode on until the switch
|
||||
// stops moving
|
||||
mHandler.postDelayed(mStartMode, WAIT_FOR_SWITCH_ANIM);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
|
||||
mSwitch = mSwitchBar.getSwitch();
|
||||
mSwitchBar.show();
|
||||
|
||||
mTriggerPref = new SettingPref(SettingPref.TYPE_GLOBAL, KEY_TURN_ON_AUTOMATICALLY,
|
||||
Global.LOW_POWER_MODE_TRIGGER_LEVEL,
|
||||
mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_lowBatteryWarningLevel),
|
||||
0, /*default*/
|
||||
getResources().getIntArray(R.array.battery_saver_trigger_values)) {
|
||||
@Override
|
||||
protected String getCaption(Resources res, int value) {
|
||||
@@ -81,20 +75,58 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
|
||||
return res.getString(R.string.battery_saver_turn_on_automatically_never);
|
||||
}
|
||||
};
|
||||
mAlwaysOnPref.init(this);
|
||||
mTriggerPref.init(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mSettingsObserver.setListening(true);
|
||||
if (!mValidListener) {
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
mValidListener = true;
|
||||
}
|
||||
updateSwitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mSettingsObserver.setListening(false);
|
||||
if (mValidListener) {
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
mValidListener = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mHandler.postDelayed(mStartMode, WAIT_FOR_SWITCH_ANIM);
|
||||
} else {
|
||||
if (DEBUG) Log.d(TAG, "Stopping LOW_POWER_MODE from settings");
|
||||
Global.putInt(getContentResolver(), Global.LOW_POWER_MODE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSwitch() {
|
||||
final boolean checked = Global.getInt(getContentResolver(), Global.LOW_POWER_MODE, 0) != 0;
|
||||
if (checked == mSwitch.isChecked()) return;
|
||||
|
||||
// set listener to null so that that code below doesn't trigger onCheckedChanged()
|
||||
if (mValidListener) {
|
||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
||||
}
|
||||
mSwitch.setChecked(checked);
|
||||
if (mValidListener) {
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private final Runnable mStartMode = new Runnable() {
|
||||
@@ -103,8 +135,8 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(TAG, "Starting LOW_POWER_MODE from settings");
|
||||
Global.putInt(mContext.getContentResolver(), Global.LOW_POWER_MODE, 1);
|
||||
if (DEBUG) Log.d(TAG, "Starting LOW_POWER_MODE from settings");
|
||||
Global.putInt(getContentResolver(), Global.LOW_POWER_MODE, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -122,7 +154,7 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (LOW_POWER_MODE_URI.equals(uri)) {
|
||||
mAlwaysOnPref.update(mContext);
|
||||
updateSwitch();
|
||||
}
|
||||
if (LOW_POWER_MODE_TRIGGER_LEVEL_URI.equals(uri)) {
|
||||
mTriggerPref.update(mContext);
|
||||
|
Reference in New Issue
Block a user