diff options
author | Marco Jacob <mjacob@union06.de> | 2012-01-14 21:07:47 +0100 |
---|---|---|
committer | Marco Jacob <mjacob@union06.de> | 2012-01-14 21:07:47 +0100 |
commit | 7fcca178c44c08aae6aa81516b1090401a7d2658 (patch) | |
tree | 47b870e83456f8d63bbee61034622befff7a5c95 /main/src/cgeo | |
parent | 78e4138738fb948eee5db9795c8d00ab6656d615 (diff) | |
parent | e61a40fc8a4a3d5ab5a59346eddd1c43bcc4857e (diff) | |
download | cgeo-7fcca178c44c08aae6aa81516b1090401a7d2658.zip cgeo-7fcca178c44c08aae6aa81516b1090401a7d2658.tar.gz cgeo-7fcca178c44c08aae6aa81516b1090401a7d2658.tar.bz2 |
Merge git://github.com/cgeo/c-geo-opensource
Diffstat (limited to 'main/src/cgeo')
25 files changed, 238 insertions, 78 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java index ea8d749..ec6e6db 100644 --- a/main/src/cgeo/geocaching/CacheCache.java +++ b/main/src/cgeo/geocaching/CacheCache.java @@ -1,11 +1,10 @@ package cgeo.geocaching; import cgeo.geocaching.cgData.StorageLocation; +import cgeo.geocaching.utils.LeastRecentlyUsedCache; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * Cache for Caches. Every cache is stored in memory while c:geo is active to @@ -15,12 +14,13 @@ import java.util.Map; */ public class CacheCache { - final private Map<String, cgCache> cachesCache; // caching caches into memory + private static final int MAX_CACHED_CACHES = 1000; + final private LeastRecentlyUsedCache<String, cgCache> cachesCache; private static CacheCache instance = null; private CacheCache() { - cachesCache = new HashMap<String, cgCache>(); + cachesCache = new LeastRecentlyUsedCache<String, cgCache>(MAX_CACHED_CACHES); } public static CacheCache getInstance() { diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index f3c12cc..5fa4c55 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -33,6 +33,7 @@ import android.content.Intent; import android.content.res.Configuration; import android.database.Cursor; import android.graphics.Bitmap; +import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; @@ -44,12 +45,15 @@ import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; +import android.text.Editable; import android.text.Html; import android.text.Spannable; import android.text.Spanned; +import android.text.format.DateUtils; import android.text.method.LinkMovementMethod; import android.text.style.ImageSpan; import android.text.style.StrikethroughSpan; +import android.text.style.StyleSpan; import android.util.DisplayMetrics; import android.util.Log; import android.view.ContextMenu; @@ -554,7 +558,7 @@ public class CacheDetailActivity extends AbstractActivity { } if (SearchResult.getError(search) != null) { - showToast(res.getString(R.string.err_dwld_details_failed_reason) + " " + SearchResult.getError(search) + "."); + showToast(res.getString(R.string.err_dwld_details_failed) + " " + SearchResult.getError(search).getErrorString(res) + "."); finish(); return; @@ -919,6 +923,17 @@ public class CacheDetailActivity extends AbstractActivity { } /** + * referenced from XML view + */ + public void showNavigationMenu(@SuppressWarnings("unused") View view) { + showNavigationMenu(); + } + + private void showNavigationMenu() { + NavigationAppFactory.showNavigationMenu(geolocation, this, cache, search); + } + + /** * Opens a context menu to do actions on an username */ private class UserActionsClickListener implements View.OnClickListener { @@ -1440,8 +1455,15 @@ public class CacheDetailActivity extends AbstractActivity { } // cache hidden - if (cache.getHiddenDate() != null && cache.getHiddenDate().getTime() > 0) { - addCacheDetail(cache.isEventCache() ? R.string.cache_event : R.string.cache_hidden, cgBase.formatFullDate(cache.getHiddenDate().getTime())); + if (cache.getHiddenDate() != null) { + long time = cache.getHiddenDate().getTime(); + if (time > 0) { + String dateString = cgBase.formatFullDate(time); + if (cache.isEventCache()) { + dateString = DateUtils.formatDateTime(cgeoapplication.getInstance().getBaseContext(), time, DateUtils.FORMAT_SHOW_WEEKDAY) + ", " + dateString; + } + addCacheDetail(cache.isEventCache() ? R.string.cache_event : R.string.cache_hidden, dateString); + } } // cache location @@ -2069,11 +2091,20 @@ public class CacheDetailActivity extends AbstractActivity { // Fast preview: parse only HTML without loading any images HtmlImageCounter imageCounter = new HtmlImageCounter(); - description = Html.fromHtml(descriptionString, imageCounter, new UnknownTagsHandler()); + final UnknownTagsHandler unknownTagsHandler = new UnknownTagsHandler(); + description = Html.fromHtml(descriptionString, imageCounter, unknownTagsHandler); publishProgress(); if (imageCounter.getImageCount() > 0) { // Complete view: parse again with loading images - if necessary ! If there are any images causing problems the user can see at least the preview - description = Html.fromHtml(descriptionString, new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), true, cache.getListId(), false), new UnknownTagsHandler()); + description = Html.fromHtml(descriptionString, new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), true, cache.getListId(), false), unknownTagsHandler); + publishProgress(); + } + + // if description has HTML table, add a note at the end of the long description + if (unknownTagsHandler.isTableDetected() && descriptionView == view.findViewById(R.id.longdesc)) { + final int startPos = description.length(); + ((Editable) description).append("\n\n" + res.getString(R.string.cache_description_table_note)); + ((Editable) description).setSpan(new StyleSpan(Typeface.ITALIC), startPos, description.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); publishProgress(); } return null; diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index bfda2ea..67ecfed 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -1,5 +1,6 @@ package cgeo.geocaching.apps.cache.navi; +import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; @@ -11,6 +12,8 @@ import cgeo.geocaching.geopoint.Geopoint; import org.apache.commons.lang3.ArrayUtils; import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -54,6 +57,25 @@ public final class NavigationAppFactory extends AbstractAppFactory { } } + public static void showNavigationMenu(final cgGeo geo, final Activity activity, final cgCache cache, final SearchResult search) { + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(R.string.cache_menu_navigate); + builder.setIcon(android.R.drawable.ic_menu_mapmode); + final List<NavigationApp> installed = getInstalledNavigationApps(activity); + String[] items = new String[installed.size()]; + for (int i = 0; i < installed.size(); i++) { + items[i] = installed.get(i).getName(); + } + builder.setItems(items, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int item) { + installed.get(item).invoke(geo, activity, cache, search, null, null); + } + }); + AlertDialog alert = builder.create(); + alert.show(); + + } + public static List<NavigationApp> getInstalledNavigationApps(final Activity activity) { final List<NavigationApp> installedNavigationApps = new ArrayList<NavigationApp>(); for (NavigationApp app : getNavigationApps()) { diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index a1c681e..c4a2f24 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -20,6 +20,7 @@ import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.twitter.Twitter; +import cgeo.geocaching.ui.DirectionImage; import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.CancellableHandler; @@ -657,7 +658,7 @@ public class cgBase { { for (cgCache oneCache : parseResult.cacheList) { if (oneCache.getCoords() == null && StringUtils.isNotEmpty(oneCache.getDirectionImg())) { - cgDirectionImg.getDrawable(oneCache.getGeocode(), oneCache.getDirectionImg()); + DirectionImage.getDrawable(oneCache.getGeocode(), oneCache.getDirectionImg()); } } } @@ -1182,7 +1183,6 @@ public class cgBase { //cache.setLogs(loadLogsFromDetails(page, cache, false)); if (Settings.isFriendLogsWanted()) { sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_logs); - int position = 0; List<cgLog> allLogs = cache.getLogs(); List<cgLog> friendLogs = loadLogsFromDetails(page, cache, true, false); if (friendLogs != null) { @@ -1190,7 +1190,7 @@ public class cgBase { if (allLogs.contains(log)) { allLogs.get(allLogs.indexOf(log)).friend = true; } else { - allLogs.add(position++, log); + allLogs.add(log); } } } diff --git a/main/src/cgeo/geocaching/cgSelectMapfile.java b/main/src/cgeo/geocaching/cgSelectMapfile.java index eebd2c9..b97d717 100644 --- a/main/src/cgeo/geocaching/cgSelectMapfile.java +++ b/main/src/cgeo/geocaching/cgSelectMapfile.java @@ -2,6 +2,7 @@ package cgeo.geocaching; import cgeo.geocaching.files.FileList; import cgeo.geocaching.files.LocalStorage; +import cgeo.geocaching.ui.MapfileListAdapter; import android.content.Intent; import android.os.Bundle; @@ -10,7 +11,7 @@ import android.os.Environment; import java.io.File; import java.util.List; -public class cgSelectMapfile extends FileList<cgMapfileListAdapter> { +public class cgSelectMapfile extends FileList<MapfileListAdapter> { public cgSelectMapfile() { super("map"); @@ -35,8 +36,8 @@ public class cgSelectMapfile extends FileList<cgMapfileListAdapter> { } @Override - protected cgMapfileListAdapter getAdapter(List<File> files) { - return new cgMapfileListAdapter(this, files); + protected MapfileListAdapter getAdapter(List<File> files) { + return new MapfileListAdapter(this, files); } @Override diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 7ff3469..aa90336 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -31,6 +31,7 @@ import cgeo.geocaching.sorting.StateComparator; import cgeo.geocaching.sorting.TerrainComparator; import cgeo.geocaching.sorting.VisitComparator; import cgeo.geocaching.sorting.VoteComparator; +import cgeo.geocaching.ui.CacheListAdapter; import cgeo.geocaching.utils.RunnableWithArgument; import org.apache.commons.collections.CollectionUtils; @@ -212,7 +213,7 @@ public class cgeocaches extends AbstractListActivity { AlertDialog alert = dialog.create(); alert.show(); } else if (app != null && SearchResult.getError(search) != null) { - showToast(res.getString(R.string.err_download_fail) + SearchResult.getError(search).getErrorString(res) + "."); + showToast(res.getString(R.string.err_download_fail) + " " + SearchResult.getError(search).getErrorString(res) + "."); hideLoading(); showProgress(false); @@ -281,7 +282,7 @@ public class cgeocaches extends AbstractListActivity { } if (SearchResult.getError(search) != null) { - showToast(res.getString(R.string.err_download_fail) + SearchResult.getError(search).getErrorString(res) + "."); + showToast(res.getString(R.string.err_download_fail) + " " + SearchResult.getError(search).getErrorString(res) + "."); listFooter.setOnClickListener(new MoreCachesListener()); hideLoading(); @@ -2634,7 +2635,7 @@ public class cgeocaches extends AbstractListActivity { else if (type == CacheListType.HISTORY) { adapter.setComparator(new VisitComparator()); } - else { + else if (adapter.getCacheComparator() != null && adapter.getCacheComparator() instanceof DateComparator) { adapter.setComparator(null); } } diff --git a/main/src/cgeo/geocaching/cgeogpxes.java b/main/src/cgeo/geocaching/cgeogpxes.java index cb8167a..ab903ec 100644 --- a/main/src/cgeo/geocaching/cgeogpxes.java +++ b/main/src/cgeo/geocaching/cgeogpxes.java @@ -4,6 +4,7 @@ import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.files.FileList; import cgeo.geocaching.files.GPXImporter; +import cgeo.geocaching.ui.GPXListAdapter; import org.apache.commons.lang3.StringUtils; @@ -15,7 +16,7 @@ import android.os.Environment; import java.io.File; import java.util.List; -public class cgeogpxes extends FileList<cgGPXListAdapter> { +public class cgeogpxes extends FileList<GPXListAdapter> { private static final String EXTRAS_LIST_ID = "list"; public cgeogpxes() { @@ -25,8 +26,8 @@ public class cgeogpxes extends FileList<cgGPXListAdapter> { private int listId = 1; @Override - protected cgGPXListAdapter getAdapter(List<File> files) { - return new cgGPXListAdapter(this, files); + protected GPXListAdapter getAdapter(List<File> files) { + return new GPXListAdapter(this, files); } @Override diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java index 45bdf43..519521d 100644 --- a/main/src/cgeo/geocaching/cgeonavigate.java +++ b/main/src/cgeo/geocaching/cgeonavigate.java @@ -3,6 +3,7 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.maps.CGeoMap; +import cgeo.geocaching.ui.CompassView; import org.apache.commons.lang3.StringUtils; @@ -48,7 +49,7 @@ public class cgeonavigate extends AbstractActivity { private TextView navLocation = null; private TextView distanceView = null; private TextView headingView = null; - private cgCompass compassView = null; + private CompassView compassView = null; private updaterThread updater = null; private Handler updaterHandler = new Handler() { @@ -124,7 +125,7 @@ public class cgeonavigate extends AbstractActivity { } // get textviews once - compassView = (cgCompass) findViewById(R.id.rose); + compassView = (CompassView) findViewById(R.id.rose); // start updater thread updater = new updaterThread(updaterHandler); diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index a112a10..09fc8f1 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -124,6 +124,7 @@ final public class OkapiClient { private static cgCache parseCache(final JSONObject response) { final cgCache cache = new cgCache(); + cache.setReliableLatLon(true); try { cache.setGeocode(response.getString(CACHE_CODE)); cache.setName(response.getString(CACHE_NAME)); diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java index 9ced045..e7853f0 100644 --- a/main/src/cgeo/geocaching/files/GPXImporter.java +++ b/main/src/cgeo/geocaching/files/GPXImporter.java @@ -1,9 +1,9 @@ package cgeo.geocaching.files; import cgeo.geocaching.R; +import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; -import cgeo.geocaching.SearchResult; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.IAbstractActivity; import cgeo.geocaching.activity.Progress; @@ -153,6 +153,9 @@ public class GPXImporter { cgeoapplication.removeCacheFromCache(cache.getGeocode()); app.addCacheToSearch(search, cache); + // save memory, imported caches are typically not used immediately + cgeoapplication.removeCacheFromCache(cache.getGeocode()); + if (progressHandler.isCancelled()) { throw new CancellationException(); } diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 5e17388..1082c9c 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -68,7 +68,7 @@ public abstract class GPXParser extends FileParser { final protected String namespace; final private String version; - private cgCache cache = new cgCache(); + private cgCache cache; private cgTrackable trackable = new cgTrackable(); private cgLog log = new cgLog(); @@ -237,6 +237,7 @@ public abstract class GPXParser extends FileParser { @Override public Collection<cgCache> parse(final InputStream stream, final CancellableHandler progressHandler) throws IOException, ParserException { + resetCache(); final RootElement root = new RootElement(namespace, "gpx"); final Element waypoint = root.getChild(namespace, "wpt"); @@ -795,6 +796,7 @@ public abstract class GPXParser extends FileParser { cmt = null; cache = new cgCache(); + cache.setReliableLatLon(true); for (int i = 0; i < userData.length; i++) { userData[i] = null; } diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java index 6f043f0..e35d7dd 100644 --- a/main/src/cgeo/geocaching/files/LocParser.java +++ b/main/src/cgeo/geocaching/files/LocParser.java @@ -51,6 +51,7 @@ public final class LocParser extends FileParser { cgCoord coord = cidCoords.get(cache.getGeocode()); copyCoordToCache(coord, cache); + cache.setReliableLatLon(false); } } } @@ -155,6 +156,7 @@ public final class LocParser extends FileParser { continue; } cgCache cache = new cgCache(); + cache.setReliableLatLon(true); copyCoordToCache(coord, cache); caches.add(cache); diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java index fede9df..377014e 100644 --- a/main/src/cgeo/geocaching/gcvote/GCVote.java +++ b/main/src/cgeo/geocaching/gcvote/GCVote.java @@ -4,6 +4,7 @@ import cgeo.geocaching.Parameters; import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; +import cgeo.geocaching.utils.LeastRecentlyUsedCache; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -26,12 +27,13 @@ public final class GCVote { private static final Pattern patternVote = Pattern.compile("voteUser='([0-9.]+)'", Pattern.CASE_INSENSITIVE); private static final Pattern patternVoteElement = Pattern.compile("<vote ([^>]+)>", Pattern.CASE_INSENSITIVE); - private static Map<String, GCVoteRating> ratingsCache = new HashMap<String, GCVoteRating>(); // key = guid + private static final int MAX_CACHED_RATINGS = 1000; + private static LeastRecentlyUsedCache<String, GCVoteRating> ratingsCache = new LeastRecentlyUsedCache<String, GCVoteRating>(MAX_CACHED_RATINGS); /** * Get user rating for a given guid or geocode. For a guid first the ratings cache is checked * before a request to gcvote.com is made. - * + * * @param guid * @param geocode * @return diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 3ba8d90..b5b648f 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -146,7 +146,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory private PositionOverlay overlayPosition = null; // data for overlays private static final int[][] INSET_RELIABLE = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; // center, 33x40 / 45x51 - private static final int[][] INSET_TYPE = { { 5, 8, 6, 10 }, { 4, 7, 5, 8 } }; // center, 22x22 / 36x36 + private static final int[][] INSET_TYPE = { { 5, 8, 6, 10 }, { 4, 4, 5, 11 } }; // center, 22x22 / 36x36 private static final int[][] INSET_OWN = { { 21, 0, 0, 26 }, { 25, 0, 0, 35 } }; // top right, 12x12 / 16x16 private static final int[][] INSET_FOUND = { { 0, 0, 21, 28 }, { 0, 0, 25, 35 } }; // top left, 12x12 / 16x16 private static final int[][] INSET_USERMODIFIEDCOORDS = { { 21, 28, 0, 0 }, { 19, 25, 0, 0 } }; // bottom right, 12x12 / 26x26 diff --git a/main/src/cgeo/geocaching/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index e417166..c2910cf 100644 --- a/main/src/cgeo/geocaching/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -1,5 +1,15 @@ -package cgeo.geocaching; - +package cgeo.geocaching.ui; + +import cgeo.geocaching.CacheDetailActivity; +import cgeo.geocaching.R; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgBase; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.R.color; +import cgeo.geocaching.R.drawable; +import cgeo.geocaching.R.id; +import cgeo.geocaching.R.layout; +import cgeo.geocaching.R.string; import cgeo.geocaching.enumerations.CacheListType; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; @@ -52,7 +62,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { final private Resources res; /** Resulting list of caches */ final private List<cgCache> list; - private cgCacheView holder = null; + private CacheView holder = null; private LayoutInflater inflater = null; private CacheComparator cacheComparator = null; private Geopoint coords = null; @@ -62,8 +72,8 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { private int checked = 0; private boolean selectMode = false; final private static Map<CacheType, Drawable> gcIconDrawables = new HashMap<CacheType, Drawable>(); - final private Set<cgCompassMini> compasses = new LinkedHashSet<cgCompassMini>(); - final private Set<cgDistanceView> distances = new LinkedHashSet<cgDistanceView>(); + final private Set<CompassMiniView> compasses = new LinkedHashSet<CompassMiniView>(); + final private Set<DistanceView> distances = new LinkedHashSet<DistanceView>(); final private int[] ratingBcgs = new int[3]; final private float pixelDensity; private static final int SWIPE_MIN_DISTANCE = 60; @@ -118,6 +128,10 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { forceSort(coords); } + public CacheComparator getCacheComparator() { + return cacheComparator; + } + /** * Called when a new page of caches was loaded. */ @@ -272,11 +286,11 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { lastSort = System.currentTimeMillis(); } - for (final cgDistanceView distance : distances) { + for (final DistanceView distance : distances) { distance.update(coordsIn); } - for (final cgCompassMini compass : compasses) { + for (final CompassMiniView compass : compasses) { compass.updateCoords(coordsIn); } } @@ -293,7 +307,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { azimuth = directionNow; if (CollectionUtils.isNotEmpty(compasses)) { - for (cgCompassMini compass : compasses) { + for (CompassMiniView compass : compasses) { compass.updateAzimuth(azimuth); } } @@ -346,15 +360,15 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { if (v == null) { v = inflater.inflate(R.layout.cache, null); - holder = new cgCacheView(); + holder = new CacheView(); holder.checkbox = (CheckBox) v.findViewById(R.id.checkbox); holder.oneInfo = (RelativeLayout) v.findViewById(R.id.one_info); holder.oneCheckbox = (RelativeLayout) v.findViewById(R.id.one_checkbox); holder.logStatusMark = (ImageView) v.findViewById(R.id.log_status_mark); holder.text = (TextView) v.findViewById(R.id.text); holder.directionLayout = (RelativeLayout) v.findViewById(R.id.direction_layout); - holder.distance = (cgDistanceView) v.findViewById(R.id.distance); - holder.direction = (cgCompassMini) v.findViewById(R.id.direction); + holder.distance = (DistanceView) v.findViewById(R.id.distance); + holder.direction = (CompassMiniView) v.findViewById(R.id.direction); holder.dirImgLayout = (RelativeLayout) v.findViewById(R.id.dirimg_layout); holder.dirImg = (ImageView) v.findViewById(R.id.dirimg); holder.inventory = (RelativeLayout) v.findViewById(R.id.inventory); @@ -363,7 +377,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { v.setTag(holder); } else { - holder = (cgCacheView) v.getTag(); + holder = (CacheView) v.getTag(); } if (cache.isOwn()) { @@ -490,7 +504,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { holder.directionLayout.setVisibility(View.GONE); holder.distance.clear(); - final Bitmap dirImgPre = BitmapFactory.decodeFile(cgDirectionImg.getDirectionFile(cache.getGeocode(), false).getPath()); + final Bitmap dirImgPre = BitmapFactory.decodeFile(DirectionImage.getDirectionFile(cache.getGeocode(), false).getPath()); final Bitmap dirImg; if (dirImgPre != null) { // null happens for invalid caches (not yet released) dirImg = dirImgPre.copy(Bitmap.Config.ARGB_8888, true); @@ -682,10 +696,10 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { class detectGesture extends GestureDetector.SimpleOnGestureListener { - private cgCacheView holder = null; + private CacheView holder = null; private cgCache cache = null; - public detectGesture(cgCacheView holderIn, cgCache cacheIn) { + public detectGesture(CacheView holderIn, cgCache cacheIn) { holder = holderIn; cache = cacheIn; } @@ -752,7 +766,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { } } - private void moveRight(cgCacheView holder, cgCache cache, boolean force) { + private void moveRight(CacheView holder, cgCache cache, boolean force) { if (cache == null) { return; } @@ -787,7 +801,7 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> { cache.setStatusCheckedView(true); } - private void moveLeft(cgCacheView holder, cgCache cache, boolean force) { + private void moveLeft(CacheView holder, cgCache cache, boolean force) { if (cache == null) { return; } diff --git a/main/src/cgeo/geocaching/cgCacheView.java b/main/src/cgeo/geocaching/ui/CacheView.java index 39f5a45..7fba55d 100644 --- a/main/src/cgeo/geocaching/cgCacheView.java +++ b/main/src/cgeo/geocaching/ui/CacheView.java @@ -1,11 +1,12 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; + import android.widget.CheckBox; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; -public class cgCacheView { +public class CacheView { // layouts & views public RelativeLayout oneInfo; public RelativeLayout oneCheckbox; @@ -16,8 +17,8 @@ public class cgCacheView { public TextView info; public RelativeLayout inventory; public RelativeLayout directionLayout; - public cgDistanceView distance; - public cgCompassMini direction; + public DistanceView distance; + public CompassMiniView direction; public RelativeLayout dirImgLayout; public ImageView dirImg; } diff --git a/main/src/cgeo/geocaching/cgCompassMini.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java index 4682502..5f3b8c2 100644 --- a/main/src/cgeo/geocaching/cgCompassMini.java +++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java @@ -1,5 +1,8 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; +import cgeo.geocaching.R; +import cgeo.geocaching.R.drawable; +import cgeo.geocaching.R.styleable; import cgeo.geocaching.geopoint.Geopoint; import android.content.Context; @@ -12,7 +15,7 @@ import android.graphics.PaintFlagsDrawFilter; import android.util.AttributeSet; import android.view.View; -public class cgCompassMini extends View { +public class CompassMiniView extends View { private int arrowSkin = R.drawable.compass_arrow_mini_white; private Context context = null; private Geopoint cacheCoords = null; @@ -22,12 +25,12 @@ public class cgCompassMini extends View { private PaintFlagsDrawFilter setfil = null; private PaintFlagsDrawFilter remfil = null; - public cgCompassMini(Context contextIn) { + public CompassMiniView(Context contextIn) { super(contextIn); context = contextIn; } - public cgCompassMini(Context contextIn, AttributeSet attrs) { + public CompassMiniView(Context contextIn, AttributeSet attrs) { super(contextIn, attrs); context = contextIn; diff --git a/main/src/cgeo/geocaching/cgCompass.java b/main/src/cgeo/geocaching/ui/CompassView.java index aa4466b..20495c0 100644 --- a/main/src/cgeo/geocaching/cgCompass.java +++ b/main/src/cgeo/geocaching/ui/CompassView.java @@ -1,4 +1,7 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; + +import cgeo.geocaching.R; +import cgeo.geocaching.Settings; import android.content.Context; import android.graphics.Bitmap; @@ -12,7 +15,7 @@ import android.util.AttributeSet; import android.util.Log; import android.view.View; -public class cgCompass extends View { +public class CompassView extends View { private changeThread watchdog = null; private volatile boolean wantStop = false; @@ -55,17 +58,17 @@ public class cgCompass extends View { try { invalidate(); } catch (Exception e) { - Log.e(Settings.tag, "cgCompass.changeHandler: " + e.toString()); + Log.e(Settings.tag, "CompassView.changeHandler: " + e.toString()); } } }; - public cgCompass(Context contextIn) { + public CompassView(Context contextIn) { super(contextIn); context = contextIn; } - public cgCompass(Context contextIn, AttributeSet attrs) { + public CompassView(Context contextIn, AttributeSet attrs) { super(contextIn, attrs); context = contextIn; } @@ -117,7 +120,7 @@ public class cgCompass extends View { } } - protected synchronized void updateNorth(double northHeadingIn, double cacheHeadingIn) { + public synchronized void updateNorth(double northHeadingIn, double cacheHeadingIn) { if (initialDisplay) { // We will force the compass to move brutally if this is the first // update since it is visible. @@ -176,7 +179,7 @@ public class cgCompass extends View { // nothing } - synchronized (cgCompass.this) { + synchronized (CompassView.this) { azimuthShown = smoothUpdate(northMeasured, azimuthShown); cacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown); } diff --git a/main/src/cgeo/geocaching/cgDirectionImg.java b/main/src/cgeo/geocaching/ui/DirectionImage.java index 7b28bf2..17c253a 100644 --- a/main/src/cgeo/geocaching/cgDirectionImg.java +++ b/main/src/cgeo/geocaching/ui/DirectionImage.java @@ -1,5 +1,7 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; +import cgeo.geocaching.Parameters; +import cgeo.geocaching.cgBase; import cgeo.geocaching.files.LocalStorage; import org.apache.commons.lang3.StringUtils; @@ -7,7 +9,7 @@ import org.apache.http.HttpResponse; import java.io.File; -public class cgDirectionImg { +public class DirectionImage { public static void getDrawable(final String geocode, final String code) { if (StringUtils.isBlank(geocode) || StringUtils.isBlank(code)) { diff --git a/main/src/cgeo/geocaching/cgDistanceView.java b/main/src/cgeo/geocaching/ui/DistanceView.java index 704a655..49c90b7 100644 --- a/main/src/cgeo/geocaching/cgDistanceView.java +++ b/main/src/cgeo/geocaching/ui/DistanceView.java @@ -1,23 +1,24 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; +import cgeo.geocaching.cgBase; import cgeo.geocaching.geopoint.Geopoint; import android.content.Context; import android.util.AttributeSet; import android.widget.TextView; -public class cgDistanceView extends TextView { +public class DistanceView extends TextView { private Geopoint cacheCoords = null; - public cgDistanceView(Context context) { + public DistanceView(Context context) { super(context); } - public cgDistanceView(Context context, AttributeSet attrs) { + public DistanceView(Context context, AttributeSet attrs) { super(context, attrs); } - public cgDistanceView(Context context, AttributeSet attrs, int defStyle) { + public DistanceView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } diff --git a/main/src/cgeo/geocaching/cgGPXListAdapter.java b/main/src/cgeo/geocaching/ui/GPXListAdapter.java index 7b163cf..23f38b0 100644 --- a/main/src/cgeo/geocaching/cgGPXListAdapter.java +++ b/main/src/cgeo/geocaching/ui/GPXListAdapter.java @@ -1,5 +1,10 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; +import cgeo.geocaching.R; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgeogpxes; +import cgeo.geocaching.R.id; +import cgeo.geocaching.R.layout; import cgeo.geocaching.files.GPXImporter; import android.app.Activity; @@ -13,12 +18,12 @@ import android.widget.TextView; import java.io.File; import java.util.List; -public class cgGPXListAdapter extends ArrayAdapter<File> { - private cgGPXView holder = null; +public class GPXListAdapter extends ArrayAdapter<File> { + private GPXView holder = null; private cgeogpxes parent = null; private LayoutInflater inflater = null; - public cgGPXListAdapter(cgeogpxes parentIn, List<File> listIn) { + public GPXListAdapter(cgeogpxes parentIn, List<File> listIn) { super(parentIn, 0, listIn); parent = parentIn; @@ -42,13 +47,13 @@ public class cgGPXListAdapter extends ArrayAdapter<File> { if (v == null) { v = inflater.inflate(R.layout.gpx_item, null); - holder = new cgGPXView(); + holder = new GPXView(); holder.filepath = (TextView) v.findViewById(R.id.filepath); holder.filename = (TextView) v.findViewById(R.id.filename); v.setTag(holder); } else { - holder = (cgGPXView) v.getTag(); + holder = (GPXView) v.getTag(); } final touchListener touchLst = new touchListener(file); diff --git a/main/src/cgeo/geocaching/cgGPXView.java b/main/src/cgeo/geocaching/ui/GPXView.java index a731f70..a93d0db 100644 --- a/main/src/cgeo/geocaching/cgGPXView.java +++ b/main/src/cgeo/geocaching/ui/GPXView.java @@ -1,8 +1,8 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; import android.widget.TextView; -public class cgGPXView { +public class GPXView { // layouts & views public TextView filepath; public TextView filename; diff --git a/main/src/cgeo/geocaching/cgMapfileListAdapter.java b/main/src/cgeo/geocaching/ui/MapfileListAdapter.java index 5294ff2..cc16733 100644 --- a/main/src/cgeo/geocaching/cgMapfileListAdapter.java +++ b/main/src/cgeo/geocaching/ui/MapfileListAdapter.java @@ -1,4 +1,10 @@ -package cgeo.geocaching; +package cgeo.geocaching.ui; + +import cgeo.geocaching.R; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgSelectMapfile; +import cgeo.geocaching.R.id; +import cgeo.geocaching.R.layout; import android.app.Activity; import android.graphics.Typeface; @@ -12,13 +18,13 @@ import android.widget.TextView; import java.io.File; import java.util.List; -public class cgMapfileListAdapter extends ArrayAdapter<File> { +public class MapfileListAdapter extends ArrayAdapter<File> { private cgSelectMapfile parentView; private LayoutInflater inflater; private MapfileView holder; - public cgMapfileListAdapter(cgSelectMapfile parentIn, List<File> listIn) { + public MapfileListAdapter(cgSelectMapfile parentIn, List<File> listIn) { super(parentIn, 0, listIn); parentView = parentIn; diff --git a/main/src/cgeo/geocaching/utils/LeastRecentlyUsedCache.java b/main/src/cgeo/geocaching/utils/LeastRecentlyUsedCache.java new file mode 100644 index 0000000..6d18cf5 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/LeastRecentlyUsedCache.java @@ -0,0 +1,24 @@ +package cgeo.geocaching.utils; + +import java.util.LinkedHashMap; + +/** + * Base class for a caching cache. Don't mix up with a geocache ! + * + * @author blafoo + */ +public class LeastRecentlyUsedCache<K, V> extends LinkedHashMap<K, V> { + + private static final long serialVersionUID = -5077882607489806620L; + private final int maxEntries; + + public LeastRecentlyUsedCache(int maxEntries) { + this.maxEntries = maxEntries; + } + + @Override + protected boolean removeEldestEntry(java.util.Map.Entry<K, V> eldest) { + return size() > maxEntries; + } + +} diff --git a/main/src/cgeo/geocaching/utils/UnknownTagsHandler.java b/main/src/cgeo/geocaching/utils/UnknownTagsHandler.java index e8f524b..9991a50 100644 --- a/main/src/cgeo/geocaching/utils/UnknownTagsHandler.java +++ b/main/src/cgeo/geocaching/utils/UnknownTagsHandler.java @@ -10,12 +10,20 @@ import android.text.style.StrikethroughSpan; public class UnknownTagsHandler implements TagHandler { private static final int UNDEFINED_POSITION = -1; + private static int countCells = 0; int strikePos = UNDEFINED_POSITION; + private boolean tableDetected = false; public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { if (tag.equalsIgnoreCase("strike") || tag.equals("s")) { handleStrike(opening, output); + } else if (tag.equalsIgnoreCase("table")) { + handleTable(); + } else if (tag.equalsIgnoreCase("td")) { + handleTd(opening, output); + } else if (tag.equalsIgnoreCase("tr")) { + handleTr(opening, output); } } @@ -30,4 +38,30 @@ public class UnknownTagsHandler implements TagHandler { } } } + + public boolean isTableDetected() { + return tableDetected; + } + + private void handleTable() { + tableDetected = true; + } + + private static void handleTd(boolean opening, Editable output) { + // insert bar for each table column, see https://en.wikipedia.org/wiki/Box-drawing_characters + if (opening) { + if (countCells++ > 0) { + output.append('┆'); + } + } + } + + private static void handleTr(boolean opening, Editable output) { + // insert new line for each table row + if (opening) { + output.append('\n'); + countCells = 0; + } + } + } |