OSDN Git Service

Band aid to fix overly long text in donut.
authorDaniel Nishi <dhnishi@google.com>
Wed, 24 May 2017 23:25:08 +0000 (16:25 -0700)
committerDaniel Nishi <dhnishi@google.com>
Mon, 5 Jun 2017 20:22:26 +0000 (13:22 -0700)
In the Storage Settings, if the text is too long, it will overlap with
the donut. After discussing with UX, we've opted to shrink the text in
the extenuating circumstances. This is because this text is more of a
helper and the full information is on the left.

Bug: 38030457
Test: Manual with Telugu
Change-Id: I18bcaaae74d049c42eaff50868d3861ae258839d

res/values/dimens.xml
src/com/android/settings/widget/DonutView.java

index 6495ab0..c8737b9 100755 (executable)
 
     <!-- Padding between the donut and the storage summary. -->
     <dimen name="storage_summary_padding_end">16dp</dimen>
+    <!-- Text size of the big number in the donut. -->
+    <dimen name="storage_donut_view_percent_text_size">30sp</dimen>
+    <!-- Text size of the label text in the donut. -->
+    <dimen name="storage_donut_view_label_text_size">14sp</dimen>
+    <!-- Text size of the label text in the donut if the label text is long. -->
+    <dimen name="storage_donut_view_shrunken_label_text_size">10sp</dimen>
 
     <!-- Battery meter view size -->
     <dimen name="battery_meter_width">66dp</dimen>
index 7a13a0e..506ada9 100644 (file)
@@ -16,6 +16,7 @@
 package com.android.settings.widget;
 
 import android.content.Context;
+import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.Paint;
@@ -34,6 +35,8 @@ import com.android.settings.Utils;
  */
 public class DonutView extends View {
     private static final int TOP = -90;
+    // From manual testing, this is the longest we can go without visual errors.
+    private static final int LINE_CHARACTER_LIMIT = 10;
     private float mStrokeWidth;
     private float mDeviceDensity;
     private int mPercent;
@@ -73,16 +76,19 @@ public class DonutView extends View {
         mFilledArc.setColor(Utils.getDefaultColor(mContext, R.color.meter_consumed_color));
         mFilledArc.setColorFilter(mAccentColorFilter);
 
+        Resources resources = context.getResources();
         mTextPaint = new TextPaint();
         mTextPaint.setColor(Utils.getColorAccent(getContext()));
         mTextPaint.setAntiAlias(true);
-        mTextPaint.setTextSize(14f * mDeviceDensity);
+        mTextPaint.setTextSize(
+                resources.getDimension(R.dimen.storage_donut_view_label_text_size));
         mTextPaint.setTextAlign(Paint.Align.CENTER);
 
         mBigNumberPaint = new TextPaint();
         mBigNumberPaint.setColor(Utils.getColorAccent(getContext()));
         mBigNumberPaint.setAntiAlias(true);
-        mBigNumberPaint.setTextSize(30f * mDeviceDensity);
+        mBigNumberPaint.setTextSize(
+                resources.getDimension(R.dimen.storage_donut_view_percent_text_size));
         mBigNumberPaint.setTextAlign(Paint.Align.CENTER);
     }
 
@@ -136,6 +142,13 @@ public class DonutView extends View {
         mPercent = percent;
         mPercentString = Utils.formatPercentage(mPercent);
         mFullString = getContext().getString(R.string.storage_percent_full);
+        if (mFullString.length() > LINE_CHARACTER_LIMIT) {
+            mTextPaint.setTextSize(
+                    getContext()
+                            .getResources()
+                            .getDimension(
+                                    R.dimen.storage_donut_view_shrunken_label_text_size));
+        }
         invalidate();
     }