Merge "Add 25% and 75% lines to improve the readability of the battery level as a short-term fix." into udc-qpr-dev

This commit is contained in:
Xinyi Mao
2023-07-14 06:31:30 +00:00
committed by Android (Google) Code Review

View File

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