Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tad Fisher
committed
May 17, 2013
1 parent
bb0e6ef
commit 776d03a
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
UrlImageViewHelper/src/com/koushikdutta/urlimageviewhelper/AssetUrlDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
package com.koushikdutta.urlimageviewhelper; | ||
|
||
import java.io.InputStream; | ||
|
||
import android.content.Context; | ||
import android.os.AsyncTask; | ||
|
||
public class AssetUrlDownloader implements UrlDownloader { | ||
@Override | ||
public void download(final Context context, final String url, final String filename, | ||
final UrlDownloaderCallback callback, final Runnable completion) { | ||
final AsyncTask<Void, Void, Void> downloader = new AsyncTask<Void, Void, Void>() { | ||
@Override | ||
protected Void doInBackground(final Void... params) { | ||
try { | ||
String relativePath = url.replaceFirst("file:///android_asset/", ""); | ||
InputStream is = context.getAssets().open(relativePath); | ||
callback.onDownloadComplete(AssetUrlDownloader.this, is, null); | ||
return null; | ||
} | ||
catch (final Throwable e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(final Void result) { | ||
completion.run(); | ||
} | ||
}; | ||
|
||
UrlImageViewHelper.executeTask(downloader); | ||
} | ||
|
||
@Override | ||
public boolean allowCache() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canDownloadUrl(String url) { | ||
return url.startsWith("file:///android_asset/"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters