本文整理汇总了Java中android.graphics.Typeface.create方法的典型用法代码示例。如果您正苦于以下问题:Java Typeface.create方法的具体用法?Java Typeface.create怎么用?Java Typeface.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Typeface
的用法示例。
在下文中一共展示了Typeface.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import android.graphics.Typeface; //导入方法依赖的package包/类
private void setup(Context context) {
AssetManager assetManager = context.getAssets();
Typeface typeface = Typeface.createFromAsset(assetManager, "fonts/DejaVuSerif.ttf");
try {
typeface = Typeface.create(typeface, getTypeface().getStyle());
} catch (Exception e) {
e.printStackTrace();
}
setTypeface(typeface);
}
示例2: ensureTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Ensures that the typeface is initialized (if possible).
*/
private void ensureTypeface() {
if (mTypeface == null || mInvalidateTypeface) {
this.mInvalidateTypeface = false;
if (!TextUtils.isEmpty(mFontFamily)) {
this.mTypeface = Typeface.create(mFontFamily, mTextStyle);
} else {
switch (mTypefaceIndex) {
case SANS_SERIF:
this.mTypeface = Typeface.SANS_SERIF;
break;
case SERIF:
this.mTypeface = Typeface.SERIF;
break;
case MONOSPACE:
this.mTypeface = Typeface.MONOSPACE;
break;
}
}
}
}
示例3: updatePaintTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Updates typeface setting for the given <var>paint</var> to the specified one.
*
* @param paint The paint to be updated.
* @param typeface The desired typeface. May be {@code null} to resolve instance of typeface
* from the specified style.
* @param style The desired text style used to resolve proper instance of typeface.
* @return {@code True} if paint's typeface setting has changed, {@code false} otherwise.
* @see Paint#setTypeface(Typeface)
*/
public static boolean updatePaintTypeface(@NonNull Paint paint, @Nullable Typeface typeface, @TextStyle int style) {
if (style > 0) {
if (typeface == null) {
typeface = Typeface.defaultFromStyle(style);
} else {
typeface = Typeface.create(typeface, style);
}
final int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
final int need = style & ~typefaceStyle;
paint.setFakeBoldText((need & Typeface.BOLD) != 0);
paint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
paint.setTypeface(typeface);
} else {
paint.setFakeBoldText(false);
paint.setTextSkewX(0);
paint.setTypeface(typeface);
}
return true;
}
示例4: createTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
private static
@Nullable Typeface createTypeface(
String fontFamilyName,
int style,
AssetManager assetManager) {
String extension = EXTENSIONS[style];
for (String fileExtension : FILE_EXTENSIONS) {
String fileName = new StringBuilder()
.append(FONTS_ASSET_PATH)
.append(fontFamilyName)
.append(extension)
.append(fileExtension)
.toString();
try {
return Typeface.createFromAsset(assetManager, fileName);
} catch (RuntimeException e) {
// unfortunately Typeface.createFromAsset throws an exception instead of returning null
// if the typeface doesn't exist
}
}
return Typeface.create(fontFamilyName, style);
}
示例5: show
import android.graphics.Typeface; //导入方法依赖的package包/类
static void show(final MarkersActivity activity) {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(null);
builder.setCancelable(true);
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.about_box, null);
TextView title = (TextView) layout.findViewById(R.id.title);
Typeface light = Typeface.create("sans-serif-light", Typeface.NORMAL);
title.setTypeface(light);
title.setText(activity.getString(R.string.AppName) + " " + getVersionString(activity));
// builder.setNegativeButton("Neat!", new OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// dialog.dismiss();
// }});
builder.create().show();
}
示例6: apply
import android.graphics.Typeface; //导入方法依赖的package包/类
private static void apply(
Paint paint,
int style,
int weight,
@Nullable String family,
AssetManager assetManager) {
int oldStyle;
Typeface typeface = paint.getTypeface();
if (typeface == null) {
oldStyle = 0;
} else {
oldStyle = typeface.getStyle();
}
int want = 0;
if ((weight == Typeface.BOLD) ||
((oldStyle & Typeface.BOLD) != 0 && weight == ReactTextShadowNode.UNSET)) {
want |= Typeface.BOLD;
}
if ((style == Typeface.ITALIC) ||
((oldStyle & Typeface.ITALIC) != 0 && style == ReactTextShadowNode.UNSET)) {
want |= Typeface.ITALIC;
}
if (family != null) {
typeface = ReactFontManager.getInstance().getTypeface(family, want, assetManager);
} else if (typeface != null) {
// TODO(t9055065): Fix custom fonts getting applied to text children with different style
typeface = Typeface.create(typeface, want);
}
if (typeface != null) {
paint.setTypeface(typeface);
} else {
paint.setTypeface(Typeface.defaultFromStyle(want));
}
}
示例7: getOrCreateTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
public static Typeface getOrCreateTypeface(String family, int style) {
FontDO fontDo = sCacheMap.get(family);
if (fontDo != null && fontDo.getTypeface() != null) {
return fontDo.getTypeface();
}
return Typeface.create(family, style);
}
示例8: readFontFamilyTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
private Typeface readFontFamilyTypeface(int resId) {
final TypedArray a = mView.getContext().obtainStyledAttributes(resId,
new int[]{android.R.attr.fontFamily});
try {
final String family = a.getString(0);
if (family != null) {
return Typeface.create(family, Typeface.NORMAL);
}
} finally {
a.recycle();
}
return null;
}
示例9: getTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Returns a derivative of a given Typeface with a different style.
*/
public static Typeface getTypeface(Typeface typeface, int style) {
if (typeface == null) {
return Typeface.defaultFromStyle(style);
}
Typeface[] cache = TYPEFACE_CACHE.get(typeface);
if (cache == null) {
// This should not happen because all Typefaces are coming from TypefaceCache,
// and thus should be registered in TYPEFACE_CACHE.
// If we get here, it's a bug and one of the 2 scenarios happened:
// a) TypefaceCache created a Typeface and didn't put it into TYPEFACE_CACHE.
// b) someone else created a Typeface bypassing TypefaceCache so it's not registered here.
//
// If it's not registered, we can just register it manually for consistency, and so that
// next time someone requests a un unknown Typeface, it's already cached and we don't create
// extra copies.
cache = new Typeface[MAX_STYLES];
cache[typeface.getStyle()] = typeface;
} else if (cache[style] != null) {
// return cached value.
return cache[style];
}
typeface = Typeface.create(typeface, style);
cache[style] = typeface;
TYPEFACE_CACHE.put(typeface, cache);
return typeface;
}
示例10: setTypeface
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Sets the typeface size used by this view.
*
* @param typeface the typeface to use on the text.
*/
public void setTypeface(Typeface typeface) {
if (textStyle == Typeface.BOLD_ITALIC) {
typeface = Typeface.create(typeface, Typeface.BOLD_ITALIC);
} else if (textStyle == Typeface.BOLD) {
typeface = Typeface.create(typeface, Typeface.BOLD);
} else if (textStyle == Typeface.ITALIC) {
typeface = Typeface.create(typeface, Typeface.ITALIC);
}
textPaint.setTypeface(typeface);
onTextPaintMeasurementChanged();
}
示例11: getRoundedLetterImage
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Creates a rounded square of a certain color with
* a character imprinted in white on it.
*
* @param character the character to write on the image.
* @param width the width of the final image.
* @param height the height of the final image.
* @param color the background color of the rounded square.
* @return a valid bitmap of a rounded square with a character on it.
*/
@NonNull
public static Bitmap getRoundedLetterImage(@NonNull Character character, int width, int height, int color) {
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
Paint paint = new Paint();
paint.setColor(color);
Typeface boldText = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
paint.setTypeface(boldText);
paint.setTextSize(Utils.dpToPx(14));
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
int radius = Utils.dpToPx(2);
RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
canvas.drawRoundRect(outer, radius, radius, paint);
int xPos = (canvas.getWidth() / 2);
int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
paint.setColor(Color.WHITE);
canvas.drawText(character.toString(), xPos, yPos, paint);
return image;
}
示例12: initialize
import android.graphics.Typeface; //导入方法依赖的package包/类
public void initialize(ResourceLoader res, String[] texts, String[] innerTexts,
boolean is24HourMode, boolean disappearsOut) {
if (mIsInitialized) {
Log.e(TAG, "This RadialTextsView may only be initialized once.");
return;
}
// Set up the paint.
int numbersTextColor = res.getColor(R.color.numbers_text_color);
mPaint.setColor(numbersTextColor);
String typefaceFamily = res.getString(R.string.radial_numbers_typeface);
mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL);
String typefaceFamilyRegular = res.getString(R.string.sans_serif);
mTypefaceRegular = Typeface.create(typefaceFamilyRegular, Typeface.NORMAL);
mPaint.setAntiAlias(true);
mPaint.setTextAlign(Align.CENTER);
mTexts = texts;
mInnerTexts = innerTexts;
mIs24HourMode = is24HourMode;
mHasInnerCircle = (innerTexts != null);
// Calculate the radius for the main circle.
if (is24HourMode) {
mCircleRadiusMultiplier = Float.parseFloat(
res.getString(R.string.circle_radius_multiplier_24HourMode));
} else {
mCircleRadiusMultiplier = Float.parseFloat(
res.getString(R.string.circle_radius_multiplier));
mAmPmCircleRadiusMultiplier =
Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
}
// Initialize the widths and heights of the grid, and calculate the values for the numbers.
mTextGridHeights = new float[7];
mTextGridWidths = new float[7];
if (mHasInnerCircle) {
mNumbersRadiusMultiplier = Float.parseFloat(
res.getString(R.string.numbers_radius_multiplier_outer));
mTextSizeMultiplier = Float.parseFloat(
res.getString(R.string.text_size_multiplier_outer));
mInnerNumbersRadiusMultiplier = Float.parseFloat(
res.getString(R.string.numbers_radius_multiplier_inner));
mInnerTextSizeMultiplier = Float.parseFloat(
res.getString(R.string.text_size_multiplier_inner));
mInnerTextGridHeights = new float[7];
mInnerTextGridWidths = new float[7];
} else {
mNumbersRadiusMultiplier = Float.parseFloat(
res.getString(R.string.numbers_radius_multiplier_normal));
mTextSizeMultiplier = Float.parseFloat(
res.getString(R.string.text_size_multiplier_normal));
}
mAnimationRadiusMultiplier = 1;
mTransitionMidRadiusMultiplier = 1f + (0.05f * (disappearsOut ? -1 : 1));
mTransitionEndRadiusMultiplier = 1f + (0.3f * (disappearsOut ? 1 : -1));
mInvalidateUpdateListener = new InvalidateUpdateListener();
mTextGridValuesDirty = true;
mIsInitialized = true;
}
示例13: RadialTimePickerView
import android.graphics.Typeface; //导入方法依赖的package包/类
public RadialTimePickerView(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs);
applyAttributes(attrs, defStyleAttr, defStyleRes);
// Pull disabled alpha from theme.
final TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
mDisabledAlpha = outValue.getFloat();
mTypeface = Typeface.create("sans-serif", Typeface.NORMAL);
mPaint[HOURS] = new Paint();
mPaint[HOURS].setAntiAlias(true);
mPaint[HOURS].setTextAlign(Paint.Align.CENTER);
mPaint[MINUTES] = new Paint();
mPaint[MINUTES].setAntiAlias(true);
mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);
mPaintCenter.setAntiAlias(true);
mPaintSelector[SELECTOR_CIRCLE] = new Paint();
mPaintSelector[SELECTOR_CIRCLE].setAntiAlias(true);
mPaintSelector[SELECTOR_DOT] = new Paint();
mPaintSelector[SELECTOR_DOT].setAntiAlias(true);
mPaintSelector[SELECTOR_LINE] = new Paint();
mPaintSelector[SELECTOR_LINE].setAntiAlias(true);
mPaintSelector[SELECTOR_LINE].setStrokeWidth(2);
mPaintBackground.setAntiAlias(true);
final Resources res = getResources();
mSelectorRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_radius);
mSelectorStroke = res.getDimensionPixelSize(R.dimen.timepicker_selector_stroke);
mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_dot_radius);
mCenterDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_center_dot_radius);
mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_normal);
mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_normal);
mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_inner);
mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_normal);
mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_normal);
mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_inner);
mShowHours = true;
mHoursToMinutes = HOURS;
mIs24HourMode = false;
mAmOrPm = AM;
// Set up accessibility components.
mTouchHelper = new RadialPickerTouchHelper();
ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
//setAccessibilityDelegate(mTouchHelper);
if(ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO){
ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
}
/*if (getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
}*/
initHoursAndMinutesText();
initData();
// Initial values
final Calendar calendar = Calendar.getInstance(Locale.getDefault());
final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
final int currentMinute = calendar.get(Calendar.MINUTE);
setCurrentHourInternal(currentHour, false, false);
setCurrentMinuteInternal(currentMinute, false);
setHapticFeedbackEnabled(true);
}
示例14: initialize
import android.graphics.Typeface; //导入方法依赖的package包/类
public void initialize(Resources res, String[] texts, String[] innerTexts,
boolean is24HourMode, boolean disappearsOut) {
if (mIsInitialized) {
Log.e(TAG, "This RadialTextsView may only be initialized once.");
return;
}
// Set up the paint.
int numbersTextColor = res.getColor(R.color.numbers_text_color);
mPaint.setColor(numbersTextColor);
String typefaceFamily = res.getString(R.string.radial_numbers_typeface);
mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL);
String typefaceFamilyRegular = res.getString(R.string.sans_serif);
mTypefaceRegular = Typeface.create(typefaceFamilyRegular, Typeface.NORMAL);
mPaint.setAntiAlias(true);
mPaint.setTextAlign(Align.CENTER);
mTexts = texts;
mInnerTexts = innerTexts;
mIs24HourMode = is24HourMode;
mHasInnerCircle = (innerTexts != null);
// Calculate the radius for the main circle.
if (is24HourMode) {
mCircleRadiusMultiplier = Float.parseFloat(
res.getString(R.string.circle_radius_multiplier_24HourMode));
} else {
mCircleRadiusMultiplier = Float.parseFloat(
res.getString(R.string.circle_radius_multiplier));
mAmPmCircleRadiusMultiplier =
Float.parseFloat(res.getString(R.string.ampm_circle_radius_multiplier));
}
// Initialize the widths and heights of the grid, and calculate the values for the numbers.
mTextGridHeights = new float[7];
mTextGridWidths = new float[7];
if (mHasInnerCircle) {
mNumbersRadiusMultiplier = Float.parseFloat(
res.getString(R.string.numbers_radius_multiplier_outer));
mTextSizeMultiplier = Float.parseFloat(
res.getString(R.string.text_size_multiplier_outer));
mInnerNumbersRadiusMultiplier = Float.parseFloat(
res.getString(R.string.numbers_radius_multiplier_inner));
mInnerTextSizeMultiplier = Float.parseFloat(
res.getString(R.string.text_size_multiplier_inner));
mInnerTextGridHeights = new float[7];
mInnerTextGridWidths = new float[7];
} else {
mNumbersRadiusMultiplier = Float.parseFloat(
res.getString(R.string.numbers_radius_multiplier_normal));
mTextSizeMultiplier = Float.parseFloat(
res.getString(R.string.text_size_multiplier_normal));
}
mAnimationRadiusMultiplier = 1;
mTransitionMidRadiusMultiplier = 1f + (0.05f * (disappearsOut ? -1 : 1));
mTransitionEndRadiusMultiplier = 1f + (0.3f * (disappearsOut ? 1 : -1));
mInvalidateUpdateListener = new InvalidateUpdateListener();
mTextGridValuesDirty = true;
mIsInitialized = true;
}
示例15: initialize
import android.graphics.Typeface; //导入方法依赖的package包/类
public void initialize(Resources res, String[] texts, String[] innerTexts,
TimePickerController controller, boolean disappearsOut) {
if (this.mIsInitialized) {
Log.e(TAG, "This RadialTextsView may only be initialized once.");
return;
}
this.mPaint.setColor(res.getColor(controller.isThemeDark() ? R.color.mdtp_white : R.color
.mdtp_numbers_text_color));
this.mTypefaceLight = Typeface.create(res.getString(R.string
.mdtp_radial_numbers_typeface), 0);
this.mTypefaceRegular = Typeface.create(res.getString(R.string.mdtp_sans_serif), 0);
this.mPaint.setAntiAlias(true);
this.mPaint.setTextAlign(Align.CENTER);
this.mSelectedPaint.setColor(res.getColor(R.color.mdtp_white));
this.mSelectedPaint.setAntiAlias(true);
this.mSelectedPaint.setTextAlign(Align.CENTER);
this.mTexts = texts;
this.mInnerTexts = innerTexts;
this.mIs24HourMode = controller.is24HourMode();
this.mHasInnerCircle = innerTexts != null;
if (this.mIs24HourMode) {
this.mCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_circle_radius_multiplier_24HourMode));
} else {
this.mCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_circle_radius_multiplier));
this.mAmPmCircleRadiusMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_ampm_circle_radius_multiplier));
}
this.mTextGridHeights = new float[7];
this.mTextGridWidths = new float[7];
if (this.mHasInnerCircle) {
this.mNumbersRadiusMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_numbers_radius_multiplier_outer));
this.mTextSizeMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_text_size_multiplier_outer));
this.mInnerNumbersRadiusMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_numbers_radius_multiplier_inner));
this.mInnerTextSizeMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_text_size_multiplier_inner));
this.mInnerTextGridHeights = new float[7];
this.mInnerTextGridWidths = new float[7];
} else {
this.mNumbersRadiusMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_numbers_radius_multiplier_normal));
this.mTextSizeMultiplier = Float.parseFloat(res.getString(R.string
.mdtp_text_size_multiplier_normal));
}
this.mAnimationRadiusMultiplier = 1.0f;
this.mTransitionMidRadiusMultiplier = (((float) (disappearsOut ? -1 : 1)) * 0.05f) + 1.0f;
this.mTransitionEndRadiusMultiplier = (((float) (disappearsOut ? 1 : -1)) * 0.3f) + 1.0f;
this.mInvalidateUpdateListener = new InvalidateUpdateListener();
this.mTextGridValuesDirty = true;
this.mIsInitialized = true;
}