aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Image.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/Image.java')
-rw-r--r--main/src/cgeo/geocaching/Image.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/Image.java b/main/src/cgeo/geocaching/Image.java
index 22c76aa..50ea80e 100644
--- a/main/src/cgeo/geocaching/Image.java
+++ b/main/src/cgeo/geocaching/Image.java
@@ -1,5 +1,7 @@
package cgeo.geocaching;
+import cgeo.geocaching.utils.FileUtils;
+
import org.apache.commons.lang3.StringUtils;
import android.content.Context;
@@ -8,6 +10,8 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
+import java.io.File;
+
public class Image implements Parcelable {
private final String url;
private final String title;
@@ -23,6 +27,10 @@ public class Image implements Parcelable {
this(url, title, null);
}
+ public Image(final File file) {
+ this("file://" + file.getAbsolutePath(), file.getName(), null);
+ }
+
public Image(final Parcel in) {
url = in.readString();
title = in.readString();
@@ -85,4 +93,22 @@ public class Image implements Parcelable {
return "???";
}
+
+ /**
+ * Check if the URL represents a file on the local file system.
+ *
+ * @return <tt>true</tt> if the URL scheme is <tt>file</tt>, <tt>false</tt> otherwise
+ */
+ public boolean isLocalFile() {
+ return FileUtils.isFileUrl(url);
+ }
+
+ /**
+ * Local file name when {@link #isLocalFile()} is <tt>true</tt>.
+ *
+ * @return the local file
+ */
+ public File localFile() {
+ return FileUtils.urlToFile(url);
+ }
}