Example usage for android.content Context getAssets

List of usage examples for android.content Context getAssets

Introduction

In this page you can find the example usage for android.content Context getAssets.

Prototype

public abstract AssetManager getAssets();

Source Link

Document

Returns an AssetManager instance for the application's package.

Usage

From source file:Main.java

public static boolean fileExists(Context ctx, String filename) {
    try {//w ww  .  j a  v a  2  s .  co  m
        for (String f : ctx.getAssets().list("")) {
            if (f.equals(filename))
                return true;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static Bitmap loadBitmapFromAssets(Context context, String name) {
    try {/*from ww w  . j  a va2  s.co  m*/
        InputStream is = context.getAssets().open(name);
        Bitmap bitmap = BitmapFactory.decodeStream(is);
        return bitmap;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Typeface getCustomTypefaceByName(Context context, String faceName) {
    Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fonts/" + faceName);
    return typeface;
}

From source file:Main.java

public static String[] getListFile(Context context, String assetPath) {
    try {// w w w . j  a  v a 2  s.c  o m
        String[] list = context.getAssets().list(assetPath);
        return list;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Reader readFile(Context context, String fileName) throws IOException {
    InputStream inputStream = context.getAssets().open(fileName);
    return new InputStreamReader(inputStream, "utf-8");
}

From source file:Main.java

public static Reader readFile(Context context, String fileName) throws IOException {
    InputStream inputStream = context.getAssets().open(fileName);
    Reader reader = new InputStreamReader(inputStream, "utf-8");
    return reader;
}

From source file:Main.java

public final static Typeface getOogie(Context ctx) {
    if (oogie == null)
        oogie = Typeface.createFromAsset(ctx.getAssets(), "fonts/OogieBoogie.ttf");
    return oogie;
}

From source file:Main.java

public static InputStream openAssetFile(Context context, String file) throws IOException {
    AssetManager assetManager = context.getAssets();

    return assetManager.open(file);

}

From source file:Main.java

public static Drawable getAsssetDrawableByName(Context context, String name) {
    try {/*from  w w w .ja  va 2s  . c om*/
        InputStream is = context.getAssets().open(name);
        return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(is));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new ColorDrawable(Color.TRANSPARENT);
}

From source file:Main.java

public static void setFontFace(TextView v, Context context) {
    if (font == null)
        font = Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
    v.setTypeface(font);/*from   w  w  w.  j a  v a  2 s  .  c o m*/
}