Update the donut view to handle new string.
Change-Id: Idb5cec6d8169f3d229375faecc4bf96501481112 Fixes: 36224266 Test: Manually verified
This commit is contained in:
@@ -8322,8 +8322,9 @@
|
|||||||
<string name="storage_size_large_alternate"><xliff:g id="number" example="128">^1</xliff:g><small> <xliff:g id="unit" example="KB">^2</xliff:g></small></string>
|
<string name="storage_size_large_alternate"><xliff:g id="number" example="128">^1</xliff:g><small> <xliff:g id="unit" example="KB">^2</xliff:g></small></string>
|
||||||
<!-- Summary of a single storage volume total space. [CHAR LIMIT=48]-->
|
<!-- Summary of a single storage volume total space. [CHAR LIMIT=48]-->
|
||||||
<string name="storage_volume_total">Used of <xliff:g id="total" example="32GB">%1$s</xliff:g></string>
|
<string name="storage_volume_total">Used of <xliff:g id="total" example="32GB">%1$s</xliff:g></string>
|
||||||
<!-- The percent of storage used by a storage volume. Exposed inside of a donut graph. [CHAR LIMIT=4]-->
|
<!-- Follows the percent of storage used by a storage volume. Exposed inside of a donut graph. [CHAR LIMIT=7]-->
|
||||||
<string name="storage_percent_used"><xliff:g id="percent" example="50%">%1$s</xliff:g>%%</string>
|
<string name="storage_percent_full">full</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Title of games app storage screen [CHAR LIMIT=30] -->
|
<!-- Title of games app storage screen [CHAR LIMIT=30] -->
|
||||||
<string name="game_storage_settings">Games</string>
|
<string name="game_storage_settings">Games</string>
|
||||||
|
@@ -22,20 +22,25 @@ import android.text.TextPaint;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.android.internal.util.Preconditions;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DonutView represents a donut graph. It visualizes a certain percentage of fullness with a
|
* DonutView represents a donut graph. It visualizes a certain percentage of fullness with a
|
||||||
* corresponding label with the fullness on the inside (i.e. "50%" inside of the donut.
|
* corresponding label with the fullness on the inside (i.e. "50%" inside of the donut).
|
||||||
*/
|
*/
|
||||||
public class DonutView extends View {
|
public class DonutView extends View {
|
||||||
private static final int TOP = -90;
|
private static final int TOP = -90;
|
||||||
private float mStrokeWidth;
|
private float mStrokeWidth;
|
||||||
|
private float mDeviceDensity;
|
||||||
private int mPercent;
|
private int mPercent;
|
||||||
private Paint mBackgroundCircle;
|
private Paint mBackgroundCircle;
|
||||||
private Paint mFilledArc;
|
private Paint mFilledArc;
|
||||||
private TextPaint mTextPaint;
|
private TextPaint mTextPaint;
|
||||||
|
private TextPaint mBigNumberPaint;
|
||||||
|
private String mPercentString;
|
||||||
|
private String mFullString;
|
||||||
|
|
||||||
public DonutView(Context context) {
|
public DonutView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -43,8 +48,8 @@ public class DonutView extends View {
|
|||||||
|
|
||||||
public DonutView(Context context, AttributeSet attrs) {
|
public DonutView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
float density = getResources().getDisplayMetrics().density;
|
mDeviceDensity = getResources().getDisplayMetrics().density;
|
||||||
mStrokeWidth = 6f * density;
|
mStrokeWidth = 6f * mDeviceDensity;
|
||||||
|
|
||||||
mBackgroundCircle = new Paint();
|
mBackgroundCircle = new Paint();
|
||||||
mBackgroundCircle.setAntiAlias(true);
|
mBackgroundCircle.setAntiAlias(true);
|
||||||
@@ -63,28 +68,43 @@ public class DonutView extends View {
|
|||||||
mTextPaint = new TextPaint();
|
mTextPaint = new TextPaint();
|
||||||
mTextPaint.setColor(Utils.getColorAccent(getContext()));
|
mTextPaint.setColor(Utils.getColorAccent(getContext()));
|
||||||
mTextPaint.setAntiAlias(true);
|
mTextPaint.setAntiAlias(true);
|
||||||
mTextPaint.setTextSize(18f * density);
|
mTextPaint.setTextSize(14f * mDeviceDensity);
|
||||||
mTextPaint.setTextAlign(Paint.Align.CENTER);
|
mTextPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
|
|
||||||
|
mBigNumberPaint = new TextPaint();
|
||||||
|
mBigNumberPaint.setColor(Utils.getColorAccent(getContext()));
|
||||||
|
mBigNumberPaint.setAntiAlias(true);
|
||||||
|
mBigNumberPaint.setTextSize(30f * mDeviceDensity);
|
||||||
|
mBigNumberPaint.setTextAlign(Paint.Align.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
drawDonut(canvas);
|
||||||
|
drawInnerText(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawDonut(Canvas canvas) {
|
||||||
canvas.drawArc(0 + mStrokeWidth, 0 + mStrokeWidth, getWidth() - mStrokeWidth,
|
canvas.drawArc(0 + mStrokeWidth, 0 + mStrokeWidth, getWidth() - mStrokeWidth,
|
||||||
getHeight() - mStrokeWidth, TOP, 360, false, mBackgroundCircle);
|
getHeight() - mStrokeWidth, TOP, 360, false, mBackgroundCircle);
|
||||||
|
|
||||||
canvas.drawArc(0 + mStrokeWidth, 0 + mStrokeWidth, getWidth() - mStrokeWidth,
|
canvas.drawArc(0 + mStrokeWidth, 0 + mStrokeWidth, getWidth() - mStrokeWidth,
|
||||||
getHeight() - mStrokeWidth, TOP, (360 * mPercent / 100), false, mFilledArc);
|
getHeight() - mStrokeWidth, TOP, (360 * mPercent / 100), false, mFilledArc);
|
||||||
|
}
|
||||||
|
|
||||||
int centerX = getWidth() / 2;
|
private void drawInnerText(Canvas canvas) {
|
||||||
int centerY = getHeight() / 2;
|
final float centerX = getWidth() / 2;
|
||||||
|
final float centerY = getHeight() / 2;
|
||||||
|
final float totalHeight = getTextHeight(mTextPaint) + getTextHeight(mBigNumberPaint);
|
||||||
|
final float startY = centerY + totalHeight / 2;
|
||||||
|
|
||||||
String percentString =
|
// The first line is the height of the bottom text + its descender above the bottom line.
|
||||||
String.format(getContext().getString(R.string.storage_percent_used), mPercent);
|
canvas.drawText(mPercentString, centerX,
|
||||||
// drawText uses the Y dimension as the floor of the text, so we do this to center.
|
startY - getTextHeight(mTextPaint) - mBigNumberPaint.descent(),
|
||||||
canvas.drawText(percentString, centerX,
|
mBigNumberPaint);
|
||||||
centerY + getTextHeight(mTextPaint) / 2 - mTextPaint.descent(),
|
// The second line starts at the bottom + room for the descender.
|
||||||
mTextPaint);
|
canvas.drawText(mFullString, centerX, startY - mTextPaint.descent(), mTextPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,6 +112,8 @@ public class DonutView extends View {
|
|||||||
*/
|
*/
|
||||||
public void setPercentage(int percent) {
|
public void setPercentage(int percent) {
|
||||||
mPercent = percent;
|
mPercent = percent;
|
||||||
|
mPercentString = Utils.formatPercentage(mPercent);
|
||||||
|
mFullString = getContext().getString(R.string.storage_percent_full);
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user