From 56984c893b40b8b692baf3c9ed6b65726c7b4027 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 24 Apr 2014 12:16:07 +0200 Subject: Add local file loading capability This will be used in implementation of #3438. --- main/src/cgeo/geocaching/network/HtmlImage.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'main/src') diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index 8ee2ba7..ae9821b 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -25,10 +25,12 @@ import rx.Scheduler; import rx.Scheduler.Inner; import rx.Subscriber; import rx.functions.Action1; +import rx.functions.Func0; import rx.functions.Func1; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; import rx.subscriptions.CompositeSubscription; +import rx.util.async.Async; import android.content.res.Resources; import android.graphics.Bitmap; @@ -132,6 +134,18 @@ public class HtmlImage implements Html.ImageGetter { return Observable.from(getTransparent1x1Image(resources)); } + // Explicit local file URLs are loaded from the filesystem regardless of their age. The IO part is short + // enough to make the whole operation on the computation scheduler. + if (url.startsWith("file://")) { + return Async.fromCallable(new Func0() { + @Override + public BitmapDrawable call() { + final Bitmap bitmap = loadCachedImage(new File(url.substring(7)), true).getLeft(); + return bitmap != null ? ImageUtils.scaleBitmapToFitDisplay(bitmap) : null; + } + }, RxUtils.computationScheduler); + } + final boolean shared = url.contains("/images/icons/icon_"); final String pseudoGeocode = shared ? SHARED : geocode; -- cgit v1.1