summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextView.java
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-04-14 14:11:02 -0700
committerRaph Levien <raph@google.com>2014-04-17 11:16:46 -0700
commit53c0077256afebb0312f01ef4f60a7445da1f5d9 (patch)
tree6195aace369328dc798b1f9f286834e1118082b9 /core/java/android/widget/TextView.java
parent31e052bfc4c81f0aa682d723a88cd9b716b6cace (diff)
Add elegantTextHeight text appearance attribute
This patch adds an elegantTextHeight text appearance attribute and plumbs it through to the paint. This attribute selects the elegant variant of fonts (when appropriate, which is typically Arabic and indic scripts), and also specifies larger vertical metrics, to avoid clipping. The intent is for this to be the default for quantum themes, but this patch doesn't change any default behavior, just adds the attribute. The larger vertical metrics are applied to top and bottom, but should not affect line spacing in the common case. Also, with the setting, metrics are no longer dependent on the font, so setting a custom font will preserve layout and spacing. Change-Id: If3b7d41f141deff50ca078f479ca90c2aa07829a
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r--core/java/android/widget/TextView.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index a7278dae4497..b91111d5e336 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -652,6 +652,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
boolean allCaps = false;
int shadowcolor = 0;
float dx = 0, dy = 0, r = 0;
+ boolean elegant = false;
final Resources.Theme theme = context.getTheme();
@@ -728,6 +729,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case com.android.internal.R.styleable.TextAppearance_shadowRadius:
r = appearance.getFloat(attr, 0);
break;
+
+ case com.android.internal.R.styleable.TextAppearance_elegantTextHeight:
+ elegant = appearance.getBoolean(attr, false);
+ break;
}
}
@@ -1065,6 +1070,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case com.android.internal.R.styleable.TextView_textAllCaps:
allCaps = a.getBoolean(attr, false);
break;
+
+ case com.android.internal.R.styleable.TextView_elegantTextHeight:
+ elegant = a.getBoolean(attr, false);
+ break;
}
}
a.recycle();
@@ -1245,6 +1254,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
setHighlightColor(textColorHighlight);
}
setRawTextSize(textSize);
+ setElegantTextHeight(elegant);
if (allCaps) {
setTransformationMethod(new AllCapsTransformationMethod(getContext()));
@@ -2468,6 +2478,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
setTransformationMethod(new AllCapsTransformationMethod(getContext()));
}
+ if (appearance.hasValue(com.android.internal.R.styleable.TextAppearance_elegantTextHeight)) {
+ setElegantTextHeight(appearance.getBoolean(
+ com.android.internal.R.styleable.TextAppearance_elegantTextHeight, false));
+ }
+
appearance.recycle();
}
@@ -2615,6 +2630,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
/**
+ * Set the TextView's elegant height metrics flag. This setting selects font
+ * variants that have not been compacted to fit Latin-based vertical
+ * metrics, and also increases top and bottom bounds to provide more space.
+ *
+ * @param elegant set the paint's elegant metrics flag.
+ */
+ public void setElegantTextHeight(boolean elegant) {
+ mTextPaint.setElegantTextHeight(elegant);
+ }
+
+ /**
* Sets the text color for all the states (normal, selected,
* focused) to be this color.
*