Search in sources :

Example 66 with AssetManager

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();
}
Also used : AssetManager(android.content.res.AssetManager) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 67 with AssetManager

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;
}
Also used : Bitmap(android.graphics.Bitmap) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 68 with AssetManager

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;
}
Also used : AssetManager(android.content.res.AssetManager) Typeface(android.graphics.Typeface)

Example 69 with AssetManager

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;
}
Also used : AssetManager(android.content.res.AssetManager) InputStreamReader(java.io.InputStreamReader) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 70 with AssetManager

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;
    }
}
Also used : AssetManager(android.content.res.AssetManager) Drawable(android.graphics.drawable.Drawable) IOException(java.io.IOException) Nullable(android.support.annotation.Nullable)

Aggregations

AssetManager (android.content.res.AssetManager)346 IOException (java.io.IOException)141 InputStream (java.io.InputStream)121 Resources (android.content.res.Resources)75 File (java.io.File)54 FileOutputStream (java.io.FileOutputStream)34 XmlResourceParser (android.content.res.XmlResourceParser)32 DisplayMetrics (android.util.DisplayMetrics)31 Bitmap (android.graphics.Bitmap)23 Configuration (android.content.res.Configuration)21 BufferedReader (java.io.BufferedReader)21 InputStreamReader (java.io.InputStreamReader)20 ArrayList (java.util.ArrayList)20 FileInputStream (java.io.FileInputStream)18 OutputStream (java.io.OutputStream)17 Context (android.content.Context)16 Intent (android.content.Intent)16 JsonParser (com.google.gson.JsonParser)16 ByteArrayInputStream (java.io.ByteArrayInputStream)16 Method (java.lang.reflect.Method)16