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:
John Spurlock
2014-08-02 17:23:46 -04:00
parent ca90af1064
commit 249cf50b19
4 changed files with 57 additions and 41 deletions

View File

@@ -1240,9 +1240,7 @@
<integer-array name="battery_saver_trigger_values" translatable="false" > <integer-array name="battery_saver_trigger_values" translatable="false" >
<item>0</item> <item>0</item>
<item>5</item> <item>5</item>
<item>10</item>
<item>15</item> <item>15</item>
<item>20</item>
</integer-array> </integer-array>
<!-- Process stats memory use details: labels for memory states --> <!-- Process stats memory use details: labels for memory states -->

View File

@@ -3986,9 +3986,6 @@
<!-- [CHAR_LIMIT=40] Battery saver: Label for feature, title + menu item --> <!-- [CHAR_LIMIT=40] Battery saver: Label for feature, title + menu item -->
<string name="battery_saver">Battery saver</string> <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 --> <!-- [CHAR_LIMIT=40] Battery saver: Title for automatic entry option -->
<string name="battery_saver_turn_on_automatically_title">Turn on automatically</string> <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 --> <!-- [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> <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 devices performance.\n\nBattery saver will be disabled when your device is plugged in.</string>
<!-- Process Stats strings --> <!-- Process Stats strings -->
<skip /> <skip />

View File

@@ -18,14 +18,6 @@
android:title="@string/battery_saver" android:title="@string/battery_saver"
android:key="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 --> <!-- Turn on automatically -->
<com.android.settings.notification.DropDownPreference <com.android.settings.notification.DropDownPreference
android:key="turn_on_automatically" android:key="turn_on_automatically"
@@ -35,7 +27,7 @@
<!-- Feature description text --> <!-- Feature description text -->
<Preference <Preference
android:key="description" android:key="description"
android:summary="@string/battery_saver_description" android:summary="@*android:string/battery_saver_description"
android:persistent="false" android:persistent="false"
android:selectable="false" /> android:selectable="false" />

View File

@@ -26,14 +26,18 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import android.util.Log; import android.util.Log;
import android.widget.Switch;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.SettingPref; 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 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 String KEY_TURN_ON_AUTOMATICALLY = "turn_on_automatically";
private static final long WAIT_FOR_SWITCH_ANIM = 500; private static final long WAIT_FOR_SWITCH_ANIM = 500;
@@ -42,8 +46,10 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
private Context mContext; private Context mContext;
private boolean mCreated; private boolean mCreated;
private SettingPref mAlwaysOnPref;
private SettingPref mTriggerPref; private SettingPref mTriggerPref;
private SwitchBar mSwitchBar;
private Switch mSwitch;
private boolean mValidListener;
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
@@ -53,25 +59,13 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
addPreferencesFromResource(R.xml.battery_saver_settings); addPreferencesFromResource(R.xml.battery_saver_settings);
mContext = getActivity(); mContext = getActivity();
mAlwaysOnPref = new SettingPref(SettingPref.TYPE_GLOBAL, KEY_ALWAYS_ON, mSwitchBar = ((SettingsActivity) mContext).getSwitchBar();
Global.LOW_POWER_MODE, 0) { mSwitch = mSwitchBar.getSwitch();
@Override mSwitchBar.show();
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;
}
}
};
mTriggerPref = new SettingPref(SettingPref.TYPE_GLOBAL, KEY_TURN_ON_AUTOMATICALLY, mTriggerPref = new SettingPref(SettingPref.TYPE_GLOBAL, KEY_TURN_ON_AUTOMATICALLY,
Global.LOW_POWER_MODE_TRIGGER_LEVEL, Global.LOW_POWER_MODE_TRIGGER_LEVEL,
mContext.getResources().getInteger( 0, /*default*/
com.android.internal.R.integer.config_lowBatteryWarningLevel),
getResources().getIntArray(R.array.battery_saver_trigger_values)) { getResources().getIntArray(R.array.battery_saver_trigger_values)) {
@Override @Override
protected String getCaption(Resources res, int value) { 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); return res.getString(R.string.battery_saver_turn_on_automatically_never);
} }
}; };
mAlwaysOnPref.init(this);
mTriggerPref.init(this); mTriggerPref.init(this);
} }
@Override
public void onDestroyView() {
super.onDestroyView();
mSwitchBar.hide();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mSettingsObserver.setListening(true); mSettingsObserver.setListening(true);
if (!mValidListener) {
mSwitchBar.addOnSwitchChangeListener(this);
mValidListener = true;
}
updateSwitch();
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
mSettingsObserver.setListening(false); 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() { private final Runnable mStartMode = new Runnable() {
@@ -103,8 +135,8 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
AsyncTask.execute(new Runnable() { AsyncTask.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.d(TAG, "Starting LOW_POWER_MODE from settings"); if (DEBUG) Log.d(TAG, "Starting LOW_POWER_MODE from settings");
Global.putInt(mContext.getContentResolver(), Global.LOW_POWER_MODE, 1); Global.putInt(getContentResolver(), Global.LOW_POWER_MODE, 1);
} }
}); });
} }
@@ -122,7 +154,7 @@ public class BatterySaverSettings extends SettingsPreferenceFragment {
@Override @Override
public void onChange(boolean selfChange, Uri uri) { public void onChange(boolean selfChange, Uri uri) {
if (LOW_POWER_MODE_URI.equals(uri)) { if (LOW_POWER_MODE_URI.equals(uri)) {
mAlwaysOnPref.update(mContext); updateSwitch();
} }
if (LOW_POWER_MODE_TRIGGER_LEVEL_URI.equals(uri)) { if (LOW_POWER_MODE_TRIGGER_LEVEL_URI.equals(uri)) {
mTriggerPref.update(mContext); mTriggerPref.update(mContext);