/** * Copy image file to temporary folder. * @param context Context * @param imageUrl Url of image to copy * @return Copied file * @throws IOException Fail to copy image file. */ public static File copyFileToTempDir(Context context, String imageUrl) throws IOException { final ImageLoader imageLoader = ImageLoader.getInstance(); final File cachedFile = DiscCacheUtil.findInCache(imageUrl, imageLoader.getDiscCache()); final Uri cachedUri = Uri.fromFile(cachedFile); final String pathDirToMake = StorageUtils.getCacheDirectory(context).getPath() + "/temp"; File dirToMake = new File(pathDirToMake); if (!dirToMake.exists()) { dirToMake.mkdirs(); } else if (!dirToMake.isDirectory()) { dirToMake.delete(); dirToMake.mkdirs(); } File fileToMake = new File(pathDirToMake + "/" + ((Long)(System.currentTimeMillis()/1000)).toString() + "." + getFileExtension(context, cachedUri)); copyFile(cachedFile, fileToMake); return fileToMake; }
private ImageView loadAvatar(final String channelJid, boolean skipCache) { ImageView avatarView = (ImageView) findViewById(R.id.bcProfilePic); DisplayImageOptions dio = new DisplayImageOptions.Builder() .cloneFrom(ImageHelper.defaultImageOptions()) .showImageOnFail(R.drawable.ic_avatar) .showImageOnLoading(R.drawable.ic_avatar) .preProcessor(ImageHelper.createRoundProcessor(16, false, -1)) .resetViewBeforeLoading(true) .build(); String avatarURL = AvatarUtils.avatarURL(this, channelJid); if (skipCache) { DiscCacheUtil.removeFromCache(avatarURL, ImageLoader.getInstance() .getDiscCache()); MemoryCacheUtil.removeFromCache(avatarURL, ImageLoader .getInstance().getMemoryCache()); } ImageLoader.getInstance().displayImage(avatarURL, avatarView, dio); return avatarView; }
@Override public void onLoadingStarted(String url, View view) { List<String> memCache = MemoryCacheUtil. findCacheKeysForImageUri(url, ImageLoader.getInstance().getMemoryCache()); cacheFound = !memCache.isEmpty(); if (!cacheFound) { File discCache = DiscCacheUtil. findInCache(url, ImageLoader.getInstance().getDiscCache()); if (discCache != null) { cacheFound = discCache.exists(); } } }