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/AbstractCachingPageViewCreator.java32
-rw-r--r--main/src/cgeo/geocaching/ui/CacheDetailsCreator.java11
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java45
-rw-r--r--main/src/cgeo/geocaching/ui/CompassMiniView.java6
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java7
-rw-r--r--main/src/cgeo/geocaching/ui/EditorDialog.java2
-rw-r--r--main/src/cgeo/geocaching/ui/Formatter.java5
-rw-r--r--main/src/cgeo/geocaching/ui/ImagesList.java9
-rw-r--r--main/src/cgeo/geocaching/ui/LoggingUI.java9
-rw-r--r--main/src/cgeo/geocaching/ui/WeakReferenceHandler.java27
10 files changed, 114 insertions, 39 deletions
diff --git a/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java
new file mode 100644
index 0000000..333ef11
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java
@@ -0,0 +1,32 @@
+package cgeo.geocaching.ui;
+
+import cgeo.geocaching.activity.AbstractViewPagerActivity.PageViewCreator;
+
+import android.view.View;
+
+/**
+ * View creator which destroys the created view on every {@link #notifyDataSetChanged()}.
+ *
+ * @param <ViewClass>
+ */
+public abstract class AbstractCachingPageViewCreator<ViewClass extends View> implements PageViewCreator {
+
+ public ViewClass view;
+
+ @Override
+ public final void notifyDataSetChanged() {
+ view = null;
+ }
+
+ @Override
+ public final View getView() {
+ if (view == null) {
+ view = getDispatchedView();
+ }
+
+ return view;
+ }
+
+ @Override
+ public abstract ViewClass getDispatchedView();
+}
diff --git a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
index 2a83ddc..9745d63 100644
--- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
+++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java
@@ -35,7 +35,7 @@ public final class CacheDetailsCreator {
}
public TextView add(final int nameId, final CharSequence value) {
- final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_item, null);
+ final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_layout, null);
final TextView nameView = (TextView) layout.findViewById(R.id.name);
nameView.setText(res.getString(nameId));
lastValueView = (TextView) layout.findViewById(R.id.value);
@@ -56,16 +56,15 @@ public final class CacheDetailsCreator {
nameView.setText(activity.getResources().getString(nameId));
lastValueView.setText(String.format("%.1f", value) + ' ' + activity.getResources().getString(R.string.cache_rating_of) + " 5");
- layoutStars.addView(createStarImages(value), 1);
+ createStarImages(layoutStars, value);
+ layoutStars.setVisibility(View.VISIBLE);
parentView.addView(layout);
return layout;
}
- private LinearLayout createStarImages(final float value) {
+ private void createStarImages(final ViewGroup starsContainer, final float value) {
final LayoutInflater inflater = LayoutInflater.from(activity);
- final LinearLayout starsContainer = new LinearLayout(activity);
- starsContainer.setOrientation(LinearLayout.HORIZONTAL);
for (int i = 0; i < 5; i++) {
ImageView star = (ImageView) inflater.inflate(R.layout.star, null);
@@ -78,8 +77,6 @@ public final class CacheDetailsCreator {
}
starsContainer.addView(star);
}
-
- return starsContainer;
}
public void addCacheState(cgCache cache) {
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 65d3fbc..efc95b8 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -12,6 +12,7 @@ import cgeo.geocaching.filter.IFilter;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.sorting.CacheComparator;
import cgeo.geocaching.sorting.DistanceComparator;
+import cgeo.geocaching.sorting.InverseComparator;
import cgeo.geocaching.sorting.VisitComparator;
import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.Log;
@@ -43,6 +44,7 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -64,6 +66,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
final private Resources res;
/** Resulting list of caches */
final private List<cgCache> list;
+ private boolean inverseSort = false;
private static final int SWIPE_MIN_DISTANCE = 60;
private static final int SWIPE_MAX_OFF_PATH = 100;
@@ -149,6 +152,14 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
* @param comparator
*/
public void setComparator(final CacheComparator comparator) {
+ // selecting the same sorting twice will toggle the order
+ if (cacheComparator != null && comparator != null && cacheComparator.getClass().equals(comparator.getClass())) {
+ inverseSort = !inverseSort;
+ }
+ else {
+ // always reset the inversion for a new sorting criteria
+ inverseSort = false;
+ }
cacheComparator = comparator;
forceSort();
}
@@ -257,7 +268,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
updateSortByDistance();
}
else {
- Collections.sort(list, cacheComparator);
+ Collections.sort(list, getPotentialInversion(cacheComparator));
}
notifyDataSetChanged();
@@ -292,7 +303,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
return;
}
final ArrayList<cgCache> oldList = new ArrayList<cgCache>(list);
- Collections.sort(list, new DistanceComparator(coords, list));
+ Collections.sort(list, getPotentialInversion(new DistanceComparator(coords, list)));
// avoid an update if the list has not changed due to location update
if (list.equals(oldList)) {
@@ -302,6 +313,13 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
lastSort = System.currentTimeMillis();
}
+ private Comparator<? super cgCache> getPotentialInversion(final CacheComparator comparator) {
+ if (inverseSort) {
+ return new InverseComparator(comparator);
+ }
+ return comparator;
+ }
+
private boolean isSortedByDistance() {
return cacheComparator == null || cacheComparator instanceof DistanceComparator;
}
@@ -390,17 +408,24 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
holder.logStatusMark.setVisibility(View.GONE);
}
- if (cache.getNameSp() == null) {
- cache.setNameSp((new Spannable.Factory()).newSpannable(cache.getName()));
- if (cache.isDisabled() || cache.isArchived()) { // strike
- cache.getNameSp().setSpan(new StrikethroughSpan(), 0, cache.getNameSp().toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- if (cache.isArchived()) {
- cache.getNameSp().setSpan(new ForegroundColorSpan(res.getColor(R.color.archived_cache_color)), 0, cache.getNameSp().toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ Spannable spannable = null;
+ if (cache.isDisabled() || cache.isArchived()) { // strike
+ spannable = Spannable.Factory.getInstance().newSpannable(cache.getName());
+ spannable.setSpan(new StrikethroughSpan(), 0, spannable.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ if (cache.isArchived()) { // red color
+ if (spannable == null) {
+ spannable = Spannable.Factory.getInstance().newSpannable(cache.getName());
}
+ spannable.setSpan(new ForegroundColorSpan(res.getColor(R.color.archived_cache_color)), 0, spannable.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
- holder.text.setText(cache.getNameSp(), TextView.BufferType.SPANNABLE);
+ if (spannable != null) {
+ holder.text.setText(spannable, TextView.BufferType.SPANNABLE);
+ }
+ else {
+ holder.text.setText(cache.getName());
+ }
holder.text.setCompoundDrawablesWithIntrinsicBounds(getCacheIcon(cache), null, null, null);
if (cache.getInventoryItems() > 0) {
diff --git a/main/src/cgeo/geocaching/ui/CompassMiniView.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java
index 44fb8e2..da8f69e 100644
--- a/main/src/cgeo/geocaching/ui/CompassMiniView.java
+++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java
@@ -97,17 +97,17 @@ final public class CompassMiniView extends View {
targetCoords = point;
}
- protected void updateAzimuth(float azimuth) {
+ public void updateAzimuth(float azimuth) {
this.azimuth = azimuth;
updateDirection();
}
- protected void updateHeading(float heading) {
+ public void updateHeading(float heading) {
this.heading = heading;
updateDirection();
}
- protected void updateCurrentCoords(final Geopoint currentCoords) {
+ public void updateCurrentCoords(final Geopoint currentCoords) {
if (currentCoords == null || targetCoords == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 048e280..0ef3a43 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -185,16 +185,13 @@ public class CompassView extends View {
int canvasCenterX = (compassRoseWidth / 2) + ((getWidth() - compassRoseWidth) / 2);
int canvasCenterY = (compassRoseHeight / 2) + ((getHeight() - compassRoseHeight) / 2);
- int marginLeftTemp;
- int marginTopTemp;
-
super.onDraw(canvas);
canvas.save();
canvas.setDrawFilter(setfil);
- marginLeftTemp = (getWidth() - compassUnderlayWidth) / 2;
- marginTopTemp = (getHeight() - compassUnderlayHeight) / 2;
+ int marginLeftTemp = (getWidth() - compassUnderlayWidth) / 2;
+ int marginTopTemp = (getHeight() - compassUnderlayHeight) / 2;
canvas.drawBitmap(compassUnderlay, marginLeftTemp, marginTopTemp, null);
diff --git a/main/src/cgeo/geocaching/ui/EditorDialog.java b/main/src/cgeo/geocaching/ui/EditorDialog.java
index 50b3e27..6dcf546 100644
--- a/main/src/cgeo/geocaching/ui/EditorDialog.java
+++ b/main/src/cgeo/geocaching/ui/EditorDialog.java
@@ -53,7 +53,7 @@ public class EditorDialog extends Dialog {
@Override
public void show() {
super.show();
- getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
+ getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
}
diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java
index 53a7276..ea2ecb5 100644
--- a/main/src/cgeo/geocaching/ui/Formatter.java
+++ b/main/src/cgeo/geocaching/ui/Formatter.java
@@ -153,8 +153,9 @@ public abstract class Formatter {
public static String formatWaypointInfo(cgWaypoint waypoint) {
final List<String> infos = new ArrayList<String>(3);
- if (WaypointType.ALL_TYPES_EXCEPT_OWN.contains(waypoint.getWaypointType())) {
- infos.add(waypoint.getWaypointType().getL10n());
+ WaypointType waypointType = waypoint.getWaypointType();
+ if (waypointType != WaypointType.OWN && waypointType != null) {
+ infos.add(waypointType.getL10n());
}
if (cgWaypoint.PREFIX_OWN.equalsIgnoreCase(waypoint.getPrefix())) {
infos.add(cgeoapplication.getInstance().getString(R.string.waypoint_custom));
diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java
index 3d6f95c..8313f2f 100644
--- a/main/src/cgeo/geocaching/ui/ImagesList.java
+++ b/main/src/cgeo/geocaching/ui/ImagesList.java
@@ -53,7 +53,7 @@ public class ImagesList {
private final int titleResId;
private final int loadingResId;
- private ImageType(final int title, final int loading) {
+ ImageType(final int title, final int loading) {
this.titleResId = title;
this.loadingResId = loading;
}
@@ -95,9 +95,8 @@ public class ImagesList {
progressDialog.setMax(count);
progressDialog.show();
- LinearLayout rowView;
for (final cgImage img : images) {
- rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null);
+ LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null);
if (StringUtils.isNotBlank(img.getTitle())) {
((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.getTitle()));
@@ -179,10 +178,6 @@ public class ImagesList {
bitmaps.clear();
}
- public cgImage getImage(int id) {
- return images.get(id);
- }
-
public void onCreateContextMenu(ContextMenu menu, View v) {
final Resources res = activity.getResources();
menu.setHeaderTitle(res.getString(R.string.cache_image));
diff --git a/main/src/cgeo/geocaching/ui/LoggingUI.java b/main/src/cgeo/geocaching/ui/LoggingUI.java
index 0e048c3..eaa25ef 100644
--- a/main/src/cgeo/geocaching/ui/LoggingUI.java
+++ b/main/src/cgeo/geocaching/ui/LoggingUI.java
@@ -4,7 +4,7 @@ import cgeo.geocaching.LogEntry;
import cgeo.geocaching.R;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.cgData;
import cgeo.geocaching.activity.IAbstractActivity;
import cgeo.geocaching.enumerations.LogType;
@@ -52,7 +52,7 @@ public class LoggingUI extends AbstractUIFactory {
private final int stringId;
- private SpecialLogType(final int stringId) {
+ SpecialLogType(final int stringId) {
this.stringId = stringId;
}
@@ -94,7 +94,7 @@ public class LoggingUI extends AbstractUIFactory {
}
private static void showOfflineMenu(final cgCache cache, final Activity activity) {
- final LogEntry currentLog = cgeoapplication.getInstance().loadLogOffline(cache.getGeocode());
+ final LogEntry currentLog = cgData.loadLogOffline(cache.getGeocode());
final LogType currentLogType = currentLog == null ? null : currentLog.type;
final List<LogType> logTypes = cache.getPossibleLogTypes();
@@ -123,7 +123,8 @@ public class LoggingUI extends AbstractUIFactory {
break;
case CLEAR_LOG:
- cgeoapplication.getInstance().clearLogOffline(cache.getGeocode());
+ cgData.clearLogOffline(cache.getGeocode());
+ break;
}
} else {
cache.logOffline(activity, logTypeEntry.logType);
diff --git a/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java b/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java
new file mode 100644
index 0000000..4724466
--- /dev/null
+++ b/main/src/cgeo/geocaching/ui/WeakReferenceHandler.java
@@ -0,0 +1,27 @@
+package cgeo.geocaching.ui;
+
+import android.app.Activity;
+import android.os.Handler;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * Standard handler implementation which uses a weak reference to its activity. This avoids that activities stay in
+ * memory due to references from the handler to the activity (see Android Lint warning "HandlerLeak")
+ *
+ * Create static private subclasses of this handler class in your activity.
+ *
+ * @param <ActivityType>
+ */
+public abstract class WeakReferenceHandler<ActivityType extends Activity> extends Handler {
+
+ private final WeakReference<ActivityType> activityRef;
+
+ protected WeakReferenceHandler(final ActivityType activity) {
+ this.activityRef = new WeakReference<ActivityType>(activity);
+ }
+
+ protected ActivityType getActivity() {
+ return activityRef.get();
+ }
+}