diff --git a/F-Droid/build.gradle b/F-Droid/build.gradle index a9a4e4a57..4219e4c4a 100644 --- a/F-Droid/build.gradle +++ b/F-Droid/build.gradle @@ -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', diff --git a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java index 6f99b3106..677bfe175 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java @@ -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, diff --git a/extern/UniversalImageLoader/build.gradle b/extern/UniversalImageLoader/build.gradle index 31f76f8ae..96b924b85 100644 --- a/extern/UniversalImageLoader/build.gradle +++ b/extern/UniversalImageLoader/build.gradle @@ -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() + } +} + diff --git a/extern/UniversalImageLoader/library/AndroidManifest.xml b/extern/UniversalImageLoader/library/AndroidManifest.xml index 359e84264..8b6a5a3ad 100644 --- a/extern/UniversalImageLoader/library/AndroidManifest.xml +++ b/extern/UniversalImageLoader/library/AndroidManifest.xml @@ -1,11 +1,11 @@ + android:versionCode="39" + android:versionName="1.9.4" > + android:targetSdkVersion="22" /> - \ No newline at end of file + diff --git a/extern/UniversalImageLoader/library/build.gradle b/extern/UniversalImageLoader/library/build.gradle index 294cf273d..b7c42bd72 100644 --- a/extern/UniversalImageLoader/library/build.gradle +++ b/extern/UniversalImageLoader/library/build.gradle @@ -1,18 +1,36 @@ -apply plugin: 'android-library' +apply plugin: 'com.android.library' android { - compileSdkVersion 16 - buildToolsVersion '22.0.1' + compileSdkVersion 22 + buildToolsVersion "22.0.1" - sourceSets { - main { - manifest.srcFile 'AndroidManifest.xml' - java.srcDirs = ['src'] - resources.srcDirs = ['src'] - aidl.srcDirs = ['src'] - renderscript.srcDirs = ['src'] - res.srcDirs = ['res'] - assets.srcDirs = ['assets'] + defaultConfig { + minSdkVersion 5 + targetSdkVersion 22 + } + buildTypes { + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + } + } + 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' } diff --git a/extern/UniversalImageLoader/library/project.properties b/extern/UniversalImageLoader/library/project.properties index 8e4bc5fdc..b756f4487 100644 --- a/extern/UniversalImageLoader/library/project.properties +++ b/extern/UniversalImageLoader/library/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-19 +target=android-21 android.library=true diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiscCacheAware.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiscCacheAware.java deleted file mode 100644 index 138fcfd8f..000000000 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiscCacheAware.java +++ /dev/null @@ -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 null 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 true - if image was saved successfully; false - 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 true - if bitmap was saved successfully; false - 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 true - if image file is deleted successfully; false - 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(); -} diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiskCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiskCache.java index ccc698617..7258b9ceb 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiskCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/DiskCache.java @@ -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 null 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 true - if image was saved successfully; false - 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 true - if bitmap was saved successfully; false - 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 true - if image file is deleted successfully; false - 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(); } diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiscCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiskCache.java similarity index 94% rename from extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiscCache.java rename to extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiskCache.java index e81f0d543..c78d2e6bf 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiscCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiskCache.java @@ -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; } diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiscCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiskCache.java similarity index 93% rename from extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiscCache.java rename to extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiskCache.java index 387a3a7e7..f367501a2 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiscCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/LimitedAgeDiskCache.java @@ -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 } diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiscCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiskCache.java similarity index 87% rename from extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiscCache.java rename to extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiskCache.java index d75222295..03fad1e96 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiscCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/UnlimitedDiskCache.java @@ -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); } } diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiscCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java similarity index 97% rename from extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiscCache.java rename to extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java index 42079eab7..aa0d91ec0 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiscCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/disc/impl/ext/LruDiskCache.java @@ -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. 0 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. 0 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); diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/BaseMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/BaseMemoryCache.java index a1cc0b779..4043719b5 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/BaseMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/BaseMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/LimitedMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/LimitedMemoryCache.java index 82ae1f1f9..d1782aaa6 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/LimitedMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/LimitedMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCache.java index 47bac924e..6a6dd582e 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCache.java @@ -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 { +public interface MemoryCache { + /** + * Puts value into cache by key + * + * @return true - if value was put into cache successfully, false - if value was not 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 keys(); + + /** Remove all items from cache */ + void clear(); } diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCacheAware.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCacheAware.java deleted file mode 100644 index d52524b5e..000000000 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/MemoryCacheAware.java +++ /dev/null @@ -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 { - /** - * Puts value into cache by key - * - * @return true - if value was put into cache successfully, false - if value was not 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 keys(); - - /** Remove all items from cache */ - void clear(); -} diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FIFOLimitedMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FIFOLimitedMemoryCache.java index 1d822b7e6..e56b1a394 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FIFOLimitedMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FIFOLimitedMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FuzzyKeyMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FuzzyKeyMemoryCache.java index d9e1d96d4..982c8128a 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FuzzyKeyMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/FuzzyKeyMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LRULimitedMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LRULimitedMemoryCache.java index 75c0d5e8c..2d25cde2f 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LRULimitedMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LRULimitedMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LargestLimitedMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LargestLimitedMemoryCache.java index 105aa559b..d7a8d19e2 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LargestLimitedMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LargestLimitedMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LimitedAgeMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LimitedAgeMemoryCache.java index 7327bf2e6..2925b6315 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LimitedAgeMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/LimitedAgeMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/UsingFreqLimitedMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/UsingFreqLimitedMemoryCache.java index cbf66358d..1c78dc1bc 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/UsingFreqLimitedMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/UsingFreqLimitedMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/WeakMemoryCache.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/WeakMemoryCache.java index 60914d65f..456257476 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/WeakMemoryCache.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/cache/memory/impl/WeakMemoryCache.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DefaultConfigurationFactory.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DefaultConfigurationFactory.java index 3157b11c1..af244d651 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DefaultConfigurationFactory.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DefaultConfigurationFactory.java @@ -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}
* 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); diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayBitmapTask.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayBitmapTask.java index 341321e13..fbdf762ff 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayBitmapTask.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayBitmapTask.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayImageOptions.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayImageOptions.java index b8ff9fd1c..b94d3baac 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayImageOptions.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/DisplayImageOptions.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoader.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoader.java index 6a745933d..e0163e6fc 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoader.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoader.java @@ -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 * diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java index 1fa2e8a00..f9f6f74ce 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java @@ -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 { *
  • threadPoolSize = {@link Builder#DEFAULT_THREAD_POOL_SIZE this}
  • *
  • threadPriority = {@link Builder#DEFAULT_THREAD_PRIORITY this}
  • *
  • allow to cache different sizes of image in memory
  • - *
  • memoryCache = {@link DefaultConfigurationFactory#createMemoryCache(int)}
  • - *
  • diskCache = {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache}
  • + *
  • memoryCache = {@link DefaultConfigurationFactory#createMemoryCache(android.content.Context, int)}
  • + *
  • diskCache = {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache}
  • *
  • imageDownloader = {@link DefaultConfigurationFactory#createImageDownloader(Context)}
  • *
  • imageDecoder = {@link DefaultConfigurationFactory#createImageDecoder(boolean)}
  • *
  • diskCacheFileNameGenerator = {@link DefaultConfigurationFactory#createFileNameGenerator()}
  • @@ -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).
    * By default: disk cache is unlimited.
    * NOTE: 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.
    * By default: disk cache is unlimited.
    * NOTE: 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.
    - * 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)}.
    *
    @@ -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()); diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderEngine.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderEngine.java index b25f6c9d7..378ce225f 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderEngine.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ImageLoaderEngine.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java index 24cbc497f..90a737b41 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java @@ -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()); - return configuration.diskCache.save(uri, is, this); + 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 */ diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ProcessAndDisplayImageTask.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ProcessAndDisplayImageTask.java index d7d759d8a..d09dc5a3a 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ProcessAndDisplayImageTask.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/ProcessAndDisplayImageTask.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ContentLengthInputStream.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ContentLengthInputStream.java index 786b2d5aa..316a52d06 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ContentLengthInputStream.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ContentLengthInputStream.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/FailReason.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/FailReason.java index f78491e58..061acffe1 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/FailReason.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/FailReason.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ImageScaleType.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ImageScaleType.java index b3eb89bd2..4dfd894e0 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ImageScaleType.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/assist/ImageScaleType.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/BaseImageDecoder.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/BaseImageDecoder.java index da3ce0efe..7b82ba689 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/BaseImageDecoder.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/BaseImageDecoder.java @@ -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); diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/ImageDecodingInfo.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/ImageDecodingInfo.java index fc4400bea..9a9ca04a1 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/ImageDecodingInfo.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/decode/ImageDecodingInfo.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/BitmapDisplayer.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/BitmapDisplayer.java index 77b800f4a..1149111ec 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/BitmapDisplayer.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/BitmapDisplayer.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/FadeInBitmapDisplayer.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/FadeInBitmapDisplayer.java index e60a18e91..686f0fd1f 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/FadeInBitmapDisplayer.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/FadeInBitmapDisplayer.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/RoundedBitmapDisplayer.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/RoundedBitmapDisplayer.java index e265e2bc5..c4dd8d5f8 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/RoundedBitmapDisplayer.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/display/RoundedBitmapDisplayer.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java index 964b51cef..f050eebc6 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java @@ -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 true - if data from connection is correct and should be read and processed; + * false - 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.startsWith("video/"); + return mimeType != null && mimeType.startsWith("video/"); } -} \ No newline at end of file + + private boolean isVideoFileUri(String uri) { + String extension = MimeTypeMap.getFileExtensionFromUrl(uri); + String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + return mimeType != null && mimeType.startsWith("video/"); + } +} diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageAware.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageAware.java index 71531fdd9..ba1f4cb83 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageAware.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageAware.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageViewAware.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageViewAware.java index 832872dcd..418f6b0a4 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageViewAware.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/ImageViewAware.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/NonViewAware.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/NonViewAware.java index 1918b5ec9..1975bdfa3 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/NonViewAware.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/core/imageaware/NonViewAware.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/DiskCacheUtils.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/DiskCacheUtils.java index 2522cd6b4..3b17fd7d4 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/DiskCacheUtils.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/DiskCacheUtils.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/ImageSizeUtils.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/ImageSizeUtils.java index 1dafddc2e..d899b8d83 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/ImageSizeUtils.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/ImageSizeUtils.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/IoUtils.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/IoUtils.java index fb900fb1f..498f3c2fc 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/IoUtils.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/IoUtils.java @@ -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) { - try { - closeable.close(); - } catch (Exception e) { - // Do nothing + if (closeable != null) { + try { + closeable.close(); + } catch (Exception ignored) { + } } } diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/L.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/L.java index 85d0e5033..427b8671e 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/L.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/L.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/MemoryCacheUtils.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/MemoryCacheUtils.java index e7f93a59c..39bed8799 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/MemoryCacheUtils.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/MemoryCacheUtils.java @@ -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. diff --git a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/StorageUtils.java b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/StorageUtils.java index ac57eefec..13026495f 100644 --- a/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/StorageUtils.java +++ b/extern/UniversalImageLoader/library/src/com/nostra13/universalimageloader/utils/StorageUtils.java @@ -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 ("/Android/data/[app_package_name]/cache/uil-images") 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"); diff --git a/extern/UniversalImageLoader/settings.gradle b/extern/UniversalImageLoader/settings.gradle new file mode 100644 index 000000000..d8f14a134 --- /dev/null +++ b/extern/UniversalImageLoader/settings.gradle @@ -0,0 +1 @@ +include ':library'