Add 25% and 75% lines to improve the readability of the battery level as a short-term fix.

[Screenshot]
Before: https://screenshot.googleplex.com/5WDToTZsRcosbjC
After:  https://screenshot.googleplex.com/C4XJ4Mnigxa27gq

Bug: 260498797
Fix: 260498797
Test: Manual
Change-Id: I08c8ec3b2868c59d341ce34d93b6e010e3440cf5
This commit is contained in:
mxyyiyi
2023-07-13 17:10:24 +08:00
parent e8e302b551
commit 881d625b25

View File

@@ -61,6 +61,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private static final String TAG = "BatteryChartView";
private static final int DIVIDER_COLOR = Color.parseColor("#CDCCC5");
private static final int HORIZONTAL_DIVIDER_COUNT = 5;
/** A callback listener for selected group index is updated. */
public interface OnSelectListener {
@@ -335,23 +336,24 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
private void drawHorizontalDividers(Canvas canvas) {
final int width = getWidth() - mIndent.right;
final int height = getHeight() - mIndent.top - mIndent.bottom;
// Draws the top divider line for 100% curve.
float offsetY = mIndent.top + mDividerWidth * .5f;
final float topOffsetY = mIndent.top + mDividerWidth * .5f;
final float bottomOffsetY = mIndent.top + (height - mDividerHeight - mDividerWidth * .5f);
final float availableSpace = bottomOffsetY - topOffsetY;
mDividerPaint.setColor(DIVIDER_COLOR);
canvas.drawLine(0, offsetY, width, offsetY, mDividerPaint);
drawPercentage(canvas, /*index=*/ 0, offsetY);
final float dividerOffsetUnit =
availableSpace / (float) (HORIZONTAL_DIVIDER_COUNT - 1);
// Draws the center divider line for 50% curve.
final float availableSpace =
height - mDividerWidth * 2 - mTrapezoidVOffset - mDividerHeight;
offsetY = mIndent.top + mDividerWidth + availableSpace * .5f;
canvas.drawLine(0, offsetY, width, offsetY, mDividerPaint);
drawPercentage(canvas, /*index=*/ 1, offsetY);
// Draws 5 divider lines.
for (int index = 0; index < HORIZONTAL_DIVIDER_COUNT; index++) {
float offsetY = topOffsetY + dividerOffsetUnit * index;
canvas.drawLine(0, offsetY, width, offsetY, mDividerPaint);
// Draws the bottom divider line for 0% curve.
offsetY = mIndent.top + (height - mDividerHeight - mDividerWidth * .5f);
canvas.drawLine(0, offsetY, width, offsetY, mDividerPaint);
drawPercentage(canvas, /*index=*/ 2, offsetY);
// Draws percentage text only for 100% / 50% / 0%
if (index % 2 == 0) {
drawPercentage(canvas, /*index=*/ (index + 1) / 2, offsetY);
}
}
}
private void drawPercentage(Canvas canvas, int index, float offsetY) {