List of usage examples for android.content Context getAssets
public abstract AssetManager getAssets();
From source file:Main.java
public static Bitmap getImageFromAssetsFile(Context ct, String fileName) { Bitmap image = null;/*w w w .j av a2s .c o m*/ AssetManager am = ct.getAssets(); try { InputStream is = am.open(fileName); image = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return image; }
From source file:org.openmidaas.library.test.Utils.java
public static JSONObject readFileAsJSON(Context context, String filename) { try {//from ww w . j a v a2s. com InputStream is = context.getAssets().open(filename); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); String bufferString = new String(buffer); return (new JSONObject(bufferString)); } catch (Exception e) { return null; } }
From source file:Main.java
/** * get Drawable from assert/*from w w w . j a v a 2s .c o m*/ * * @param context * @param fileName * @return */ public static Drawable getDrawableFromAssets(Context context, String fileName) { try { return Drawable.createFromStream(context.getAssets().open(fileName), fileName); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * * @param assetPath/*w w w. j a v a 2 s . c o m*/ * @return */ public static InputStream openAssetPostion(Context context, String assetPath) { InputStream is = null; try { is = context.getAssets().open(assetPath); return is; } catch (IOException e) { return null; } }
From source file:Main.java
public static void copyAssetFileToFiles(Context context, String root, String filename) throws IOException { InputStream is = context.getAssets().open(filename); byte[] buffer = new byte[is.available()]; is.read(buffer);/*from w w w . ja v a 2s . com*/ is.close(); File tgtfile = new File(root + "/" + filename); tgtfile.createNewFile(); tgtfile.setExecutable(true); FileOutputStream os = new FileOutputStream(tgtfile); os.write(buffer); os.close(); }
From source file:Main.java
public static String[] getListBoardFromAssets(Context context) { String[] listBoardsName = null; try {// w w w . ja v a 2 s . co m listBoardsName = context.getAssets().list(DIR_BOARDS_ASSETS); } catch (IOException ex) { ex.printStackTrace(); } return listBoardsName; }
From source file:Main.java
public static Typeface getTypeface53(Context context) { if (appTypeface53 == null) { appTypeface53 = Typeface.createFromAsset(context.getAssets(), "fonts/en53.otf"); }/*from w ww .jav a2s . co m*/ return appTypeface53; }
From source file:Main.java
public static byte[] getAssetAsBuffer(Context ctx, String assetName) throws IOException { InputStream is = ctx.getAssets().open(assetName); int read, available, offset = 0; byte[] result = new byte[available = is.available()]; while (available > 0 && (read = is.read(result, offset, available)) != -1) { offset += read;//ww w. ja v a 2 s . co m available = is.available(); if (offset + available > result.length) { byte[] newResult = new byte[offset + available]; System.arraycopy(result, 0, newResult, 0, offset); result = newResult; } } return result; }
From source file:Main.java
public static Typeface getTypeface35(Context context) { if (appTypeface35 == null) { appTypeface35 = Typeface.createFromAsset(context.getAssets(), "fonts/en35.otf"); }/*from w w w . j ava2 s . c om*/ return appTypeface35; }
From source file:Main.java
/** * opean a file in assets path//from w ww . ja v a 2s . c o m * * @param context * @param assetFilePath * @return */ public static InputStream open(final Context context, final String assetFilePath) { try { return context.getAssets().open(assetFilePath); } catch (IOException e) { return null; } }