Set the bidi flags on Paints in DonutView
Previously, DonutView used Canvas.drawText with a Paint with default bidi directions, which is LTR. This meant that even in RTL locales, text was displayed assuming the direction of the paragraph the text was appearing in was LTR. This caused an incorrect display of Arabic percentages. Now we set the Paint bidiFlags according to the Locale's direction. Change-Id: Ic10228b8a23dc49de60246c37adfbaf7f8fd4e9e Fixes: 63767043 Test: Manual (tested in ar-EG, ar-MA, fa-IR, ur-PK, and he-IL locales)
This commit is contained in:
@@ -26,11 +26,15 @@ import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 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).
|
||||
@@ -101,12 +105,19 @@ public class DonutView extends View {
|
||||
mFilledArc.setColorFilter(mAccentColorFilter);
|
||||
}
|
||||
|
||||
final Locale locale = resources.getConfiguration().locale;
|
||||
final int layoutDirection = TextUtils.getLayoutDirectionFromLocale(locale);
|
||||
final int bidiFlags = (layoutDirection == LAYOUT_DIRECTION_LTR)
|
||||
? Paint.BIDI_LTR
|
||||
: Paint.BIDI_RTL;
|
||||
|
||||
mTextPaint = new TextPaint();
|
||||
mTextPaint.setColor(Utils.getColorAccent(getContext()));
|
||||
mTextPaint.setAntiAlias(true);
|
||||
mTextPaint.setTextSize(
|
||||
resources.getDimension(R.dimen.storage_donut_view_label_text_size));
|
||||
mTextPaint.setTextAlign(Paint.Align.CENTER);
|
||||
mTextPaint.setBidiFlags(bidiFlags);
|
||||
|
||||
mBigNumberPaint = new TextPaint();
|
||||
mBigNumberPaint.setColor(Utils.getColorAccent(getContext()));
|
||||
@@ -117,6 +128,7 @@ public class DonutView extends View {
|
||||
mBigNumberPaint.setTypeface(Typeface.create(
|
||||
context.getString(com.android.internal.R.string.config_headlineFontFamily),
|
||||
Typeface.NORMAL));
|
||||
mBigNumberPaint.setBidiFlags(bidiFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user