Merge changes from topic 'battery3'
* changes: Fix regression in battery size. Clean up BatteryMeterDrawable internal api.
This commit is contained in:
committed by
Android (Google) Code Review
commit
fa234b2f47
@@ -58,8 +58,8 @@
|
||||
<dimen name="drawer_item_top_bottom_margin">4dp</dimen>
|
||||
<dimen name="drawer_spacer_height">32dp</dimen>
|
||||
|
||||
<dimen name="battery_height">48dp</dimen>
|
||||
<dimen name="battery_width">38dp</dimen>
|
||||
<dimen name="battery_height">14.5dp</dimen>
|
||||
<dimen name="battery_width">9.5dp</dimen>
|
||||
|
||||
<!-- Margin on the right side of the system icon group on Keyguard. -->
|
||||
<fraction name="battery_button_height_fraction">10.5%</fraction>
|
||||
|
||||
@@ -37,14 +37,13 @@ public class BatteryMeterDrawableBase extends Drawable {
|
||||
|
||||
private static final float ASPECT_RATIO = 9.5f / 14.5f;
|
||||
public static final String TAG = BatteryMeterDrawableBase.class.getSimpleName();
|
||||
public static final String SHOW_PERCENT_SETTING = "status_bar_show_battery_percent";
|
||||
|
||||
protected final Context mContext;
|
||||
|
||||
protected int mLevel = -1;
|
||||
protected boolean mPluggedIn;
|
||||
protected boolean mPowerSaveEnabled;
|
||||
protected boolean mShowPercent;
|
||||
private int mLevel = -1;
|
||||
private boolean mPluggedIn;
|
||||
private boolean mPowerSaveEnabled;
|
||||
private boolean mShowPercent;
|
||||
|
||||
private static final boolean SINGLE_DIGIT_PERCENT = false;
|
||||
|
||||
@@ -104,7 +103,7 @@ public class BatteryMeterDrawableBase extends Drawable {
|
||||
}
|
||||
levels.recycle();
|
||||
colors.recycle();
|
||||
updateShowPercent();
|
||||
|
||||
mWarningString = context.getString(R.string.battery_meter_very_low_overlay_symbol);
|
||||
mCriticalLevel = mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_criticalBatteryWarningLevel);
|
||||
@@ -143,10 +142,10 @@ public class BatteryMeterDrawableBase extends Drawable {
|
||||
|
||||
mBoltPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mBoltPaint.setColor(Utils.getDefaultColor(mContext, R.color.batterymeter_bolt_color));
|
||||
mBoltPoints = loadBoltPoints(res);
|
||||
mBoltPoints = loadPoints(res, R.array.batterymeter_bolt_points);
|
||||
|
||||
mPlusPaint = new Paint(mBoltPaint);
|
||||
mPlusPoints = loadPlusPoints(res);
|
||||
mPlusPoints = loadPoints(res, R.array.batterymeter_plus_points);
|
||||
|
||||
mDarkModeBackgroundColor =
|
||||
Utils.getDefaultColor(mContext, R.color.dark_mode_icon_color_dual_tone_background);
|
||||
@@ -171,32 +170,34 @@ public class BatteryMeterDrawableBase extends Drawable {
|
||||
return mIntrinsicWidth;
|
||||
}
|
||||
|
||||
public void disableShowPercent() {
|
||||
mShowPercent = false;
|
||||
public void setShowPercent(boolean show) {
|
||||
mShowPercent = show;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setPluggedIn(boolean val) {
|
||||
mPluggedIn = val;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setBatteryLevel(int val) {
|
||||
mLevel = val;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
public void setPowerSave(boolean val) {
|
||||
mPowerSaveEnabled = val;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
// an approximation of View.postInvalidate()
|
||||
protected void postInvalidate() {
|
||||
unscheduleSelf(this::invalidateSelf);
|
||||
scheduleSelf(this::invalidateSelf, 0);
|
||||
}
|
||||
|
||||
private static float[] loadBoltPoints(Resources res) {
|
||||
final int[] pts = res.getIntArray(R.array.batterymeter_bolt_points);
|
||||
int maxX = 0, maxY = 0;
|
||||
for (int i = 0; i < pts.length; i += 2) {
|
||||
maxX = Math.max(maxX, pts[i]);
|
||||
maxY = Math.max(maxY, pts[i + 1]);
|
||||
}
|
||||
final float[] ptsF = new float[pts.length];
|
||||
for (int i = 0; i < pts.length; i += 2) {
|
||||
ptsF[i] = (float) pts[i] / maxX;
|
||||
ptsF[i + 1] = (float) pts[i + 1] / maxY;
|
||||
}
|
||||
return ptsF;
|
||||
}
|
||||
|
||||
private static float[] loadPlusPoints(Resources res) {
|
||||
final int[] pts = res.getIntArray(R.array.batterymeter_plus_points);
|
||||
private static float[] loadPoints(Resources res, int pointArrayRes) {
|
||||
final int[] pts = res.getIntArray(pointArrayRes);
|
||||
int maxX = 0, maxY = 0;
|
||||
for (int i = 0; i < pts.length; i += 2) {
|
||||
maxX = Math.max(maxX, pts[i]);
|
||||
@@ -219,10 +220,6 @@ public class BatteryMeterDrawableBase extends Drawable {
|
||||
mWarningTextHeight = -mWarningTextPaint.getFontMetrics().ascent;
|
||||
}
|
||||
|
||||
protected void updateShowPercent() {
|
||||
mShowPercent = true;
|
||||
}
|
||||
|
||||
private int getColorForLevel(int percent) {
|
||||
// If we are in power save mode, always use the normal color.
|
||||
if (mPowerSaveEnabled) {
|
||||
|
||||
@@ -48,4 +48,24 @@ public class BatteryMeterDrawableBaseTest {
|
||||
verify(canvas, never()).drawPath(any(), any());
|
||||
verify(canvas, never()).drawText(anyString(), anyFloat(), anyFloat(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDrawingForTypicalValues() {
|
||||
final Canvas canvas = mock(Canvas.class);
|
||||
final int levels[] = { 0, 1, 5, 10, 25, 50, 75, 90, 95, 99, 100 };
|
||||
final boolean bools[] = { false, true };
|
||||
for (int l : levels) {
|
||||
for (boolean plugged : bools) {
|
||||
for (boolean saver : bools) {
|
||||
for (boolean percent : bools) {
|
||||
mBatteryDrawable.setBatteryLevel(l);
|
||||
mBatteryDrawable.setPowerSave(saver);
|
||||
mBatteryDrawable.setPluggedIn(plugged);
|
||||
mBatteryDrawable.setShowPercent(percent);
|
||||
mBatteryDrawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ import com.android.systemui.statusbar.policy.BatteryController;
|
||||
public class BatteryMeterDrawable extends BatteryMeterDrawableBase implements
|
||||
BatteryController.BatteryStateChangeCallback {
|
||||
|
||||
public static final String SHOW_PERCENT_SETTING = "status_bar_show_battery_percent";
|
||||
|
||||
private BatteryController mBatteryController;
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
@@ -38,16 +40,13 @@ public class BatteryMeterDrawable extends BatteryMeterDrawableBase implements
|
||||
|
||||
@Override
|
||||
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
|
||||
mLevel = level;
|
||||
mPluggedIn = pluggedIn;
|
||||
|
||||
postInvalidate();
|
||||
setBatteryLevel(level);
|
||||
setPluggedIn(pluggedIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPowerSaveChanged(boolean isPowerSave) {
|
||||
mPowerSaveEnabled = isPowerSave;
|
||||
invalidateSelf();
|
||||
setPowerSave(isPowerSave);
|
||||
}
|
||||
|
||||
public void startListening() {
|
||||
@@ -62,15 +61,14 @@ public class BatteryMeterDrawable extends BatteryMeterDrawableBase implements
|
||||
mBatteryController.removeCallback(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateShowPercent() {
|
||||
mShowPercent = 0 != Settings.System.getInt(mContext.getContentResolver(),
|
||||
SHOW_PERCENT_SETTING, 0);
|
||||
setShowPercent(0 != Settings.System.getInt(mContext.getContentResolver(),
|
||||
SHOW_PERCENT_SETTING, 0));
|
||||
}
|
||||
|
||||
public void setBatteryController(BatteryController batteryController) {
|
||||
mBatteryController = batteryController;
|
||||
mPowerSaveEnabled = mBatteryController.isPowerSave();
|
||||
setPowerSave(mBatteryController.isPowerSave());
|
||||
}
|
||||
|
||||
private final class SettingObserver extends ContentObserver {
|
||||
|
||||
@@ -197,7 +197,7 @@ public class BatteryTile extends QSTile<QSTile.State> implements BatteryControll
|
||||
}
|
||||
mDrawable.onBatteryLevelChanged(100, false, false);
|
||||
mDrawable.onPowerSaveChanged(true);
|
||||
mDrawable.disableShowPercent();
|
||||
mDrawable.setShowPercent(false);
|
||||
((ImageView) mCurrentView.findViewById(android.R.id.icon)).setImageDrawable(mDrawable);
|
||||
Checkable checkbox = (Checkable) mCurrentView.findViewById(android.R.id.toggle);
|
||||
checkbox.setChecked(mPowerSave);
|
||||
|
||||
@@ -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.settingslib.graph.BatteryMeterDrawableBase.SHOW_PERCENT_SETTING;
|
||||
import static com.android.systemui.BatteryMeterDrawable.SHOW_PERCENT_SETTING;
|
||||
|
||||
public class BatteryPreference extends DropDownPreference implements TunerService.Tunable {
|
||||
|
||||
|
||||
@@ -38,12 +38,10 @@ import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.settingslib.graph.BatteryMeterDrawableBase;
|
||||
import static com.android.systemui.BatteryMeterDrawable.SHOW_PERCENT_SETTING;
|
||||
import com.android.systemui.DemoMode;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SystemUI;
|
||||
import com.android.systemui.SystemUIApplication;
|
||||
import com.android.systemui.settings.CurrentUserTracker;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconController;
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog;
|
||||
@@ -201,7 +199,7 @@ public class TunerService {
|
||||
// A couple special cases.
|
||||
Settings.Global.putString(mContentResolver, DemoMode.DEMO_MODE_ALLOWED, null);
|
||||
Settings.System.putString(mContentResolver,
|
||||
BatteryMeterDrawableBase.SHOW_PERCENT_SETTING, null);
|
||||
SHOW_PERCENT_SETTING, null);
|
||||
Intent intent = new Intent(DemoMode.ACTION_DEMO);
|
||||
intent.putExtra(DemoMode.EXTRA_COMMAND, DemoMode.COMMAND_EXIT);
|
||||
mContext.sendBroadcast(intent);
|
||||
|
||||
Reference in New Issue
Block a user