Java Code Examples for android.graphics.Typeface#createFromFile()
The following examples show how to use
android.graphics.Typeface#createFromFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypefaceCompatBaseImpl.java From Carbon with Apache License 2.0 | 8 votes |
protected Typeface createFromInputStream(Context context, InputStream is) { final File tmpFile = TypefaceCompatUtil.getTempFile(context); if (tmpFile == null) { return null; } try { if (!TypefaceCompatUtil.copyToFile(tmpFile, is)) { return null; } return Typeface.createFromFile(tmpFile.getPath()); } catch (RuntimeException e) { // This was thrown from Typeface.createFromFile when a Typeface could not be loaded, // such as due to an invalid ttf or unreadable file. We don't want to throw that // exception anymore. return null; } finally { tmpFile.delete(); } }
Example 2
Source File: CustomTypefaceManager.java From zom-android-matrix with Apache License 2.0 | 7 votes |
public static void loadFromKeyboard (Context context) { PackageManager packageManager = context.getPackageManager(); String fontName = "DDC_Uchen.ttf"; try { Resources res = packageManager.getResourcesForApplication("org.ironrabbit.bhoboard"); InputStream reader = res.getAssets().open(fontName); File fileFont = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),fontName); OutputStream writer = new FileOutputStream(fileFont); byte[] buffer = new byte[32000]; int l = 0; while((l = reader.read(buffer)) > 0) { writer.write(buffer, 0, l); } writer.close(); mTypeface = Typeface.createFromFile(fileFont); } catch (Exception e) { Log.e("CustomTypeface","can't find assets",e); } }
Example 3
Source File: TypefaceCompat.java From AppCompat-Extension-Library with Apache License 2.0 | 7 votes |
@Deprecated private static void initialize() { Log.w("TypefaceCompat", "TypefaceCompat is deprecated. Use downloadable fonts or FontsContractCompat instead."); if (mTypefaceDetectionEnabled && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Typeface roboto = Typeface.createFromFile(SYSTEM_ROBOTO_REGULAR_FILE_PATH); if (roboto != null) { mIsUsingDefaultFont = TypefaceUtils.sameAs(roboto, Typeface.SANS_SERIF); } } mInitialized = true; }
Example 4
Source File: FontAdapter.java From HaoReader with GNU General Public License v3.0 | 7 votes |
public void upData(File[] files) { if (files != null) { fileList.clear(); for (File file : files) { try { Typeface.createFromFile(file); fileList.add(file); } catch (Exception e) { e.printStackTrace(); } } } notifyDataSetChanged(); }
Example 5
Source File: Cocos2dxTypefaces.java From Example-of-Cocos2DX with MIT License | 6 votes |
public static synchronized Typeface get(final Context pContext, final String pAssetName) { if (!Cocos2dxTypefaces.sTypefaceCache.containsKey(pAssetName)) { Typeface typeface = null; if (pAssetName.startsWith("/")) { typeface = Typeface.createFromFile(pAssetName); } else { typeface = Typeface.createFromAsset(pContext.getAssets(), pAssetName); } Cocos2dxTypefaces.sTypefaceCache.put(pAssetName, typeface); } return Cocos2dxTypefaces.sTypefaceCache.get(pAssetName); }
Example 6
Source File: Cocos2dxTypefaces.java From Earlybird with Apache License 2.0 | 6 votes |
public static synchronized Typeface get(final Context pContext, final String pAssetName) { if (!Cocos2dxTypefaces.sTypefaceCache.containsKey(pAssetName)) { Typeface typeface = null; if (pAssetName.startsWith("/")) { typeface = Typeface.createFromFile(pAssetName); } else { typeface = Typeface.createFromAsset(pContext.getAssets(), pAssetName); } Cocos2dxTypefaces.sTypefaceCache.put(pAssetName, typeface); } return Cocos2dxTypefaces.sTypefaceCache.get(pAssetName); }
Example 7
Source File: MaterialIcon.java From material-design-icons-for-android with Apache License 2.0 | 6 votes |
public static final Typeface getTypeface(Context context) throws Exception { if (typeface != null) { return typeface; } File InternalFolder = new File(context.getFilesDir(), "typeface"); if (!InternalFolder.exists()) { InternalFolder.mkdirs(); } File fontFile = new File(InternalFolder, "google_material_design_icon.ttf"); if (!fontFile.exists()) { InputStream is = context.getResources().openRawResource(R.raw.google_material_design_icon); byte[] buffer = new byte[is.available()]; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fontFile)); int l = 0; while ((l = is.read(buffer)) > 0) { bos.write(buffer, 0, l); } bos.close(); } typeface = Typeface.createFromFile( fontFile ); return typeface; }
Example 8
Source File: FontAdapter.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
@Override public void onBindViewHolder(@NonNull MyViewHolder holder, int position) { if (fileList.size() > 0) { Typeface typeface = Typeface.createFromFile(fileList.get(position)); holder.tvFont.setTypeface(typeface); holder.tvFont.setText(fileList.get(position).getName()); if (fileList.get(position).getAbsolutePath().equals(selectPath)) { holder.ivChecked.setVisibility(View.VISIBLE); } else { holder.ivChecked.setVisibility(View.INVISIBLE); } holder.tvFont.setOnClickListener(view -> { if (thisListener != null) { thisListener.setFontPath(fileList.get(position).getAbsolutePath()); } }); } else { holder.tvFont.setText(R.string.fonts_folder); } }
Example 9
Source File: ReadBottomStatusBar.java From HaoReader with GNU General Public License v3.0 | 6 votes |
public void updateTextTypeface(String fontPath, boolean bold) { Typeface typeface; try { if (fontPath != null) { typeface = Typeface.createFromFile(fontPath); } else { typeface = Typeface.SANS_SERIF; } } catch (Exception e) { typeface = Typeface.SANS_SERIF; } tvTime.setTypeface(typeface); tvTitle.setTypeface(typeface); tvTitleLeft.setTypeface(typeface); tvChapterIndex.setTypeface(typeface); tvTime.getPaint().setFakeBoldText(bold); tvTitle.getPaint().setFakeBoldText(bold); tvTitleLeft.getPaint().setFakeBoldText(bold); tvChapterIndex.getPaint().setFakeBoldText(bold); }
Example 10
Source File: ChooserDialogFragment.java From storage-chooser with Mozilla Public License 2.0 | 5 votes |
public static Typeface getSCTypeface(Context context, String path, boolean assets) { if (assets) { return Typeface.createFromAsset(context.getAssets(), path); } return Typeface.createFromFile(path); }
Example 11
Source File: FontsManager.java From FontsManager with Eclipse Public License 1.0 | 5 votes |
/** * 初始化 * * @param fontFile 字体包文件 */ public static void initFormFile(File fontFile) { try { defaultTypeface = Typeface.createFromFile(fontFile); } catch (Exception e) { Log.e(TAG, "初始化失败,请检查fontFile是否是字体文件"); throw new IllegalStateException("初始化失败,请检查fontFile是否是字体文件"); } }
Example 12
Source File: ExtStorageFontProvider.java From document-viewer with GNU General Public License v3.0 | 5 votes |
@Override protected Typeface loadTypeface(final FontFamilyType type, final FontInfo fi) { final File f = getFontFile(fi); try { return f.exists() ? Typeface.createFromFile(f) : null; } catch (final Throwable th) { th.printStackTrace(); } return null; }
Example 13
Source File: FontFactory.java From Android_Skin_2.0 with Apache License 2.0 | 5 votes |
@Override public FontFamily createFrom(Context context, String fontPath) { FontFamily family = null; try { TTFParser parser = new TTFParser(); parser.parse(fontPath); String fontName = parser.getFontName(); Typeface typeface = Typeface.createFromFile(fontPath); family = new FontFamily(fontPath, fontName, typeface); } catch (IOException e) { e.printStackTrace(); } return family; }
Example 14
Source File: FontAdapter.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
void upData(File[] files) { if (files != null) { fileList.clear(); for (File file : files) { try { Typeface.createFromFile(file); fileList.add(file); } catch (Exception e) { e.printStackTrace(); } } } notifyDataSetChanged(); }
Example 15
Source File: TypefaceUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * create typeface from file path * * @param filePath * @return */ static Typeface createFromFile( String filePath) { try { return Typeface.createFromFile(filePath); } catch (Exception e) { return null; } }
Example 16
Source File: Widget.java From PdDroidPublisher with GNU General Public License v3.0 | 5 votes |
public Widget(PdDroidPatchView app) { parent = app; if(defaultFont == null) { defaultFont = FileHelper.loadFontFromRaw(parent.getContext(), R.raw.dejavu_sans_mono_bold, "dejavu_sans_mono_bold.ttf"); } fontsize = (int)((float)parent.fontsize); font = defaultFont; File f = null; // set an aliased font f = parent.getPatch().getFile("font.ttf"); if (f.exists() && f.canRead() && f.isFile()) { font = Typeface.createFromFile(f); } else { // set an anti-aliased font f = parent.getPatch().getFile("font-antialiased.ttf"); if (f.exists() && f.canRead() && f.isFile()) { font = Typeface.createFromFile(f); paint.setAntiAlias(true); } } paint.setColor(fgcolor); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setTypeface(font); paint.setTextSize(fontsize); textoffset[0] = 0.0f; textoffset[1] = 0.0f; }
Example 17
Source File: FontAdapter.java From a with GNU General Public License v3.0 | 5 votes |
public void upData(File[] files) { if (files != null) { fileList.clear(); for (File file : files) { try { Typeface.createFromFile(file); fileList.add(file); } catch (Exception e) { e.printStackTrace(); } } } notifyDataSetChanged(); }
Example 18
Source File: PFileIO.java From PHONK with GNU General Public License v3.0 | 4 votes |
@PhonkMethod(description = "Loads a font", example = "") @PhonkMethodParam(params = {"fontFile"}) public Typeface loadFont(String fontName) { return Typeface.createFromFile(getAppRunner().getProject().getFullPathForFile(fontName)); }
Example 19
Source File: MainActivity.java From Quran-For-My-Android with Apache License 2.0 | 4 votes |
private void setTextTypeface(){ //no change has been made if(!FontSettingActivity.isDataChanged()){ return; } if(FontItemContainer.getAllFontFiles()==null){ //Initialize from predefined storage location FontItemContainer.initializeFontFiles(MainActivity.this); } /*if (PRIMARY_TEXT_INDEX == Word_Info_Index || PRIMARY_TEXT_INDEX == Arabic_Text_Index) { mainText.setTypeface(defaultTypefaces[1]); } else { mainText.setTypeface(Typeface.DEFAULT); }*/ if(FontItemContainer.getSelectedFontName(PRIMARY_TEXT_INDEX).equals( FontItemContainer.Default_Font_File_Name)) { mainText.setTypeface(Typeface.DEFAULT); return; } int fontFileIndex=FontItemContainer.getFontFileIndexInAsset(PRIMARY_TEXT_INDEX); if(fontFileIndex!=-1){//file found in asset mainText.setTypeface(defaultTypefaces.get(fontFileIndex)); } else{//file not found in asset fontFileIndex=FontItemContainer.getFontFileIndexInFiles(PRIMARY_TEXT_INDEX); if(fontFileIndex!=-1){//file found in storage Typeface typeface=Typeface.createFromFile(FontItemContainer.getFontFile(fontFileIndex)); mainText.setTypeface(typeface); } else{//file not found in storage mainText.setTypeface(Typeface.DEFAULT); FontItemContainer.setSelectedFontName(PRIMARY_TEXT_INDEX, FontItemContainer.Default_Font_File_Name); } } }
Example 20
Source File: FileHelper.java From gdx-pd with Apache License 2.0 | 3 votes |
public static Typeface loadFontFromRaw(Context context, int resource, String uniqueName) { Typeface tf = null; File f = new File(context.getCacheDir(), uniqueName); copyResource(context, resource, f); tf = Typeface.createFromFile(f); return tf; }