Skip to content

Commit

Permalink
Make Volley an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Jun 29, 2014
1 parent 0181060 commit 700284e
Show file tree
Hide file tree
Showing 31 changed files with 505 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ samples/flickr/out
samples/flickr/bin
samples/flickr/local.properties
samples/flickr/target
integration/volley/target/**
**/local.properties
*.keystore
**/.idea/*
.settings
Expand Down
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
Glide
=====
Glide is fast and efficient image loading library for Android that wraps image downloading, resizing, memory and disk caching, and bitmap recycling into one simple and easy to use interface. By default, Glide includes an implementation for fetching images over http based on Google's Volley project for fast, parallelized network operations on Android.
Glide is fast and efficient image loading library for Android that wraps image downloading, resizing, memory and disk
caching, and bitmap recycling into one simple and easy to use interface. Glide includes a flexible api allowing it to
plug in to almost any network stack. By default Glide uses a custom HttpUrlConnection based stack, but also includes a
utility library to plug in to Google's Volley project instead.

Glide's primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.
Glide's primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is
also effective for almost any case where you need to fetch, resize, and display a remote image.

Download
--------
You can download a jar from GitHub's [release page](https://github.com/bumptech/glide/releases) or to use the 3.0 alpha branch, use Gradle:
You can download a jar from GitHub's [release page](https://github.com/bumptech/glide/releases) or to use the 3.0 alpha
branch, use Gradle:

```groovy
repositories {
Expand Down Expand Up @@ -38,12 +43,41 @@ In your module:
```xml
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<artifactId>library</artifactId>
<version>3.3.0-SNAPSHOT</version>
<type>aar</type>
</dependency>
```

Volley
-------
Volley is now an optional dependency that can be included via a utility library. More utility libraries for other
projects will hopefully be coming soon. To use the utility library with Gradle, add:

```groovy
dependencies {
compile group: 'com.github.bumptech.glide', name:'volley', version:'3.3.0-SNAPSHOT', changing:true
compile 'com.mcxiaoke.volley:library:1.0.+'
}
```

Or with maven:

```xml
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>volley</artifactId>
<version>3.3.0-SNAPSHOT</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.mcxiaoke.volley</groupId>
<artifactId>library</artifactId>
<version>1.0.5</version>
<type>aar</type>
</dependency>
```

How do I use Glide?
-------------------
Checkout the GitHub wiki for pages on a variety of topics and links to javadocs.
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ task wrapper(type: Wrapper) {
gradleVersion = '1.10'
}

evaluationDependsOnChildren();
evaluationDependsOn(":integration:volley")
evaluationDependsOn(":third_party:gif_decoder")
evaluationDependsOn(":library")

def getAndroidSdkDirectory() {
project("library").android.sdkDirectory
Expand Down Expand Up @@ -44,7 +46,7 @@ getAndroidLibraryVariants().each { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {

// Get the variant from each subproject that matches our current variant's name.
def childEquivalentChildVariants = getAndroidChildren().collect { project ->
def childEquivalentChildVariants = getAndroidChildren().collect { project ->
project.android.libraryVariants.findAll { type -> type.name == variant.name }
}.sum()

Expand Down
19 changes: 19 additions & 0 deletions integration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide-parent</artifactId>
<version>3.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>glide-integration</artifactId>
<packaging>pom</packaging>
<name>Glide Integration</name>

<modules>
<module>volley</module>
</modules>
</project>
8 changes: 8 additions & 0 deletions integration/volley/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bumptech.glide.volley"
android:versionCode="1"
android:versionName="1.0.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<application />
</manifest>
33 changes: 33 additions & 0 deletions integration/volley/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.2'
}
}

apply plugin: 'android-library'

repositories {
mavenCentral()
}

dependencies {
compile project(':library')

compile 'com.mcxiaoke.volley:library:1.0.+'
}

android {
compileSdkVersion 19
buildToolsVersion = '19.1.0'
sourceSets {
main {
java.srcDirs = ['src/main/java']
manifest.srcFile 'AndroidManifest.xml'
}
}
}

apply from: "https://raw.githubusercontent.com/mcxiaoke/gradle-mvn-push/master/gradle-mvn-push.gradle"
6 changes: 6 additions & 0 deletions integration/volley/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POM_NAME=Glide Volley Integration
POM_ARTIFACT_ID=glide-volley-integration
POM_PACKAGING=aar
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
4 changes: 4 additions & 0 deletions integration/volley/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="AllowBackup" severity="ignore" />
</lint>
30 changes: 30 additions & 0 deletions integration/volley/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide-integration</artifactId>
<version>3.3.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>glide-volley-integration</artifactId>
<packaging>aar</packaging>
<name>Glide Volley Integration</name>

<dependencies>
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>library</artifactId>
<version>3.3.0-SNAPSHOT</version>
<type>aar</type>
</dependency>
<dependency>
<groupId>com.mcxiaoke.volley</groupId>
<artifactId>library</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>

</project>
6 changes: 6 additions & 0 deletions integration/volley/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target=android-19

# https://code.google.com/p/android/issues/detail?id=40487
renderscript.opt.level=O0

android.library=true
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
import com.android.volley.toolbox.HttpStack;
import com.android.volley.toolbox.HurlStack;
import com.android.volley.toolbox.NoCache;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.load.engine.cache.DiskCache;

import static android.content.pm.PackageManager.NameNotFoundException;

/**
* A clone of the {@link Volley#newRequestQueue(Context)} allowing the user to set a disk cache and defaulting to
* no disk cache.
*/
public class RequestQueueWrapper {

public static RequestQueue getRequestQueue(Context context) {
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ android {
}

def getJarName() {
return "glide-${getVersionName()}.jar"
"glide-${getVersionName()}.jar"
}

// Build a jar, from http://stackoverflow.com/a/19037807/1002054.
Expand Down
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
POM_NAME=Glide Library
POM_ARTIFACT_ID=glide
POM_ARTIFACT_ID=library
POM_PACKAGING=aar
5 changes: 3 additions & 2 deletions library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>glide</artifactId>
<artifactId>library</artifactId>
<packaging>aar</packaging>
<name>Glide Library</name>

Expand Down Expand Up @@ -56,9 +56,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.bumptech.glide</groupId>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide-gif-decoder</artifactId>
<version>3.3.0-SNAPSHOT</version>
<type>aar</type>
</dependency>
</dependencies>
</project>
17 changes: 3 additions & 14 deletions library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import com.android.volley.RequestQueue;
import com.bumptech.glide.load.engine.Engine;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.engine.cache.DiskCache;
Expand All @@ -29,6 +28,7 @@
import com.bumptech.glide.load.model.file_descriptor.FileDescriptorResourceLoader;
import com.bumptech.glide.load.model.file_descriptor.FileDescriptorStringLoader;
import com.bumptech.glide.load.model.file_descriptor.FileDescriptorUriLoader;
import com.bumptech.glide.load.model.stream.HttpUrlGlideUrlLoader;
import com.bumptech.glide.load.model.stream.StreamFileLoader;
import com.bumptech.glide.load.model.stream.StreamModelLoader;
import com.bumptech.glide.load.model.stream.StreamResourceLoader;
Expand Down Expand Up @@ -58,7 +58,6 @@
import com.bumptech.glide.request.target.ImageViewTargetFactory;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.target.ViewTarget;
import com.bumptech.glide.volley.VolleyUrlLoader;

import java.io.File;
import java.io.InputStream;
Expand All @@ -81,7 +80,6 @@ public class Glide {
private static Glide GLIDE;

private final GenericLoaderFactory loaderFactory = new GenericLoaderFactory();
private final RequestQueue requestQueue;
private final Engine engine;
private final BitmapPool bitmapPool;
private final MemoryCache memoryCache;
Expand Down Expand Up @@ -170,10 +168,8 @@ static void tearDown() {
GLIDE = null;
}

Glide(Engine engine, RequestQueue requestQueue, MemoryCache memoryCache, BitmapPool bitmapPool,
Context context) {
Glide(Engine engine, MemoryCache memoryCache, BitmapPool bitmapPool, Context context) {
this.engine = engine;
this.requestQueue = requestQueue;
this.bitmapPool = bitmapPool;
this.memoryCache = memoryCache;

Expand Down Expand Up @@ -201,7 +197,7 @@ static void tearDown() {
register(Uri.class, ParcelFileDescriptor.class, new FileDescriptorUriLoader.Factory());
register(Uri.class, InputStream.class, new StreamUriLoader.Factory());
register(URL.class, InputStream.class, new StreamUrlLoader.Factory());
register(GlideUrl.class, InputStream.class, new VolleyUrlLoader.Factory(requestQueue));
register(GlideUrl.class, InputStream.class, new HttpUrlGlideUrlLoader.Factory());

transcoderFactory.register(Bitmap.class, BitmapDrawable.class,
new BitmapDrawableTranscoder(context.getResources(), bitmapPool));
Expand Down Expand Up @@ -257,13 +253,6 @@ private GenericLoaderFactory getLoaderFactory() {
return loaderFactory;
}

/**
* Returns the {@link RequestQueue} Glide is using to fetch images over http/https.
*/
public RequestQueue getRequestQueue() {
return requestQueue;
}

/**
* Clears as much memory as possible.
*
Expand Down
14 changes: 1 addition & 13 deletions library/src/main/java/com/bumptech/glide/GlideBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.os.Build;
import com.android.volley.RequestQueue;
import com.bumptech.glide.load.engine.Engine;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPoolAdapter;
Expand All @@ -14,13 +13,11 @@
import com.bumptech.glide.load.engine.cache.MemoryCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.load.engine.executor.FifoPriorityThreadPoolExecutor;
import com.bumptech.glide.volley.RequestQueueWrapper;

import java.io.File;
import java.util.concurrent.ExecutorService;

public class GlideBuilder {
private RequestQueue requestQueue;
private Context context;
private Engine engine;
private BitmapPool bitmapPool;
Expand All @@ -33,11 +30,6 @@ public GlideBuilder(Context context) {
this.context = context.getApplicationContext();
}

public GlideBuilder setRequestQueue(RequestQueue requestQueue) {
this.requestQueue = requestQueue;
return this;
}

public GlideBuilder setBitmapPool(BitmapPool bitmapPool) {
this.bitmapPool = bitmapPool;
return this;
Expand Down Expand Up @@ -77,10 +69,6 @@ Glide createGlide() {
diskCacheService = new FifoPriorityThreadPoolExecutor(1);
}

if (requestQueue == null) {
requestQueue = RequestQueueWrapper.getRequestQueue(context);
}

MemorySizeCalculator calculator = new MemorySizeCalculator(context);
if (bitmapPool == null) {
if (Build.VERSION.SDK_INT >= 11) {
Expand Down Expand Up @@ -108,6 +96,6 @@ Glide createGlide() {
engine = new Engine(memoryCache, diskCache, resizeService, diskCacheService);
}

return new Glide(engine, requestQueue, memoryCache, bitmapPool, context);
return new Glide(engine, memoryCache, bitmapPool, context);
}
}
Loading

0 comments on commit 700284e

Please sign in to comment.