本文整理汇总了Java中android.graphics.Typeface.createFromFile方法的典型用法代码示例。如果您正苦于以下问题:Java Typeface.createFromFile方法的具体用法?Java Typeface.createFromFile怎么用?Java Typeface.createFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Typeface
的用法示例。
在下文中一共展示了Typeface.createFromFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFont
import android.graphics.Typeface; //导入方法依赖的package包/类
public boolean setFont(Context context, String fontPath) {
try {
if (TextUtils.isEmpty(fontPath) == true) {
typeface = null;
this.fontPath = null;
return true;
} else {
typeface = Typeface.createFromFile(fontPath);
if (typeface != null) {
this.fontPath = fontPath;
return true;
} else {
this.fontPath = null;
}
}
} catch (Throwable t) {
t.printStackTrace();
}
return false;
}
示例2: getChatFont
import android.graphics.Typeface; //导入方法依赖的package包/类
public Typeface getChatFont() {
if (mCachedFont != null)
return mCachedFont;
String font = mPreferences.getString(PREF_CHAT_FONT, "default");
if (ListWithCustomSetting.isPrefCustomValue(font)) {
File file = ListWithCustomSetting.getCustomFile(mContext, PREF_CHAT_FONT, font);
try {
mCachedFont = Typeface.createFromFile(file);
return mCachedFont;
} catch (Exception ignored) {
}
}
if (font.equals("monospace"))
return Typeface.MONOSPACE;
else if (font.equals("serif"))
return Typeface.SERIF;
else
return Typeface.DEFAULT;
}
示例3: createFromFile
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* create typeface from file path
*
* @param filePath
* @return
*/
private static Typeface createFromFile(final String filePath) {
try {
return Typeface.createFromFile(filePath);
} catch (Exception e) {
LogUtil.e("create typeface " + filePath + " from file failed", e);
return null;
}
}
示例4: setFont
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Apply font to the sample
* @param font name of applying font
*/
private void setFont(String font){
Typeface type;
try {
type = Typeface.createFromFile("/system/fonts/" + font + ".ttf");
}catch (Exception e){
type = Typeface.createFromAsset(getActivity().getAssets(), "fonts/" + font + ".otf");
}
tvSample.setTypeface(type);
}
示例5: applySpacing
import android.graphics.Typeface; //导入方法依赖的package包/类
/**
* Apply spacing letter to sample text
*/
private void applySpacing(){
Typeface typeface;
try {
typeface = Typeface.createFromAsset(getActivity().getAssets(), SettingManager.getFont(settingsManager.getSettings().get("font"), letterSpace));
}catch(Exception e){
typeface = Typeface.createFromFile("/system/fonts/" + settingsManager.getSettings().get("font") + ".ttf");
rbS0.setEnabled(false);
rbS1.setEnabled(false);
rbS2.setEnabled(false);
}
tvSample.setTypeface(typeface);
}
示例6: getFont
import android.graphics.Typeface; //导入方法依赖的package包/类
public static Typeface getFont(Context context, String name) {
Typeface font = knownFonts.get(name);
if (font == null) {
if (name.startsWith("/")) {
font = Typeface.createFromFile(name);
} else {
font = Typeface.createFromAsset(context.getAssets(),"fonts/" + name);
}
knownFonts.put(name, font);
}
//Log.d(LOGTAG, "typeface for " + name + " is " + (font == null?"null":"not null"));
return font;
}
示例7:
import android.graphics.Typeface; //导入方法依赖的package包/类
public static Typeface 取字体(String $文件) {
return Typeface.createFromFile(文件工具.取文件对象($文件));
}
示例8: loadFont
import android.graphics.Typeface; //导入方法依赖的package包/类
@ProtoMethod(description = "Loads a font", example = "")
@ProtoMethodParam(params = {"fontFile"})
public Typeface loadFont(String fontName) {
return Typeface.createFromFile(getAppRunner().getProject().getFullPathForFile(fontName));
}
示例9: loadFont
import android.graphics.Typeface; //导入方法依赖的package包/类
@ReactMethod
public void loadFont(final ReadableMap options, final Callback callback) throws Exception {
Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
callback.invoke("Invalid activity");
return;
}
String name = (options.hasKey("name")) ? options.getString("name") : null,
data = (options.hasKey("data")) ? options.getString("data") : null,
type = null;
if (name == null || name.length() == 0) {
callback.invoke("Name property empty");
return;
}
if (data == null || data.length() == 0) {
callback.invoke("Data property empty");
return;
}
if (("data:").equalsIgnoreCase(data.substring(0, 5))) {
Integer pos = data.indexOf(',');
if (pos > 0) {
String[] encodingParams = data.substring(5, pos).split(";");
String mimeType = encodingParams[0];
data = data.substring(pos + 1);
if (("application/x-font-ttf").equalsIgnoreCase(mimeType) ||
("application/x-font-truetype").equalsIgnoreCase(mimeType) ||
("font/ttf").equalsIgnoreCase(mimeType)) {
type = "ttf";
} else if (("application/x-font-opentype").equalsIgnoreCase(mimeType) ||
("font/opentype").equalsIgnoreCase(mimeType)) {
type = "otf";
}
}
}
if (options.hasKey("type"))
type = options.getString("type");
if (type == null)
type = "ttf";
try {
byte[] decodedBytes = Base64.decode(data, Base64.DEFAULT);
File cacheFile = new File(currentActivity.getCacheDir(), "tempFont" + (tempNameCounter++) + type);
FileOutputStream stream = new FileOutputStream(cacheFile);
try {
stream.write(decodedBytes);
} finally {
stream.close();
}
//Load the font from the temporary file we just created
Typeface typeface = Typeface.createFromFile(cacheFile);
//Cache the font for react
ReactFontManager.getInstance().setTypeface(name, typeface.getStyle(), typeface);
cacheFile.delete();
} catch(Exception e) {
callback.invoke(e.getMessage());
} finally {
callback.invoke(null, name);
}
}