com.nostra13.universalimageloader.utils.L Java Examples

The following examples show how to use com.nostra13.universalimageloader.utils.L. 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: LoadAndDisplayImageTask.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
/** @return <b>true</b> - if task should be interrupted; <b>false</b> - otherwise */
private boolean waitIfPaused() {
	AtomicBoolean pause = engine.getPause();
	if (pause.get()) {
		synchronized (engine.getPauseLock()) {
			if (pause.get()) {
				L.d(LOG_WAITING_FOR_RESUME, memoryCacheKey);
				try {
					engine.getPauseLock().wait();
				} catch (InterruptedException e) {
					L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
					return true;
				}
				L.d(LOG_RESUME_AFTER_PAUSE, memoryCacheKey);
			}
		}
	}
	return isTaskNotActual();
}
 
Example #2
Source File: ImageLoaderConfiguration.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public Builder threadPriority(int i1)
{
    if (k != null || l != null)
    {
        L.w("threadPoolSize(), threadPriority() and tasksProcessingOrder() calls can overlap taskExecutor() and taskExecutorForCachedImages() calls.", new Object[0]);
    }
    if (i1 < 1)
    {
        p = 1;
        return this;
    }
    if (i1 > 10)
    {
        p = 10;
        return this;
    } else
    {
        p = i1;
        return this;
    }
}
 
Example #3
Source File: LoadAndDisplayImageTask.java    From letv with Apache License 2.0 6 votes vote down vote up
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
    File targetFile = this.configuration.diskCache.get(this.uri);
    if (targetFile == null || !targetFile.exists()) {
        return false;
    }
    Bitmap bmp = this.decoder.decode(new ImageDecodingInfo(this.memoryCacheKey, Scheme.FILE.wrap(targetFile.getAbsolutePath()), this.uri, new ImageSize(maxWidth, maxHeight), ViewScaleType.FIT_INSIDE, getDownloader(), new Builder().cloneFrom(this.options).imageScaleType(ImageScaleType.IN_SAMPLE_INT).build()));
    if (!(bmp == null || this.configuration.processorForDiskCache == null)) {
        L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, this.memoryCacheKey);
        bmp = this.configuration.processorForDiskCache.process(bmp);
        if (bmp == null) {
            L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, this.memoryCacheKey);
        }
    }
    if (bmp == null) {
        return false;
    }
    boolean saved = this.configuration.diskCache.save(this.uri, bmp);
    bmp.recycle();
    return saved;
}
 
Example #4
Source File: DisplayBitmapTask.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 6 votes vote down vote up
/**
 * 线程任务执行方法
 */
@Override
public void run() {
	//判断当前imageAware是否被回收
	if (imageAware.isCollected()) {
		L.d(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED, memoryCacheKey);
		//进行回调加载取消
		listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
	} else if (isViewWasReused()) {
		//判断对象是否为同一个
		L.d(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED, memoryCacheKey);
		listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
	} else {
		//进行显示
		L.d(LOG_DISPLAY_IMAGE_IN_IMAGEAWARE, loadedFrom, memoryCacheKey);
		//显示图片
		displayer.display(bitmap, imageAware, loadedFrom);
		engine.cancelDisplayTaskFor(imageAware);
		//图片显示完成回调
		listener.onLoadingComplete(imageUri, imageAware.getWrappedView(), bitmap);
	}
}
 
Example #5
Source File: ImageLoaderConfiguration.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
private ImageLoaderConfiguration(final Builder builder) {
	resources = builder.context.getResources();
	maxImageWidthForMemoryCache = builder.maxImageWidthForMemoryCache;
	maxImageHeightForMemoryCache = builder.maxImageHeightForMemoryCache;
	maxImageWidthForDiskCache = builder.maxImageWidthForDiskCache;
	maxImageHeightForDiskCache = builder.maxImageHeightForDiskCache;
	processorForDiskCache = builder.processorForDiskCache;
	taskExecutor = builder.taskExecutor;
	taskExecutorForCachedImages = builder.taskExecutorForCachedImages;
	threadPoolSize = builder.threadPoolSize;
	threadPriority = builder.threadPriority;
	tasksProcessingType = builder.tasksProcessingType;
	diskCache = builder.diskCache;
	memoryCache = builder.memoryCache;
	defaultDisplayImageOptions = builder.defaultDisplayImageOptions;
	downloader = builder.downloader;
	decoder = builder.decoder;

	customExecutor = builder.customExecutor;
	customExecutorForCachedImages = builder.customExecutorForCachedImages;

	networkDeniedDownloader = new NetworkDeniedImageDownloader(downloader);
	slowNetworkDownloader = new SlowNetworkImageDownloader(downloader);

	L.writeDebugLogs(builder.writeLogs);
}
 
Example #6
Source File: BaseImageDecoder.java    From candybar with Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }

    Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example #7
Source File: ImageLoaderConfiguration.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
private ImageLoaderConfiguration(final Builder builder) {
	resources = builder.context.getResources();
	maxImageWidthForMemoryCache = builder.maxImageWidthForMemoryCache;
	maxImageHeightForMemoryCache = builder.maxImageHeightForMemoryCache;
	maxImageWidthForDiskCache = builder.maxImageWidthForDiskCache;
	maxImageHeightForDiskCache = builder.maxImageHeightForDiskCache;
	processorForDiskCache = builder.processorForDiskCache;
	taskExecutor = builder.taskExecutor;
	taskExecutorForCachedImages = builder.taskExecutorForCachedImages;
	threadPoolSize = builder.threadPoolSize;
	threadPriority = builder.threadPriority;
	tasksProcessingType = builder.tasksProcessingType;
	diskCache = builder.diskCache;
	memoryCache = builder.memoryCache;
	defaultDisplayImageOptions = builder.defaultDisplayImageOptions;
	downloader = builder.downloader;
	decoder = builder.decoder;

	customExecutor = builder.customExecutor;
	customExecutorForCachedImages = builder.customExecutorForCachedImages;

	networkDeniedDownloader = new NetworkDeniedImageDownloader(downloader);
	slowNetworkDownloader = new SlowNetworkImageDownloader(downloader);

	L.writeDebugLogs(builder.writeLogs);
}
 
Example #8
Source File: BaseImageDecoder.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
protected Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	int scale;
	if (scaleType == ImageScaleType.NONE) {
		scale = 1;
	} else if (scaleType == ImageScaleType.NONE_SAFE) {
		scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
	} else {
		ImageSize targetSize = decodingInfo.getTargetSize();
		boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
		scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
	}
	if (scale > 1 && loggingEnabled) {
		L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
	}

	Options decodingOptions = decodingInfo.getDecodingOptions();
	decodingOptions.inSampleSize = scale;
	return decodingOptions;
}
 
Example #9
Source File: ImageLoaderConfiguration$Builder.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public o threadPriority(int i1)
{
    if (k != null || l != null)
    {
        L.w("threadPoolSize(), threadPriority() and tasksProcessingOrder() calls can overlap taskExecutor() and taskExecutorForCachedImages() calls.", new Object[0]);
    }
    if (i1 < 1)
    {
        p = 1;
        return this;
    }
    if (i1 > 10)
    {
        p = 10;
        return this;
    } else
    {
        p = i1;
        return this;
    }
}
 
Example #10
Source File: ImageLoaderConfiguration.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
private ImageLoaderConfiguration(final Builder builder) {
	resources = builder.context.getResources();
	maxImageWidthForMemoryCache = builder.maxImageWidthForMemoryCache;
	maxImageHeightForMemoryCache = builder.maxImageHeightForMemoryCache;
	maxImageWidthForDiskCache = builder.maxImageWidthForDiskCache;
	maxImageHeightForDiskCache = builder.maxImageHeightForDiskCache;
	processorForDiskCache = builder.processorForDiskCache;
	taskExecutor = builder.taskExecutor;
	taskExecutorForCachedImages = builder.taskExecutorForCachedImages;
	threadPoolSize = builder.threadPoolSize;
	threadPriority = builder.threadPriority;
	tasksProcessingType = builder.tasksProcessingType;
	diskCache = builder.diskCache;
	memoryCache = builder.memoryCache;
	defaultDisplayImageOptions = builder.defaultDisplayImageOptions;
	downloader = builder.downloader;
	decoder = builder.decoder;

	customExecutor = builder.customExecutor;
	customExecutorForCachedImages = builder.customExecutorForCachedImages;

	networkDeniedDownloader = new NetworkDeniedImageDownloader(downloader);
	slowNetworkDownloader = new SlowNetworkImageDownloader(downloader);

	L.writeDebugLogs(builder.writeLogs);
}
 
Example #11
Source File: LoadAndDisplayImageTask.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 6 votes vote down vote up
/**
 * @return <b>true</b> - if task should be interrupted; <b>false</b> - otherwise
 * 判断是否需要等待暂时
 */
private boolean waitIfPaused() {
	AtomicBoolean pause = engine.getPause();
	if (pause.get()) {
		synchronized (engine.getPauseLock()) {
			if (pause.get()) {
				L.d(LOG_WAITING_FOR_RESUME, memoryCacheKey);
				try {
					engine.getPauseLock().wait();
				} catch (InterruptedException e) {
					L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
					return true;
				}
				L.d(LOG_RESUME_AFTER_PAUSE, memoryCacheKey);
			}
		}
	}
	return isTaskNotActual();
}
 
Example #12
Source File: DiskDecoder.java    From talk-android with MIT License 6 votes vote down vote up
protected BitmapFactory.Options prepareDecodingOptions(ImageSize imageSize, ImageDecodingInfo decodingInfo) {
    ImageScaleType scaleType = decodingInfo.getImageScaleType();
    int scale;
    if (scaleType == ImageScaleType.NONE) {
        scale = 1;
    } else if (scaleType == ImageScaleType.NONE_SAFE) {
        scale = ImageSizeUtils.computeMinImageSampleSize(imageSize);
    } else {
        ImageSize targetSize = decodingInfo.getTargetSize();
        boolean powerOf2 = scaleType == ImageScaleType.IN_SAMPLE_POWER_OF_2;
        scale = ImageSizeUtils.computeImageSampleSize(imageSize, targetSize, decodingInfo.getViewScaleType(), powerOf2);
    }
    if (scale > 1 && loggingEnabled) {
        L.d(LOG_SUBSAMPLE_IMAGE, imageSize, imageSize.scaleDown(scale), scale, decodingInfo.getImageKey());
    }

    BitmapFactory.Options decodingOptions = decodingInfo.getDecodingOptions();
    decodingOptions.inSampleSize = scale;
    return decodingOptions;
}
 
Example #13
Source File: LruDiscCache.java    From letv with Apache License 2.0 6 votes vote down vote up
public File get(String imageUri) {
    File file = null;
    Snapshot snapshot = null;
    try {
        snapshot = this.cache.get(getKey(imageUri));
        if (snapshot != null) {
            file = snapshot.getFile(0);
        }
        if (snapshot != null) {
            snapshot.close();
        }
    } catch (IOException e) {
        L.e(e);
        if (snapshot != null) {
            snapshot.close();
        }
    } catch (Throwable th) {
        if (snapshot != null) {
            snapshot.close();
        }
    }
    return file;
}
 
Example #14
Source File: l.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
private boolean n()
{
    String s1 = z.a(b);
    boolean flag;
    if (!H.equals(s1))
    {
        flag = true;
    } else
    {
        flag = false;
    }
    if (flag)
    {
        Object aobj[] = new Object[1];
        aobj[0] = H;
        L.d("ImageAware is reused for another image. Task is cancelled. [%s]", aobj);
        return true;
    } else
    {
        return false;
    }
}
 
Example #15
Source File: DisplayBitmapTask.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	if (imageAware.isCollected()) {
		L.d(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED, memoryCacheKey);
		listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
	} else if (isViewWasReused()) {
		L.d(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED, memoryCacheKey);
		listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
	} else {
		L.d(LOG_DISPLAY_IMAGE_IN_IMAGEAWARE, loadedFrom, memoryCacheKey);
		displayer.display(bitmap, imageAware, loadedFrom);
		engine.cancelDisplayTaskFor(imageAware);
		listener.onLoadingComplete(imageUri, imageAware.getWrappedView(), bitmap);
	}
}
 
Example #16
Source File: ImageLoaderConfiguration.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
/**
 * Sets maximum memory cache size (in percent of available app memory) for {@link android.graphics.Bitmap
 * bitmaps}.<br />
 * Default value - 1/8 of available app memory.<br />
 * <b>NOTE:</b> If you use this method then
 * {@link com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache LruMemoryCache} will be used as
 * memory cache. You can use {@link #memoryCache(MemoryCache)} method to set your own implementation of
 * {@link MemoryCache}.
 */
public Builder memoryCacheSizePercentage(int availableMemoryPercent) {
	if (availableMemoryPercent <= 0 || availableMemoryPercent >= 100) {
		throw new IllegalArgumentException("availableMemoryPercent must be in range (0 < % < 100)");
	}

	if (memoryCache != null) {
		L.w(WARNING_OVERLAP_MEMORY_CACHE);
	}

	long availableMemory = Runtime.getRuntime().maxMemory();
	memoryCacheSize = (int) (availableMemory * (availableMemoryPercent / 100f));
	return this;
}
 
Example #17
Source File: LruDiskCache.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
private void initCache(File cacheDir, File reserveCacheDir, long cacheMaxSize, int cacheMaxFileCount)
		throws IOException {
	try {
		cache = DiskLruCache.open(cacheDir, 1, 1, cacheMaxSize, cacheMaxFileCount);
	} catch (IOException e) {
		L.e(e);
		if (reserveCacheDir != null) {
			initCache(reserveCacheDir, null, cacheMaxSize, cacheMaxFileCount);
		}
		if (cache == null) {
			throw e; //new RuntimeException("Can't initialize disk cache", e);
		}
	}
}
 
Example #18
Source File: DiskDecoder.java    From talk-android with MIT License 5 votes vote down vote up
/**
 * Decodes image from URI into {@link Bitmap}. Image is scaled close to incoming {@linkplain ImageSize target size}
 * during decoding (depend on incoming parameters).
 *
 * @param decodingInfo Needed data for decoding image
 * @return Decoded bitmap
 * @throws IOException                   if some I/O exception occurs during image reading
 * @throws UnsupportedOperationException if image URI has unsupported scheme(protocol)
 */
@Override
public Bitmap decode(ImageDecodingInfo decodingInfo) throws IOException {
    Bitmap decodedBitmap;
    ImageFileInfo imageInfo;

    InputStream imageStream = getImageStream(decodingInfo);
    if (imageStream == null) {
        L.e(ERROR_NO_IMAGE_STREAM, decodingInfo.getImageKey());
        return null;
    }
    try {
        imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
        imageStream = resetStream(imageStream, decodingInfo);
        BitmapFactory.Options decodingOptions = prepareDecodingOptions(imageInfo.imageSize, decodingInfo);
        decodedBitmap = BitmapFactory.decodeStream(imageStream, null, decodingOptions);
    } finally {
        IoUtils.closeSilently(imageStream);
    }

    if (decodedBitmap == null) {
        L.e(ERROR_CANT_DECODE_IMAGE, decodingInfo.getImageKey());
    } else {
        decodedBitmap = considerExactScaleAndOrientatiton(decodedBitmap, decodingInfo, imageInfo.exif.rotation,
                imageInfo.exif.flipHorizontal);
    }
    return decodedBitmap;
}
 
Example #19
Source File: DisplayBitmapTask.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	if (imageAware.isCollected()) {
		L.d(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED, memoryCacheKey);
		listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
	} else if (isViewWasReused()) {
		L.d(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED, memoryCacheKey);
		listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
	} else {
		L.d(LOG_DISPLAY_IMAGE_IN_IMAGEAWARE, loadedFrom, memoryCacheKey);
		displayer.display(bitmap, imageAware, loadedFrom);
		engine.cancelDisplayTaskFor(imageAware);
		listener.onLoadingComplete(imageUri, imageAware.getWrappedView(), bitmap);
	}
}
 
Example #20
Source File: Md5FileNameGenerator.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
private byte[] getMD5(byte[] data) {
	byte[] hash = null;
	try {
		MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
		digest.update(data);
		hash = digest.digest();
	} catch (NoSuchAlgorithmException e) {
		L.e(e);
	}
	return hash;
}
 
Example #21
Source File: ProcessAndDisplayImageTask.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void run() {
	L.d(LOG_POSTPROCESS_IMAGE, imageLoadingInfo.memoryCacheKey);

	BitmapProcessor processor = imageLoadingInfo.options.getPostProcessor();
	Bitmap processedBitmap = processor.process(bitmap);
	com.nostra13.universalimageloader.core.DisplayBitmapTask displayBitmapTask = new com.nostra13.universalimageloader.core.DisplayBitmapTask(processedBitmap, imageLoadingInfo, engine,
			LoadedFrom.MEMORY_CACHE);
	com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.runTask(displayBitmapTask, imageLoadingInfo.options.isSyncLoading(), handler, engine);
}
 
Example #22
Source File: ImageLoaderConfiguration.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
/**
 * Sets maximum file count in disk cache directory.<br />
 * By default: disk cache is unlimited.<br />
 * <b>NOTE:</b> If you use this method then
 * {@link com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache LruDiskCache}
 * will be used as disk cache. You can use {@link #diskCache(DiskCache)} method for introduction your own
 * implementation of {@link DiskCache}
 */
public Builder diskCacheFileCount(int maxFileCount) {
	if (maxFileCount <= 0) throw new IllegalArgumentException("maxFileCount must be a positive number");

	if (diskCache != null) {
		L.w(WARNING_OVERLAP_DISK_CACHE_PARAMS);
	}

	this.diskCacheFileCount = maxFileCount;
	return this;
}
 
Example #23
Source File: ImageLoaderConfiguration.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets name generator for files cached in disk cache.<br />
 * Default value -
 * {@link com.nostra13.universalimageloader.core.DefaultConfigurationFactory#createFileNameGenerator()
 * DefaultConfigurationFactory.createFileNameGenerator()}
 */
public Builder diskCacheFileNameGenerator(FileNameGenerator fileNameGenerator) {
	if (diskCache != null) {
		L.w(WARNING_OVERLAP_DISK_CACHE_NAME_GENERATOR);
	}

	this.diskCacheFileNameGenerator = fileNameGenerator;
	return this;
}
 
Example #24
Source File: LruDiskCache.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
@Override
public File get(String imageUri) {
	DiskLruCache.Snapshot snapshot = null;
	try {
		snapshot = cache.get(getKey(imageUri));
		return snapshot == null ? null : snapshot.getFile(0);
	} catch (IOException e) {
		L.e(e);
		return null;
	} finally {
		if (snapshot != null) {
			snapshot.close();
		}
	}
}
 
Example #25
Source File: ImageLoaderConfiguration.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets type of queue processing for tasks for loading and displaying images.<br />
 * Default value - {@link QueueProcessingType#FIFO}
 */
public Builder tasksProcessingOrder(QueueProcessingType tasksProcessingType) {
	if (taskExecutor != null || taskExecutorForCachedImages != null) {
		L.w(WARNING_OVERLAP_EXECUTOR);
	}

	this.tasksProcessingType = tasksProcessingType;
	return this;
}
 
Example #26
Source File: ImageLoaderConfiguration.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
/**
 * Sets type of queue processing for tasks for loading and displaying images.<br />
 * Default value - {@link QueueProcessingType#FIFO}
 */
public Builder tasksProcessingOrder(QueueProcessingType tasksProcessingType) {
	if (taskExecutor != null || taskExecutorForCachedImages != null) {
		L.w(WARNING_OVERLAP_EXECUTOR);
	}

	this.tasksProcessingType = tasksProcessingType;
	return this;
}
 
Example #27
Source File: ImageLoader.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes ImageLoader instance with configuration.<br />
 * If configurations was set before ( {@link #isInited()} == true) then this method does nothing.<br />
 * To force initialization with new configuration you should {@linkplain #destroy() destroy ImageLoader} at first.
 *
 * @param configuration {@linkplain ImageLoaderConfiguration ImageLoader configuration}
 * @throws IllegalArgumentException if <b>configuration</b> parameter is null
 */
public synchronized void init(ImageLoaderConfiguration configuration) {
	if (configuration == null) {
		throw new IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL);
	}
	if (this.configuration == null) {
		L.d(LOG_INIT_CONFIG);
		engine = new ImageLoaderEngine(configuration);
		this.configuration = configuration;
	} else {
		L.w(WARNING_RE_INIT_CONFIG);
	}
}
 
Example #28
Source File: ImageLoaderConfiguration.java    From letv with Apache License 2.0 5 votes vote down vote up
public Builder memoryCacheSizePercentage(int availableMemoryPercent) {
    if (availableMemoryPercent <= 0 || availableMemoryPercent >= 100) {
        throw new IllegalArgumentException("availableMemoryPercent must be in range (0 < % < 100)");
    }
    if (this.memoryCache != null) {
        L.w(WARNING_OVERLAP_MEMORY_CACHE, new Object[0]);
    }
    this.memoryCacheSize = (int) (((float) Runtime.getRuntime().maxMemory()) * (((float) availableMemoryPercent) / 100.0f));
    return this;
}
 
Example #29
Source File: BaseImageDecoder.java    From Android-Universal-Image-Loader-Modify with Apache License 2.0 5 votes vote down vote up
protected Bitmap considerExactScaleAndOrientatiton(Bitmap subsampledBitmap, ImageDecodingInfo decodingInfo,
		int rotation, boolean flipHorizontal) {
	Matrix m = new Matrix();
	// Scale to exact size if need
	ImageScaleType scaleType = decodingInfo.getImageScaleType();
	if (scaleType == ImageScaleType.EXACTLY || scaleType == ImageScaleType.EXACTLY_STRETCHED) {
		ImageSize srcSize = new ImageSize(subsampledBitmap.getWidth(), subsampledBitmap.getHeight(), rotation);
		float scale = ImageSizeUtils.computeImageScale(srcSize, decodingInfo.getTargetSize(), decodingInfo
				.getViewScaleType(), scaleType == ImageScaleType.EXACTLY_STRETCHED);
		if (Float.compare(scale, 1f) != 0) {
			m.setScale(scale, scale);

			if (loggingEnabled) {
				L.d(LOG_SCALE_IMAGE, srcSize, srcSize.scale(scale), scale, decodingInfo.getImageKey());
			}
		}
	}
	// Flip bitmap if need
	if (flipHorizontal) {
		m.postScale(-1, 1);

		if (loggingEnabled) L.d(LOG_FLIP_IMAGE, decodingInfo.getImageKey());
	}
	// Rotate bitmap if need
	if (rotation != 0) {
		m.postRotate(rotation);

		if (loggingEnabled) L.d(LOG_ROTATE_IMAGE, rotation, decodingInfo.getImageKey());
	}

	Bitmap finalBitmap = Bitmap.createBitmap(subsampledBitmap, 0, 0, subsampledBitmap.getWidth(), subsampledBitmap
			.getHeight(), m, true);
	if (finalBitmap != subsampledBitmap) {
		subsampledBitmap.recycle();
	}
	return finalBitmap;
}
 
Example #30
Source File: LruDiscCache.java    From letv with Apache License 2.0 5 votes vote down vote up
public void clear() {
    try {
        this.cache.delete();
    } catch (IOException e) {
        L.e(e);
    }
    try {
        initCache(this.cache.getDirectory(), this.reserveCacheDir, this.cache.getMaxSize(), this.cache.getMaxFileCount());
    } catch (IOException e2) {
        L.e(e2);
    }
}