Update UIL to 1.9.4
This commit is contained in:
parent
8fd1bc39f3
commit
35f9900101
@ -21,7 +21,7 @@ if ( !hasProperty( 'sourceDeps' ) ) {
|
|||||||
'com.android.support:support-annotations:20.0.0',
|
'com.android.support:support-annotations:20.0.0',
|
||||||
|
|
||||||
'org.thoughtcrime.ssl.pinning:AndroidPinning:1.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',
|
'com.google.zxing:core:3.2.0',
|
||||||
'eu.chainfire:libsuperuser:1.0.0.201504231659',
|
'eu.chainfire:libsuperuser:1.0.0.201504231659',
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ import android.os.RemoteException;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.widget.Toast;
|
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.cache.disc.naming.FileNameGenerator;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||||
@ -216,7 +216,7 @@ public class FDroidApp extends Application {
|
|||||||
|
|
||||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
|
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
|
||||||
.imageDownloader(new IconDownloader(getApplicationContext()))
|
.imageDownloader(new IconDownloader(getApplicationContext()))
|
||||||
.diskCache(new LimitedAgeDiscCache(
|
.diskCache(new LimitedAgeDiskCache(
|
||||||
new File(StorageUtils.getCacheDirectory(getApplicationContext(), true),
|
new File(StorageUtils.getCacheDirectory(getApplicationContext(), true),
|
||||||
"icons"),
|
"icons"),
|
||||||
null,
|
null,
|
||||||
|
11
extern/UniversalImageLoader/build.gradle
vendored
11
extern/UniversalImageLoader/build.gradle
vendored
@ -1,8 +1,17 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:1.0.0'
|
classpath 'com.android.tools.build:gradle:1.2.3'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.nostra13.universalimageloader"
|
package="com.nostra13.universalimageloader"
|
||||||
android:versionCode="38"
|
android:versionCode="39"
|
||||||
android:versionName="1.9.3" >
|
android:versionName="1.9.4" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="5"
|
android:minSdkVersion="5"
|
||||||
android:targetSdkVersion="19" />
|
android:targetSdkVersion="22" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
42
extern/UniversalImageLoader/library/build.gradle
vendored
42
extern/UniversalImageLoader/library/build.gradle
vendored
@ -1,18 +1,36 @@
|
|||||||
apply plugin: 'android-library'
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 16
|
compileSdkVersion 22
|
||||||
buildToolsVersion '22.0.1'
|
buildToolsVersion "22.0.1"
|
||||||
|
|
||||||
sourceSets {
|
defaultConfig {
|
||||||
main {
|
minSdkVersion 5
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
targetSdkVersion 22
|
||||||
java.srcDirs = ['src']
|
}
|
||||||
resources.srcDirs = ['src']
|
buildTypes {
|
||||||
aidl.srcDirs = ['src']
|
sourceSets {
|
||||||
renderscript.srcDirs = ['src']
|
main {
|
||||||
res.srcDirs = ['res']
|
manifest.srcFile 'AndroidManifest.xml'
|
||||||
assets.srcDirs = ['assets']
|
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'
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,5 @@
|
|||||||
# project structure.
|
# project structure.
|
||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=android-19
|
target=android-21
|
||||||
android.library=true
|
android.library=true
|
||||||
|
@ -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();
|
|
||||||
}
|
|
@ -15,11 +15,71 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.nostra13.universalimageloader.cache.disc;
|
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
|
* Interface for disk cache
|
||||||
*
|
*
|
||||||
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
|
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
|
||||||
* @since 1.9.2
|
* @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();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -35,7 +35,7 @@ import java.io.OutputStream;
|
|||||||
* @see FileNameGenerator
|
* @see FileNameGenerator
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public abstract class BaseDiscCache implements DiskCache {
|
public abstract class BaseDiskCache implements DiskCache {
|
||||||
/** {@value */
|
/** {@value */
|
||||||
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
|
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
|
||||||
/** {@value */
|
/** {@value */
|
||||||
@ -57,7 +57,7 @@ public abstract class BaseDiscCache implements DiskCache {
|
|||||||
protected int compressQuality = DEFAULT_COMPRESS_QUALITY;
|
protected int compressQuality = DEFAULT_COMPRESS_QUALITY;
|
||||||
|
|
||||||
/** @param cacheDir Directory for file caching */
|
/** @param cacheDir Directory for file caching */
|
||||||
public BaseDiscCache(File cacheDir) {
|
public BaseDiskCache(File cacheDir) {
|
||||||
this(cacheDir, null);
|
this(cacheDir, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ public abstract class BaseDiscCache implements DiskCache {
|
|||||||
* @param cacheDir Directory for file caching
|
* @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.
|
* @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());
|
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
|
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
|
||||||
* Name generator} for cached files
|
* Name generator} for cached files
|
||||||
*/
|
*/
|
||||||
public BaseDiscCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
|
public BaseDiskCache(File cacheDir, File reserveCacheDir, FileNameGenerator fileNameGenerator) {
|
||||||
if (cacheDir == null) {
|
if (cacheDir == null) {
|
||||||
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);
|
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);
|
||||||
}
|
}
|
||||||
@ -111,7 +111,6 @@ public abstract class BaseDiscCache implements DiskCache {
|
|||||||
IoUtils.closeSilently(os);
|
IoUtils.closeSilently(os);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
IoUtils.closeSilently(imageStream);
|
|
||||||
if (loaded && !tmpFile.renameTo(imageFile)) {
|
if (loaded && !tmpFile.renameTo(imageFile)) {
|
||||||
loaded = false;
|
loaded = false;
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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)
|
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
|
||||||
* @since 1.3.1
|
* @since 1.3.1
|
||||||
*/
|
*/
|
||||||
public class LimitedAgeDiscCache extends BaseDiscCache {
|
public class LimitedAgeDiskCache extends BaseDiskCache {
|
||||||
|
|
||||||
private final long maxFileAge;
|
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
|
* @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).
|
* treatment (and therefore be reloaded).
|
||||||
*/
|
*/
|
||||||
public LimitedAgeDiscCache(File cacheDir, long maxAge) {
|
public LimitedAgeDiskCache(File cacheDir, long maxAge) {
|
||||||
this(cacheDir, null, DefaultConfigurationFactory.createFileNameGenerator(), 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
|
* @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).
|
* 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);
|
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
|
* @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).
|
* 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);
|
super(cacheDir, reserveCacheDir, fileNameGenerator);
|
||||||
this.maxFileAge = maxAge * 1000; // to milliseconds
|
this.maxFileAge = maxAge * 1000; // to milliseconds
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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)
|
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public class UnlimitedDiscCache extends BaseDiscCache {
|
public class UnlimitedDiskCache extends BaseDiskCache {
|
||||||
/** @param cacheDir Directory for file caching */
|
/** @param cacheDir Directory for file caching */
|
||||||
public UnlimitedDiscCache(File cacheDir) {
|
public UnlimitedDiskCache(File cacheDir) {
|
||||||
super(cacheDir);
|
super(cacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public class UnlimitedDiscCache extends BaseDiscCache {
|
|||||||
* @param cacheDir Directory for file caching
|
* @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.
|
* @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);
|
super(cacheDir, reserveCacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ public class UnlimitedDiscCache extends BaseDiscCache {
|
|||||||
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
|
* @param fileNameGenerator {@linkplain com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator
|
||||||
* Name generator} for cached files
|
* 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);
|
super(cacheDir, reserveCacheDir, fileNameGenerator);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ import java.io.OutputStream;
|
|||||||
* @see FileNameGenerator
|
* @see FileNameGenerator
|
||||||
* @since 1.9.2
|
* @since 1.9.2
|
||||||
*/
|
*/
|
||||||
public class LruDiscCache implements DiskCache {
|
public class LruDiskCache implements DiskCache {
|
||||||
/** {@value */
|
/** {@value */
|
||||||
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
|
public static final int DEFAULT_BUFFER_SIZE = 32 * 1024; // 32 Kb
|
||||||
/** {@value */
|
/** {@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.
|
* @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")
|
* @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);
|
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.
|
* @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")
|
* @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 {
|
int cacheMaxFileCount) throws IOException {
|
||||||
if (cacheDir == null) {
|
if (cacheDir == null) {
|
||||||
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);
|
throw new IllegalArgumentException("cacheDir" + ERROR_ARG_NULL);
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,11 +17,32 @@ package com.nostra13.universalimageloader.cache.memory;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for memory cache
|
* Interface for memory cache
|
||||||
*
|
*
|
||||||
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
|
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
|
||||||
* @since 1.9.2
|
* @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();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,10 +15,14 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.nostra13.universalimageloader.core;
|
package com.nostra13.universalimageloader.core;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
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.DiskCache;
|
||||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
|
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||||
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiscCache;
|
import com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache;
|
||||||
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
|
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
|
||||||
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
|
import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator;
|
||||||
import com.nostra13.universalimageloader.cache.memory.MemoryCache;
|
import com.nostra13.universalimageloader.cache.memory.MemoryCache;
|
||||||
@ -82,7 +86,7 @@ public class DefaultConfigurationFactory {
|
|||||||
if (diskCacheSize > 0 || diskCacheFileCount > 0) {
|
if (diskCacheSize > 0 || diskCacheFileCount > 0) {
|
||||||
File individualCacheDir = StorageUtils.getIndividualCacheDirectory(context);
|
File individualCacheDir = StorageUtils.getIndividualCacheDirectory(context);
|
||||||
try {
|
try {
|
||||||
return new LruDiscCache(individualCacheDir, reserveCacheDir, diskCacheFileNameGenerator, diskCacheSize,
|
return new LruDiskCache(individualCacheDir, reserveCacheDir, diskCacheFileNameGenerator, diskCacheSize,
|
||||||
diskCacheFileCount);
|
diskCacheFileCount);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
L.e(e);
|
L.e(e);
|
||||||
@ -90,7 +94,7 @@ public class DefaultConfigurationFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
File cacheDir = StorageUtils.getCacheDirectory(context);
|
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 */
|
/** 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 />
|
* Creates default implementation of {@link MemoryCache} - {@link LruMemoryCache}<br />
|
||||||
* Default cache size = 1/8 of available app memory.
|
* 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) {
|
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);
|
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} */
|
/** Creates default implementation of {@link ImageDownloader} - {@link BaseImageDownloader} */
|
||||||
public static ImageDownloader createImageDownloader(Context context) {
|
public static ImageDownloader createImageDownloader(Context context) {
|
||||||
return new BaseImageDownloader(context);
|
return new BaseImageDownloader(context);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 ImageLoaderConfiguration configuration;
|
||||||
private ImageLoaderEngine engine;
|
private ImageLoaderEngine engine;
|
||||||
|
|
||||||
private final ImageLoadingListener emptyListener = new SimpleImageLoadingListener();
|
private ImageLoadingListener defaultListener = new SimpleImageLoadingListener();
|
||||||
|
|
||||||
private volatile static ImageLoader instance;
|
private volatile static ImageLoader instance;
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ public class ImageLoader {
|
|||||||
throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
|
throw new IllegalArgumentException(ERROR_WRONG_ARGUMENTS);
|
||||||
}
|
}
|
||||||
if (listener == null) {
|
if (listener == null) {
|
||||||
listener = emptyListener;
|
listener = defaultListener;
|
||||||
}
|
}
|
||||||
if (options == null) {
|
if (options == null) {
|
||||||
options = configuration.defaultDisplayImageOptions;
|
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
|
* Returns memory cache
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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>threadPoolSize = {@link Builder#DEFAULT_THREAD_POOL_SIZE this}</li>
|
||||||
* <li>threadPriority = {@link Builder#DEFAULT_THREAD_PRIORITY this}</li>
|
* <li>threadPriority = {@link Builder#DEFAULT_THREAD_PRIORITY this}</li>
|
||||||
* <li>allow to cache different sizes of image in memory</li>
|
* <li>allow to cache different sizes of image in memory</li>
|
||||||
* <li>memoryCache = {@link DefaultConfigurationFactory#createMemoryCache(int)}</li>
|
* <li>memoryCache = {@link DefaultConfigurationFactory#createMemoryCache(android.content.Context, int)}</li>
|
||||||
* <li>diskCache = {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache}</li>
|
* <li>diskCache = {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache}</li>
|
||||||
* <li>imageDownloader = {@link DefaultConfigurationFactory#createImageDownloader(Context)}</li>
|
* <li>imageDownloader = {@link DefaultConfigurationFactory#createImageDownloader(Context)}</li>
|
||||||
* <li>imageDecoder = {@link DefaultConfigurationFactory#createImageDecoder(boolean)}</li>
|
* <li>imageDecoder = {@link DefaultConfigurationFactory#createImageDecoder(boolean)}</li>
|
||||||
* <li>diskCacheFileNameGenerator = {@link DefaultConfigurationFactory#createFileNameGenerator()}</li>
|
* <li>diskCacheFileNameGenerator = {@link DefaultConfigurationFactory#createFileNameGenerator()}</li>
|
||||||
@ -157,7 +157,7 @@ public final class ImageLoaderConfiguration {
|
|||||||
/** {@value} */
|
/** {@value} */
|
||||||
public static final int DEFAULT_THREAD_POOL_SIZE = 3;
|
public static final int DEFAULT_THREAD_POOL_SIZE = 3;
|
||||||
/** {@value} */
|
/** {@value} */
|
||||||
public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 1;
|
public static final int DEFAULT_THREAD_PRIORITY = Thread.NORM_PRIORITY - 2;
|
||||||
/** {@value} */
|
/** {@value} */
|
||||||
public static final QueueProcessingType DEFAULT_TASK_PROCESSING_TYPE = QueueProcessingType.FIFO;
|
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 />
|
* Sets maximum disk cache size for images (in bytes).<br />
|
||||||
* By default: disk cache is unlimited.<br />
|
* By default: disk cache is unlimited.<br />
|
||||||
* <b>NOTE:</b> If you use this method then
|
* <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
|
* will be used as disk cache. You can use {@link #diskCache(DiskCache)} method for introduction your own
|
||||||
* implementation of {@link DiskCache}
|
* implementation of {@link DiskCache}
|
||||||
*/
|
*/
|
||||||
@ -443,7 +443,7 @@ public final class ImageLoaderConfiguration {
|
|||||||
* Sets maximum file count in disk cache directory.<br />
|
* Sets maximum file count in disk cache directory.<br />
|
||||||
* By default: disk cache is unlimited.<br />
|
* By default: disk cache is unlimited.<br />
|
||||||
* <b>NOTE:</b> If you use this method then
|
* <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
|
* will be used as disk cache. You can use {@link #diskCache(DiskCache)} method for introduction your own
|
||||||
* implementation of {@link DiskCache}
|
* implementation of {@link DiskCache}
|
||||||
*/
|
*/
|
||||||
@ -487,8 +487,8 @@ public final class ImageLoaderConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets disk cache for images.<br />
|
* Sets disk cache for images.<br />
|
||||||
* Default value - {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache
|
* Default value - {@link com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache
|
||||||
* BaseDiscCache}. Cache directory is defined by
|
* UnlimitedDiskCache}. Cache directory is defined by
|
||||||
* {@link com.nostra13.universalimageloader.utils.StorageUtils#getCacheDirectory(Context)
|
* {@link com.nostra13.universalimageloader.utils.StorageUtils#getCacheDirectory(Context)
|
||||||
* StorageUtils.getCacheDirectory(Context)}.<br />
|
* StorageUtils.getCacheDirectory(Context)}.<br />
|
||||||
* <br />
|
* <br />
|
||||||
@ -581,7 +581,7 @@ public final class ImageLoaderConfiguration {
|
|||||||
.createDiskCache(context, diskCacheFileNameGenerator, diskCacheSize, diskCacheFileCount);
|
.createDiskCache(context, diskCacheFileNameGenerator, diskCacheSize, diskCacheFileCount);
|
||||||
}
|
}
|
||||||
if (memoryCache == null) {
|
if (memoryCache == null) {
|
||||||
memoryCache = DefaultConfigurationFactory.createMemoryCache(memoryCacheSize);
|
memoryCache = DefaultConfigurationFactory.createMemoryCache(context, memoryCacheSize);
|
||||||
}
|
}
|
||||||
if (denyCacheImageMultipleSizesInMemory) {
|
if (denyCacheImageMultipleSizesInMemory) {
|
||||||
memoryCache = new FuzzyKeyMemoryCache(memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
|
memoryCache = new FuzzyKeyMemoryCache(memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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_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 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_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_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]";
|
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;
|
Bitmap bitmap = null;
|
||||||
try {
|
try {
|
||||||
File imageFile = configuration.diskCache.get(uri);
|
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);
|
L.d(LOG_LOAD_IMAGE_FROM_DISK_CACHE, memoryCacheKey);
|
||||||
loadedFrom = LoadedFrom.DISC_CACHE;
|
loadedFrom = LoadedFrom.DISC_CACHE;
|
||||||
|
|
||||||
@ -288,7 +289,16 @@ final class LoadAndDisplayImageTask implements Runnable, IoUtils.CopyListener {
|
|||||||
|
|
||||||
private boolean downloadImage() throws IOException {
|
private boolean downloadImage() throws IOException {
|
||||||
InputStream is = getDownloader().getStream(uri, options.getExtraForDownloader());
|
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 */
|
/** Decodes image file into Bitmap, resize it and save it back */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2013 Sergey Tarasevich
|
* Copyright 2013-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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_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_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 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 static final String ERROR_CANT_DECODE_IMAGE = "Image can't be decoded [%s]";
|
||||||
|
|
||||||
protected final boolean loggingEnabled;
|
protected final boolean loggingEnabled;
|
||||||
@ -71,6 +72,10 @@ public class BaseImageDecoder implements ImageDecoder {
|
|||||||
ImageFileInfo imageInfo;
|
ImageFileInfo imageInfo;
|
||||||
|
|
||||||
InputStream imageStream = getImageStream(decodingInfo);
|
InputStream imageStream = getImageStream(decodingInfo);
|
||||||
|
if (imageStream == null) {
|
||||||
|
L.e(ERROR_NO_IMAGE_STREAM, decodingInfo.getImageKey());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
|
imageInfo = defineImageSizeAndRotation(imageStream, decodingInfo);
|
||||||
imageStream = resetStream(imageStream, decodingInfo);
|
imageStream = resetStream(imageStream, decodingInfo);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2013 Sergey Tarasevich
|
* Copyright 2013-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,13 +15,17 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.nostra13.universalimageloader.core.download;
|
package com.nostra13.universalimageloader.core.download;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Bitmap.CompressFormat;
|
import android.graphics.Bitmap.CompressFormat;
|
||||||
|
import android.media.ThumbnailUtils;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.webkit.MimeTypeMap;
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
|
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
|
||||||
import com.nostra13.universalimageloader.utils.IoUtils;
|
import com.nostra13.universalimageloader.utils.IoUtils;
|
||||||
@ -67,9 +71,7 @@ public class BaseImageDownloader implements ImageDownloader {
|
|||||||
protected final int readTimeout;
|
protected final int readTimeout;
|
||||||
|
|
||||||
public BaseImageDownloader(Context context) {
|
public BaseImageDownloader(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this(context, DEFAULT_HTTP_CONNECT_TIMEOUT, DEFAULT_HTTP_READ_TIMEOUT);
|
||||||
this.connectTimeout = DEFAULT_HTTP_CONNECT_TIMEOUT;
|
|
||||||
this.readTimeout = DEFAULT_HTTP_READ_TIMEOUT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseImageDownloader(Context context, int connectTimeout, int readTimeout) {
|
public BaseImageDownloader(Context context, int connectTimeout, int readTimeout) {
|
||||||
@ -125,9 +127,24 @@ public class BaseImageDownloader implements ImageDownloader {
|
|||||||
IoUtils.readAndCloseStream(conn.getErrorStream());
|
IoUtils.readAndCloseStream(conn.getErrorStream());
|
||||||
throw e;
|
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());
|
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
|
* 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 {
|
protected InputStream getStreamFromFile(String imageUri, Object extra) throws IOException {
|
||||||
String filePath = Scheme.FILE.crop(imageUri);
|
String filePath = Scheme.FILE.crop(imageUri);
|
||||||
return new ContentLengthInputStream(new BufferedInputStream(new FileInputStream(filePath), BUFFER_SIZE),
|
if (isVideoFileUri(imageUri)) {
|
||||||
(int) new File(filePath).length());
|
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();
|
ContentResolver res = context.getContentResolver();
|
||||||
|
|
||||||
Uri uri = Uri.parse(imageUri);
|
Uri uri = Uri.parse(imageUri);
|
||||||
if (isVideoUri(uri)) { // video thumbnail
|
if (isVideoContentUri(uri)) { // video thumbnail
|
||||||
Long origId = Long.valueOf(uri.getLastPathSegment());
|
Long origId = Long.valueOf(uri.getLastPathSegment());
|
||||||
Bitmap bitmap = MediaStore.Video.Thumbnails
|
Bitmap bitmap = MediaStore.Video.Thumbnails
|
||||||
.getThumbnail(res, origId, MediaStore.Images.Thumbnails.MINI_KIND, null);
|
.getThumbnail(res, origId, MediaStore.Images.Thumbnails.MINI_KIND, null);
|
||||||
@ -184,12 +219,22 @@ public class BaseImageDownloader implements ImageDownloader {
|
|||||||
return new ByteArrayInputStream(bos.toByteArray());
|
return new ByteArrayInputStream(bos.toByteArray());
|
||||||
}
|
}
|
||||||
} else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { // contacts photo
|
} else if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) { // contacts photo
|
||||||
return ContactsContract.Contacts.openContactPhotoInputStream(res, uri);
|
return getContactPhotoStream(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.openInputStream(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).
|
* 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));
|
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);
|
String mimeType = context.getContentResolver().getType(uri);
|
||||||
|
return mimeType != null && mimeType.startsWith("video/");
|
||||||
|
}
|
||||||
|
|
||||||
if (mimeType == null) {
|
private boolean isVideoFileUri(String uri) {
|
||||||
return false;
|
String extension = MimeTypeMap.getFileExtensionFromUrl(uri);
|
||||||
}
|
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||||
|
return mimeType != null && mimeType.startsWith("video/");
|
||||||
return mimeType.startsWith("video/");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2013 Sergey Tarasevich
|
* Copyright 2013-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2013 Sergey Tarasevich
|
* Copyright 2013-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2013 Sergey Tarasevich
|
* Copyright 2013-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2013 Sergey Tarasevich
|
* Copyright 2013-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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) {
|
public static void readAndCloseStream(InputStream is) {
|
||||||
final byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
|
final byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
|
||||||
try {
|
try {
|
||||||
while (is.read(bytes, 0, DEFAULT_BUFFER_SIZE) != -1) {
|
while (is.read(bytes, 0, DEFAULT_BUFFER_SIZE) != -1);
|
||||||
}
|
} catch (IOException ignored) {
|
||||||
} catch (IOException e) {
|
|
||||||
// Do nothing
|
|
||||||
} finally {
|
} finally {
|
||||||
closeSilently(is);
|
closeSilently(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeSilently(Closeable closeable) {
|
public static void closeSilently(Closeable closeable) {
|
||||||
try {
|
if (closeable != null) {
|
||||||
closeable.close();
|
try {
|
||||||
} catch (Exception e) {
|
closeable.close();
|
||||||
// Do nothing
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright 2011-2013 Sergey Tarasevich
|
* Copyright 2011-2014 Sergey Tarasevich
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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();
|
externalStorageState = Environment.getExternalStorageState();
|
||||||
} catch (NullPointerException e) { // (sh)it happens (Issue #660)
|
} catch (NullPointerException e) { // (sh)it happens (Issue #660)
|
||||||
externalStorageState = "";
|
externalStorageState = "";
|
||||||
|
} catch (IncompatibleClassChangeError e) { // (sh)it happens too (Issue #989)
|
||||||
|
externalStorageState = "";
|
||||||
}
|
}
|
||||||
if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
|
if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
|
||||||
appCacheDir = getExternalCacheDir(context);
|
appCacheDir = getExternalCacheDir(context);
|
||||||
@ -94,11 +96,24 @@ public final class StorageUtils {
|
|||||||
* @return Cache {@link File directory}
|
* @return Cache {@link File directory}
|
||||||
*/
|
*/
|
||||||
public static File getIndividualCacheDirectory(Context context) {
|
public static File getIndividualCacheDirectory(Context context) {
|
||||||
File cacheDir = getCacheDirectory(context);
|
return getIndividualCacheDirectory(context, INDIVIDUAL_DIR_NAME);
|
||||||
File individualCacheDir = new File(cacheDir, 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.exists()) {
|
||||||
if (!individualCacheDir.mkdir()) {
|
if (!individualCacheDir.mkdir()) {
|
||||||
individualCacheDir = cacheDir;
|
individualCacheDir = appCacheDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return individualCacheDir;
|
return individualCacheDir;
|
||||||
@ -123,6 +138,25 @@ public final class StorageUtils {
|
|||||||
return appCacheDir;
|
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) {
|
private static File getExternalCacheDir(Context context) {
|
||||||
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
|
File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
|
||||||
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
|
File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
|
||||||
|
1
extern/UniversalImageLoader/settings.gradle
vendored
Normal file
1
extern/UniversalImageLoader/settings.gradle
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
include ':library'
|
Loading…
x
Reference in New Issue
Block a user