Permalink
Browse files

Merge branch 'handle307' into develop

  • Loading branch information...
2 parents e0d1ae6 + ab3e09d commit 6b5d6f917ee2d0a0a8f4cb6fc19fc25288d18945 @friedger friedger committed Sep 24, 2012
Showing with 28 additions and 21 deletions.
  1. +7 −14 README.textile
  2. +21 −7 core/src/main/java/com/novoda/imageloader/core/network/UrlNetworkManager.java
View
@@ -3,11 +3,11 @@
h1. ImageLoader
ImageLoader is a simple library that makes it easy to download, display and cache remote images in Android apps.
-Download happens away from the UI thread and the images are cached with a two-level in-memory/SD card cache.
+Image download happens off the UI thread and the images are cached with a two-level in-memory/SD card cache.
h2. Recent changes
-h3. 1.5.6-SNAPSHOT
+h3. 1.5.6
* Removed necessity to set a service in the manifest for the clean up. Everything is done in the BasicFileManager with a background thread.
@@ -109,13 +109,13 @@ h3. Cleaning the SD card cache
If you want ImageLoader to clean up the SD card cache, add the following code in the onCreate of the Application class:
-<pre><code>imageManager.getFileManager().clean(this);</code></pre>
+<pre><code>imageManager.getFileManager().clean();</code></pre>
In the settings builder you can configure the expiration period (it's set to 7 days by default).
h3. In the AndroidManifest.xml
-There are two things you need to add: Permissions and the Service to clean up the SD cache.
+There are two things you need to add: Permissions and the Service to clean up the SD cache. (Since 1.5.6 the cleanup service is no longer required!)
<pre><code><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
@@ -169,22 +169,15 @@ h3. Using Maven
If you are using Maven you can define the repo and dependency in your POM:
-<pre><code><repositories>
- <repository>
- <id>public-mvn-repo-releases</id>
- <url>https://github.com/novoda/public-mvn-repo/raw/master/releases</url>
- </repository>
-</repositories></code></pre>
-
<pre><code><dependency>
<groupId>com.novoda.imageloader</groupId>
<artifactId>imageloader-core</artifactId>
- <version>1.5.5</version>
+ <version>1.5.6</version>
</dependency></code></pre>
h3. As a .jar
-You can also simply include the "latest version":https://github.com/novoda/public-mvn-repo/raw/master/releases/com/novoda/imageloader/imageloader-core/1.5.5/imageloader-core-1.5.5.jar of the .jar file (v 1.5.5) in you project.
+You can also simply include the "latest version":http://search.maven.org/remotecontent?filepath=com/novoda/imageloader/imageloader-core/1.5.6/imageloader-core-1.5.6.jar of the .jar file (v 1.5.6) in you project.
h2. Helping out
@@ -212,7 +205,7 @@ Note : By default we run instrumentation tests, if you don't attach a device the
h3. Eclipse
-An easy way to set up the project for eclipse is like so:
+Here are some simple steps to set up the project in Eclipse:
* Run <code>mvn clean install -Peclipse</code>. This command copies the dependencies to libs for working in Eclipse. The demo and acceptance projects should be configured as Android projects.
* Import the core project as a Maven project
@@ -30,17 +30,20 @@
import com.novoda.imageloader.core.file.util.FileUtil;
/**
- * Basic implementation of the NetworkManager using URL connection.
+ * Basic implementation of the NetworkManager using URL connection.
*/
public class UrlNetworkManager implements NetworkManager {
+ private static final int TEMP_REDIRECT = 307;
+
private FileUtil fileUtil;
private LoaderSettings settings;
+ private int manualRedirects;
public UrlNetworkManager(LoaderSettings settings) {
this(settings, new FileUtil());
}
-
+
public UrlNetworkManager(LoaderSettings settings, FileUtil fileUtil) {
this.settings = settings;
this.fileUtil = fileUtil;
@@ -56,9 +59,13 @@ public void retrieveImage(String url, File f) {
conn = openConnection(url);
conn.setConnectTimeout(settings.getConnectionTimeout());
conn.setReadTimeout(settings.getReadTimeout());
- is = conn.getInputStream();
- os = new FileOutputStream(f);
- fileUtil.copyStream(is, os);
+ if (conn.getResponseCode() == TEMP_REDIRECT) {
+ redirectManually(f, conn);
+ } else {
+ is = conn.getInputStream();
+ os = new FileOutputStream(f);
+ fileUtil.copyStream(is, os);
+ }
} catch (FileNotFoundException fnfe) {
throw new ImageNotFoundException();
} catch (Throwable ex) {
@@ -72,6 +79,14 @@ public void retrieveImage(String url, File f) {
}
}
+ public void redirectManually(File f, HttpURLConnection conn) {
+ if (manualRedirects++ < 3) {
+ retrieveImage(conn.getHeaderField("Location"), f);
+ } else {
+ manualRedirects = 0;
+ }
+ }
+
@Override
public InputStream retrieveInputStream(String url) {
HttpURLConnection conn = null;
@@ -83,11 +98,10 @@ public InputStream retrieveInputStream(String url) {
} catch (FileNotFoundException fnfe) {
throw new ImageNotFoundException();
} catch (Throwable ex) {
- //
return null;
}
}
-
+
protected HttpURLConnection openConnection(String url) throws IOException, MalformedURLException {
return (HttpURLConnection) new URL(url).openConnection();
}

0 comments on commit 6b5d6f9

Please sign in to comment.