diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
16 files changed, 715 insertions, 108 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..e98bd77 100644 --- a/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java +++ b/main/src/cgeo/geocaching/ui/CacheDetailsCreator.java @@ -1,7 +1,7 @@ package cgeo.geocaching.ui; +import cgeo.geocaching.Geocache; import cgeo.geocaching.R; -import cgeo.geocaching.cgCache; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Units; @@ -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_information_item, null); final TextView nameView = (TextView) layout.findViewById(R.id.name); nameView.setText(res.getString(nameId)); lastValueView = (TextView) layout.findViewById(R.id.value); @@ -49,23 +49,22 @@ public final class CacheDetailsCreator { } public RelativeLayout addStars(final int nameId, final float value) { - final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_layout, null); + final RelativeLayout layout = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.cache_information_item, null); final TextView nameView = (TextView) layout.findViewById(R.id.name); lastValueView = (TextView) layout.findViewById(R.id.value); final LinearLayout layoutStars = (LinearLayout) layout.findViewById(R.id.stars); 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,11 +77,9 @@ public final class CacheDetailsCreator { } starsContainer.addView(star); } - - return starsContainer; } - public void addCacheState(cgCache cache) { + public void addCacheState(Geocache cache) { if (cache.isLogOffline() || cache.isArchived() || cache.isDisabled() || cache.isPremiumMembersOnly() || cache.isFound()) { final List<String> states = new ArrayList<String>(5); if (cache.isLogOffline()) { @@ -104,7 +101,7 @@ public final class CacheDetailsCreator { } } - public void addRating(cgCache cache) { + public void addRating(Geocache cache) { if (cache.getRating() > 0) { final RelativeLayout itemLayout = addStars(R.string.cache_rating, cache.getRating()); if (cache.getVotes() > 0) { @@ -115,25 +112,25 @@ public final class CacheDetailsCreator { } } - public void addSize(cgCache cache) { + public void addSize(Geocache cache) { if (null != cache.getSize() && cache.showSize()) { add(R.string.cache_size, cache.getSize().getL10n()); } } - public void addDifficulty(cgCache cache) { + public void addDifficulty(Geocache cache) { if (cache.getDifficulty() > 0) { addStars(R.string.cache_difficulty, cache.getDifficulty()); } } - public void addTerrain(cgCache cache) { + public void addTerrain(Geocache cache) { if (cache.getTerrain() > 0) { addStars(R.string.cache_terrain, cache.getTerrain()); } } - public void addDistance(final cgCache cache, final TextView cacheDistanceView) { + public void addDistance(final Geocache cache, final TextView cacheDistanceView) { Float distance = null; if (cache.getCoords() != null) { final Geopoint currentCoords = cgeoapplication.getInstance().currentGeo().getCoords(); diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index 65d3fbc..41e27a6 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -1,10 +1,10 @@ package cgeo.geocaching.ui; import cgeo.geocaching.CacheDetailActivity; +import cgeo.geocaching.Geocache; import cgeo.geocaching.IGeoData; import cgeo.geocaching.R; import cgeo.geocaching.Settings; -import cgeo.geocaching.cgCache; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheListType; import cgeo.geocaching.enumerations.CacheType; @@ -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,11 +44,12 @@ 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; -public class CacheListAdapter extends ArrayAdapter<cgCache> { +public class CacheListAdapter extends ArrayAdapter<Geocache> { private LayoutInflater inflater = null; private CacheComparator cacheComparator = null; @@ -56,14 +58,15 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private long lastSort = 0L; private boolean selectMode = false; private IFilter currentFilter = null; - private List<cgCache> originalList = null; + private List<Geocache> originalList = null; final private Set<CompassMiniView> compasses = new LinkedHashSet<CompassMiniView>(); final private Set<DistanceView> distances = new LinkedHashSet<DistanceView>(); final private CacheListType cacheListType; final private Resources res; /** Resulting list of caches */ - final private List<cgCache> list; + final private List<Geocache> list; + private boolean inverseSort = false; private static final int SWIPE_MIN_DISTANCE = 60; private static final int SWIPE_MAX_OFF_PATH = 100; @@ -104,7 +107,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { ImageView dirImg; } - public CacheListAdapter(final Activity activity, final List<cgCache> list, CacheListType cacheListType) { + public CacheListAdapter(final Activity activity, final List<Geocache> list, CacheListType cacheListType) { super(activity, 0, list); final IGeoData currentGeo = cgeoapplication.getInstance().currentGeo(); if (currentGeo != null) { @@ -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(); } @@ -157,7 +168,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { return cacheComparator; } - public cgCache findCacheByGeocode(String geocode) { + public Geocache findCacheByGeocode(String geocode) { for (int i = 0; i < getCount(); i++) { if (getItem(i).getGeocode().equalsIgnoreCase(geocode)) { return getItem(i); @@ -172,7 +183,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { public void reFilter() { if (currentFilter != null) { // Back up the list again - originalList = new ArrayList<cgCache>(list); + originalList = new ArrayList<Geocache>(list); currentFilter.filter(list); } @@ -184,7 +195,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { public void setFilter(final IFilter filter) { // Backup current caches list if it isn't backed up yet if (originalList == null) { - originalList = new ArrayList<cgCache>(list); + originalList = new ArrayList<Geocache>(list); } // If there is already a filter in place, this is a request to change or clear the filter, so we have to @@ -213,7 +224,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { public int getCheckedCount() { int checked = 0; - for (cgCache cache : list) { + for (Geocache cache : list) { if (cache.isStatusChecked()) { checked++; } @@ -225,7 +236,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { this.selectMode = selectMode; if (!selectMode) { - for (final cgCache cache : list) { + for (final Geocache cache : list) { cache.setStatusChecked(false); } } @@ -241,7 +252,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { } public void invertSelection() { - for (cgCache cache : list) { + for (Geocache cache : list) { cache.setStatusChecked(!cache.isStatusChecked()); } notifyDataSetChanged(); @@ -257,7 +268,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { updateSortByDistance(); } else { - Collections.sort(list, cacheComparator); + Collections.sort(list, getPotentialInversion(cacheComparator)); } notifyDataSetChanged(); @@ -291,8 +302,8 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { if (coords == null) { return; } - final ArrayList<cgCache> oldList = new ArrayList<cgCache>(list); - Collections.sort(list, new DistanceComparator(coords, list)); + final ArrayList<Geocache> oldList = new ArrayList<Geocache>(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 Geocache> getPotentialInversion(final CacheComparator comparator) { + if (inverseSort) { + return new InverseComparator(comparator); + } + return comparator; + } + private boolean isSortedByDistance() { return cacheComparator == null || cacheComparator instanceof DistanceComparator; } @@ -328,7 +346,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { return null; } - final cgCache cache = getItem(position); + final Geocache cache = getItem(position); View v = rowView; @@ -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) { @@ -508,7 +533,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { return v; } - private static Drawable getCacheIcon(cgCache cache) { + private static Drawable getCacheIcon(Geocache cache) { int hashCode = getIconHashCode(cache.getType(), cache.hasUserModifiedCoords() || cache.hasFinalDefined()); final Drawable drawable = gcIconDrawables.get(hashCode); if (drawable != null) { @@ -529,9 +554,9 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private static class SelectionCheckBoxListener implements View.OnClickListener { - private final cgCache cache; + private final Geocache cache; - public SelectionCheckBoxListener(cgCache cache) { + public SelectionCheckBoxListener(Geocache cache) { this.cache = cache; } @@ -546,9 +571,9 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private boolean touch = true; private final GestureDetector gestureDetector; - private final cgCache cache; + private final Geocache cache; - public TouchListener(final cgCache cache) { + public TouchListener(final Geocache cache) { this.cache = cache; final FlingGesture dGesture = new FlingGesture(cache); gestureDetector = new GestureDetector(getContext(), dGesture); @@ -597,9 +622,9 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private class FlingGesture extends GestureDetector.SimpleOnGestureListener { - private final cgCache cache; + private final Geocache cache; - public FlingGesture(cgCache cache) { + public FlingGesture(Geocache cache) { this.cache = cache; } @@ -627,20 +652,20 @@ 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; } } - public List<cgCache> getFilteredList() { + public List<Geocache> getFilteredList() { return list; } - public List<cgCache> getCheckedCaches() { - final ArrayList<cgCache> result = new ArrayList<cgCache>(); - for (cgCache cache : list) { + public List<Geocache> getCheckedCaches() { + final ArrayList<Geocache> result = new ArrayList<Geocache>(); + for (Geocache cache : list) { if (cache.isStatusChecked()) { result.add(cache); } @@ -648,12 +673,12 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { return result; } - public List<cgCache> getCheckedOrAllCaches() { - final List<cgCache> result = getCheckedCaches(); + public List<Geocache> getCheckedOrAllCaches() { + final List<Geocache> result = getCheckedCaches(); if (!result.isEmpty()) { return result; } - return new ArrayList<cgCache>(list); + return new ArrayList<Geocache>(list); } public int getCheckedOrAllCount() { 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/FileSelectionListAdapter.java b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java index 1b5d47f..1db3f21 100644 --- a/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java +++ b/main/src/cgeo/geocaching/ui/FileSelectionListAdapter.java @@ -61,7 +61,7 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> { holder.filename.setTypeface(holder.filename.getTypeface(), Typeface.NORMAL); } - final touchListener touchLst = new touchListener(file); + final TouchListener touchLst = new TouchListener(file); v.setOnClickListener(touchLst); holder.filepath.setText(file.getParent()); @@ -70,10 +70,10 @@ public class FileSelectionListAdapter extends ArrayAdapter<File> { return v; } - private class touchListener implements View.OnClickListener { + private class TouchListener implements View.OnClickListener { private File file = null; - public touchListener(File fileIn) { + public TouchListener(File fileIn) { file = fileIn; } diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java index 53a7276..412b993 100644 --- a/main/src/cgeo/geocaching/ui/Formatter.java +++ b/main/src/cgeo/geocaching/ui/Formatter.java @@ -1,8 +1,8 @@ package cgeo.geocaching.ui; +import cgeo.geocaching.Geocache; 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); } /** @@ -108,7 +109,7 @@ public abstract class Formatter { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL); } - public static String formatCacheInfoLong(cgCache cache, CacheListType cacheListType) { + public static String formatCacheInfoLong(Geocache cache, CacheListType cacheListType) { final ArrayList<String> infos = new ArrayList<String>(); if (StringUtils.isNotBlank(cache.getGeocode())) { infos.add(cache.getGeocode()); @@ -125,7 +126,7 @@ public abstract class Formatter { return StringUtils.join(infos, Formatter.SEPARATOR); } - public static String formatCacheInfoShort(cgCache cache) { + public static String formatCacheInfoShort(Geocache cache) { final ArrayList<String> infos = new ArrayList<String>(); if (cache.hasDifficulty()) { infos.add("D " + String.format("%.1f", cache.getDifficulty())); @@ -143,7 +144,7 @@ public abstract class Formatter { return StringUtils.join(infos, Formatter.SEPARATOR); } - public static String formatCacheInfoHistory(cgCache cache) { + public static String formatCacheInfoHistory(Geocache cache) { final ArrayList<String> infos = new ArrayList<String>(3); infos.add(StringUtils.upperCase(cache.getGeocode())); infos.add(Formatter.formatDate(cache.getVisitedDate())); @@ -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/GPXListAdapter.java b/main/src/cgeo/geocaching/ui/GPXListAdapter.java index 45e1f52..9f6c14c 100644 --- a/main/src/cgeo/geocaching/ui/GPXListAdapter.java +++ b/main/src/cgeo/geocaching/ui/GPXListAdapter.java @@ -1,7 +1,7 @@ package cgeo.geocaching.ui; import cgeo.geocaching.R; -import cgeo.geocaching.cgeogpxes; +import cgeo.geocaching.GpxFileListActivity; import cgeo.geocaching.files.GPXImporter; import cgeo.geocaching.utils.Log; @@ -18,7 +18,7 @@ import java.io.File; import java.util.List; public class GPXListAdapter extends ArrayAdapter<File> { - private cgeogpxes activity = null; + private GpxFileListActivity activity = null; private LayoutInflater inflater = null; private static class ViewHolder { @@ -26,7 +26,7 @@ public class GPXListAdapter extends ArrayAdapter<File> { TextView filename; } - public GPXListAdapter(cgeogpxes parentIn, List<File> listIn) { + public GPXListAdapter(GpxFileListActivity parentIn, List<File> listIn) { super(parentIn, 0, listIn); activity = parentIn; 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..2615947 100644 --- a/main/src/cgeo/geocaching/ui/LoggingUI.java +++ b/main/src/cgeo/geocaching/ui/LoggingUI.java @@ -1,10 +1,10 @@ package cgeo.geocaching.ui; +import cgeo.geocaching.Geocache; 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; } @@ -65,7 +65,7 @@ public class LoggingUI extends AbstractUIFactory { private static final int MENU_LOG_VISIT = 100; private static final int MENU_LOG_VISIT_OFFLINE = 101; - public static void addMenuItems(final Menu menu, final cgCache cache) { + public static void addMenuItems(final Menu menu, final Geocache cache) { if (cache == null) { return; } @@ -80,7 +80,7 @@ public class LoggingUI extends AbstractUIFactory { } } - public static boolean onMenuItemSelected(final MenuItem item, IAbstractActivity activity, cgCache cache) { + public static boolean onMenuItemSelected(final MenuItem item, IAbstractActivity activity, Geocache cache) { switch (item.getItemId()) { case MENU_LOG_VISIT: cache.logVisit(activity); @@ -93,8 +93,8 @@ public class LoggingUI extends AbstractUIFactory { } } - private static void showOfflineMenu(final cgCache cache, final Activity activity) { - final LogEntry currentLog = cgeoapplication.getInstance().loadLogOffline(cache.getGeocode()); + private static void showOfflineMenu(final Geocache cache, final Activity activity) { + 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(); + } +} diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java new file mode 100644 index 0000000..dada8fd --- /dev/null +++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java @@ -0,0 +1,484 @@ +package cgeo.geocaching.ui.dialog; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.IGeoData; +import cgeo.geocaching.R; +import cgeo.geocaching.Settings; +import cgeo.geocaching.Settings.coordInputFormatEnum; +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 org.apache.commons.lang3.StringUtils; + +import android.app.Dialog; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.view.ViewGroup.LayoutParams; +import android.view.Window; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; + +public class CoordinatesInputDialog extends Dialog { + + final private AbstractActivity context; + final private IGeoData geo; + final private Geocache cache; + private Geopoint gp; + + private EditText eLat, eLon; + private Button bLat, bLon; + private EditText eLatDeg, eLatMin, eLatSec, eLatSub; + private EditText eLonDeg, eLonMin, eLonSec, eLonSub; + private TextView tLatSep1, tLatSep2, tLatSep3; + private TextView tLonSep1, tLonSep2, tLonSep3; + + private CoordinateUpdate cuListener; + + private coordInputFormatEnum currentFormat = null; + + public CoordinatesInputDialog(final AbstractActivity context, final Geocache cache, final Geopoint gp, final IGeoData geo) { + super(context, ActivityMixin.getTheme()); + this.context = context; + this.geo = geo; + this.cache = cache; + + if (gp != null) { + this.gp = gp; + } else if (geo != null && geo.getCoords() != null) { + this.gp = geo.getCoords(); + } else { + this.gp = new Geopoint(0.0, 0.0); + } + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + try { + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + } catch (Exception e) { + // nothing + } + + setContentView(R.layout.coords); + + findViewById(R.id.actionBarManualbutton).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + ActivityMixin.goManual(context, "c:geo-geocoordinate-input"); + } + }); + + final Spinner spinner = (Spinner) findViewById(R.id.spinnerCoordinateFormats); + final ArrayAdapter<CharSequence> adapter = + ArrayAdapter.createFromResource(context, + R.array.waypoint_coordinate_formats, + android.R.layout.simple_spinner_item); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + spinner.setSelection(Settings.getCoordInputFormat().ordinal()); + spinner.setOnItemSelectedListener(new CoordinateFormatListener()); + + bLat = (Button) findViewById(R.id.ButtonLat); + eLat = (EditText) findViewById(R.id.latitude); + eLatDeg = (EditText) findViewById(R.id.EditTextLatDeg); + eLatMin = (EditText) findViewById(R.id.EditTextLatMin); + eLatSec = (EditText) findViewById(R.id.EditTextLatSec); + eLatSub = (EditText) findViewById(R.id.EditTextLatSecFrac); + tLatSep1 = (TextView) findViewById(R.id.LatSeparator1); + tLatSep2 = (TextView) findViewById(R.id.LatSeparator2); + tLatSep3 = (TextView) findViewById(R.id.LatSeparator3); + + bLon = (Button) findViewById(R.id.ButtonLon); + eLon = (EditText) findViewById(R.id.longitude); + eLonDeg = (EditText) findViewById(R.id.EditTextLonDeg); + eLonMin = (EditText) findViewById(R.id.EditTextLonMin); + eLonSec = (EditText) findViewById(R.id.EditTextLonSec); + eLonSub = (EditText) findViewById(R.id.EditTextLonSecFrac); + tLonSep1 = (TextView) findViewById(R.id.LonSeparator1); + tLonSep2 = (TextView) findViewById(R.id.LonSeparator2); + tLonSep3 = (TextView) findViewById(R.id.LonSeparator3); + + eLatDeg.addTextChangedListener(new TextChanged(eLatDeg)); + eLatMin.addTextChangedListener(new TextChanged(eLatMin)); + eLatSec.addTextChangedListener(new TextChanged(eLatSec)); + eLatSub.addTextChangedListener(new TextChanged(eLatSub)); + eLonDeg.addTextChangedListener(new TextChanged(eLonDeg)); + eLonMin.addTextChangedListener(new TextChanged(eLonMin)); + 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); + + bLat.setOnClickListener(new ButtonClickListener()); + bLon.setOnClickListener(new ButtonClickListener()); + + final Button buttonCurrent = (Button) findViewById(R.id.current); + buttonCurrent.setOnClickListener(new CurrentListener()); + final Button buttonCache = (Button) findViewById(R.id.cache); + if (cache != null) { + buttonCache.setOnClickListener(new CacheListener()); + } else { + buttonCache.setVisibility(View.GONE); + } + final Button buttonDone = (Button) findViewById(R.id.done); + buttonDone.setOnClickListener(new InputDoneListener()); + } + + private void updateGUI() { + if (gp == null) { + return; + } + + bLat.setText(String.valueOf(gp.getLatDir())); + bLon.setText(String.valueOf(gp.getLonDir())); + + switch (currentFormat) { + case Plain: + findViewById(R.id.coordTable).setVisibility(View.GONE); + eLat.setVisibility(View.VISIBLE); + eLon.setVisibility(View.VISIBLE); + eLat.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); + eLon.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); + break; + case Deg: // DDD.DDDDD° + findViewById(R.id.coordTable).setVisibility(View.VISIBLE); + eLat.setVisibility(View.GONE); + eLon.setVisibility(View.GONE); + eLatSec.setVisibility(View.GONE); + eLonSec.setVisibility(View.GONE); + tLatSep3.setVisibility(View.GONE); + tLonSep3.setVisibility(View.GONE); + eLatSub.setVisibility(View.GONE); + eLonSub.setVisibility(View.GONE); + + tLatSep1.setText("."); + tLonSep1.setText("."); + tLatSep2.setText("°"); + tLonSep2.setText("°"); + + eLatDeg.setText(addZeros(gp.getLatDeg(), 2)); + eLatMin.setText(addZeros(gp.getLatDegFrac(), 5)); + eLonDeg.setText(addZeros(gp.getLonDeg(), 3)); + eLonMin.setText(addZeros(gp.getLonDegFrac(), 5)); + break; + case Min: // DDD° MM.MMM + findViewById(R.id.coordTable).setVisibility(View.VISIBLE); + eLat.setVisibility(View.GONE); + eLon.setVisibility(View.GONE); + eLatSec.setVisibility(View.VISIBLE); + eLonSec.setVisibility(View.VISIBLE); + tLatSep3.setVisibility(View.VISIBLE); + tLonSep3.setVisibility(View.VISIBLE); + eLatSub.setVisibility(View.GONE); + eLonSub.setVisibility(View.GONE); + + tLatSep1.setText("°"); + tLonSep1.setText("°"); + tLatSep2.setText("."); + tLonSep2.setText("."); + tLatSep3.setText("'"); + tLonSep3.setText("'"); + + eLatDeg.setText(addZeros(gp.getLatDeg(), 2)); + eLatMin.setText(addZeros(gp.getLatMin(), 2)); + eLatSec.setText(addZeros(gp.getLatMinFrac(), 3)); + eLonDeg.setText(addZeros(gp.getLonDeg(), 3)); + eLonMin.setText(addZeros(gp.getLonMin(), 2)); + eLonSec.setText(addZeros(gp.getLonMinFrac(), 3)); + break; + case Sec: // DDD° MM SS.SSS + findViewById(R.id.coordTable).setVisibility(View.VISIBLE); + eLat.setVisibility(View.GONE); + eLon.setVisibility(View.GONE); + eLatSec.setVisibility(View.VISIBLE); + eLonSec.setVisibility(View.VISIBLE); + tLatSep3.setVisibility(View.VISIBLE); + tLonSep3.setVisibility(View.VISIBLE); + eLatSub.setVisibility(View.VISIBLE); + eLonSub.setVisibility(View.VISIBLE); + + tLatSep1.setText("°"); + tLonSep1.setText("°"); + tLatSep2.setText("'"); + tLonSep2.setText("'"); + tLatSep3.setText("."); + tLonSep3.setText("."); + + eLatDeg.setText(addZeros(gp.getLatDeg(), 2)); + eLatMin.setText(addZeros(gp.getLatMin(), 2)); + eLatSec.setText(addZeros(gp.getLatSec(), 2)); + eLatSub.setText(addZeros(gp.getLatSecFrac(), 3)); + eLonDeg.setText(addZeros(gp.getLonDeg(), 3)); + eLonMin.setText(addZeros(gp.getLonMin(), 2)); + eLonSec.setText(addZeros(gp.getLonSec(), 2)); + eLonSub.setText(addZeros(gp.getLonSecFrac(), 3)); + break; + } + } + + private static String addZeros(final int value, final int len) { + return StringUtils.leftPad(Integer.toString(value), len, '0'); + } + + private class ButtonClickListener implements View.OnClickListener { + + @Override + public void onClick(View view) { + final Button button = (Button) view; + final CharSequence text = button.getText(); + if (StringUtils.isBlank(text)) { + return; + } + switch (text.charAt(0)) { + case 'N': + button.setText("S"); + break; + case 'S': + button.setText("N"); + break; + case 'E': + button.setText("W"); + break; + case 'W': + button.setText("E"); + break; + default: + break; + } + calc(true); + } + } + + private class TextChanged implements TextWatcher { + + private final EditText editText; + + public TextChanged(EditText editText) { + this.editText = editText; + } + + @Override + public void afterTextChanged(Editable s) { + /* + * Max lengths, depending on currentFormat + * + * formatPlain = disabled + * DEG MIN SEC SUB + * formatDeg 2/3 5 - - + * formatMin 2/3 2 3 - + * formatSec 2/3 2 2 3 + */ + + if (currentFormat == coordInputFormatEnum.Plain) { + return; + } + + final int maxLength = getMaxLengthFromCurrentField(editText); + if (s.length() == maxLength) { + if (editText == eLatDeg) { + eLatMin.requestFocus(); + } else if (editText == eLatMin) { + if (eLatSec.getVisibility() == View.GONE) { + eLonDeg.requestFocus(); + } else { + eLatSec.requestFocus(); + } + } else if (editText == eLatSec) { + if (eLatSub.getVisibility() == View.GONE) { + eLonDeg.requestFocus(); + } else { + eLatSub.requestFocus(); + } + } else if (editText == eLatSub) { + eLonDeg.requestFocus(); + } else if (editText == eLonDeg) { + eLonMin.requestFocus(); + } else if (editText == eLonMin) { + if (eLonSec.getVisibility() == View.GONE) { + eLatDeg.requestFocus(); + } else { + eLonSec.requestFocus(); + } + } else if (editText == eLonSec) { + if (eLonSub.getVisibility() == View.GONE) { + eLatDeg.requestFocus(); + } else { + eLonSub.requestFocus(); + } + } else if (editText == eLonSub) { + eLatDeg.requestFocus(); + } + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + } + + private boolean calc(final boolean signalError) { + if (currentFormat == coordInputFormatEnum.Plain) { + try { + gp = new Geopoint(eLat.getText().toString(), eLon.getText().toString()); + } catch (Geopoint.ParseException e) { + if (signalError) { + context.showToast(context.getResources().getString(R.string.err_parse_lat_lon)); + } + return false; + } + return true; + } + + String latDir = bLat.getText().toString(); + String lonDir = bLon.getText().toString(); + String latDeg = eLatDeg.getText().toString(); + String lonDeg = eLonDeg.getText().toString(); + String latDegFrac = eLatMin.getText().toString(); + String lonDegFrac = eLonMin.getText().toString(); + String latMin = eLatMin.getText().toString(); + String lonMin = eLonMin.getText().toString(); + String latMinFrac = eLatSec.getText().toString(); + String lonMinFrac = eLonSec.getText().toString(); + String latSec = eLatSec.getText().toString(); + String lonSec = eLonSec.getText().toString(); + String latSecFrac = eLatSub.getText().toString(); + String lonSecFrac = eLonSub.getText().toString(); + + switch (currentFormat) { + case Deg: + gp = new Geopoint(latDir, latDeg, latDegFrac, lonDir, lonDeg, lonDegFrac); + break; + case Min: + gp = new Geopoint(latDir, latDeg, latMin, latMinFrac, lonDir, lonDeg, lonMin, lonMinFrac); + break; + case Sec: + gp = new Geopoint(latDir, latDeg, latMin, latSec, latSecFrac, lonDir, lonDeg, lonMin, lonSec, lonSecFrac); + break; + case Plain: + // This case has been handled above + default: + throw new IllegalArgumentException(); + } + + return true; + } + + public int getMaxLengthFromCurrentField(final EditText editText) { + if (editText == eLonDeg || editText == eLatSub || editText == eLonSub) { + return 3; + } + if ((editText == eLatMin || editText == eLonMin) && currentFormat == coordInputFormatEnum.Deg) { + return 5; + } + if ((editText == eLatSec || editText == eLonSec) && currentFormat == coordInputFormatEnum.Min) { + return 3; + } + return 2; + } + + private class CoordinateFormatListener implements OnItemSelectedListener { + + @Override + public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { + // Ignore first call, which comes from onCreate() + if (currentFormat != null) { + + // Start new format with an acceptable value: either the current one + // entered by the user, else our current coordinates, else (0,0). + if (!calc(false)) { + if (geo != null && geo.getCoords() != null) { + gp = geo.getCoords(); + } else { + gp = new Geopoint(0.0, 0.0); + } + } + } + + currentFormat = coordInputFormatEnum.fromInt(pos); + Settings.setCoordInputFormat(currentFormat); + updateGUI(); + } + + @Override + public void onNothingSelected(AdapterView<?> arg0) { + } + + } + + private class CurrentListener implements View.OnClickListener { + + @Override + public void onClick(View v) { + if (geo == null || geo.getCoords() == null) { + context.showToast(context.getResources().getString(R.string.err_point_unknown_position)); + return; + } + + gp = geo.getCoords(); + updateGUI(); + } + } + + private class CacheListener implements View.OnClickListener { + + @Override + public void onClick(View v) { + if (cache == null || cache.getCoords() == null) { + context.showToast(context.getResources().getString(R.string.err_location_unknown)); + return; + } + + gp = cache.getCoords(); + updateGUI(); + } + } + + private class InputDoneListener implements View.OnClickListener { + + @Override + public void onClick(View v) { + if (!calc(true)) { + return; + } + if (gp != null) { + cuListener.update(gp); + } + dismiss(); + } + } + + public void setOnCoordinateUpdate(CoordinateUpdate cu) { + cuListener = cu; + } + + public interface CoordinateUpdate { + public void update(final Geopoint gp); + } + +} diff --git a/main/src/cgeo/geocaching/ui/CustomProgressDialog.java b/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java index f7772be..c2b722c 100644 --- a/main/src/cgeo/geocaching/ui/CustomProgressDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/CustomProgressDialog.java @@ -1,5 +1,6 @@ -package cgeo.geocaching.ui; +package cgeo.geocaching.ui.dialog; +import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.utils.Log; import android.app.ProgressDialog; @@ -18,7 +19,7 @@ import java.lang.reflect.Method; public class CustomProgressDialog extends ProgressDialog { public CustomProgressDialog(Context context) { - super(context); + super(context, ActivityMixin.getTheme()); } @Override diff --git a/main/src/cgeo/geocaching/ui/DateDialog.java b/main/src/cgeo/geocaching/ui/dialog/DateDialog.java index 5dfd9b9..a9c579c 100644 --- a/main/src/cgeo/geocaching/ui/DateDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/DateDialog.java @@ -1,4 +1,4 @@ -package cgeo.geocaching.ui; +package cgeo.geocaching.ui.dialog; import cgeo.geocaching.R; diff --git a/main/src/cgeo/geocaching/ui/EditorDialog.java b/main/src/cgeo/geocaching/ui/dialog/EditorDialog.java index 50b3e27..4db69e5 100644 --- a/main/src/cgeo/geocaching/ui/EditorDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/EditorDialog.java @@ -1,7 +1,8 @@ -package cgeo.geocaching.ui; +package cgeo.geocaching.ui.dialog; import cgeo.geocaching.CacheDetailActivity; import cgeo.geocaching.R; +import cgeo.geocaching.activity.ActivityMixin; import android.app.Dialog; import android.os.Bundle; @@ -17,7 +18,7 @@ public class EditorDialog extends Dialog { private EditorUpdate editorUpdate; public EditorDialog(CacheDetailActivity cacheDetailActivity, CharSequence editable) { - super(cacheDetailActivity); + super(cacheDetailActivity, ActivityMixin.getTheme()); this.editorText = editable; } @@ -53,7 +54,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/dialog/LiveMapInfoDialogBuilder.java b/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java new file mode 100644 index 0000000..862b1a0 --- /dev/null +++ b/main/src/cgeo/geocaching/ui/dialog/LiveMapInfoDialogBuilder.java @@ -0,0 +1,45 @@ +package cgeo.geocaching.ui.dialog; + +import cgeo.geocaching.R; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgeoapplication; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.view.ContextThemeWrapper; +import android.view.View; +import android.widget.CheckBox; + +public class LiveMapInfoDialogBuilder { + + public static AlertDialog create(Activity activity) { + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + + // AlertDialog has always dark style, so we have to apply it as well always + final View layout = View.inflate(new ContextThemeWrapper(activity, R.style.dark), R.layout.livemapinfo, null); + builder.setView(layout); + + final CheckBox checkBoxHide = (CheckBox) layout.findViewById(R.id.live_map_hint_hide); + + final int showCount = Settings.getLiveMapHintShowCount(); + if (showCount > 2) { + checkBoxHide.setVisibility(View.VISIBLE); + } + Settings.setLiveMapHintShowCount(showCount + 1); + + builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + cgeoapplication.getInstance().setLiveMapHintShown(); + if (checkBoxHide.getVisibility() == View.VISIBLE && checkBoxHide.isChecked()) { + Settings.setHideLiveHint(true); + } + } + }); + return builder.create(); + } + +} |
