am 75ef98f8: Merge "Add fontFamily XML attribute to select font family by string" into jb-dev
* commit '75ef98f8210fa1845d04a6e8206f4c7be5499052': Add fontFamily XML attribute to select font family by string
This commit is contained in:
@@ -485,6 +485,7 @@ package android {
|
|||||||
field public static final int focusable = 16842970; // 0x10100da
|
field public static final int focusable = 16842970; // 0x10100da
|
||||||
field public static final int focusableInTouchMode = 16842971; // 0x10100db
|
field public static final int focusableInTouchMode = 16842971; // 0x10100db
|
||||||
field public static final int focusedMonthDateColor = 16843587; // 0x1010343
|
field public static final int focusedMonthDateColor = 16843587; // 0x1010343
|
||||||
|
field public static final int fontFamily = 16843692; // 0x10103ac
|
||||||
field public static final int footerDividersEnabled = 16843311; // 0x101022f
|
field public static final int footerDividersEnabled = 16843311; // 0x101022f
|
||||||
field public static final int foreground = 16843017; // 0x1010109
|
field public static final int foreground = 16843017; // 0x1010109
|
||||||
field public static final int foregroundGravity = 16843264; // 0x1010200
|
field public static final int foregroundGravity = 16843264; // 0x1010200
|
||||||
|
|||||||
@@ -68,24 +68,29 @@ public class TextAppearanceSpan extends MetricAffectingSpan implements Parcelabl
|
|||||||
TextAppearance_textSize, -1);
|
TextAppearance_textSize, -1);
|
||||||
|
|
||||||
mStyle = a.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, 0);
|
mStyle = a.getInt(com.android.internal.R.styleable.TextAppearance_textStyle, 0);
|
||||||
int tf = a.getInt(com.android.internal.R.styleable.TextAppearance_typeface, 0);
|
String family = a.getString(com.android.internal.R.styleable.TextAppearance_fontFamily);
|
||||||
|
if (family != null) {
|
||||||
|
mTypeface = family;
|
||||||
|
} else {
|
||||||
|
int tf = a.getInt(com.android.internal.R.styleable.TextAppearance_typeface, 0);
|
||||||
|
|
||||||
switch (tf) {
|
switch (tf) {
|
||||||
case 1:
|
case 1:
|
||||||
mTypeface = "sans";
|
mTypeface = "sans";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
mTypeface = "serif";
|
mTypeface = "serif";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
mTypeface = "monospace";
|
mTypeface = "monospace";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
mTypeface = null;
|
mTypeface = null;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ import java.util.Locale;
|
|||||||
* @attr ref android.R.styleable#TextView_textColorLink
|
* @attr ref android.R.styleable#TextView_textColorLink
|
||||||
* @attr ref android.R.styleable#TextView_textSize
|
* @attr ref android.R.styleable#TextView_textSize
|
||||||
* @attr ref android.R.styleable#TextView_textScaleX
|
* @attr ref android.R.styleable#TextView_textScaleX
|
||||||
|
* @attr ref android.R.styleable#TextView_fontFamily
|
||||||
* @attr ref android.R.styleable#TextView_typeface
|
* @attr ref android.R.styleable#TextView_typeface
|
||||||
* @attr ref android.R.styleable#TextView_textStyle
|
* @attr ref android.R.styleable#TextView_textStyle
|
||||||
* @attr ref android.R.styleable#TextView_cursorVisible
|
* @attr ref android.R.styleable#TextView_cursorVisible
|
||||||
@@ -464,6 +465,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
ColorStateList textColorHint = null;
|
ColorStateList textColorHint = null;
|
||||||
ColorStateList textColorLink = null;
|
ColorStateList textColorLink = null;
|
||||||
int textSize = 15;
|
int textSize = 15;
|
||||||
|
String fontFamily = null;
|
||||||
int typefaceIndex = -1;
|
int typefaceIndex = -1;
|
||||||
int styleIndex = -1;
|
int styleIndex = -1;
|
||||||
boolean allCaps = false;
|
boolean allCaps = false;
|
||||||
@@ -516,6 +518,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
typefaceIndex = appearance.getInt(attr, -1);
|
typefaceIndex = appearance.getInt(attr, -1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case com.android.internal.R.styleable.TextAppearance_fontFamily:
|
||||||
|
fontFamily = appearance.getString(attr);
|
||||||
|
break;
|
||||||
|
|
||||||
case com.android.internal.R.styleable.TextAppearance_textStyle:
|
case com.android.internal.R.styleable.TextAppearance_textStyle:
|
||||||
styleIndex = appearance.getInt(attr, -1);
|
styleIndex = appearance.getInt(attr, -1);
|
||||||
break;
|
break;
|
||||||
@@ -781,6 +787,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
styleIndex = a.getInt(attr, styleIndex);
|
styleIndex = a.getInt(attr, styleIndex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case com.android.internal.R.styleable.TextView_fontFamily:
|
||||||
|
fontFamily = a.getString(attr);
|
||||||
|
break;
|
||||||
|
|
||||||
case com.android.internal.R.styleable.TextView_password:
|
case com.android.internal.R.styleable.TextView_password:
|
||||||
password = a.getBoolean(attr, password);
|
password = a.getBoolean(attr, password);
|
||||||
break;
|
break;
|
||||||
@@ -1051,7 +1061,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
typefaceIndex = MONOSPACE;
|
typefaceIndex = MONOSPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTypefaceByIndex(typefaceIndex, styleIndex);
|
setTypefaceFromAttrs(fontFamily, typefaceIndex, styleIndex);
|
||||||
|
|
||||||
if (shadowcolor != 0) {
|
if (shadowcolor != 0) {
|
||||||
setShadowLayer(r, dx, dy, shadowcolor);
|
setShadowLayer(r, dx, dy, shadowcolor);
|
||||||
@@ -1111,8 +1121,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTypefaceByIndex(int typefaceIndex, int styleIndex) {
|
private void setTypefaceFromAttrs(String familyName, int typefaceIndex, int styleIndex) {
|
||||||
Typeface tf = null;
|
Typeface tf = null;
|
||||||
|
if (familyName != null) {
|
||||||
|
tf = Typeface.create(familyName, styleIndex);
|
||||||
|
if (tf != null) {
|
||||||
|
setTypeface(tf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (typefaceIndex) {
|
switch (typefaceIndex) {
|
||||||
case SANS:
|
case SANS:
|
||||||
tf = Typeface.SANS_SERIF;
|
tf = Typeface.SANS_SERIF;
|
||||||
@@ -2160,14 +2177,17 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
setLinkTextColor(colors);
|
setLinkTextColor(colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String familyName;
|
||||||
int typefaceIndex, styleIndex;
|
int typefaceIndex, styleIndex;
|
||||||
|
|
||||||
|
familyName = appearance.getString(com.android.internal.R.styleable.
|
||||||
|
TextAppearance_fontFamily);
|
||||||
typefaceIndex = appearance.getInt(com.android.internal.R.styleable.
|
typefaceIndex = appearance.getInt(com.android.internal.R.styleable.
|
||||||
TextAppearance_typeface, -1);
|
TextAppearance_typeface, -1);
|
||||||
styleIndex = appearance.getInt(com.android.internal.R.styleable.
|
styleIndex = appearance.getInt(com.android.internal.R.styleable.
|
||||||
TextAppearance_textStyle, -1);
|
TextAppearance_textStyle, -1);
|
||||||
|
|
||||||
setTypefaceByIndex(typefaceIndex, styleIndex);
|
setTypefaceFromAttrs(familyName, typefaceIndex, styleIndex);
|
||||||
|
|
||||||
if (appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps,
|
if (appearance.getBoolean(com.android.internal.R.styleable.TextAppearance_textAllCaps,
|
||||||
false)) {
|
false)) {
|
||||||
@@ -2269,6 +2289,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
*
|
*
|
||||||
* @see #getTypeface()
|
* @see #getTypeface()
|
||||||
*
|
*
|
||||||
|
* @attr ref android.R.styleable#TextView_fontFamily
|
||||||
* @attr ref android.R.styleable#TextView_typeface
|
* @attr ref android.R.styleable#TextView_typeface
|
||||||
* @attr ref android.R.styleable#TextView_textStyle
|
* @attr ref android.R.styleable#TextView_textStyle
|
||||||
*/
|
*/
|
||||||
@@ -2290,6 +2311,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
*
|
*
|
||||||
* @see #setTypeface(Typeface)
|
* @see #setTypeface(Typeface)
|
||||||
*
|
*
|
||||||
|
* @attr ref android.R.styleable#TextView_fontFamily
|
||||||
* @attr ref android.R.styleable#TextView_typeface
|
* @attr ref android.R.styleable#TextView_typeface
|
||||||
* @attr ref android.R.styleable#TextView_textStyle
|
* @attr ref android.R.styleable#TextView_textStyle
|
||||||
*/
|
*/
|
||||||
@@ -3690,15 +3712,15 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
boolean forceUpdate = false;
|
boolean forceUpdate = false;
|
||||||
if (isPassword) {
|
if (isPassword) {
|
||||||
setTransformationMethod(PasswordTransformationMethod.getInstance());
|
setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||||
setTypefaceByIndex(MONOSPACE, 0);
|
setTypefaceFromAttrs(null /* fontFamily */, MONOSPACE, 0);
|
||||||
} else if (isVisiblePassword) {
|
} else if (isVisiblePassword) {
|
||||||
if (mTransformation == PasswordTransformationMethod.getInstance()) {
|
if (mTransformation == PasswordTransformationMethod.getInstance()) {
|
||||||
forceUpdate = true;
|
forceUpdate = true;
|
||||||
}
|
}
|
||||||
setTypefaceByIndex(MONOSPACE, 0);
|
setTypefaceFromAttrs(null /* fontFamily */, MONOSPACE, 0);
|
||||||
} else if (wasPassword || wasVisiblePassword) {
|
} else if (wasPassword || wasVisiblePassword) {
|
||||||
// not in password mode, clean up typeface and transformation
|
// not in password mode, clean up typeface and transformation
|
||||||
setTypefaceByIndex(-1, -1);
|
setTypefaceFromAttrs(null /* fontFamily */, -1, -1);
|
||||||
if (mTransformation == PasswordTransformationMethod.getInstance()) {
|
if (mTransformation == PasswordTransformationMethod.getInstance()) {
|
||||||
forceUpdate = true;
|
forceUpdate = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -857,6 +857,9 @@
|
|||||||
-->
|
-->
|
||||||
<attr name="textSize" format="dimension" />
|
<attr name="textSize" format="dimension" />
|
||||||
|
|
||||||
|
<!-- Default font family. -->
|
||||||
|
<attr name="fontFamily" format="string" />
|
||||||
|
|
||||||
<!-- Default text typeface. -->
|
<!-- Default text typeface. -->
|
||||||
<attr name="typeface">
|
<attr name="typeface">
|
||||||
<enum name="normal" value="0" />
|
<enum name="normal" value="0" />
|
||||||
@@ -2999,6 +3002,8 @@
|
|||||||
<attr name="textStyle" />
|
<attr name="textStyle" />
|
||||||
<!-- Typeface (normal, sans, serif, monospace) for the text. -->
|
<!-- Typeface (normal, sans, serif, monospace) for the text. -->
|
||||||
<attr name="typeface" />
|
<attr name="typeface" />
|
||||||
|
<!-- Font family (named by string) for the text. -->
|
||||||
|
<attr name="fontFamily" />
|
||||||
<!-- Color of the text selection highlight. -->
|
<!-- Color of the text selection highlight. -->
|
||||||
<attr name="textColorHighlight" />
|
<attr name="textColorHighlight" />
|
||||||
<!-- Color of the hint text. -->
|
<!-- Color of the hint text. -->
|
||||||
@@ -3044,6 +3049,8 @@
|
|||||||
<attr name="typeface" />
|
<attr name="typeface" />
|
||||||
<!-- Style (bold, italic, bolditalic) for the text. -->
|
<!-- Style (bold, italic, bolditalic) for the text. -->
|
||||||
<attr name="textStyle" />
|
<attr name="textStyle" />
|
||||||
|
<!-- Font family (named by string) for the text. -->
|
||||||
|
<attr name="fontFamily" />
|
||||||
<!-- Text color for links. -->
|
<!-- Text color for links. -->
|
||||||
<attr name="textColorLink" />
|
<attr name="textColorLink" />
|
||||||
<!-- Makes the cursor visible (the default) or invisible. -->
|
<!-- Makes the cursor visible (the default) or invisible. -->
|
||||||
|
|||||||
@@ -3605,4 +3605,6 @@
|
|||||||
<public type="attr" name="importantForAccessibility" id="0x010103aa" />
|
<public type="attr" name="importantForAccessibility" id="0x010103aa" />
|
||||||
<public type="attr" name="kcm" id="0x010103ab" />
|
<public type="attr" name="kcm" id="0x010103ab" />
|
||||||
|
|
||||||
|
<public type="attr" name="fontFamily" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user