diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
| -rw-r--r-- | main/src/cgeo/geocaching/ui/AbstractCachingPageViewCreator.java | 32 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheDetailsCreator.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CacheListAdapter.java | 47 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CompassMiniView.java | 6 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CompassView.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/EditorDialog.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/Formatter.java | 16 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/ImagesList.java | 27 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/LoggingUI.java | 9 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/WeakReferenceHandler.java | 27 |
10 files changed, 130 insertions, 54 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..d6224a9 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) { @@ -627,7 +652,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { return true; } } catch (Exception e) { - Log.w("CacheListAdapter.FlingGesture.onFling: " + e.toString()); + Log.w("CacheListAdapter.FlingGesture.onFling", e); } return false; 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..4d23952 100644 --- a/main/src/cgeo/geocaching/ui/Formatter.java +++ b/main/src/cgeo/geocaching/ui/Formatter.java @@ -2,7 +2,7 @@ package cgeo.geocaching.ui; import cgeo.geocaching.R; import cgeo.geocaching.cgCache; -import cgeo.geocaching.cgWaypoint; +import cgeo.geocaching.Waypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheListType; import cgeo.geocaching.enumerations.CacheSize; @@ -13,6 +13,7 @@ import org.apache.commons.lang3.StringUtils; import android.content.Context; import android.text.format.DateUtils; +import java.text.DateFormat; import java.util.ArrayList; import java.util.List; @@ -70,8 +71,8 @@ public abstract class Formatter { * @return the formatted string */ public static String formatShortDate(long date) { - return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE - | DateUtils.FORMAT_NUMERIC_DATE); + DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(context); + return dateFormat.format(date); } /** @@ -151,12 +152,13 @@ public abstract class Formatter { return StringUtils.join(infos, Formatter.SEPARATOR); } - public static String formatWaypointInfo(cgWaypoint waypoint) { + public static String formatWaypointInfo(Waypoint 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())) { + if (Waypoint.PREFIX_OWN.equalsIgnoreCase(waypoint.getPrefix())) { infos.add(cgeoapplication.getInstance().getString(R.string.waypoint_custom)); } else { if (StringUtils.isNotBlank(waypoint.getPrefix())) { diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java index 3d6f95c..9464114 100644 --- a/main/src/cgeo/geocaching/ui/ImagesList.java +++ b/main/src/cgeo/geocaching/ui/ImagesList.java @@ -1,14 +1,14 @@ package cgeo.geocaching.ui; +import cgeo.geocaching.Image; import cgeo.geocaching.R; import cgeo.geocaching.StoredList; -import cgeo.geocaching.cgImage; import cgeo.geocaching.files.LocalStorage; import cgeo.geocaching.network.HtmlImage; +import cgeo.geocaching.utils.IOUtils; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; -import org.mapsforge.core.IOUtils; import android.app.Activity; import android.app.ProgressDialog; @@ -43,7 +43,7 @@ public class ImagesList { private static final int MENU_BROWSER = 202; private BitmapDrawable currentDrawable; - private cgImage currentImage; + private Image currentImage; public enum ImageType { LogImages(R.string.cache_log_images_title, R.string.cache_log_images_loading), @@ -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; } @@ -73,7 +73,7 @@ public class ImagesList { /** * map image view id to image */ - private final SparseArray<cgImage> images = new SparseArray<cgImage>(); + private final SparseArray<Image> images = new SparseArray<Image>(); private final String geocode; private LinearLayout imagesView; @@ -83,7 +83,7 @@ public class ImagesList { inflater = activity.getLayoutInflater(); } - public void loadImages(final View parentView, final List<cgImage> images, ImageType imageType, final boolean offline) { + public void loadImages(final View parentView, final List<Image> images, ImageType imageType, final boolean offline) { imagesView = (LinearLayout) parentView.findViewById(R.id.spoiler_list); @@ -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); + for (final Image img : images) { + 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())); @@ -118,10 +117,10 @@ public class ImagesList { private class AsyncImgLoader extends AsyncTask<Void, Void, BitmapDrawable> { final private LinearLayout view; - final private cgImage img; + final private Image img; final boolean offline; - public AsyncImgLoader(final LinearLayout view, final cgImage img, final boolean offline) { + public AsyncImgLoader(final LinearLayout view, final Image img, final boolean offline) { this.view = view; this.img = img; this.offline = offline; @@ -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)); @@ -215,7 +210,7 @@ public class ImagesList { fos = new FileOutputStream(file); image.getBitmap().compress(CompressFormat.JPEG, 100, fos); } catch (Exception e) { - Log.e("ImagesActivity.handleMessage.onClick: " + e.toString()); + Log.e("ImagesActivity.handleMessage.onClick", e); return; } finally { IOUtils.closeQuietly(fos); 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(); + } +} |
