Java Code Examples for android.content.ContextWrapper#getDir()
The following examples show how to use
android.content.ContextWrapper#getDir() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KcaUtils.java From kcanotify_h5-master with GNU General Public License v3.0 | 7 votes |
public static JsonArray getJsonArrayFromStorage(Context context, String name, KcaDBHelper helper) { if (getBooleanPreferences(context, PREF_RES_USELOCAL)) { return getJsonArrayFromAsset(context, name, helper); } else { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("data", Context.MODE_PRIVATE); File jsonFile = new File(directory, name); JsonArray data = new JsonArray(); try { Reader reader = new FileReader(jsonFile); data = new JsonParser().parse(reader).getAsJsonArray(); reader.close(); } catch (IOException | IllegalStateException | JsonSyntaxException e ) { e.printStackTrace(); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getJsonArrayFromStorage", "0", getStringFromException(e)); data = getJsonArrayFromAsset(context, name, helper); } return data; } }
Example 2
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 6 votes |
public static JsonObject getJsonObjectFromStorage(Context context, String name, KcaDBHelper helper) { if (getBooleanPreferences(context, PREF_RES_USELOCAL)) { return getJsonObjectFromAsset(context, name, helper); } else { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("data", Context.MODE_PRIVATE); File jsonFile = new File(directory, name); JsonObject data = null; try { Reader reader = new FileReader(jsonFile); data = new JsonParser().parse(reader).getAsJsonObject(); reader.close(); } catch (IOException | IllegalStateException | JsonSyntaxException e) { e.printStackTrace(); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getJsonObjectFromStorage", "0", getStringFromException(e)); data = getJsonObjectFromAsset(context, name, helper); } return data; } }
Example 3
Source File: UtilsServiceHandler.java From Aerlink-for-Android with MIT License | 6 votes |
private void saveToInternalStorage(Bitmap bitmap, String bundleIdentifier) { Log.i(LOG_TAG, "Saving icon"); ContextWrapper cw = new ContextWrapper(mContext); File directory = cw.getDir("AppIconDir", Context.MODE_PRIVATE); File path = new File(directory, bundleIdentifier+".png"); try (FileOutputStream fos = new FileOutputStream(path)) { // Use the compress method on the BitMap object to write image to the OutputStream bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); Log.i(LOG_TAG, "Icon saved"); } catch (Exception e) { e.printStackTrace(); } }
Example 4
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 6 votes |
public static boolean validateResourceFiles(Context context, KcaDBHelper helper) { int count = 0; ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("data", Context.MODE_PRIVATE); for (final File entry : directory.listFiles()) { try { Reader reader = new FileReader(entry); new JsonParser().parse(reader); count += 1; } catch (FileNotFoundException | IllegalStateException | JsonSyntaxException e ) { e.printStackTrace(); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, entry.getName(), "validateResourceFiles", "2", getStringFromException(e)); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); return false; } } return count > 0; }
Example 5
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 6 votes |
public static void setFairyImageFromStorage(Context context, String name, ImageView view, int dp) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); int fairy_id = Integer.parseInt(name.replace("noti_icon_", "")); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics); ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File myImageFile = new File(directory, KcaUtils.format("%s.png", name)); if (myImageFile.exists()) { if (px > 0) { GlideApp.with(context).load(myImageFile.getPath()) .dontAnimate().override(px, px).into(view); } else { GlideApp.with(context).load(myImageFile.getPath()).into(view); } } else if (FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) { view.setImageResource(getId(name, R.mipmap.class)); } else { view.setImageResource(R.mipmap.noti_icon_0); } }
Example 6
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 6 votes |
public static boolean checkFairyImageFileFromStorage(Context context, String name) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File myImageFile = new File(directory, KcaUtils.format("%s", name)); Bitmap bitmap = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; try { InputStream is = new FileInputStream(myImageFile); bitmap = BitmapFactory.decodeStream(is, null, options); is.close(); } catch (IOException e) { // Log.e("KCA", getStringFromException(e)); return false; } if (bitmap == null) { return false; } return true; }
Example 7
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 6 votes |
public static JsonArray getJsonArrayFromStorage(Context context, String name, KcaDBHelper helper) { if (getBooleanPreferences(context, PREF_RES_USELOCAL)) { return getJsonArrayFromAsset(context, name, helper); } else { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("data", Context.MODE_PRIVATE); File jsonFile = new File(directory, name); JsonArray data = new JsonArray(); try { Reader reader = new FileReader(jsonFile); data = new JsonParser().parse(reader).getAsJsonArray(); reader.close(); } catch (IOException | IllegalStateException | JsonSyntaxException e ) { e.printStackTrace(); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getJsonArrayFromStorage", "0", getStringFromException(e)); data = getJsonArrayFromAsset(context, name, helper); } return data; } }
Example 8
Source File: KcaUtils.java From kcanotify_h5-master with GNU General Public License v3.0 | 6 votes |
public static boolean validateResourceFiles(Context context, KcaDBHelper helper) { int count = 0; ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("data", Context.MODE_PRIVATE); for (final File entry : directory.listFiles()) { try { Reader reader = new FileReader(entry); new JsonParser().parse(reader); count += 1; } catch (FileNotFoundException | IllegalStateException | JsonSyntaxException e ) { e.printStackTrace(); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, entry.getName(), "validateResourceFiles", "2", getStringFromException(e)); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); return false; } } return count > 0; }
Example 9
Source File: MainActivity.java From Quran-For-My-Android with Apache License 2.0 | 6 votes |
private void prepareAudioStorageDir(){ String state=Environment.getExternalStorageState(); // has writable external storage if (Environment.MEDIA_MOUNTED.equals(state)) { audioStorageDir = new File(Environment.getExternalStorageDirectory(),storageFolderName+"/"+AudioStorageDirName); } else { ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext()); audioStorageDir = contextWrapper.getDir(storageFolderName+"/"+AudioStorageDirName, Context.MODE_PRIVATE); } if(!audioStorageDir.exists()){ audioStorageDir.mkdirs(); }else{//check if new 10 char file added, if yes then shorten new AudioFileFolderizingTask(this).execute(); } }
Example 10
Source File: KcaUtils.java From kcanotify_h5-master with GNU General Public License v3.0 | 6 votes |
public static boolean checkFairyImageFileFromStorage(Context context, String name) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File myImageFile = new File(directory, KcaUtils.format("%s", name)); Bitmap bitmap = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; try { InputStream is = new FileInputStream(myImageFile); bitmap = BitmapFactory.decodeStream(is, null, options); is.close(); } catch (IOException e) { // Log.e("KCA", getStringFromException(e)); return false; } if (bitmap == null) { return false; } return true; }
Example 11
Source File: KcaUtils.java From kcanotify_h5-master with GNU General Public License v3.0 | 6 votes |
public static JsonObject getJsonObjectFromStorage(Context context, String name, KcaDBHelper helper) { if (getBooleanPreferences(context, PREF_RES_USELOCAL)) { return getJsonObjectFromAsset(context, name, helper); } else { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("data", Context.MODE_PRIVATE); File jsonFile = new File(directory, name); JsonObject data = null; try { Reader reader = new FileReader(jsonFile); data = new JsonParser().parse(reader).getAsJsonObject(); reader.close(); } catch (IOException | IllegalStateException | JsonSyntaxException e) { e.printStackTrace(); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getJsonObjectFromStorage", "0", getStringFromException(e)); data = getJsonObjectFromAsset(context, name, helper); } return data; } }
Example 12
Source File: Camera2BasicFragment.java From opencv-documentscanner-android with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ContextWrapper cw = new ContextWrapper(getActivity().getApplicationContext()); File directory = cw.getDir("imageDir", Context.MODE_PRIVATE); mFile = new File(directory, System.currentTimeMillis() + ".png"); }
Example 13
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 5 votes |
public static boolean clearFairyImageFileFromStorage(Context context) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); for (File file: directory.listFiles()) { if (!file.isDirectory()) file.delete(); } return true; }
Example 14
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 5 votes |
public static Bitmap getFairyImageFromStorage(Context context, String name, KcaDBHelper helper) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File myImageFile = new File(directory, KcaUtils.format("%s.png", name)); Bitmap bitmap = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; int fairy_id = Integer.parseInt(name.replace("noti_icon_", "")); if (fairy_id == 0) { bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0); } else if (FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) { bitmap = BitmapFactory.decodeResource(context.getResources(), getId(name, R.mipmap.class)); } else { try { bitmap = BitmapFactory.decodeStream(new FileInputStream(myImageFile), null, options); } catch (FileNotFoundException e) { e.printStackTrace(); setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getFairyImageFromStorage", "0", getStringFromException(e)); bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0); } if (bitmap == null) { setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getFairyImageFromStorage", "0", "bitmap==null"); bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0); } } return bitmap; }
Example 15
Source File: KcaUtils.java From kcanotify_h5-master with GNU General Public License v3.0 | 5 votes |
public static Bitmap getFairyImageFromStorage(Context context, String name, KcaDBHelper helper) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File myImageFile = new File(directory, KcaUtils.format("%s.png", name)); Bitmap bitmap = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; int fairy_id = Integer.parseInt(name.replace("noti_icon_", "")); if (fairy_id == 0) { bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0); } else if (FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) { bitmap = BitmapFactory.decodeResource(context.getResources(), getId(name, R.mipmap.class)); } else { try { bitmap = BitmapFactory.decodeStream(new FileInputStream(myImageFile), null, options); } catch (FileNotFoundException e) { try { int item_id =KcaUtils.getId(name, R.mipmap.class); bitmap = BitmapFactory.decodeResource(KcaApplication.getInstance().getResources(), item_id); } catch (Exception ex){ e.printStackTrace(); } if(bitmap == null) { setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getFairyImageFromStorage", "0", getStringFromException(e)); bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0); } } if (bitmap == null) { setPreferences(context, PREF_DATALOAD_ERROR_FLAG, true); if (helper != null) helper.recordErrorLog(ERROR_TYPE_DATALOAD, name, "getFairyImageFromStorage", "0", "bitmap==null"); bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.noti_icon_0); } } return bitmap; }
Example 16
Source File: ProductServiceImpl.java From privacy-friendly-shopping-list with Apache License 2.0 | 5 votes |
@Override public String getProductImagePath(String id) { ContextWrapper contextWrapper = new ContextWrapper(context); File directory = contextWrapper.getDir(IMAGE_DIR_NAME, Context.MODE_PRIVATE); File path = new File(directory, getUniqueName(id)); return path.getAbsolutePath(); }
Example 17
Source File: Helper.java From smartcoins-wallet with MIT License | 5 votes |
public static Bitmap loadImageFromStorage(Context context) { Bitmap bitmap = null; try { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("imageDir", Context.MODE_PRIVATE); File f = new File(directory, "gravatar.jpg"); bitmap = BitmapFactory.decodeStream(new FileInputStream(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } return bitmap; }
Example 18
Source File: OtherActivityHandler.java From mobikul-standalone-pos with MIT License | 4 votes |
public OtherActivityHandler(Context context) { this.context = context; ContextWrapper cw = new ContextWrapper(context); ImageDirectory = cw.getDir("imageDir", Context.MODE_PRIVATE); }
Example 19
Source File: KcaUtils.java From kcanotify with GNU General Public License v3.0 | 4 votes |
public static boolean checkFairyImageInStorage(Context context, String name) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File image = new File(directory, name); return image.exists(); }
Example 20
Source File: KcaUtils.java From kcanotify_h5-master with GNU General Public License v3.0 | 4 votes |
public static boolean checkFairyImageInStorage(Context context, String name) { ContextWrapper cw = new ContextWrapper(context); File directory = cw.getDir("fairy", Context.MODE_PRIVATE); File image = new File(directory, name); return image.exists(); }