List of usage examples for android.graphics Typeface createFromAsset
public static Typeface createFromAsset(AssetManager mgr, String path)
From source file:qr.cloud.util.Typefaces.java
public static Typeface get(Context c, String typefaceName) { Typeface typeface = sTypefaceCache.get(typefaceName); if (typeface == null) { try {//from w ww . j a va 2 s . c o m typeface = Typeface.createFromAsset(c.getApplicationContext().getAssets(), typefaceName); sTypefaceCache.put(typefaceName, typeface); } catch (Exception e) { if (QRCloudUtils.DEBUG) { Log.e(TAG, "Could not get typeface '" + typefaceName + "' - " + e.getMessage()); } } } return typeface; }
From source file:Main.java
/** * The most useful answer about text drawing ever. http://stackoverflow.com/a/32081250 *///from ww w . ja v a 2s .co m @Nullable public static Bitmap createTypefaceBitmap(final Context context, @NonNull final String text, final int color, final float textSizePx) { final Typeface robotoMedium = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf"); final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setTypeface(robotoMedium); paint.setStyle(Paint.Style.FILL); paint.setColor(color); paint.setTextSize(textSizePx); final Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); Bitmap bitmap = null; if (!bounds.isEmpty()) { final int width = bounds.width(); final int height = bounds.height(); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444); final float x = bounds.left; final float y = height - bounds.bottom; final Canvas canvas = new Canvas(bitmap); canvas.drawText(text, x, y, paint); } return bitmap; }
From source file:Main.java
/** * Get custom typeface from assets/*from ww w . j a v a2 s.c o m*/ * * @param assetsPath * @return */ public static Typeface getCustomTypeface(String assetsPath) { if (mFontMaps.get(assetsPath) == null) { mFontMaps.put(assetsPath, Typeface.createFromAsset(mAssetManager, assetsPath)); } return mFontMaps.get(assetsPath); }
From source file:Main.java
/** * Sets a determined font on a text view element * * @param context Context in which the TextView can be found * @param font Font to be set in the text view see available fonts as static attributes of this class * @param textViews TextViews to which the font will be applied *//*from ww w.j a v a2 s .c o m*/ public static void setTypeface(Context context, String font, TextView... textViews) { Typeface tf = Typeface.createFromAsset(context.getAssets(), font); for (TextView txt : textViews) { txt.setTypeface(tf); } }
From source file:Main.java
public static Typeface getTypefaceZh(Context context) { if (appTypefaceZh == null) { appTypefaceZh = Typeface.createFromAsset(context.getAssets(), "fonts/en53.otf"); ;//Typeface.createFromAsset (context.getAssets() , "fonts/zh.otf"); }// w w w . j a va2 s . c o m return appTypefaceZh; }
From source file:com.keepassdroid.assets.TypefaceFactory.java
public static Typeface getTypeface(Context ctx, String fontPath) { Typeface tf;// www . j ava2s . com tf = (Typeface) typefaceMap.get(fontPath); if (tf != null) { return tf; } try { return Typeface.createFromAsset(ctx.getAssets(), fontPath); } catch (Exception e) { // Return null if we can't create it return null; } }
From source file:com.nabilhachicha.kc.utils.TypefaceUtils.java
/** * A helper loading a custom font.//from w ww. j a v a 2 s.c o m * * @param assetManager App's asset manager. * @param filePath The path of the file. * @return Return {@link android.graphics.Typeface} or null if the path is invalid. */ public static Typeface load(AssetManager assetManager, String filePath) { synchronized (sCachedFonts) { try { if (sCachedFonts.get(filePath) == null) { Typeface typeface = Typeface.createFromAsset(assetManager, filePath); sCachedFonts.put(filePath, typeface); return typeface; } } catch (Exception e) { return null; } return sCachedFonts.get(filePath); } }
From source file:Main.java
public static Typeface getTypefaceEn(Context context) { if (appTypefaceEn == null) { appTypefaceEn = Typeface.createFromAsset(context.getAssets(), "fonts/en_arial.ttf"); }//from w w w.j av a2s . c om return appTypefaceEn; }
From source file:Main.java
/** * Sets a determined font on a button element view * * @param context Context in which the TextView can be found * @param font Font to be set in the text view see available fonts as static attributes of this class * @param buttons Buttons to which the font will be applied *//*from w w w . j a v a 2 s .c o m*/ public static void setTypeface(Context context, String font, Button... buttons) { Typeface tf = Typeface.createFromAsset(context.getAssets(), font); for (Button txt : buttons) { txt.setTypeface(tf); } }
From source file:no.mofifo.imber.fragments.AboutFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment getActivity().setTitle(R.string.about_title); View view = inflater.inflate(R.layout.fragment_about, container, false); setHasOptionsMenu(true);// ww w . j a va2 s.c om TextView imberLogo = (TextView) view.findViewById(R.id.imberLogo); Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/Pattaya-Regular.ttf"); imberLogo.setTypeface(tf); return view; }