本文整理汇总了Java中com.nostra13.universalimageloader.utils.MemoryCacheUtils类的典型用法代码示例。如果您正苦于以下问题:Java MemoryCacheUtils类的具体用法?Java MemoryCacheUtils怎么用?Java MemoryCacheUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryCacheUtils类属于com.nostra13.universalimageloader.utils包,在下文中一共展示了MemoryCacheUtils类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMemoryCachedAvatarBitmap
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
/**
* 从ImageLoader内存缓存中取出头像位图
*/
private static Bitmap getMemoryCachedAvatarBitmap(UserInfoProvider.UserInfo userInfo) {
if(userInfo == null || !isImageUriValid(userInfo.getAvatar())) {
return null;
}
String key = HeadImageView.getAvatarCacheKey(userInfo.getAvatar());
// DiskCacheUtils.findInCache(uri, ImageLoader.getInstance().getDiskCache() 查询磁盘缓存示例
List<Bitmap> bitmaps = MemoryCacheUtils.findCachedBitmapsForImageUri(key, ImageLoader.getInstance().getMemoryCache());
if(bitmaps.size() > 0) {
return bitmaps.get(0);
}
return null;
}
示例2: cleanUp
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
@SuppressLint("SetTextI18n")
private void cleanUp() {
progressbar.setProgress(0);
totalOriginalSize.setText("0 kb");
totalFileSize.setText("0 kb");
reductionPercent.setText("0 %");
DownloadStorageSizes.clearAll();
for (String image: imageUrls) {
MemoryCacheUtils.removeFromCache(image, imageLoader.getMemoryCache());
DiskCacheUtils.removeFromCache(image, imageLoader.getDiskCache());
}
for (ImageView imageView : imageViews) {
if (imageView != null) {
imageLoader.cancelDisplayTask(imageView);
imageView.setImageResource(android.R.color.transparent);
}
}
imageUrls.clear();
}
示例3: initEmptyFieldsWithDefaultValues
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
private void initEmptyFieldsWithDefaultValues() {
if (this.taskExecutor == null) {
this.taskExecutor = DefaultConfigurationFactory.createExecutor(this.threadPoolSize, this.threadPriority, this.tasksProcessingType);
} else {
this.customExecutor = true;
}
if (this.taskExecutorForCachedImages == null) {
this.taskExecutorForCachedImages = DefaultConfigurationFactory.createExecutor(this.threadPoolSize, this.threadPriority, this.tasksProcessingType);
} else {
this.customExecutorForCachedImages = true;
}
if (this.diskCache == null) {
if (this.diskCacheFileNameGenerator == null) {
this.diskCacheFileNameGenerator = DefaultConfigurationFactory.createFileNameGenerator();
}
this.diskCache = DefaultConfigurationFactory.createDiskCache(this.context, this.diskCacheFileNameGenerator, this.diskCacheSize, this.diskCacheFileCount);
}
if (this.memoryCache == null) {
this.memoryCache = DefaultConfigurationFactory.createMemoryCache(this.memoryCacheSize);
}
if (this.denyCacheImageMultipleSizesInMemory) {
this.memoryCache = new FuzzyKeyMemoryCache(this.memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
}
if (this.downloader == null) {
this.downloader = DefaultConfigurationFactory.createImageDownloader(this.context);
}
if (this.decoder == null) {
this.decoder = DefaultConfigurationFactory.createImageDecoder(this.writeLogs);
}
if (this.defaultDisplayImageOptions == null) {
this.defaultDisplayImageOptions = DisplayImageOptions.createSimple();
}
}
示例4: initEmptyFieldsWithDefaultValues
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
private void initEmptyFieldsWithDefaultValues() {
if (this.taskExecutor == null) {
this.taskExecutor = DefaultConfigurationFactory.createExecutor(this
.threadPoolSize, this.threadPriority, this.tasksProcessingType);
} else {
this.customExecutor = true;
}
if (this.taskExecutorForCachedImages == null) {
this.taskExecutorForCachedImages = DefaultConfigurationFactory.createExecutor
(this.threadPoolSize, this.threadPriority, this.tasksProcessingType);
} else {
this.customExecutorForCachedImages = true;
}
if (this.diskCache == null) {
if (this.diskCacheFileNameGenerator == null) {
this.diskCacheFileNameGenerator = DefaultConfigurationFactory
.createFileNameGenerator();
}
this.diskCache = DefaultConfigurationFactory.createDiskCache(this.context, this
.diskCacheFileNameGenerator, this.diskCacheSize, this.diskCacheFileCount);
}
if (this.memoryCache == null) {
this.memoryCache = DefaultConfigurationFactory.createMemoryCache(this.context,
this.memoryCacheSize);
}
if (this.denyCacheImageMultipleSizesInMemory) {
this.memoryCache = new FuzzyKeyMemoryCache(this.memoryCache, MemoryCacheUtils
.createFuzzyKeyComparator());
}
if (this.downloader == null) {
this.downloader = DefaultConfigurationFactory.createImageDownloader(this.context);
}
if (this.decoder == null) {
this.decoder = DefaultConfigurationFactory.createImageDecoder(this.writeLogs);
}
if (this.defaultDisplayImageOptions == null) {
this.defaultDisplayImageOptions = DisplayImageOptions.createSimple();
}
}
示例5: init
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@AfterViews
public void init() {
if (isProtrait) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mProtraitRelativeLayout.setVisibility(View.VISIBLE);
} else {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mLandscapeRelativeLayout.setVisibility(View.VISIBLE);
}
MemoryCacheUtils.removeFromCache("file://" + photoPath, ImageLoader.getInstance().getMemoryCache());
DiscCacheUtils.removeFromCache("file://" + photoPath, ImageLoader.getInstance().getDiscCache());
mImageLoader.displayImage("file://" + photoPath, imageView, ImageLoaderConfig.options);
mRelativeLayout.setOnClickListener(this);
}
示例6: onCreate
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_thumb_view);
final DisplayImageOptions thumbOptions = new DisplayImageOptions.Builder().cacheInMemory(true).build();
final ImageLoader imageLoader = Global.getImageLoader(getApplicationContext());
final ViewGroup root = (ViewGroup) findViewById(R.id.root);
int l = root.getChildCount();
for (int i = 0; i < l; i++) {
final int fi = i;
final ImageView thumb = (ImageView) ((ViewGroup) root.getChildAt(i)).getChildAt(0);
final ImageViewAware thumbAware = new ImageViewAware(thumb);
final String url = Global.getTestImage(i).getThumb(100, 100).url;
imageLoader.displayImage(url, thumbAware, thumbOptions);
thumb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ThumbViewActivity.this, PicViewActivity.class);
intent.putExtra("image", Global.getTestImage(fi));
ImageSize targetSize = new ImageSize(thumbAware.getWidth(), thumbAware.getHeight());
String memoryCacheKey = MemoryCacheUtils.generateKey(url, targetSize);
intent.putExtra("cache_key", memoryCacheKey);
Rect rect = new Rect();
thumb.getGlobalVisibleRect(rect);
intent.putExtra("rect", rect);
intent.putExtra("scaleType", thumb.getScaleType());
startActivity(intent);
}
});
}
}
示例7: onLoadingComplete
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (view == null) return;
Object tag = view.getTag(R.id.tag_image);
if (enableDebugLog) FLog.d("tag: %s", tag);
if (tag != null && tag instanceof String) {
String actualUri = tag.toString();
File pngFile = AssistUtil.getCopiedFile(context, actualUri);
if (pngFile == null) {
if (enableDebugLog) FLog.w("Can't locate the file!!! %s", actualUri);
} else if (pngFile.exists()) {
boolean isApng = AssistUtil.isApng(pngFile);
if (isApng) {
if (enableDebugLog) FLog.d("Setup apng drawable");
ApngDrawable drawable = new ApngDrawable(context, loadedImage, Uri.fromFile(pngFile));
((ImageView) view).setImageDrawable(drawable);
} else {
((ImageView) view).setImageBitmap(loadedImage);
}
} else {
if (enableDebugLog) FLog.d("Clear cache and reload");
MemoryCacheUtils.removeFromCache(actualUri, ApngImageLoader.getInstance().getMemoryCache());
DiskCacheUtils.removeFromCache(actualUri, ApngImageLoader.getInstance().getDiskCache());
ApngImageLoader.getInstance().displayImage(actualUri, (ImageView) view, this);
}
}
if (shouldForward()) callback.onLoadFinish(true, imageUri, view);
}
示例8: displayImage
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener) {
checkConfiguration();
if (imageAware == null) {
throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
}
if (listener == null) {
listener = this.emptyListener;
}
if (options == null) {
options = this.configuration.defaultDisplayImageOptions;
}
if (TextUtils.isEmpty(uri)) {
this.engine.cancelDisplayTaskFor(imageAware);
listener.onLoadingStarted(uri, imageAware.getWrappedView());
if (options.shouldShowImageForEmptyUri()) {
imageAware.setImageDrawable(options.getImageForEmptyUri(this.configuration.resources));
} else {
imageAware.setImageDrawable(null);
}
listener.onLoadingComplete(uri, imageAware.getWrappedView(), null);
return;
}
ImageSize targetSize = ImageSizeUtils.defineTargetSizeForView(imageAware, this.configuration.getMaxImageSize());
String memoryCacheKey = MemoryCacheUtils.generateKey(uri, targetSize);
this.engine.prepareDisplayTaskFor(imageAware, memoryCacheKey);
listener.onLoadingStarted(uri, imageAware.getWrappedView());
Bitmap bmp = (Bitmap) this.configuration.memoryCache.get(memoryCacheKey);
if (bmp == null || bmp.isRecycled()) {
if (options.shouldShowImageOnLoading()) {
imageAware.setImageDrawable(options.getImageOnLoading(this.configuration.resources));
} else if (options.isResetViewBeforeLoading()) {
imageAware.setImageDrawable(null);
}
LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask(this.engine, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options, listener, progressListener, this.engine.getLockForUri(uri)), defineHandler(options));
if (options.isSyncLoading()) {
displayTask.run();
return;
} else {
this.engine.submit(displayTask);
return;
}
}
L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
if (options.shouldPostProcess()) {
ProcessAndDisplayImageTask displayTask2 = new ProcessAndDisplayImageTask(this.engine, bmp, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options, listener, progressListener, this.engine.getLockForUri(uri)), defineHandler(options));
if (options.isSyncLoading()) {
displayTask2.run();
return;
} else {
this.engine.submit(displayTask2);
return;
}
}
options.getDisplayer().display(bmp, imageAware, LoadedFrom.MEMORY_CACHE);
listener.onLoadingComplete(uri, imageAware.getWrappedView(), bmp);
}
示例9: displayImage
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions options,
ImageSize targetSize, ImageLoadingListener listener,
ImageLoadingProgressListener progressListener) {
checkConfiguration();
if (imageAware == null) {
throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
}
if (listener == null) {
listener = this.defaultListener;
}
if (options == null) {
options = this.configuration.defaultDisplayImageOptions;
}
if (TextUtils.isEmpty(uri)) {
this.engine.cancelDisplayTaskFor(imageAware);
listener.onLoadingStarted(uri, imageAware.getWrappedView());
if (options.shouldShowImageForEmptyUri()) {
imageAware.setImageDrawable(options.getImageForEmptyUri(this.configuration
.resources));
} else {
imageAware.setImageDrawable(null);
}
listener.onLoadingComplete(uri, imageAware.getWrappedView(), null);
return;
}
if (targetSize == null) {
targetSize = ImageSizeUtils.defineTargetSizeForView(imageAware, this.configuration
.getMaxImageSize());
}
String memoryCacheKey = MemoryCacheUtils.generateKey(uri, targetSize);
this.engine.prepareDisplayTaskFor(imageAware, memoryCacheKey);
listener.onLoadingStarted(uri, imageAware.getWrappedView());
Bitmap bmp = this.configuration.memoryCache.get(memoryCacheKey);
if (bmp == null || bmp.isRecycled()) {
if (options.shouldShowImageOnLoading()) {
imageAware.setImageDrawable(options.getImageOnLoading(this.configuration
.resources));
} else if (options.isResetViewBeforeLoading()) {
imageAware.setImageDrawable(null);
}
LoadAndDisplayImageTask displayTask = new LoadAndDisplayImageTask(this.engine, new
ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey, options,
listener, progressListener, this.engine.getLockForUri(uri)), defineHandler
(options));
if (options.isSyncLoading()) {
displayTask.run();
return;
} else {
this.engine.submit(displayTask);
return;
}
}
L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
if (options.shouldPostProcess()) {
ProcessAndDisplayImageTask displayTask2 = new ProcessAndDisplayImageTask(this.engine,
bmp, new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey,
options, listener, progressListener, this.engine.getLockForUri(uri)),
defineHandler(options));
if (options.isSyncLoading()) {
displayTask2.run();
return;
} else {
this.engine.submit(displayTask2);
return;
}
}
options.getDisplayer().display(bmp, imageAware, LoadedFrom.MEMORY_CACHE);
listener.onLoadingComplete(uri, imageAware.getWrappedView(), bmp);
}
示例10: getMemoryCache
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
public List getMemoryCache(String s)
{
return MemoryCacheUtils.findCachedBitmapsForImageUri(s, b.getMemoryCache());
}
示例11: removeImageCache
import com.nostra13.universalimageloader.utils.MemoryCacheUtils; //导入依赖的package包/类
public void removeImageCache(String s)
{
MemoryCacheUtils.removeFromCache(s, b.getMemoryCache());
DiskCacheUtils.removeFromCache(s, b.getDiscCache());
}