use of android.content.res.AssetManager in project browser by scoute-dich.
the class Javascript method loadHosts.
private static void loadHosts(final Context context) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
AssetManager manager = context.getAssets();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(manager.open(FILE)));
String line;
while ((line = reader.readLine()) != null) {
hostsJS.add(line.toLowerCase(locale));
}
} catch (IOException i) {
Log.w("Browser", "Error loading hosts");
}
}
});
thread.start();
}
use of android.content.res.AssetManager in project GomoTest by suReZj.
the class StickerFragment method getImageFromAssetsFile.
/**
* 从Assert文件夹中读取位图数据
*
* @param fileName
* @return
*/
private Bitmap getImageFromAssetsFile(String fileName) {
Bitmap image = null;
AssetManager am = getResources().getAssets();
try {
InputStream is = am.open(fileName);
image = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
use of android.content.res.AssetManager in project gh4a by slapperwan.
the class TypefaceCache method getTypeface.
public static Typeface getTypeface(int typeface) {
if (typeface < TF_REGULAR || typeface > TF_BOLDCONDENSED) {
return null;
}
Typeface tf = sTypefaces.get(typeface);
if (tf == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// L has all typefaces we need, use system fonts
tf = Typeface.create(FONT_FAMILIES[typeface], FONT_STYLES[typeface]);
} else {
// use our fonts
AssetManager assets = Gh4Application.get().getAssets();
tf = Typeface.createFromAsset(assets, FONT_FILENAMES[typeface]);
}
sTypefaces.put(typeface, tf);
}
return tf;
}
use of android.content.res.AssetManager in project box-android-sdk by box.
the class SdkUtils method getAssetFile.
/**
* Helper method for reading an asset file into a string.
* @param context current context.
* @param assetName the asset name
* @return a string representation of a file in assets.
*/
public static String getAssetFile(final Context context, final String assetName) {
// if the file is not found create it and return that.
// if we do not have a file we copy our asset out to create one.
AssetManager assetManager = context.getAssets();
BufferedReader in = null;
try {
StringBuilder buf = new StringBuilder();
InputStream is = assetManager.open(assetName);
in = new BufferedReader(new InputStreamReader(is));
String str;
boolean isFirst = true;
while ((str = in.readLine()) != null) {
if (isFirst)
isFirst = false;
else
buf.append('\n');
buf.append(str);
}
return buf.toString();
} catch (IOException e) {
BoxLogUtils.e("getAssetFile", assetName, e);
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e) {
BoxLogUtils.e("getAssetFile", assetName, e);
}
}
// should never get here unless the asset file is inaccessible or cannot be copied out.
return null;
}
use of android.content.res.AssetManager in project WeatherApp by Cilestal.
the class AssetsUtils method getFlag.
@Nullable
public Drawable getFlag(Context context, final String code) {
if (code == null || code.length() != 2) {
return null;
}
if (mFlagIcons.containsKey(code)) {
return mFlagIcons.get(code);
}
String flagPath = String.format(FLAGS_FILE_FORMAT, code.toLowerCase());
AssetManager assets = context.getAssets();
try {
Drawable drawable = Drawable.createFromStream(assets.open(flagPath), null);
mFlagIcons.put(code, drawable);
return drawable;
} catch (IOException e) {
Timber.d("Flag %s not found.", code);
return null;
}
}
Aggregations