aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2014-04-06 19:51:52 +0200
committerSamuel Tardieu <sam@rfc1149.net>2014-04-06 19:51:52 +0200
commitfcbfb693f0a2dd166025dd4b5e44cb3ae843ccfc (patch)
treef30166d77849e6198d641436f2fd0267e2c6d0d1 /main/src/cgeo/geocaching/ui
parentff836c41e90deeb735f5b7b9c9e88872b9cb68fe (diff)
downloadcgeo-fcbfb693f0a2dd166025dd4b5e44cb3ae843ccfc.zip
cgeo-fcbfb693f0a2dd166025dd4b5e44cb3ae843ccfc.tar.gz
cgeo-fcbfb693f0a2dd166025dd4b5e44cb3ae843ccfc.tar.bz2
fix #3736: wrong image when opening a spoiler with Photos
The Photos application seems to do some image caching. For most images, we already have an accessible on-disk copy that can be used instead of a unique temporary name.
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r--main/src/cgeo/geocaching/ui/ImagesList.java37
1 files changed, 24 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java
index d3f107a..d1b2a64 100644
--- a/main/src/cgeo/geocaching/ui/ImagesList.java
+++ b/main/src/cgeo/geocaching/ui/ImagesList.java
@@ -30,12 +30,14 @@ import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
+import android.webkit.MimeTypeMap;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Collection;
import java.util.LinkedList;
@@ -140,7 +142,7 @@ public class ImagesList {
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
- viewImageInStandardApp(image);
+ viewImageInStandardApp(img, image);
}
});
activity.registerForContextMenu(imageView);
@@ -180,7 +182,7 @@ public class ImagesList {
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.image_open_file:
- viewImageInStandardApp(currentDrawable);
+ viewImageInStandardApp(currentImage, currentDrawable);
return true;
case R.id.image_open_browser:
if (currentImage != null) {
@@ -192,26 +194,35 @@ public class ImagesList {
}
}
- private void viewImageInStandardApp(final BitmapDrawable image) {
+ private static String mimeTypeForUrl(final String url) {
+ return StringUtils.defaultString(MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url)), "image/*");
+ }
+
+ private static File saveToTemporaryJPGFile(final BitmapDrawable image) throws FileNotFoundException {
final File file = LocalStorage.getStorageFile(null, "temp.jpg", false, true);
BufferedOutputStream stream = null;
try {
stream = new BufferedOutputStream(new FileOutputStream(file));
image.getBitmap().compress(CompressFormat.JPEG, 100, stream);
- } catch (Exception e) {
- Log.e("ImagesList.viewImageInStandardApp", e);
- return;
} finally {
IOUtils.closeQuietly(stream);
}
+ file.deleteOnExit();
+ return file;
+ }
- final Intent intent = new Intent();
- intent.setAction(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.fromFile(file), "image/jpeg");
- activity.startActivity(intent);
-
- if (file.exists()) {
- file.deleteOnExit();
+ private void viewImageInStandardApp(final Image img, final BitmapDrawable image) {
+ try {
+ final Intent intent = new Intent().setAction(android.content.Intent.ACTION_VIEW);
+ final File file = LocalStorage.getStorageFile(geocode, img.getUrl(), true, true);
+ if (file.exists()) {
+ intent.setDataAndType(Uri.fromFile(file), mimeTypeForUrl(img.getUrl()));
+ } else {
+ intent.setDataAndType(Uri.fromFile(saveToTemporaryJPGFile(image)), "image/jpeg");
+ }
+ activity.startActivity(intent);
+ } catch (Exception e) {
+ Log.e("ImagesList.viewImageInStandardApp", e);
}
}