aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java49
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java11
-rw-r--r--main/src/cgeo/geocaching/ui/ImagesList.java52
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java18
4 files changed, 63 insertions, 67 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index ca4e825..d827e3e 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -379,6 +379,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
final TouchListener touchListener = new TouchListener(cache, v);
v.setOnClickListener(touchListener);
+ v.setOnLongClickListener(touchListener);
v.setOnTouchListener(touchListener);
holder.checkbox.setVisibility(selectMode ? View.VISIBLE : View.GONE);
@@ -535,62 +536,48 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> {
}
}
- private class TouchListener implements View.OnClickListener, View.OnTouchListener {
+ private class TouchListener implements View.OnClickListener, View.OnLongClickListener, View.OnTouchListener {
- private boolean touch = true;
- private final GestureDetector gestureDetector;
private final Geocache cache;
+ private final GestureDetector gestureDetector;
public TouchListener(final Geocache cache, final View view) {
this.cache = cache;
- final FlingGesture dGesture = new FlingGesture(cache, view);
- gestureDetector = new GestureDetector(getContext(), dGesture);
+ gestureDetector = new GestureDetector(getContext(), new FlingGesture(cache));
}
- // tap on item
+ // Tap on item
@Override
- public void onClick(View view) {
- if (!touch) {
- touch = true;
- return;
- }
-
+ public void onClick(final View view) {
if (isSelectMode()) {
cache.setStatusChecked(!cache.isStatusChecked());
notifyDataSetChanged();
- return;
+ } else {
+ CacheDetailActivity.startActivity(getContext(), cache.getGeocode(), cache.getName());
}
+ }
- // load cache details
- CacheDetailActivity.startActivity(getContext(), cache.getGeocode(), cache.getName());
+ // Long tap on item
+ @Override
+ public boolean onLongClick(final View view) {
+ view.showContextMenu();
+ return true;
}
- // swipe on item
+ // Swipe on item
@Override
- public boolean onTouch(View view, MotionEvent event) {
- if (gestureDetector.onTouchEvent(event)) {
- touch = false;
- return true;
- }
+ public boolean onTouch(final View view, final MotionEvent event) {
+ return gestureDetector.onTouchEvent(event);
- return false;
}
}
private class FlingGesture extends GestureDetector.SimpleOnGestureListener {
private final Geocache cache;
- private final View view;
- public FlingGesture(final Geocache cache, final View view) {
+ public FlingGesture(final Geocache cache) {
this.cache = cache;
- this.view = view;
- }
-
- // long tap on item
- @Override
- public void onLongPress(MotionEvent e) {
- view.showContextMenu();
}
@Override
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index eaaf711..f7111f7 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -16,7 +16,6 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.util.AttributeSet;
-import android.util.FloatMath;
import android.view.View;
import java.util.concurrent.TimeUnit;
@@ -158,19 +157,19 @@ public class CompassView extends View {
* @return the new value
*/
static protected float smoothUpdate(float goal, float actual) {
- final float diff = AngleUtils.difference(actual, goal);
+ final double diff = AngleUtils.difference(actual, goal);
- float offset = 0;
+ double offset = 0;
// If the difference is smaller than 1 degree, do nothing as it
// causes the arrow to vibrate. Round away from 0.
if (diff > 1.0) {
- offset = FloatMath.ceil(diff / 10.0f); // for larger angles, rotate faster
+ offset = Math.ceil(diff / 10.0); // for larger angles, rotate faster
} else if (diff < 1.0) {
- offset = FloatMath.floor(diff / 10.0f);
+ offset = Math.floor(diff / 10.0);
}
- return AngleUtils.normalize(actual + offset);
+ return AngleUtils.normalize((float) (actual + offset));
}
@Override
diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java
index 31a61b5..d1b2a64 100644
--- a/main/src/cgeo/geocaching/ui/ImagesList.java
+++ b/main/src/cgeo/geocaching/ui/ImagesList.java
@@ -6,11 +6,11 @@ import cgeo.geocaching.files.LocalStorage;
import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.RxUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import rx.Subscription;
-import rx.android.observables.AndroidObservable;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.subscriptions.CompositeSubscription;
@@ -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;
@@ -116,13 +118,12 @@ public class ImagesList {
final ImageView imageView = (ImageView) inflater.inflate(R.layout.image_item, null);
assert(imageView != null);
- subscriptions.add(AndroidObservable.bindActivity(activity, imgGetter.fetchDrawable(img.getUrl()))
- .subscribe(new Action1<BitmapDrawable>() {
- @Override
- public void call(final BitmapDrawable image) {
- display(imageView, image, img, rowView);
- }
- }));
+ subscriptions.add(RxUtils.subscribeThenUI(imgGetter.fetchDrawable(img.getUrl()), new Action1<BitmapDrawable>() {
+ @Override
+ public void call(final BitmapDrawable image) {
+ display(imageView, image, img, rowView);
+ }
+ }));
rowView.addView(imageView);
imagesView.addView(rowView);
}
@@ -141,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);
@@ -181,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) {
@@ -193,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);
}
}
diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
index c150434..cb52319 100644
--- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
@@ -5,11 +5,11 @@ import cgeo.geocaching.sensors.IGeoData;
import cgeo.geocaching.R;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.ActivityMixin;
-import cgeo.geocaching.compatibility.Compatibility;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.settings.Settings.CoordInputFormatEnum;
+import cgeo.geocaching.utils.EditUtils;
import org.apache.commons.lang3.StringUtils;
@@ -103,14 +103,14 @@ public class CoordinatesInputDialog extends NoTitleDialog {
eLonSec.addTextChangedListener(new TextChanged(eLonSec));
eLonSub.addTextChangedListener(new TextChanged(eLonSub));
- Compatibility.disableSuggestions(eLatDeg);
- Compatibility.disableSuggestions(eLatMin);
- Compatibility.disableSuggestions(eLatSec);
- Compatibility.disableSuggestions(eLatSub);
- Compatibility.disableSuggestions(eLonDeg);
- Compatibility.disableSuggestions(eLonMin);
- Compatibility.disableSuggestions(eLonSec);
- Compatibility.disableSuggestions(eLonSub);
+ EditUtils.disableSuggestions(eLatDeg);
+ EditUtils.disableSuggestions(eLatMin);
+ EditUtils.disableSuggestions(eLatSec);
+ EditUtils.disableSuggestions(eLatSub);
+ EditUtils.disableSuggestions(eLonDeg);
+ EditUtils.disableSuggestions(eLonMin);
+ EditUtils.disableSuggestions(eLonSec);
+ EditUtils.disableSuggestions(eLonSub);
bLat.setOnClickListener(new ButtonClickListener());
bLon.setOnClickListener(new ButtonClickListener());