Add battery saver conditional
Change-Id: If80b749185537f252dae88230f80b29bcf321fdf
This commit is contained in:
@@ -6708,4 +6708,10 @@
|
|||||||
<!-- Title of condition that do not disturb is on [CHAR LIMIT=30] -->
|
<!-- Title of condition that do not disturb is on [CHAR LIMIT=30] -->
|
||||||
<string name="condition_zen_title">Do not disturb is on (<xliff:g name="zen_mode_type" example="Alarms only">%1$s</xliff:g>)</string>
|
<string name="condition_zen_title">Do not disturb is on (<xliff:g name="zen_mode_type" example="Alarms only">%1$s</xliff:g>)</string>
|
||||||
|
|
||||||
|
<!-- Title of condition that battery saver is on [CHAR LIMIT=30] -->
|
||||||
|
<string name="condition_battery_title">Battery Saver is on</string>
|
||||||
|
|
||||||
|
<!-- Summary of condition that battery saver is on [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="condition_battery_summary">Performance is reduced. Location services and background data are turned off.</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.android.settings.dashboard.conditional;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.fuelgauge.BatterySaverSettings;
|
||||||
|
|
||||||
|
public class BatterySaverCondition extends Condition {
|
||||||
|
public BatterySaverCondition(ConditionManager manager) {
|
||||||
|
super(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshState() {
|
||||||
|
PowerManager powerManager = mManager.getContext().getSystemService(PowerManager.class);
|
||||||
|
setActive(powerManager.isPowerSaveMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getIcon() {
|
||||||
|
return Icon.createWithResource(mManager.getContext(), R.drawable.ic_settings_battery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getTitle() {
|
||||||
|
return mManager.getContext().getString(R.string.condition_battery_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence getSummary() {
|
||||||
|
return mManager.getContext().getString(R.string.condition_battery_summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence[] getActions() {
|
||||||
|
return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) };
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrimaryClick() {
|
||||||
|
Utils.startWithFragment(mManager.getContext(), BatterySaverSettings.class.getName(), null,
|
||||||
|
null, 0, R.string.battery_saver, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActionClick(int index) {
|
||||||
|
if (index == 0) {
|
||||||
|
mManager.getContext().getSystemService(PowerManager.class).setPowerSaveMode(false);
|
||||||
|
refreshState();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unexpected index " + index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -131,6 +131,7 @@ public class ConditionManager {
|
|||||||
addIfMissing(AirplaneModeCondition.class);
|
addIfMissing(AirplaneModeCondition.class);
|
||||||
addIfMissing(HotspotCondition.class);
|
addIfMissing(HotspotCondition.class);
|
||||||
addIfMissing(DndCondition.class);
|
addIfMissing(DndCondition.class);
|
||||||
|
addIfMissing(BatterySaverCondition.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addIfMissing(Class<? extends Condition> clz) {
|
private void addIfMissing(Class<? extends Condition> clz) {
|
||||||
@@ -147,6 +148,8 @@ public class ConditionManager {
|
|||||||
return new HotspotCondition(this);
|
return new HotspotCondition(this);
|
||||||
} else if (DndCondition.class == clz) {
|
} else if (DndCondition.class == clz) {
|
||||||
return new DndCondition(this);
|
return new DndCondition(this);
|
||||||
|
} else if (BatterySaverCondition.class == clz) {
|
||||||
|
return new BatterySaverCondition(this);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Constructor<?> constructor = clz.getConstructor(ConditionManager.class);
|
Constructor<?> constructor = clz.getConstructor(ConditionManager.class);
|
||||||
|
@@ -37,6 +37,8 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
import com.android.settings.dashboard.conditional.BatterySaverCondition;
|
||||||
|
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||||
import com.android.settings.notification.SettingPref;
|
import com.android.settings.notification.SettingPref;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
@@ -144,6 +146,8 @@ public class BatterySaverSettings extends SettingsPreferenceFragment
|
|||||||
if (DEBUG) Log.d(TAG, "Setting mode failed, fallback to current value");
|
if (DEBUG) Log.d(TAG, "Setting mode failed, fallback to current value");
|
||||||
mHandler.post(mUpdateSwitch);
|
mHandler.post(mUpdateSwitch);
|
||||||
}
|
}
|
||||||
|
// TODO: Remove once broadcast is in place.
|
||||||
|
ConditionManager.get(getContext()).getCondition(BatterySaverCondition.class).refreshState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSwitch() {
|
private void updateSwitch() {
|
||||||
|
Reference in New Issue
Block a user