Example usage for android.app Activity getAssets

List of usage examples for android.app Activity getAssets

Introduction

In this page you can find the example usage for android.app Activity getAssets.

Prototype

@Override
    public AssetManager getAssets() 

Source Link

Usage

From source file:Main.java

public static Typeface getFont(Activity ac) {
    return Typeface.createFromAsset(ac.getAssets(), "DS-DIGI.TTF");
}

From source file:Main.java

public static String readFile(Activity activity, String fileName) {
    AssetManager assets = activity.getAssets();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    byte buf[] = new byte[1024];
    int len;/* w w w. j  a  v  a 2 s.com*/
    try {
        InputStream inputStream = assets.open(fileName);
        while ((len = inputStream.read(buf)) != -1) {
            outputStream.write(buf, 0, len);
        }
        outputStream.close();
        inputStream.close();
        return outputStream.toString();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

private static CharSequence readEula(Activity activity) {
    BufferedReader in = null;/*w  ww  . j av  a2 s .c o  m*/
    try {
        in = new BufferedReader(new InputStreamReader(activity.getAssets().open(assets_Instructions)));
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = in.readLine()) != null)
            buffer.append(line).append('\n');
        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        closeStream(in);
    }
}

From source file:Main.java

public static Drawable getAssetDrawable(Activity activity, String photoId) {

    try {/*ww  w.ja  va2  s.c o  m*/
        String assetFile = "images/" + photoId + ".jpg";
        InputStream stream = activity.getAssets().open(assetFile);
        return Drawable.createFromStream(stream, null);
    } catch (Exception error) {
    }
    return null;
}

From source file:br.fucapi.fapeam.monitori.eula.Eula.java

private static CharSequence readEula(Activity activity) {
    BufferedReader in = null;/*  w ww .  j av  a2s.c o  m*/
    try {
        in = new BufferedReader(new InputStreamReader(activity.getAssets().open(ASSET_EULA)));
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = in.readLine()) != null)
            buffer.append(line).append('\n');
        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        closeStream(in);
    }
}

From source file:Main.java

public static String getBinaryHash(Activity activity) throws IOException, NoSuchAlgorithmException {
    ArrayList<String> manifestEntries = new ArrayList<String>();
    addFolderEntriesToManifest(manifestEntries, "www", activity.getAssets());
    Collections.sort(manifestEntries);
    JSONArray manifestJSONArray = new JSONArray();
    for (String manifestEntry : manifestEntries) {
        manifestJSONArray.put(manifestEntry);
    }//w  ww . ja  va  2s.  c om

    // The JSON serialization turns path separators into "\/", e.g. "www\/images\/image.png"
    String manifestString = manifestJSONArray.toString().replace("\\/", "/");
    return computeHash(new ByteArrayInputStream(manifestString.getBytes()));
}

From source file:com.neuron.trafikanten.HelperFunctions.java

public static Typeface getTypeface(Activity activity) {
    if (mTypeface == null) {
        mTypeface = Typeface.createFromAsset(activity.getAssets(), "fonts/DejaVuSans.ttf");
    }//from   ww w. ja v a2 s .  co  m
    return mTypeface;
}

From source file:com.group7.dragonwars.engine.MapReader.java

private static List<String> readFile(final String filename, final Activity activity) {
    AssetManager am = activity.getAssets();
    List<String> text = new ArrayList<String>();

    try {// ww  w  . j av a 2s. com
        BufferedReader in = new BufferedReader(new InputStreamReader(am.open(filename)));
        String line;

        while ((line = in.readLine()) != null) {
            text.add(line);
        }

        in.close();
    } catch (FileNotFoundException fnf) {
        System.err.println("Couldn't find " + fnf.getMessage());
        System.exit(1);
    } catch (IOException ioe) {
        System.err.println("Couldn't read " + ioe.getMessage());
        System.exit(1);
    }

    return text;
}

From source file:se.rebootit.android.tagbiljetter.DataParser.java

public static CharSequence readAsset(String asset, Activity activity) {
    BufferedReader in = null;//from  w  w w. ja v a 2s . c o m

    try {
        in = new BufferedReader(new InputStreamReader(activity.getAssets().open(asset)));

        String line;
        StringBuilder buffer = new StringBuilder();

        while ((line = in.readLine()) != null) {
            buffer.append(line).append('\n');
        }

        return buffer;
    } catch (IOException e) {
        return "";
    } finally {
        try {
            in.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.digitalcampus.oppia.utils.FileUtils.java

public static String getLocalizedFilePath(Activity act, String currentLang, String fileName) {
    String filePath = "www" + File.separator + currentLang + File.separator + fileName;
    try {//from   w w  w.  ja  v  a 2 s.c  o  m
        InputStream stream = act.getAssets().open(filePath);
        stream.close();
        return "file:///android_asset/" + filePath;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }

    String localeFilePath = "www" + File.separator + Locale.getDefault().getLanguage() + File.separator
            + fileName;
    try {
        InputStream stream = act.getAssets().open(localeFilePath);
        stream.close();
        return "file:///android_asset/" + localeFilePath;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }

    String defaultFilePath = "www" + File.separator + MobileLearning.DEFAULT_LANG + File.separator + fileName;
    try {
        InputStream stream = act.getAssets().open(defaultFilePath);
        stream.close();
        return "file:///android_asset/" + defaultFilePath;
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
    return "";

}