Reduce size of 'GB' and '%' in storage settings.

Test: Manual
Fixes: 62548317
Change-Id: I5ff8ff8c463c2718e48bf04731924922bc0ecc9c
This commit is contained in:
Jane Chiang
2018-03-23 14:27:28 +08:00
parent b0f251597c
commit a2860a488d
3 changed files with 28 additions and 6 deletions

View File

@@ -24,9 +24,16 @@ import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Typeface;
import android.icu.text.DecimalFormatSymbols;
import android.support.annotation.ColorRes;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.RelativeSizeSpan;
import android.util.AttributeSet;
import android.view.View;
@@ -124,7 +131,6 @@ public class DonutView extends View {
mBigNumberPaint.setAntiAlias(true);
mBigNumberPaint.setTextSize(
resources.getDimension(R.dimen.storage_donut_view_percent_text_size));
mBigNumberPaint.setTextAlign(Paint.Align.CENTER);
mBigNumberPaint.setTypeface(Typeface.create(
context.getString(com.android.internal.R.string.config_headlineFontFamily),
Typeface.NORMAL));
@@ -167,11 +173,25 @@ public class DonutView extends View {
final float centerY = getHeight() / 2;
final float totalHeight = getTextHeight(mTextPaint) + getTextHeight(mBigNumberPaint);
final float startY = centerY + totalHeight / 2;
final float fontProportion = getResources().getDimension(
R.dimen.storage_donut_view_percent_sign_size) /
getResources().getDimension(R.dimen.storage_donut_view_percent_text_size);
// Support from Android P
final String localizedPercentSign = new DecimalFormatSymbols().getPercentString();
final int startIndex = mPercentString.indexOf(localizedPercentSign);
final int endIndex = startIndex + localizedPercentSign.length();
// The first line y-coordinates start at (total height - all TextPaint height) / 2
canvas.save();
final Spannable percentStringSpan = new SpannableString(mPercentString);
percentStringSpan.setSpan(new RelativeSizeSpan(fontProportion),
startIndex, endIndex, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
final StaticLayout percentStringLayout = new StaticLayout(percentStringSpan,
mBigNumberPaint, getWidth(), Layout.Alignment.ALIGN_CENTER, 1, 0, false);
canvas.translate(0, (getHeight() - totalHeight) / 2);
percentStringLayout.draw(canvas);
canvas.restore();
// The first line is the height of the bottom text + its descender above the bottom line.
canvas.drawText(mPercentString, centerX,
startY - getTextHeight(mTextPaint) - mBigNumberPaint.descent(),
mBigNumberPaint);
// The second line starts at the bottom + room for the descender.
canvas.drawText(mFullString, centerX, startY - mTextPaint.descent(), mTextPaint);
}