List of usage examples for android.content Context getCacheDir
public abstract File getCacheDir();
From source file:com.dm.material.dashboard.candybar.helpers.IconsHelper.java
public static void selectIcon(@NonNull Context context, int action, Icon icon) { if (action == IntentHelper.ICON_PICKER) { Intent intent = new Intent(); Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" + icon.getRes(), ImageConfig.getRawImageOptions().build()); intent.putExtra("icon", bitmap); ((AppCompatActivity) context).setResult(bitmap != null ? Activity.RESULT_OK : Activity.RESULT_CANCELED, intent);// www .j av a 2 s. com ((AppCompatActivity) context).finish(); } else if (action == IntentHelper.IMAGE_PICKER) { Intent intent = new Intent(); Bitmap bitmap = ImageLoader.getInstance().loadImageSync("drawable://" + icon.getRes(), ImageConfig.getRawImageOptions().build()); if (bitmap != null) { File file = new File(context.getCacheDir(), icon.getTitle() + ".png"); FileOutputStream outStream; try { outStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream); outStream.flush(); outStream.close(); Uri uri = FileHelper.getUriFromFile(context, context.getPackageName(), file); if (uri == null) uri = Uri.fromFile(file); intent.putExtra(Intent.EXTRA_STREAM, uri); intent.setData(uri); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } catch (Exception | OutOfMemoryError e) { LogUtil.e(Log.getStackTraceString(e)); } intent.putExtra("return-data", false); } ((AppCompatActivity) context).setResult(bitmap != null ? Activity.RESULT_OK : Activity.RESULT_CANCELED, intent); ((AppCompatActivity) context).finish(); } else { IconPreviewFragment.showIconPreview(((AppCompatActivity) context).getSupportFragmentManager(), icon.getTitle(), icon.getRes()); } }
From source file:pas.com.mm.shoopingcart.util.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use/*from www. j av a 2s . c o m*/ * @param uniqueName A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use external cache dir // otherwise use internal cache dir // final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); final String cachePath = context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:uk.org.ngo.squeezer.util.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use/* ww w . j ava 2 s .c o m*/ * @param uniqueName A unique directory name to append to the cache dir * * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use external cache dir // otherwise use internal cache dir File externalCacheDir = getExternalCacheDir(context); final String cachePath = ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable()) && externalCacheDir != null) ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:com.example.photoutil.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * /* w ww .j a va 2 s . c o m*/ * @param context * The context to use * @param uniqueName * A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use // external cache dir // otherwise use internal cache dir String cachePath; /*if (Environment.MEDIA_MOUNTED.equals(Environment .getExternalStorageState()) || !isExternalStorageRemovable()) { cachePath = getExternalCacheDir(context).getPath(); } else {*/ cachePath = context.getCacheDir().getPath(); //} return new File(cachePath + File.separator + uniqueName); }
From source file:com.aizen.manga.util.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use/*from w ww. j av a 2 s . c om*/ * @param uniqueName A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use external cache dir // otherwise use internal cache dir final String cachePath = // Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || // !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:com.corebase.android.bitmap.util.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * //from www . j ava 2 s .c om * @param context * The context to use * @param uniqueName * A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use // external cache dir // otherwise use internal cache dir final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return photoCacheDir = new File(cachePath + File.separator + uniqueName); }
From source file:com.alex.develop.cache.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use//from w ww .j a va2 s .c om * @param uniqueName A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use external cache dir // otherwise use internal cache dir String cachePath = null; try { cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); } catch (Exception e) { e.printStackTrace(); } return new File(cachePath + File.separator + uniqueName); }
From source file:com.rp.justcast.photos.ImageCache.java
/** * Get a usable cache directory (external if available, internal otherwise). * * @param context The context to use/* www. java 2s .c om*/ * @param uniqueName A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use external cache dir // otherwise use internal cache dir final String cachePath = (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable()) && (getExternalCacheDir(context) != null) ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:com.rsegismont.androlife.common.utils.ImageCacher.java
/** * Get a usable cache directory (external if available, internal otherwise). * /* w w w . j a v a 2s . co m*/ * @param context * The context to use * @param uniqueName * A unique directory name to append to the cache dir * @return The cache dir */ public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use // external cache dir // otherwise use internal cache dir String cachePath = ""; final String storageState = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(storageState) && (!isExternalStorageRemovable())) { cachePath = getExternalCacheDir(context).getPath(); } else { cachePath = context.getCacheDir().getPath(); } // TODO : catch where there is no sd return new File(cachePath + File.separator + uniqueName); }
From source file:com.truebanana.cache.AbstractDiskLruCache.java
public AbstractDiskLruCache(Context context, long maxSize) { this(context.getCacheDir(), maxSize); }