Move battery percent constant to Settings

This switch is moving to system settings so it should also be declared
by Settings. Also changed the constant's name to make sense in the
System context.

Test: runtest systemui
Bug: 32539932
Change-Id: I7cce21b50702f31465328dd8faed3fbac47528ea
This commit is contained in:
Evan Laird
2017-03-10 10:56:45 -05:00
parent d9e529b398
commit bcf631d48b
4 changed files with 24 additions and 10 deletions

View File

@@ -3851,6 +3851,17 @@ public final class Settings {
}
};
/**
* Setting to determine whether or not to show the battery percentage in the status bar.
* 0 - Don't show percentage
* 1 - Show percentage
* @hide
*/
public static final String SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
/** @hide */
private static final Validator SHOW_BATTERY_PERCENT_VALIDATOR = sBooleanValidator;
/**
* IMPORTANT: If you add a new public settings you also have to add it to
* PUBLIC_SETTINGS below. If the new setting is hidden you have to add
@@ -3913,7 +3924,8 @@ public final class Settings {
RINGTONE,
LOCK_TO_APP_ENABLED,
NOTIFICATION_SOUND,
ACCELEROMETER_ROTATION
ACCELEROMETER_ROTATION,
SHOW_BATTERY_PERCENT
};
/**
@@ -4013,6 +4025,7 @@ public final class Settings {
PRIVATE_SETTINGS.add(POINTER_SPEED);
PRIVATE_SETTINGS.add(LOCK_TO_APP_ENABLED);
PRIVATE_SETTINGS.add(EGG_MODE);
PRIVATE_SETTINGS.add(SHOW_BATTERY_PERCENT);
}
/**
@@ -4090,6 +4103,7 @@ public final class Settings {
VALIDATORS.put(WIFI_STATIC_NETMASK, WIFI_STATIC_NETMASK_VALIDATOR);
VALIDATORS.put(WIFI_STATIC_DNS1, WIFI_STATIC_DNS1_VALIDATOR);
VALIDATORS.put(WIFI_STATIC_DNS2, WIFI_STATIC_DNS2_VALIDATOR);
VALIDATORS.put(SHOW_BATTERY_PERCENT, SHOW_BATTERY_PERCENT_VALIDATOR);
}
/**

View File

@@ -15,6 +15,8 @@
*/
package com.android.systemui;
import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -50,8 +52,6 @@ import java.text.NumberFormat;
public class BatteryMeterView extends LinearLayout implements
BatteryStateChangeCallback, Tunable, DarkReceiver, ConfigurationListener {
public static final String SHOW_PERCENT_SETTING = "status_bar_show_battery_percent";
private final BatteryMeterDrawableBase mDrawable;
private final String mSlotBattery;
private final ImageView mBatteryIconView;
@@ -129,7 +129,7 @@ public class BatteryMeterView extends LinearLayout implements
mBatteryController = Dependency.get(BatteryController.class);
mBatteryController.addCallback(this);
getContext().getContentResolver().registerContentObserver(
Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver);
updateShowPercent();
Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
Dependency.get(ConfigurationController.class).addCallback(this);
@@ -175,7 +175,7 @@ public class BatteryMeterView extends LinearLayout implements
private void updateShowPercent() {
final boolean showing = mBatteryPercentView != null;
if (0 != Settings.System.getInt(getContext().getContentResolver(),
BatteryMeterView.SHOW_PERCENT_SETTING, 0) || mForceShowPercent) {
SHOW_BATTERY_PERCENT, 0) || mForceShowPercent) {
if (!showing) {
mBatteryPercentView = loadPercentView();
if (mTextColor != 0) mBatteryPercentView.setTextColor(mTextColor);

View File

@@ -25,7 +25,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
import com.android.systemui.statusbar.phone.StatusBarIconController;
import static com.android.systemui.BatteryMeterView.SHOW_PERCENT_SETTING;
import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
public class BatteryPreference extends DropDownPreference implements TunerService.Tunable {
@@ -49,7 +49,7 @@ public class BatteryPreference extends DropDownPreference implements TunerServic
public void onAttached() {
super.onAttached();
mHasPercentage = Settings.System.getInt(getContext().getContentResolver(),
SHOW_PERCENT_SETTING, 0) != 0;
SHOW_BATTERY_PERCENT, 0) != 0;
Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST);
}
@@ -84,7 +84,7 @@ public class BatteryPreference extends DropDownPreference implements TunerServic
protected boolean persistString(String value) {
final boolean v = PERCENT.equals(value);
MetricsLogger.action(getContext(), MetricsEvent.TUNER_BATTERY_PERCENTAGE, v);
Settings.System.putInt(getContext().getContentResolver(), SHOW_PERCENT_SETTING, v ? 1 : 0);
Settings.System.putInt(getContext().getContentResolver(), SHOW_BATTERY_PERCENT, v ? 1 : 0);
if (DISABLED.equals(value)) {
mBlacklist.add(mBattery);
} else {

View File

@@ -38,7 +38,7 @@ import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import static com.android.systemui.BatteryMeterView.SHOW_PERCENT_SETTING;
import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
import com.android.systemui.DemoMode;
import com.android.systemui.Dependency;
import com.android.systemui.R;
@@ -213,7 +213,7 @@ public class TunerService {
// A couple special cases.
Settings.Global.putString(mContentResolver, DemoMode.DEMO_MODE_ALLOWED, null);
Settings.System.putString(mContentResolver,
SHOW_PERCENT_SETTING, null);
SHOW_BATTERY_PERCENT, null);
Intent intent = new Intent(DemoMode.ACTION_DEMO);
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_EXIT);
mContext.sendBroadcast(intent);