public static class CalligraphyConfig.Builder
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static int |
INVALID_ATTR_ID
Default AttrID if not set.
|
| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
CalligraphyConfig.Builder |
addCustomStyle(java.lang.Class<? extends android.widget.TextView> styleClass,
int styleResourceAttribute)
Add a custom style to get looked up.
|
CalligraphyConfig.Builder |
addCustomViewWithSetTypeface(java.lang.Class<?> clazz)
Register custom non-
TextView's which implement setTypeface so they can have the Typeface applied during inflation. |
CalligraphyConfig |
build() |
CalligraphyConfig.Builder |
disableCustomViewInflation()
Due to the poor inflation order where custom views are created and never returned inside an
onCreateView(...) method. |
CalligraphyConfig.Builder |
disablePrivateFactoryInjection()
Turn of the use of Reflection to inject the private factory.
|
CalligraphyConfig.Builder |
setDefaultFontPath(java.lang.String defaultFontAssetPath)
Set the default font if you don't define one else where in your styles.
|
CalligraphyConfig.Builder |
setFontAttrId(int fontAssetAttrId)
This defaults to R.attr.fontPath.
|
public static final int INVALID_ATTR_ID
public CalligraphyConfig.Builder setFontAttrId(int fontAssetAttrId)
fontAssetAttrId - the custom attribute to look for fonts in assets.public CalligraphyConfig.Builder setDefaultFontPath(java.lang.String defaultFontAssetPath)
defaultFontAssetPath - a path to a font file in the assets folder, e.g. "fonts/Roboto-light.ttf",
passing null will default to the device font-family.public CalligraphyConfig.Builder disablePrivateFactoryInjection()
Turn of the use of Reflection to inject the private factory. This has operational consequences! Please read and understand before disabling. This is already disabled on pre Honeycomb devices. (API 11)
If you disable this you will need to override your Activity.onCreateView(android.view.View, String, android.content.Context, android.util.AttributeSet)
as this is set as the LayoutInflater private factory.
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
return CalligraphyContextWrapper.onActivityCreateView(this, parent, super.onCreateView(parent, name, context, attrs), name, context, attrs);
}
public CalligraphyConfig.Builder disableCustomViewInflation()
onCreateView(...) method. We have to create CustomView's at the latest point in the
overrideable injection flow.
On HoneyComb+ this is inside the Activity.onCreateView(android.view.View, String, android.content.Context, android.util.AttributeSet)
Pre HoneyComb this is in the LayoutInflater.onCreateView(String, android.util.AttributeSet)
We wrap base implementations, so if you LayoutInflater/Factory/Activity creates the
custom view before we get to this point, your view is used. (Such is the case with the
TintEditText etc)
The problem is, the native methods pass there parents context to the constructor in a really
specific place. We have to mimic this in CalligraphyLayoutInflater.createCustomViewInternal(android.view.View, android.view.View, String, android.content.Context, android.util.AttributeSet)
To mimic this we have to use reflection as the Class constructor args are hidden to us.
We have discussed other means of doing this but this is the only semi-clean way of doing it.
(Without having to do proxy classes etc).
Calling this will of course speed up inflation by turning off reflection, but not by much,
But if you want Calligraphy to inject the correct typeface then you will need to make sure your CustomView's
are created before reaching the LayoutInflater onViewCreated.public CalligraphyConfig.Builder addCustomStyle(java.lang.Class<? extends android.widget.TextView> styleClass, int styleResourceAttribute)
MyTextField.class which looked up it's default style as
R.attr.textFieldStyle you would add those here.
builder.addCustomStyle(MyTextField.class,R.attr.textFieldStylestyleClass - the class that related to the parent styleResource. null is ignored.styleResourceAttribute - e.g. R.attr.textFieldStyle, 0 is ignored.public CalligraphyConfig.Builder addCustomViewWithSetTypeface(java.lang.Class<?> clazz)
TextView's which implement setTypeface so they can have the Typeface applied during inflation.public CalligraphyConfig build()