Update UIL to 1.9.4

This commit is contained in:
Daniel Martí 2015-05-29 12:27:45 +02:00
parent 8fd1bc39f3
commit 35f9900101
50 changed files with 351 additions and 257 deletions

View File

@ -21,7 +21,7 @@ if ( !hasProperty( 'sourceDeps' ) ) {
'com.android.support:support-annotations:20.0.0',
'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0',
'com.nostra13.universalimageloader:universal-image-loader:1.9.3',
'com.nostra13.universalimageloader:universal-image-loader:1.9.4',
'com.google.zxing:core:3.2.0',
'eu.chainfire:libsuperuser:1.0.0.201504231659',

View File

@ -41,7 +41,7 @@ import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.widget.Toast;
import com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiscCache;
import com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
@ -216,7 +216,7 @@ public class FDroidApp extends Application {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.imageDownloader(new IconDownloader(getApplicationContext()))
.diskCache(new LimitedAgeDiscCache(
.diskCache(new LimitedAgeDiskCache(
new File(StorageUtils.getCacheDirectory(getApplicationContext(), true),
"icons"),
null,

View File

@ -1,8 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nostra13.universalimageloader"
android:versionCode="38"
android:versionName="1.9.3" >
android:versionCode="39"
android:versionName="1.9.4" >
<uses-sdk
android:minSdkVersion="5"
android:targetSdkVersion="19" />
android:targetSdkVersion="22" />
</manifest>

View File

@ -1,9 +1,14 @@
apply plugin: 'android-library'
apply plugin: 'com.android.library'
android {
compileSdkVersion 16
buildToolsVersion '22.0.1'
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 5
targetSdkVersion 22
}
buildTypes {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
@ -12,7 +17,20 @@ android {
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
compile 'com.android.support:support-v4:22.1.1'
}

View File

@ -8,5 +8,5 @@
# project structure.
# Project target.
target=android-19
target=android-21
android.library=true

View File

@ -1,87 +0,0 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.nostra13.universalimageloader.cache.disc;
import android.graphics.Bitmap;
import com.nostra13.universalimageloader.utils.IoUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* Interface for disk cache
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.0.0
* @deprecated Use {@link DiskCache DiskCache} instead
*/
@Deprecated
public interface DiscCacheAware {
/**
* Returns root directory of disk cache
*
* @return Root directory of disk cache
*/
File getDirectory();
/**
* Returns file of cached image
*
* @param imageUri Original image URI
* @return File of cached image or <b>null</b> if image wasn't cached
*/
File get(String imageUri);
/**
* Saves image stream in disk cache.
*
* @param imageUri Original image URI
* @param imageStream Input stream of image
* @param listener Listener for saving progress, can be ignored if you don't use
* {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
* progress listener} in ImageLoader calls
* @return <b>true</b> - if image was saved successfully; <b>false</b> - if image wasn't saved in disk cache.
* @throws IOException
*/
boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException;
/**
* Saves image bitmap in disk cache.
*
* @param imageUri Original image URI
* @param bitmap Image bitmap
* @return <b>true</b> - if bitmap was saved successfully; <b>false</b> - if bitmap wasn't saved in disk cache.
* @throws IOException
*/
boolean save(String imageUri, Bitmap bitmap) throws IOException;
/**
* Removes image file associated with incoming URI
*
* @param imageUri Image URI
* @return <b>true</b> - if image file is deleted successfully; <b>false</b> - if image file doesn't exist for
* incoming URI or image file can't be deleted.
*/
boolean remove(String imageUri);
/** Closes disk cache, releases resources. */
void close();
/** Clears disk cache. */
void clear();
}

View File

@ -15,11 +15,71 @@
*******************************************************************************/
package com.nostra13.universalimageloader.cache.disc;
import android.graphics.Bitmap;
import com.nostra13.universalimageloader.utils.IoUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
/**
* Interface for disk cache
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.9.2
*/
public interface DiskCache extends DiscCacheAware {
public interface DiskCache {
/**
* Returns root directory of disk cache
*
* @return Root directory of disk cache
*/
File getDirectory();
/**
* Returns file of cached image
*
* @param imageUri Original image URI
* @return File of cached image or <b>null</b> if image wasn't cached
*/
File get(String imageUri);
/**
* Saves image stream in disk cache.
* Incoming image stream shouldn't be closed in this method.
*
* @param imageUri Original image URI
* @param imageStream Input stream of image (shouldn't be closed in this method)
* @param listener Listener for saving progress, can be ignored if you don't use
* {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
* progress listener} in ImageLoader calls
* @return <b>true</b> - if image was saved successfully; <b>false</b> - if image wasn't saved in disk cache.
* @throws java.io.IOException
*/
boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener) throws IOException;
/**
* Saves image bitmap in disk cache.
*
* @param imageUri Original image URI
* @param bitmap Image bitmap
* @return <b>true</b> - if bitmap was saved successfully; <b>false</b> - if bitmap wasn't saved in disk cache.
* @throws IOException
*/
boolean save(String imageUri, Bitmap bitmap) throws IOException;
/**
* Removes image file associated with incoming URI
*
* @param imageUri Image URI
* @return <b>true</b> - if image file is deleted successfully; <b>false</b> - if image file doesn't exist for
* incoming URI or image file can't be deleted.
*/
boolean remove(String imageUri);
/** Closes disk cache, releases resources. */
void close();
/** Clears disk cache. */
void clear();
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ import java.io.OutputStream;
* @see FileNameGenerator
* @since 1.0.0
*/
public abstract class BaseDiscCache implements DiskCache {
public abstract class BaseDiskCache implements DiskCache {
/** {@value */
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
/** {@value */
@ -57,7 +57,7 @@ public abstract class BaseDiscCache implements DiskCache {
protected int compressQuality = DEFAULT_COMPRESS_QUALITY;
/** @param cacheDir Directory for file caching */
public BaseDiscCache(File cacheDir) {
public BaseDiskCache(File cacheDir) {
this(cacheDir, null);
}
@ -65,7 +65,7 @@ public abstract class BaseDiscCache implements DiskCache {
* @param cacheDir Directory for file caching
* @param reserveCacheDir null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
*/
public BaseDiscCache(File cacheDir, File reserveCacheDir) {
public BaseDiskCache(File cacheDir, File reserveCacheDir) {
this(cacheDir, reserveCacheDir, DefaultConfigurationFactory.createFileNameGenerator());
}
@ -75,7 +75,7 @@ public abstract class BaseDiscCache implements DiskCache {
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
* Name generator} for cached files
*/
public BaseDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
public BaseDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
if (cacheDir == null) {
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);
}
@ -111,7 +111,6 @@ public abstract class BaseDiscCache implements DiskCache {
IoUtils.closeSilently(os);
}
} finally {
IoUtils.closeSilently(imageStream);
if (loaded && !tmpFile.renameTo(imageFile)) {
loaded = false;
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ import java.util.Map;
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.3.1
*/
public class LimitedAgeDiscCache extends BaseDiscCache {
public class LimitedAgeDiskCache extends BaseDiskCache {
private final long maxFileAge;
@ -44,7 +44,7 @@ public class LimitedAgeDiscCache extends BaseDiscCache {
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
* treatment (and therefore be reloaded).
*/
public LimitedAgeDiscCache(File cacheDir, long maxAge) {
public LimitedAgeDiskCache(File cacheDir, long maxAge) {
this(cacheDir, null, DefaultConfigurationFactory.createFileNameGenerator(), maxAge);
}
@ -53,7 +53,7 @@ public class LimitedAgeDiscCache extends BaseDiscCache {
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
* treatment (and therefore be reloaded).
*/
public LimitedAgeDiscCache(File cacheDir, File reserveCacheDir, long maxAge) {
public LimitedAgeDiskCache(File cacheDir, File reserveCacheDir, long maxAge) {
this(cacheDir, reserveCacheDir, DefaultConfigurationFactory.createFileNameGenerator(), maxAge);
}
@ -64,7 +64,7 @@ public class LimitedAgeDiscCache extends BaseDiscCache {
* @param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
* treatment (and therefore be reloaded).
*/
public LimitedAgeDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long maxAge) {
public LimitedAgeDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long maxAge) {
super(cacheDir, reserveCacheDir, fileNameGenerator);
this.maxFileAge = maxAge * 1000; // to milliseconds
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -26,9 +26,9 @@ import java.io.File;
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.0.0
*/
public class UnlimitedDiscCache extends BaseDiscCache {
public class UnlimitedDiskCache extends BaseDiskCache {
/** @param cacheDir Directory for file caching */
public UnlimitedDiscCache(File cacheDir) {
public UnlimitedDiskCache(File cacheDir) {
super(cacheDir);
}
@ -36,7 +36,7 @@ public class UnlimitedDiscCache extends BaseDiscCache {
* @param cacheDir Directory for file caching
* @param reserveCacheDir null-ok; Reserve directory for file caching. It's used when the primary directory isn't available.
*/
public UnlimitedDiscCache(File cacheDir, File reserveCacheDir) {
public UnlimitedDiskCache(File cacheDir, File reserveCacheDir) {
super(cacheDir, reserveCacheDir);
}
@ -46,7 +46,7 @@ public class UnlimitedDiscCache extends BaseDiscCache {
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
* Name generator} for cached files
*/
public UnlimitedDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
public UnlimitedDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
super(cacheDir, reserveCacheDir, fileNameGenerator);
}
}

View File

@ -36,7 +36,7 @@ import java.io.OutputStream;
* @see FileNameGenerator
* @since 1.9.2
*/
public class LruDiscCache implements DiskCache {
public class LruDiskCache implements DiskCache {
/** {@value */
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
/** {@value */
@ -65,7 +65,7 @@ public class LruDiscCache implements DiskCache {
* @param cacheMaxSize Max cache size in bytes. <b>0</b> means cache size is unlimited.
* @throws IOException if cache can't be initialized (e.g. "No space left on device")
*/
public LruDiscCache(File cacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize) throws IOException {
public LruDiskCache(File cacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize) throws IOException {
this(cacheDir, null, fileNameGenerator, cacheMaxSize, 0);
}
@ -79,7 +79,7 @@ public class LruDiscCache implements DiskCache {
* @param cacheMaxFileCount Max file count in cache. <b>0</b> means file count is unlimited.
* @throws IOException if cache can't be initialized (e.g. "No space left on device")
*/
public LruDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize,
public LruDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator, long cacheMaxSize,
int cacheMaxFileCount) throws IOException {
if (cacheDir == null) {
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -17,11 +17,32 @@ package com.nostra13.universalimageloader.cache.memory;
import android.graphics.Bitmap;
import java.util.Collection;
/**
* Interface for memory cache
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.9.2
*/
public interface MemoryCache extends MemoryCacheAware<String, Bitmap> {
public interface MemoryCache {
/**
* Puts value into cache by key
*
* @return <b>true</b> - if value was put into cache successfully, <b>false</b> - if value was <b>not</b> put into
* cache
*/
boolean put(String key, Bitmap value);
/** Returns value by key. If there is no value for key then null will be returned. */
Bitmap get(String key);
/** Removes item by key */
Bitmap remove(String key);
/** Returns all keys of cache */
Collection<String> keys();
/** Remove all items from cache */
void clear();
}

View File

@ -1,49 +0,0 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.nostra13.universalimageloader.cache.memory;
import java.util.Collection;
/**
* Interface for memory cache
*
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
* @since 1.0.0
* @deprecated Use {@link com.nostra13.universalimageloader.cache.memory.MemoryCache MemoryCache}
* instead
*/
@Deprecated
public interface MemoryCacheAware<K, V> {
/**
* Puts value into cache by key
*
* @return <b>true</b> - if value was put into cache successfully, <b>false</b> - if value was <b>not</b> put into
* cache
*/
boolean put(K key, V value);
/** Returns value by key. If there is no value for key then null will be returned. */
V get(K key);
/** Removes item by key */
V remove(K key);
/** Returns all keys of cache */
Collection<K> keys();
/** Remove all items from cache */
void clear();
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,10 +15,14 @@
*******************************************************************************/
package com.nostra13.universalimageloader.core;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Build;
import com.nostra13.universalimageloader.cache.disc.DiskCache;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.MemoryCache;
@ -82,7 +86,7 @@ public class DefaultConfigurationFactory {
if (diskCacheSize > 0 || diskCacheFileCount > 0) {
File individualCacheDir = StorageUtils.getIndividualCacheDirectory(context);
try {
return new LruDiscCache(individualCacheDir, reserveCacheDir, diskCacheFileNameGenerator, diskCacheSize,
return new LruDiskCache(individualCacheDir, reserveCacheDir, diskCacheFileNameGenerator, diskCacheSize,
diskCacheFileCount);
} catch (IOException e) {
L.e(e);
@ -90,7 +94,7 @@ public class DefaultConfigurationFactory {
}
}
File cacheDir = StorageUtils.getCacheDirectory(context);
return new UnlimitedDiscCache(cacheDir, reserveCacheDir, diskCacheFileNameGenerator);
return new UnlimitedDiskCache(cacheDir, reserveCacheDir, diskCacheFileNameGenerator);
}
/** Creates reserve disk cache folder which will be used if primary disk cache folder becomes unavailable */
@ -107,13 +111,32 @@ public class DefaultConfigurationFactory {
* Creates default implementation of {@link MemoryCache} - {@link LruMemoryCache}<br />
* Default cache size = 1/8 of available app memory.
*/
public static MemoryCache createMemoryCache(int memoryCacheSize) {
public static MemoryCache createMemoryCache(Context context, int memoryCacheSize) {
if (memoryCacheSize == 0) {
memoryCacheSize = (int) (Runtime.getRuntime().maxMemory() / 8);
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int memoryClass = am.getMemoryClass();
if (hasHoneycomb() && isLargeHeap(context)) {
memoryClass = getLargeMemoryClass(am);
}
memoryCacheSize = 1024 * 1024 * memoryClass / 8;
}
return new LruMemoryCache(memoryCacheSize);
}
private static boolean hasHoneycomb() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static boolean isLargeHeap(Context context) {
return (context.getApplicationInfo().flags & ApplicationInfo.FLAG_LARGE_HEAP) != 0;
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static int getLargeMemoryClass(ActivityManager am) {
return am.getLargeMemoryClass();
}
/** Creates default implementation of {@link ImageDownloader} - {@link BaseImageDownloader} */
public static ImageDownloader createImageDownloader(Context context) {
return new BaseImageDownloader(context);

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -61,7 +61,7 @@ public class ImageLoader {
private ImageLoaderConfiguration configuration;
private ImageLoaderEngine engine;
private final ImageLoadingListener emptyListener = new SimpleImageLoadingListener();
private ImageLoadingListener defaultListener = new SimpleImageLoadingListener();
private volatile static ImageLoader instance;
@ -210,7 +210,7 @@ public class ImageLoader {
throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
}
if (listener == null) {
listener = emptyListener;
listener = defaultListener;
}
if (options == null) {
options = configuration.defaultDisplayImageOptions;
@ -569,6 +569,11 @@ public class ImageLoader {
}
}
/** Sets a default loading listener for all display and loading tasks. */
public void setDefaultLoadingListener(ImageLoadingListener listener) {
defaultListener = listener == null ? new SimpleImageLoadingListener() : listener;
}
/**
* Returns memory cache
*

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -113,8 +113,8 @@ public final class ImageLoaderConfiguration {
* <li>threadPoolSize = {@link Builder#DEFAULT_THREAD_POOL_SIZE this}</li>
* <li>threadPriority = {@link Builder#DEFAULT_THREAD_PRIORITY this}</li>
* <li>allow to cache different sizes of image in memory</li>
* <li>memoryCache = {@link DefaultConfigurationFactory#createMemoryCache(int)}</li>
* <li>diskCache = {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache}</li>
* <li>memoryCache = {@link DefaultConfigurationFactory#createMemoryCache(android.content.Context, int)}</li>
* <li>diskCache = {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache}</li>
* <li>imageDownloader = {@link DefaultConfigurationFactory#createImageDownloader(Context)}</li>
* <li>imageDecoder = {@link DefaultConfigurationFactory#createImageDecoder(boolean)}</li>
* <li>diskCacheFileNameGenerator = {@link DefaultConfigurationFactory#createFileNameGenerator()}</li>
@ -157,7 +157,7 @@ public final class ImageLoaderConfiguration {
/** {@value} */
public static final int DEFAULT_THREAD_POOL_SIZE = 3;
/** {@value} */
public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1;
public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 2;
/** {@value} */
public static final QueueProcessingType DEFAULT_TASK_PROCESSING_TYPE = QueueProcessingType.FIFO;
@ -418,7 +418,7 @@ public final class ImageLoaderConfiguration {
* Sets maximum disk cache size for images (in bytes).<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.LruDiscCache LruDiscCache}
* {@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}
*/
@ -443,7 +443,7 @@ public final class ImageLoaderConfiguration {
* 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.LruDiscCache LruDiscCache}
* {@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}
*/
@ -487,8 +487,8 @@ public final class ImageLoaderConfiguration {
/**
* Sets disk cache for images.<br />
* Default value - {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache
* BaseDiscCache}. Cache directory is defined by
* Default value - {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache
* UnlimitedDiskCache}. Cache directory is defined by
* {@link com.nostra13.universalimageloader.utils.StorageUtils#getCacheDirectory(Context)
* StorageUtils.getCacheDirectory(Context)}.<br />
* <br />
@ -581,7 +581,7 @@ public final class ImageLoaderConfiguration {
.createDiskCache(context, diskCacheFileNameGenerator, diskCacheSize, diskCacheFileCount);
}
if (memoryCache == null) {
memoryCache = DefaultConfigurationFactory.createMemoryCache(memoryCacheSize);
memoryCache = DefaultConfigurationFactory.createMemoryCache(context, memoryCacheSize);
}
if (denyCacheImageMultipleSizesInMemory) {
memoryCache = new FuzzyKeyMemoryCache(memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -68,6 +68,7 @@ final class LoadAndDisplayImageTask implements Runnable, IoUtils.CopyListener {
private static final String LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED = "ImageAware was collected by GC. Task is cancelled. [%s]";
private static final String LOG_TASK_INTERRUPTED = "Task was interrupted [%s]";
private static final String ERROR_NO_IMAGE_STREAM = "No stream for image [%s]";
private static final String ERROR_PRE_PROCESSOR_NULL = "Pre-processor returned null [%s]";
private static final String ERROR_POST_PROCESSOR_NULL = "Post-processor returned null [%s]";
private static final String ERROR_PROCESSOR_FOR_DISK_CACHE_NULL = "Bitmap processor for disk cache returned null [%s]";
@ -214,7 +215,7 @@ final class LoadAndDisplayImageTask implements Runnable, IoUtils.CopyListener {
Bitmap bitmap = null;
try {
File imageFile = configuration.diskCache.get(uri);
if (imageFile != null && imageFile.exists()) {
if (imageFile != null && imageFile.exists() && imageFile.length() > 0) {
L.d(LOG_LOAD_IMAGE_FROM_DISK_CACHE, memoryCacheKey);
loadedFrom = LoadedFrom.DISC_CACHE;
@ -288,7 +289,16 @@ final class LoadAndDisplayImageTask implements Runnable, IoUtils.CopyListener {
private boolean downloadImage() throws IOException {
InputStream is = getDownloader().getStream(uri, options.getExtraForDownloader());
if (is == null) {
L.e(ERROR_NO_IMAGE_STREAM, memoryCacheKey);
return false;
} else {
try {
return configuration.diskCache.save(uri, is, this);
} finally {
IoUtils.closeSilently(is);
}
}
}
/** Decodes image file into Bitmap, resize it and save it back */

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013 Sergey Tarasevich
* Copyright 2013-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -43,6 +43,7 @@ public class BaseImageDecoder implements ImageDecoder {
protected static final String LOG_SCALE_IMAGE = "Scale subsampled image (%1$s) to %2$s (scale = %3$.5f) [%4$s]";
protected static final String LOG_ROTATE_IMAGE = "Rotate image on %1$d\u00B0 [%2$s]";
protected static final String LOG_FLIP_IMAGE = "Flip image horizontally [%s]";
protected static final String ERROR_NO_IMAGE_STREAM = "No stream for image [%s]";
protected static final String ERROR_CANT_DECODE_IMAGE = "Image can't be decoded [%s]";
protected final boolean loggingEnabled;
@ -71,6 +72,10 @@ public class BaseImageDecoder implements ImageDecoder {
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);

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013 Sergey Tarasevich
* Copyright 2013-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich, Daniel Martí
* Copyright 2011-2014 Sergey Tarasevich, Daniel Martí
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -15,13 +15,17 @@
*******************************************************************************/
package com.nostra13.universalimageloader.core.download;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;
import android.provider.MediaStore;
import android.webkit.MimeTypeMap;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
import com.nostra13.universalimageloader.utils.IoUtils;
@ -67,9 +71,7 @@ public class BaseImageDownloader implements ImageDownloader {
protected final int readTimeout;
public BaseImageDownloader(Context context) {
this.context = context.getApplicationContext();
this.connectTimeout = DEFAULT_HTTP_CONNECT_TIMEOUT;
this.readTimeout = DEFAULT_HTTP_READ_TIMEOUT;
this(context, DEFAULT_HTTP_CONNECT_TIMEOUT, DEFAULT_HTTP_READ_TIMEOUT);
}
public BaseImageDownloader(Context context, int connectTimeout, int readTimeout) {
@ -125,9 +127,24 @@ public class BaseImageDownloader implements ImageDownloader {
IoUtils.readAndCloseStream(conn.getErrorStream());
throw e;
}
if (!shouldBeProcessed(conn)) {
IoUtils.closeSilently(imageStream);
throw new IOException("Image request failed with response code " + conn.getResponseCode());
}
return new ContentLengthInputStream(new BufferedInputStream(imageStream, BUFFER_SIZE), conn.getContentLength());
}
/**
* @param conn Opened request connection (response code is available)
* @return <b>true</b> - if data from connection is correct and should be read and processed;
* <b>false</b> - if response contains irrelevant data and shouldn't be processed
* @throws IOException
*/
protected boolean shouldBeProcessed(HttpURLConnection conn) throws IOException {
return conn.getResponseCode() == 200;
}
/**
* Create {@linkplain HttpURLConnection HTTP connection} for incoming URL
*
@ -157,8 +174,26 @@ public class BaseImageDownloader implements ImageDownloader {
*/
protected InputStream getStreamFromFile(String imageUri, Object extra) throws IOException {
String filePath = Scheme.FILE.crop(imageUri);
return new ContentLengthInputStream(new BufferedInputStream(new FileInputStream(filePath), BUFFER_SIZE),
(int) new File(filePath).length());
if (isVideoFileUri(imageUri)) {
return getVideoThumbnailStream(filePath);
} else {
BufferedInputStream imageStream = new BufferedInputStream(new FileInputStream(filePath), BUFFER_SIZE);
return new ContentLengthInputStream(imageStream, (int) new File(filePath).length());
}
}
@TargetApi(Build.VERSION_CODES.FROYO)
private InputStream getVideoThumbnailStream(String filePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
Bitmap bitmap = ThumbnailUtils
.createVideoThumbnail(filePath, MediaStore.Images.Thumbnails.FULL_SCREEN_KIND);
if (bitmap != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 0, bos);
return new ByteArrayInputStream(bos.toByteArray());
}
}
return null;
}
/**
@ -174,7 +209,7 @@ public class BaseImageDownloader implements ImageDownloader {
ContentResolver res = context.getContentResolver();
Uri uri = Uri.parse(imageUri);
if (isVideoUri(uri)) { // video thumbnail
if (isVideoContentUri(uri)) { // video thumbnail
Long origId = Long.valueOf(uri.getLastPathSegment());
Bitmap bitmap = MediaStore.Video.Thumbnails
.getThumbnail(res, origId, MediaStore.Images.Thumbnails.MINI_KIND, null);
@ -184,12 +219,22 @@ public class BaseImageDownloader implements ImageDownloader {
return new ByteArrayInputStream(bos.toByteArray());
}
} else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { // contacts photo
return ContactsContract.Contacts.openContactPhotoInputStream(res, uri);
return getContactPhotoStream(uri);
}
return res.openInputStream(uri);
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected InputStream getContactPhotoStream(Uri uri) {
ContentResolver res = context.getContentResolver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
return ContactsContract.Contacts.openContactPhotoInputStream(res, uri, true);
} else {
return ContactsContract.Contacts.openContactPhotoInputStream(res, uri);
}
}
/**
* Retrieves {@link InputStream} of image by URI (image is located in assets of application).
*
@ -235,13 +280,14 @@ public class BaseImageDownloader implements ImageDownloader {
throw new UnsupportedOperationException(String.format(ERROR_UNSUPPORTED_SCHEME, imageUri));
}
private boolean isVideoUri(Uri uri) {
private boolean isVideoContentUri(Uri uri) {
String mimeType = context.getContentResolver().getType(uri);
if (mimeType == null) {
return false;
return mimeType != null && mimeType.startsWith("video/");
}
return mimeType.startsWith("video/");
private boolean isVideoFileUri(String uri) {
String extension = MimeTypeMap.getFileExtensionFromUrl(uri);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
return mimeType != null && mimeType.startsWith("video/");
}
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013 Sergey Tarasevich
* Copyright 2013-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013 Sergey Tarasevich
* Copyright 2013-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013 Sergey Tarasevich
* Copyright 2013-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2013 Sergey Tarasevich
* Copyright 2013-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -103,20 +103,19 @@ public final class IoUtils {
public static void readAndCloseStream(InputStream is) {
final byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
try {
while (is.read(bytes, 0, DEFAULT_BUFFER_SIZE) != -1) {
}
} catch (IOException e) {
// Do nothing
while (is.read(bytes, 0, DEFAULT_BUFFER_SIZE) != -1);
} catch (IOException ignored) {
} finally {
closeSilently(is);
}
}
public static void closeSilently(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (Exception e) {
// Do nothing
} catch (Exception ignored) {
}
}
}

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2011-2013 Sergey Tarasevich
* Copyright 2011-2014 Sergey Tarasevich
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -70,6 +70,8 @@ public final class StorageUtils {
externalStorageState = Environment.getExternalStorageState();
} catch (NullPointerException e) { // (sh)it happens (Issue #660)
externalStorageState = "";
} catch (IncompatibleClassChangeError e) { // (sh)it happens too (Issue #989)
externalStorageState = "";
}
if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
appCacheDir = getExternalCacheDir(context);
@ -94,11 +96,24 @@ public final class StorageUtils {
* @return Cache {@link File directory}
*/
public static File getIndividualCacheDirectory(Context context) {
File cacheDir = getCacheDirectory(context);
File individualCacheDir = new File(cacheDir, INDIVIDUAL_DIR_NAME);
return getIndividualCacheDirectory(context, INDIVIDUAL_DIR_NAME);
}
/**
* Returns individual application cache directory (for only image caching from ImageLoader). Cache directory will be
* created on SD card <i>("/Android/data/[app_package_name]/cache/uil-images")</i> if card is mounted and app has
* appropriate permission. Else - Android defines cache directory on device's file system.
*
* @param context Application context
* @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images")
* @return Cache {@link File directory}
*/
public static File getIndividualCacheDirectory(Context context, String cacheDir) {
File appCacheDir = getCacheDirectory(context);
File individualCacheDir = new File(appCacheDir, cacheDir);
if (!individualCacheDir.exists()) {
if (!individualCacheDir.mkdir()) {
individualCacheDir = cacheDir;
individualCacheDir = appCacheDir;
}
}
return individualCacheDir;
@ -123,6 +138,25 @@ public final class StorageUtils {
return appCacheDir;
}
/**
* Returns specified application cache directory. Cache directory will be created on SD card by defined path if card
* is mounted and app has appropriate permission. Else - Android defines cache directory on device's file system.
*
* @param context Application context
* @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images")
* @return Cache {@link File directory}
*/
public static File getOwnCacheDirectory(Context context, String cacheDir, boolean preferExternal) {
File appCacheDir = null;
if (preferExternal && MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && hasExternalStoragePermission(context)) {
appCacheDir = new File(Environment.getExternalStorageDirectory(), cacheDir);
}
if (appCacheDir == null || (!appCacheDir.exists() && !appCacheDir.mkdirs())) {
appCacheDir = context.getCacheDir();
}
return appCacheDir;
}
private static File getExternalCacheDir(Context context) {
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");

View File

@ -0,0 +1 @@
include ':library'