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 String getStringFromFile(Context context, String fileName) throws IOException {
    InputStream inputStream = context.getAssets().open(fileName);
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    StringBuilder sb = new StringBuilder();
    String line;/*from   ww  w.  j  a v  a 2  s .com*/
    while ((line = reader.readLine()) != null) {
        sb.append(line).append('\n');
    }
    return sb.toString();
}

From source file:Main.java

public static String readAsset(Context c, String fileName) {
    try {//from w ww  .  jav a 2  s.c  o  m
        InputStream is = c.getAssets().open(fileName);
        byte[] buffer = new byte[is.available()];
        //noinspection ResultOfMethodCallIgnored
        is.read(buffer); // buffer is exactly the right size, a guarantee of asset files
        return new String(buffer);
    } catch (IOException ignore) {
    }
    return null;
}

From source file:Main.java

private static String[] listAssetFiles(String path, Context applicationContext) throws IOException {
    AssetManager assetManager = applicationContext.getAssets();
    String[] listOfFonts = assetManager.list(path);
    return listOfFonts;
}

From source file:Main.java

private static InputStream openEclipseAssetFile(Context context, String fileName) {
    InputStream is = null;/*from  ww w.j  a  va 2  s . c o m*/
    try {
        is = context.getAssets().open(fileName);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return is;
}

From source file:Main.java

public static Typeface getRobotoRegular(Context context) {
    if (mRobotoReg == null) {
        mRobotoReg = Typeface.createFromAsset(context.getAssets(), "Roboto-Regular.ttf");
    }/* ww  w .  j  a  va 2s  .  co m*/
    return mRobotoReg;
}

From source file:Main.java

public static Bitmap getBitmapFromAssets(Context context, String fileName) {
    try {//from w w w . ja  v a  2s .  c om

        InputStream inputStream = context.getAssets().open(fileName);

        return BitmapFactory.decodeStream(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static Typeface getTypeface(Context context) {
    if (tfTextView == null) {
        tfTextView = Typeface.createFromAsset(context.getAssets(), "fonts/times.ttf");
    }//from   w  ww .j  av  a  2s . c o  m
    return tfTextView;
}

From source file:Main.java

public static String getAssertString(Context context, String filename) {
    AssetManager am = context.getAssets();
    InputStream is = null;/*from ww  w  .  j  a va2 s  .  c om*/

    try {
        is = am.open(filename);
        return new String(readInputStream(is)).trim();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

/**
 * Open an asset using streaming mode. This provides access to files that have been bundled with an
 * application as assets -- that is, files placed in to the "assets" directory.
 *
 * @param context  {@link Context} used to access the {@link android.content.res.AssetManager}.
 * @param fileName The name of the asset to open. This name can be hierarchical.
 *
 * @return An {@link InputStream} containing the contents of the asset.
 *//*from  w w w .  j av a 2  s .  c om*/
public static InputStream open(final Context context, final String fileName) throws IOException {
    return context.getAssets().open(fileName);
}

From source file:Main.java

public static String readFromAssetsFile(Context context, String name) throws IOException {
    AssetManager am = context.getAssets();
    BufferedReader reader = new BufferedReader(new InputStreamReader(am.open(name)));
    String line;/*from ww w .j av  a2s  .  c  o m*/
    StringBuilder builder = new StringBuilder();
    while ((line = reader.readLine()) != null) {
        builder.append(line);
    }
    reader.close();
    return builder.toString();
}