summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-05-29 15:03:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-05-29 15:03:16 +0000
commit4402f4bb12cc70eef3bae20631a4a9fe210c7c80 (patch)
tree742d3a966f19e7a340d95e81a29fdf761ab0b4c5 /packages
parente796112904a737e61f2ecce3f0fd42d2cba25436 (diff)
parentf40d08f8a3094ac5d5478efc5de0b96f57d2c5df (diff)
downloadframeworks_base-4402f4bb12cc70eef3bae20631a4a9fe210c7c80.zip
frameworks_base-4402f4bb12cc70eef3bae20631a4a9fe210c7c80.tar.gz
frameworks_base-4402f4bb12cc70eef3bae20631a4a9fe210c7c80.tar.bz2
Merge "Tuner: add battery pct preference." into mnc-dev
Diffstat (limited to 'packages')
-rw-r--r--packages/SystemUI/res/values/strings.xml6
-rw-r--r--packages/SystemUI/res/xml/tuner_prefs.xml8
-rwxr-xr-xpackages/SystemUI/src/com/android/systemui/BatteryMeterView.java234
-rw-r--r--packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java55
4 files changed, 195 insertions, 108 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index f1bbb0d..5b1a5b3 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1025,6 +1025,12 @@
<!-- Name of special SystemUI debug settings -->
<string name="system_ui_tuner">System UI tuner</string>
+ <!-- Preference to show/hide embedded battery percentage [CHAR LIMIT=50] -->
+ <string name="show_battery_percentage">Show embedded battery percentage</string>
+
+ <!-- Summary for battery percentage preference [CHAR LIMIT=NONE] -->
+ <string name="show_battery_percentage_summary">Show battery level percentage inside the status bar icon when not charging</string>
+
<!-- Name of quick settings -->
<string name="quick_settings">Quick Settings</string>
diff --git a/packages/SystemUI/res/xml/tuner_prefs.xml b/packages/SystemUI/res/xml/tuner_prefs.xml
index deb3f4f..135cc82 100644
--- a/packages/SystemUI/res/xml/tuner_prefs.xml
+++ b/packages/SystemUI/res/xml/tuner_prefs.xml
@@ -17,10 +17,14 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/system_ui_tuner">
- <!-- Tuner prefs go here -->
-
<Preference
android:key="qs_tuner"
android:title="@string/quick_settings" />
+ <SwitchPreference
+ android:key="battery_pct"
+ android:title="@string/show_battery_percentage"
+ android:summary="@string/show_battery_percentage_summary"
+ android:persistent="false" />
+
</PreferenceScreen>
diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
index 0d331d1..95b58e5 100755
--- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
+++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java
@@ -23,16 +23,17 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
import android.graphics.RectF;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.BatteryManager;
import android.os.Bundle;
+import android.os.Handler;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
@@ -43,10 +44,9 @@ public class BatteryMeterView extends View implements DemoMode,
BatteryController.BatteryStateChangeCallback {
public static final String TAG = BatteryMeterView.class.getSimpleName();
public static final String ACTION_LEVEL_TEST = "com.android.systemui.BATTERY_LEVEL_TEST";
+ public static final String SHOW_PERCENT_SETTING = "status_bar_show_battery_percent";
- private static final boolean ENABLE_PERCENT = true;
private static final boolean SINGLE_DIGIT_PERCENT = false;
- private static final boolean SHOW_100_PERCENT = false;
private static final int FULL = 96;
@@ -54,7 +54,7 @@ public class BatteryMeterView extends View implements DemoMode,
private final int[] mColors;
- boolean mShowPercent = true;
+ private boolean mShowPercent;
private float mButtonHeightFraction;
private float mSubpixelSmoothingLeft;
private float mSubpixelSmoothingRight;
@@ -87,103 +87,8 @@ public class BatteryMeterView extends View implements DemoMode,
private int mLightModeBackgroundColor;
private int mLightModeFillColor;
- private class BatteryTracker extends BroadcastReceiver {
- public static final int UNKNOWN_LEVEL = -1;
-
- // current battery status
- int level = UNKNOWN_LEVEL;
- String percentStr;
- int plugType;
- boolean plugged;
- int health;
- int status;
- String technology;
- int voltage;
- int temperature;
- boolean testmode = false;
-
- @Override
- public void onReceive(Context context, Intent intent) {
- final String action = intent.getAction();
- if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
- if (testmode && ! intent.getBooleanExtra("testmode", false)) return;
-
- level = (int)(100f
- * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
- / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
-
- plugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
- plugged = plugType != 0;
- health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH,
- BatteryManager.BATTERY_HEALTH_UNKNOWN);
- status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
- BatteryManager.BATTERY_STATUS_UNKNOWN);
- technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY);
- voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);
- temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
-
- setContentDescription(
- context.getString(R.string.accessibility_battery_level, level));
- postInvalidate();
- } else if (action.equals(ACTION_LEVEL_TEST)) {
- testmode = true;
- post(new Runnable() {
- int curLevel = 0;
- int incr = 1;
- int saveLevel = level;
- int savePlugged = plugType;
- Intent dummy = new Intent(Intent.ACTION_BATTERY_CHANGED);
- @Override
- public void run() {
- if (curLevel < 0) {
- testmode = false;
- dummy.putExtra("level", saveLevel);
- dummy.putExtra("plugged", savePlugged);
- dummy.putExtra("testmode", false);
- } else {
- dummy.putExtra("level", curLevel);
- dummy.putExtra("plugged", incr > 0 ? BatteryManager.BATTERY_PLUGGED_AC : 0);
- dummy.putExtra("testmode", true);
- }
- getContext().sendBroadcast(dummy);
-
- if (!testmode) return;
-
- curLevel += incr;
- if (curLevel == 100) {
- incr *= -1;
- }
- postDelayed(this, 200);
- }
- });
- }
- }
- }
-
- BatteryTracker mTracker = new BatteryTracker();
-
- @Override
- public void onAttachedToWindow() {
- super.onAttachedToWindow();
-
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_BATTERY_CHANGED);
- filter.addAction(ACTION_LEVEL_TEST);
- final Intent sticky = getContext().registerReceiver(mTracker, filter);
- if (sticky != null) {
- // preload the battery level
- mTracker.onReceive(getContext(), sticky);
- }
- mBatteryController.addStateChangedCallback(this);
- }
-
- @Override
- public void onDetachedFromWindow() {
- super.onDetachedFromWindow();
-
- getContext().unregisterReceiver(mTracker);
- mBatteryController.removeStateChangedCallback(this);
- }
+ private BatteryTracker mTracker = new BatteryTracker();
+ private final SettingObserver mSettingObserver = new SettingObserver();
public BatteryMeterView(Context context) {
this(context, null, 0);
@@ -213,8 +118,7 @@ public class BatteryMeterView extends View implements DemoMode,
levels.recycle();
colors.recycle();
atts.recycle();
- mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
- context.getContentResolver(), "status_bar_show_battery_percent", 0);
+ updateShowPercent();
mWarningString = context.getString(R.string.battery_meter_very_low_overlay_symbol);
mCriticalLevel = mContext.getResources().getInteger(
com.android.internal.R.integer.config_criticalBatteryWarningLevel);
@@ -261,6 +165,32 @@ public class BatteryMeterView extends View implements DemoMode,
mLightModeFillColor = context.getColor(R.color.light_mode_icon_color_dual_tone_fill);
}
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+ filter.addAction(ACTION_LEVEL_TEST);
+ final Intent sticky = getContext().registerReceiver(mTracker, filter);
+ if (sticky != null) {
+ // preload the battery level
+ mTracker.onReceive(getContext(), sticky);
+ }
+ mBatteryController.addStateChangedCallback(this);
+ getContext().getContentResolver().registerContentObserver(
+ Settings.System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+
+ getContext().unregisterReceiver(mTracker);
+ mBatteryController.removeStateChangedCallback(this);
+ getContext().getContentResolver().unregisterContentObserver(mSettingObserver);
+ }
+
public void setBatteryController(BatteryController batteryController) {
mBatteryController = batteryController;
mPowerSaveEnabled = mBatteryController.isPowerSave();
@@ -300,6 +230,11 @@ public class BatteryMeterView extends View implements DemoMode,
mWarningTextHeight = -mWarningTextPaint.getFontMetrics().ascent;
}
+ private void updateShowPercent() {
+ mShowPercent = 0 != Settings.System.getInt(getContext().getContentResolver(),
+ SHOW_PERCENT_SETTING, 0);
+ }
+
private int getColorForLevel(int percent) {
// If we are in power save mode, always use the normal color.
@@ -447,8 +382,7 @@ public class BatteryMeterView extends View implements DemoMode,
boolean pctOpaque = false;
float pctX = 0, pctY = 0;
String pctText = null;
- if (!tracker.plugged && level > mCriticalLevel && mShowPercent
- && !(tracker.level == 100 && !SHOW_100_PERCENT)) {
+ if (!tracker.plugged && level > mCriticalLevel && mShowPercent) {
mTextPaint.setColor(getColorForLevel(level));
mTextPaint.setTextSize(height *
(SINGLE_DIGIT_PERCENT ? 0.75f
@@ -518,4 +452,92 @@ public class BatteryMeterView extends View implements DemoMode,
postInvalidate();
}
}
+
+ private final class BatteryTracker extends BroadcastReceiver {
+ public static final int UNKNOWN_LEVEL = -1;
+
+ // current battery status
+ int level = UNKNOWN_LEVEL;
+ String percentStr;
+ int plugType;
+ boolean plugged;
+ int health;
+ int status;
+ String technology;
+ int voltage;
+ int temperature;
+ boolean testmode = false;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
+ if (testmode && ! intent.getBooleanExtra("testmode", false)) return;
+
+ level = (int)(100f
+ * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
+ / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100));
+
+ plugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0);
+ plugged = plugType != 0;
+ health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH,
+ BatteryManager.BATTERY_HEALTH_UNKNOWN);
+ status = intent.getIntExtra(BatteryManager.EXTRA_STATUS,
+ BatteryManager.BATTERY_STATUS_UNKNOWN);
+ technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY);
+ voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);
+ temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0);
+
+ setContentDescription(
+ context.getString(R.string.accessibility_battery_level, level));
+ postInvalidate();
+ } else if (action.equals(ACTION_LEVEL_TEST)) {
+ testmode = true;
+ post(new Runnable() {
+ int curLevel = 0;
+ int incr = 1;
+ int saveLevel = level;
+ int savePlugged = plugType;
+ Intent dummy = new Intent(Intent.ACTION_BATTERY_CHANGED);
+ @Override
+ public void run() {
+ if (curLevel < 0) {
+ testmode = false;
+ dummy.putExtra("level", saveLevel);
+ dummy.putExtra("plugged", savePlugged);
+ dummy.putExtra("testmode", false);
+ } else {
+ dummy.putExtra("level", curLevel);
+ dummy.putExtra("plugged", incr > 0 ? BatteryManager.BATTERY_PLUGGED_AC
+ : 0);
+ dummy.putExtra("testmode", true);
+ }
+ getContext().sendBroadcast(dummy);
+
+ if (!testmode) return;
+
+ curLevel += incr;
+ if (curLevel == 100) {
+ incr *= -1;
+ }
+ postDelayed(this, 200);
+ }
+ });
+ }
+ }
+ }
+
+ private final class SettingObserver extends ContentObserver {
+ public SettingObserver() {
+ super(new Handler());
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri) {
+ super.onChange(selfChange, uri);
+ updateShowPercent();
+ postInvalidate();
+ }
+ }
+
}
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java
index 457bade..b40adaf 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerFragment.java
@@ -15,11 +15,19 @@
*/
package com.android.systemui.tuner;
+import static com.android.systemui.BatteryMeterView.SHOW_PERCENT_SETTING;
+
import android.app.FragmentTransaction;
+import android.database.ContentObserver;
+import android.net.Uri;
import android.os.Bundle;
+import android.os.Handler;
import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceFragment;
+import android.preference.SwitchPreference;
+import android.provider.Settings.System;
import android.view.MenuItem;
import com.android.systemui.R;
@@ -27,6 +35,11 @@ import com.android.systemui.R;
public class TunerFragment extends PreferenceFragment {
private static final String KEY_QS_TUNER = "qs_tuner";
+ private static final String KEY_BATTERY_PCT = "battery_pct";
+
+ private final SettingObserver mSettingObserver = new SettingObserver();
+
+ private SwitchPreference mBatteryPct;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -45,6 +58,21 @@ public class TunerFragment extends PreferenceFragment {
return false;
}
});
+ mBatteryPct = (SwitchPreference) findPreference(KEY_BATTERY_PCT);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updateBatteryPct();
+ getContext().getContentResolver().registerContentObserver(
+ System.getUriFor(SHOW_PERCENT_SETTING), false, mSettingObserver);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getContext().getContentResolver().unregisterContentObserver(mSettingObserver);
}
@Override
@@ -57,4 +85,31 @@ public class TunerFragment extends PreferenceFragment {
return super.onOptionsItemSelected(item);
}
+ private void updateBatteryPct() {
+ mBatteryPct.setOnPreferenceChangeListener(null);
+ mBatteryPct.setChecked(System.getInt(getContext().getContentResolver(),
+ SHOW_PERCENT_SETTING, 0) != 0);
+ mBatteryPct.setOnPreferenceChangeListener(mBatteryPctChange);
+ }
+
+ private final class SettingObserver extends ContentObserver {
+ public SettingObserver() {
+ super(new Handler());
+ }
+
+ @Override
+ public void onChange(boolean selfChange, Uri uri, int userId) {
+ super.onChange(selfChange, uri, userId);
+ updateBatteryPct();
+ }
+ }
+
+ private final OnPreferenceChangeListener mBatteryPctChange = new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean v = (Boolean) newValue;
+ System.putInt(getContext().getContentResolver(), SHOW_PERCENT_SETTING, v ? 1 : 0);
+ return true;
+ }
+ };
}