diff options
Diffstat (limited to 'main/src')
31 files changed, 467 insertions, 239 deletions
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 3d96baf..2007493 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -812,7 +812,11 @@ public final class Settings { } public static CacheType getCacheType() { - return CacheType.getById(sharedPrefs.getString(KEY_CACHE_TYPE, null)); + String cacheFilterType = sharedPrefs.getString(KEY_CACHE_TYPE, null); + if (cacheFilterType == null) { + return null; + } + return CacheType.getById(cacheFilterType); } public static int getWayPointsThreshold() { diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java index 5792fbe..ba3db88 100644 --- a/main/src/cgeo/geocaching/activity/AbstractActivity.java +++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java @@ -60,7 +60,7 @@ public abstract class AbstractActivity extends Activity implements IAbstractActi } public final void helpDialog(final String title, final String message) { - ActivityMixin.helpDialog(this, title, message, null); + ActivityMixin.helpDialog(this, title, message); } public final void helpDialog(final String title, final String message, final Drawable icon) { diff --git a/main/src/cgeo/geocaching/activity/ActivityMixin.java b/main/src/cgeo/geocaching/activity/ActivityMixin.java index d4f9edb..5561cc7 100644 --- a/main/src/cgeo/geocaching/activity/ActivityMixin.java +++ b/main/src/cgeo/geocaching/activity/ActivityMixin.java @@ -122,6 +122,10 @@ public final class ActivityMixin { alert.show(); } + public static void helpDialog(Activity activity, String title, String message) { + helpDialog(activity, title, message, null); + } + protected static void addVisitMenu(IAbstractActivity activity, Menu menu, cgCache cache) { if (cache == null) { return; @@ -145,5 +149,4 @@ public final class ActivityMixin { } } } - } diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 17a7835..a615ae7 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -449,8 +449,8 @@ public class cgBase { } HttpResponse loginResponse = request("https://www.geocaching.com/login/default.aspx", null, false, false, false); - String loginData = getResponseDataOnError(loginResponse); - if (loginResponse.getStatusLine().getStatusCode() == 503 && patternMaintenance.matcher(loginData).find()) { + String loginData = getResponseData(loginResponse); + if (loginResponse != null && loginResponse.getStatusLine().getStatusCode() == 503 && patternMaintenance.matcher(loginData).find()) { return StatusCode.MAINTENANCE; } @@ -1231,15 +1231,17 @@ public class cgBase { final Matcher matcherSpoilersInside = GCConstants.PATTERN_SPOILERSINSIDE.matcher(spoilers); while (matcherSpoilersInside.find()) { - final cgImage spoiler = new cgImage(); - spoiler.url = matcherSpoilersInside.group(1); + String url = matcherSpoilersInside.group(1); + String title = null; if (matcherSpoilersInside.group(2) != null) { - spoiler.title = matcherSpoilersInside.group(2); + title = matcherSpoilersInside.group(2); } + String description = null; if (matcherSpoilersInside.group(3) != null) { - spoiler.description = matcherSpoilersInside.group(3); + description = matcherSpoilersInside.group(3); } + final cgImage spoiler = new cgImage(url, title, description); if (cache.getSpoilers() == null) { cache.setSpoilers(new ArrayList<cgImage>()); @@ -1356,7 +1358,7 @@ public class cgBase { try { final Matcher matcherWpType = patternWpType.matcher(wp[3]); if (matcherWpType.find() && matcherWpType.groupCount() > 0) { - waypoint.setWaypointType(WaypointType.FIND_BY_ID.get(matcherWpType.group(1).trim())); + waypoint.setWaypointType(WaypointType.findById(matcherWpType.group(1).trim())); } } catch (Exception e) { // failed to parse type @@ -1551,9 +1553,9 @@ public class cgBase { final JSONArray images = entry.getJSONArray("Images"); for (int i = 0; i < images.length(); i++) { final JSONObject image = images.getJSONObject(i); - final cgImage logImage = new cgImage(); - logImage.url = "http://img.geocaching.com/cache/log/" + image.getString("FileName"); - logImage.title = image.getString("Name"); + String url = "http://img.geocaching.com/cache/log/" + image.getString("FileName"); + String title = image.getString("Name"); + final cgImage logImage = new cgImage(url, title); if (logDone.logImages == null) { logDone.logImages = new ArrayList<cgImage>(); } @@ -2935,7 +2937,7 @@ public class cgBase { // store spoilers if (CollectionUtils.isNotEmpty(cache.getSpoilers())) { for (cgImage oneSpoiler : cache.getSpoilers()) { - imgGetter.getDrawable(oneSpoiler.url); + imgGetter.getDrawable(oneSpoiler.getUrl()); } } @@ -2948,7 +2950,7 @@ public class cgBase { for (cgLog log : cache.getLogs()) { if (CollectionUtils.isNotEmpty(log.logImages)) { for (cgImage oneLogImg : log.logImages) { - imgGetter.getDrawable(oneLogImg.url); + imgGetter.getDrawable(oneLogImg.getUrl()); } } } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 37b20ad..1724fdd 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -221,6 +221,7 @@ public class cgData { public boolean initialized = false; private SQLiteStatement statementDescription; private SQLiteStatement statementLogCount; + private static boolean newlyCreatedDatabase = false; public cgData(Context contextIn) { context = contextIn; @@ -385,6 +386,7 @@ public class cgData { @Override public void onCreate(SQLiteDatabase db) { + newlyCreatedDatabase = true; db.execSQL(dbCreateCaches); db.execSQL(dbCreateLists); db.execSQL(dbCreateAttributes); @@ -1554,9 +1556,9 @@ public class cgData { values.clear(); values.put("geocode", geocode); values.put("updated", timeStamp); - values.put("url", oneSpoiler.url); - values.put("title", oneSpoiler.title); - values.put("description", oneSpoiler.description); + values.put("url", oneSpoiler.getUrl()); + values.put("title", oneSpoiler.getTitle()); + values.put("description", oneSpoiler.getDescription()); databaseRW.insert(dbTableSpoilers, null, values); } @@ -1608,8 +1610,8 @@ public class cgData { for (cgImage img : log.logImages) { values.clear(); values.put("log_id", log_id); - values.put("title", img.title); - values.put("url", img.url); + values.put("title", img.getTitle()); + values.put("url", img.getUrl()); databaseRW.insert(dbTableLogImages, null, values); } } @@ -2226,7 +2228,7 @@ public class cgData { waypoint.setId(cursor.getInt(cursor.getColumnIndex("_id"))); waypoint.setGeocode(cursor.getString(cursor.getColumnIndex("geocode"))); - waypoint.setWaypointType(WaypointType.FIND_BY_ID.get(cursor.getString(cursor.getColumnIndex("type")))); + waypoint.setWaypointType(WaypointType.findById(cursor.getString(cursor.getColumnIndex("type")))); waypoint.setPrefix(cursor.getString(cursor.getColumnIndex("prefix"))); waypoint.setLookup(cursor.getString(cursor.getColumnIndex("lookup"))); waypoint.setName(cursor.getString(cursor.getColumnIndex("name"))); @@ -2263,10 +2265,7 @@ public class cgData { int indexDescription = cursor.getColumnIndex("description"); do { - cgImage spoiler = new cgImage(); - spoiler.url = cursor.getString(indexUrl); - spoiler.title = cursor.getString(indexTitle); - spoiler.description = cursor.getString(indexDescription); + cgImage spoiler = new cgImage(cursor.getString(indexUrl), cursor.getString(indexTitle), cursor.getString(indexDescription)); spoilers.add(spoiler); } while (cursor.moveToNext()); @@ -2382,18 +2381,12 @@ public class cgData { logs.add(log); } if (!cursor.isNull(indexLogImagesId)) { - final cgImage log_img = new cgImage(); - log_img.title = cursor.getString(indexTitle); - if (log_img.title == null) { - log_img.title = ""; - } - log_img.url = cursor.getString(indexUrl); - if (log_img.url == null) { - log_img.url = ""; - } + String title = cursor.getString(indexTitle); + String url = cursor.getString(indexUrl); if (log.logImages == null) { log.logImages = new ArrayList<cgImage>(); } + final cgImage log_img = new cgImage(url, title); log.logImages.add(log_img); } } @@ -3373,4 +3366,20 @@ public class cgData { return null; } + + /** + * checks if this is a newly created database + * + * @return + */ + public static boolean isNewlyCreatedDatebase() { + return newlyCreatedDatabase; + } + + /** + * resets flag for newly created database to avoid asking the user multiple times + */ + public static void resetNewlyCreatedDatabase() { + newlyCreatedDatabase = false; + } } diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java index 180a7a4..ebd6525 100644 --- a/main/src/cgeo/geocaching/cgGeo.java +++ b/main/src/cgeo/geocaching/cgGeo.java @@ -1,6 +1,7 @@ package cgeo.geocaching; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4Cache; import android.content.Context; import android.content.SharedPreferences; diff --git a/main/src/cgeo/geocaching/cgImage.java b/main/src/cgeo/geocaching/cgImage.java index 3dba437..2be27b2 100644 --- a/main/src/cgeo/geocaching/cgImage.java +++ b/main/src/cgeo/geocaching/cgImage.java @@ -1,14 +1,26 @@ package cgeo.geocaching; +import org.apache.commons.lang3.StringUtils; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; public class cgImage implements Parcelable { - public String url = ""; - public String title = ""; - public String description = ""; + private final String url; + private final String title; + private final String description; + + public cgImage(final String url, final String title, final String description) { + this.url = url; + this.title = title; + this.description = description; + } - public cgImage() { + public cgImage(final String url, final String title) { + this(url, title, null); } public cgImage(final Parcel in) { @@ -39,4 +51,24 @@ public class cgImage implements Parcelable { return new cgImage[size]; } }; + + public String getUrl() { + return url; + } + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public void openInBrowser(final Context fromActivity) { + if (StringUtils.isBlank(url)) { + return; + } + final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + fromActivity.startActivity(browserIntent); + } } diff --git a/main/src/cgeo/geocaching/cgUser.java b/main/src/cgeo/geocaching/cgUser.java deleted file mode 100644 index 2249133..0000000 --- a/main/src/cgeo/geocaching/cgUser.java +++ /dev/null @@ -1,13 +0,0 @@ -package cgeo.geocaching; - -import cgeo.geocaching.geopoint.Geopoint; - -import java.util.Date; - -public class cgUser { - public Date located = null; - public String username = null; - public Geopoint coords = null; - public String action = null; - public String client = null; -} diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index 2a4fb13..6be2e98 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -11,7 +11,9 @@ import cgeo.geocaching.maps.CGeoMap; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; @@ -446,7 +448,7 @@ public class cgeo extends AbstractActivity { (new firstLogin()).start(); } - (new countBubbleUpdate()).start(); + updateCacheCounter(); (new cleanDatabase()).start(); if (Settings.getCacheType() != null && !cgBase.cacheTypesInv.containsKey(Settings.getCacheType())) { @@ -478,7 +480,7 @@ public class cgeo extends AbstractActivity { }); registerForContextMenu(findByOffline); - (new countBubbleUpdate()).start(); + updateCacheCounter(); final View advanced = findViewById(R.id.advanced_button); advanced.setClickable(true); @@ -506,6 +508,37 @@ public class cgeo extends AbstractActivity { }); setFilterTitle(); + checkRestore(); + } + + private void updateCacheCounter() { + (new countBubbleUpdate()).start(); + } + + private void checkRestore() { + if (!cgData.isNewlyCreatedDatebase() || null == cgData.isRestoreFile()) { + return; + } + new AlertDialog.Builder(this) + .setTitle(res.getString(R.string.init_backup_restore)) + .setMessage(res.getString(R.string.init_restore_confirm)) + .setCancelable(false) + .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + cgData.resetNewlyCreatedDatabase(); + app.restoreDatabase(cgeo.this); + updateCacheCounter(); + } + }) + .setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + cgData.resetNewlyCreatedDatabase(); + } + }) + .create() + .show(); } private class update extends cgUpdateLoc { diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 486665a..7ae1575 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -1,5 +1,6 @@ package cgeo.geocaching; +import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; @@ -7,8 +8,13 @@ import cgeo.geocaching.geopoint.Geopoint; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import android.app.Activity; import android.app.Application; +import android.app.ProgressDialog; import android.content.Context; +import android.content.res.Resources; +import android.os.Handler; +import android.os.Message; import android.util.Log; import java.io.File; @@ -17,6 +23,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; public class cgeoapplication extends Application { @@ -81,8 +88,33 @@ public class cgeoapplication extends Application { return cgData.isRestoreFile(); } - public boolean restoreDatabase() { - return storage.restoreDatabase(); + /** + * restore the database in a new thread, showing a progress window + * + * @param fromActivity + * calling activity + */ + public void restoreDatabase(final Activity fromActivity) { + final Resources res = this.getResources(); + final ProgressDialog dialog = ProgressDialog.show(fromActivity, res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_running), true, false); + final AtomicBoolean atomic = new AtomicBoolean(false); + Thread restoreThread = new Thread() { + final Handler handler = new Handler() { + public void handleMessage(Message msg) { + dialog.dismiss(); + boolean restored = atomic.get(); + String message = restored ? res.getString(R.string.init_restore_success) : res.getString(R.string.init_restore_failed); + ActivityMixin.helpDialog(fromActivity, res.getString(R.string.init_backup_restore), message); + } + }; + + @Override + public void run() { + atomic.set(storage.restoreDatabase()); + handler.sendMessage(handler.obtainMessage()); + } + }; + restoreThread.start(); } public void cleanGeo() { diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java index 84c208b..a818859 100644 --- a/main/src/cgeo/geocaching/cgeodetail.java +++ b/main/src/cgeo/geocaching/cgeodetail.java @@ -77,6 +77,12 @@ import java.util.Map.Entry; */ public class cgeodetail extends AbstractActivity { + private static final int MENU_SHARE = 12; + private static final int MENU_CALENDAR = 11; + private static final int MENU_CACHES_AROUND = 10; + private static final int MENU_BROWSER = 7; + private static final int MENU_SPOILERS = 5; + private static final int MENU_NAVIGATE = 2; private static final int CONTEXT_MENU_WAYPOINT_DELETE = 1235; private static final int CONTEXT_MENU_WAYPOINT_DUPLICATE = 1234; @@ -580,33 +586,30 @@ public class cgeodetail extends AbstractActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - if (cache != null && cache.getCoords() != null) { - menu.add(0, 2, 0, res.getString(R.string.cache_menu_compass)).setIcon(android.R.drawable.ic_menu_compass); // compass - SubMenu subMenu = menu.addSubMenu(1, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); + if (null != cache) { + menu.add(0, MENU_NAVIGATE, 0, res.getString(R.string.cache_menu_compass)).setIcon(android.R.drawable.ic_menu_compass); // compass + final SubMenu subMenu = menu.addSubMenu(1, 0, 0, res.getString(R.string.cache_menu_navigate)).setIcon(android.R.drawable.ic_menu_mapmode); addNavigationMenuItems(subMenu); + menu.add(1, MENU_CALENDAR, 0, res.getString(R.string.cache_menu_event)).setIcon(android.R.drawable.ic_menu_agenda); // add event to calendar + addVisitMenu(menu, cache); + menu.add(1, MENU_SPOILERS, 0, res.getString(R.string.cache_menu_spoilers)).setIcon(android.R.drawable.ic_menu_gallery); // spoiler images + menu.add(0, MENU_CACHES_AROUND, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around + menu.add(1, MENU_BROWSER, 0, res.getString(R.string.cache_menu_browser)).setIcon(R.drawable.ic_menu_globe); // browser + menu.add(0, MENU_SHARE, 0, res.getString(R.string.cache_menu_share)).setIcon(android.R.drawable.ic_menu_share); // share cache } - - if (cache != null && cache.canBeAddedToCalendar()) { - menu.add(1, 11, 0, res.getString(R.string.cache_menu_event)).setIcon(android.R.drawable.ic_menu_agenda); // add event to calendar - } - addVisitMenu(menu, cache); - - if (cache != null && CollectionUtils.isNotEmpty(cache.getSpoilers())) { - menu.add(1, 5, 0, res.getString(R.string.cache_menu_spoilers)).setIcon(android.R.drawable.ic_menu_gallery); // spoiler images - } - - if (cache != null && cache.getCoords() != null && cache.supportsCachesAround()) { - menu.add(0, 10, 0, res.getString(R.string.cache_menu_around)).setIcon(android.R.drawable.ic_menu_rotate); // caches around - } - - if (cache != null && cache.canOpenInBrowser()) { - menu.add(1, 7, 0, res.getString(R.string.cache_menu_browser)).setIcon(R.drawable.ic_menu_globe); // browser - } - menu.add(0, 12, 0, res.getString(R.string.cache_menu_share)).setIcon(android.R.drawable.ic_menu_share); // share cache - return true; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.findItem(MENU_NAVIGATE).setVisible(null != cache.getCoords()); + menu.findItem(MENU_CALENDAR).setVisible(cache.canBeAddedToCalendar()); + menu.findItem(MENU_SPOILERS).setVisible(CollectionUtils.isNotEmpty(cache.getSpoilers())); + menu.findItem(MENU_CACHES_AROUND).setVisible(null != cache.getCoords() && cache.supportsCachesAround()); + menu.findItem(MENU_BROWSER).setVisible(cache.canOpenInBrowser()); + return super.onPrepareOptionsMenu(menu); + } + private void addNavigationMenuItems(final Menu menu) { NavigationAppFactory.addMenuItems(menu, this, res); GeneralAppsFactory.addMenuItems(menu, this, res, cache); @@ -621,25 +624,25 @@ public class cgeodetail extends AbstractActivity { return false; } - if (menuItem == 2) { + if (menuItem == MENU_NAVIGATE) { navigateTo(); return true; } else if (menuItem == MENU_LOG_VISIT) { logVisit(); return true; - } else if (menuItem == 5) { + } else if (menuItem == MENU_SPOILERS) { showSpoilers(); return true; - } else if (menuItem == 7) { + } else if (menuItem == MENU_BROWSER) { cache.openInBrowser(this); return true; - } else if (menuItem == 10) { + } else if (menuItem == MENU_CACHES_AROUND) { cachesAround(); return true; - } else if (menuItem == 11) { + } else if (menuItem == MENU_CALENDAR) { addToCalendar(); return true; - } else if (menuItem == 12) { + } else if (menuItem == MENU_SHARE) { if (cache != null) { cache.shareCache(this, res); return true; @@ -1306,17 +1309,13 @@ public class cgeodetail extends AbstractActivity { final View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { - Intent logImgIntent = new Intent(cgeodetail.this, cgeoimages.class); - logImgIntent.putExtra("geocode", geocode.toUpperCase()); - logImgIntent.putExtra("type", cgeoimages.LOG_IMAGES); - logImgIntent.putParcelableArrayListExtra("images", logImages); - startActivity(logImgIntent); + cgeoimages.startActivityLogImages(cgeodetail.this, geocode, logImages); } }; ArrayList<String> titles = new ArrayList<String>(); for (int i_img_cnt = 0; i_img_cnt < log.logImages.size(); i_img_cnt++) { - String img_title = log.logImages.get(i_img_cnt).title; + String img_title = log.logImages.get(i_img_cnt).getTitle(); if (!StringUtils.isBlank(img_title)) { titles.add(img_title); } @@ -1647,11 +1646,7 @@ public class cgeodetail extends AbstractActivity { showToast(res.getString(R.string.err_detail_no_spoiler)); } - Intent spoilersIntent = new Intent(this, cgeoimages.class); - spoilersIntent.putExtra("geocode", geocode.toUpperCase()); - spoilersIntent.putExtra("type", cgeoimages.SPOILER_IMAGES); - spoilersIntent.putParcelableArrayListExtra("images", cache.getSpoilers()); - startActivity(spoilersIntent); + cgeoimages.startActivitySpoilerImages(cgeodetail.this, geocode, cache.getSpoilers()); } public class codeHint implements View.OnClickListener { diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java index 48b7985..a6f1740 100644 --- a/main/src/cgeo/geocaching/cgeoimages.java +++ b/main/src/cgeo/geocaching/cgeoimages.java @@ -8,6 +8,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import android.app.ProgressDialog; +import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; @@ -18,7 +19,10 @@ import android.os.AsyncTask; import android.os.Bundle; import android.text.Html; import android.util.Log; +import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.ImageView; @@ -30,13 +34,16 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.List; public class cgeoimages extends AbstractActivity { + private static final int MENU_BROWSER = 2; + private static final int MENU_FILE = 1; private static final int UNKNOWN_TYPE = 0; - public static final int LOG_IMAGES = 1; - public static final int SPOILER_IMAGES = 2; + private static final int LOG_IMAGES = 1; + private static final int SPOILER_IMAGES = 2; private String geocode = null; private LayoutInflater inflater = null; @@ -44,8 +51,11 @@ public class cgeoimages extends AbstractActivity { private LinearLayout imagesView = null; private int count = 0; private int countDone = 0; + private final HashMap<Integer, cgImage> images = new HashMap<Integer, cgImage>(); + private BitmapDrawable currentDrawable; + private cgImage currentImage; - static private Collection<Bitmap> bitmaps = Collections.synchronizedCollection(new ArrayList<Bitmap>()); + static private final Collection<Bitmap> bitmaps = Collections.synchronizedCollection(new ArrayList<Bitmap>()); private void loadImages(final List<cgImage> images, final int progressMessage, final boolean offline) { @@ -61,11 +71,11 @@ public class cgeoimages extends AbstractActivity { for (final cgImage img : images) { rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); - ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.title)); + ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.getTitle())); - if (StringUtils.isNotBlank(img.description)) { + if (StringUtils.isNotBlank(img.getDescription())) { final TextView descView = (TextView) rowView.findViewById(R.id.description); - descView.setText(Html.fromHtml(img.description), TextView.BufferType.SPANNABLE); + descView.setText(Html.fromHtml(img.getDescription()), TextView.BufferType.SPANNABLE); descView.setVisibility(View.VISIBLE); } @@ -89,7 +99,7 @@ public class cgeoimages extends AbstractActivity { @Override protected BitmapDrawable doInBackground(Void... params) { final HtmlImage imgGetter = new HtmlImage(cgeoimages.this, geocode, true, offline ? 1 : 0, false); - return imgGetter.getDrawable(img.url); + return imgGetter.getDrawable(img.getUrl()); } @Override @@ -105,30 +115,17 @@ public class cgeoimages extends AbstractActivity { image_view.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { - final File file = LocalStorage.getStorageFile(null, "temp.jpg", false); - try { - final FileOutputStream fos = new FileOutputStream(file); - image.getBitmap().compress(CompressFormat.JPEG, 100, fos); - fos.close(); - } catch (Exception e) { - Log.e(Settings.tag, "cgeoimages.handleMessage.onClick: " + e.toString()); - return; - } - - Intent intent = new Intent(); - intent.setAction(android.content.Intent.ACTION_VIEW); - intent.setDataAndType(Uri.fromFile(file), "image/jpg"); - startActivity(intent); - - if (file.exists()) - file.deleteOnExit(); + viewImageInStandardApp(image); } }); + cgeoimages.this.registerForContextMenu(image_view); image_view.setImageDrawable(image); image_view.setScaleType(ImageView.ScaleType.CENTER_CROP); image_view.setLayoutParams(new LayoutParams(bounds.width(), bounds.height())); view.addView(image_view); + + images.put(image_view.getId(), img); } synchronized (cgeoimages.this) { @@ -146,7 +143,7 @@ public class cgeoimages extends AbstractActivity { super.onCreate(savedInstanceState); // get parameters - Bundle extras = getIntent().getExtras(); + final Bundle extras = getIntent().getExtras(); // try to get data from extras int img_type = UNKNOWN_TYPE; @@ -200,10 +197,68 @@ public class cgeoimages extends AbstractActivity { super.onDestroy(); } - @Override - public void onResume() { - super.onResume(); + private void viewImageInStandardApp(final BitmapDrawable image) { + final File file = LocalStorage.getStorageFile(null, "temp.jpg", false); + try { + final FileOutputStream fos = new FileOutputStream(file); + image.getBitmap().compress(CompressFormat.JPEG, 100, fos); + fos.close(); + } catch (Exception e) { + Log.e(Settings.tag, "cgeoimages.handleMessage.onClick: " + e.toString()); + return; + } + + final Intent intent = new Intent(); + intent.setAction(android.content.Intent.ACTION_VIEW); + intent.setDataAndType(Uri.fromFile(file), "image/jpg"); + startActivity(intent); + + if (file.exists()) { + file.deleteOnExit(); + } + } + + public static void startActivityLogImages(final Context fromActivity, final String geocode, ArrayList<cgImage> logImages) { + startActivity(fromActivity, geocode, logImages, cgeoimages.LOG_IMAGES); + } + private static void startActivity(final Context fromActivity, final String geocode, ArrayList<cgImage> logImages, int imageType) { + final Intent logImgIntent = new Intent(fromActivity, cgeoimages.class); + logImgIntent.putExtra("geocode", geocode.toUpperCase()); + logImgIntent.putExtra("type", imageType); + logImgIntent.putParcelableArrayListExtra("images", logImages); + fromActivity.startActivity(logImgIntent); } + public static void startActivitySpoilerImages(final Context fromActivity, String geocode, ArrayList<cgImage> spoilers) { + startActivity(fromActivity, geocode, spoilers, cgeoimages.SPOILER_IMAGES); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, v, menuInfo); + menu.setHeaderTitle(res.getString(R.string.cache_image)); + menu.add(0, MENU_FILE, 0, res.getString(R.string.cache_image_open_file)); + menu.add(0, MENU_BROWSER, 0, res.getString(R.string.cache_image_open_browser)); + final ImageView view = (ImageView) v; + currentDrawable = (BitmapDrawable) view.getDrawable(); + currentImage = images.get(view.getId()); + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + switch (item.getItemId()) { + case MENU_FILE: + viewImageInStandardApp(currentDrawable); + return true; + case MENU_BROWSER: + if (currentImage != null) { + currentImage.openInBrowser(this); + } + return true; + default: + break; + } + return super.onContextItemSelected(item); + } } diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index 8391f15..13a358c 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -33,7 +33,6 @@ import android.widget.Spinner; import android.widget.TextView; import java.io.File; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; public class cgeoinit extends AbstractActivity { @@ -603,28 +602,7 @@ public class cgeoinit extends AbstractActivity { * unused here but needed since this method is referenced from XML layout */ public void restore(View view) { - final ProgressDialog dialog = ProgressDialog.show(this, res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_running), true, false); - final AtomicBoolean atomic = new AtomicBoolean(false); - Thread restoreThread = new Thread() { - final Handler handler = new Handler() { - public void handleMessage(Message msg) { - dialog.dismiss(); - boolean restored = atomic.get(); - if (restored) { - helpDialog(res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_success)); - } else { - helpDialog(res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_failed)); - } - } - }; - - @Override - public void run() { - atomic.set(app.restoreDatabase()); - handler.sendMessage(handler.obtainMessage()); - } - }; - restoreThread.start(); + app.restoreDatabase(this); } public boolean saveValues() { diff --git a/main/src/cgeo/geocaching/cgeovisit.java b/main/src/cgeo/geocaching/cgeovisit.java index a07dfeb..3544054 100644 --- a/main/src/cgeo/geocaching/cgeovisit.java +++ b/main/src/cgeo/geocaching/cgeovisit.java @@ -674,7 +674,6 @@ public class cgeovisit extends cgLogForm { types.addAll(typesPre); types.remove(Integer.valueOf(cgBase.LOG_UPDATE_COORDINATES)); } - typesPre.clear(); } catch (Exception e) { Log.e(Settings.tag, "cgeovisit.loadData.run: " + e.toString()); } diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java index 7b0326c..39e6dee 100644 --- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java +++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java @@ -1,6 +1,6 @@ package cgeo.geocaching.connector; -import cgeo.geocaching.cgCache; +import cgeo.geocaching.ICache; import cgeo.geocaching.connector.opencaching.ApiOpenCachingConnector; import cgeo.geocaching.connector.opencaching.OpenCachingConnector; @@ -9,7 +9,7 @@ import org.apache.commons.lang3.StringUtils; public final class ConnectorFactory { private static final UnknownConnector UNKNOWN_CONNECTOR = new UnknownConnector(); private static final IConnector[] connectors = new IConnector[] { - new GCConnector(), + GCConnector.getInstance(), new OpenCachingConnector("OpenCaching.DE", "www.opencaching.de", "OC"), new OpenCachingConnector("OpenCaching.CZ", "www.opencaching.cz", "OZ"), new ApiOpenCachingConnector("OpenCaching.CO.UK", "www.opencaching.org.uk", "OK", "arU4okouc4GEjMniE2fq"), @@ -42,7 +42,7 @@ public final class ConnectorFactory { return false; } - public static IConnector getConnector(cgCache cache) { + public static IConnector getConnector(ICache cache) { return getConnector(cache.getGeocode()); } @@ -60,6 +60,6 @@ public final class ConnectorFactory { } private static boolean isInvalidGeocode(final String geocode) { - return StringUtils.isBlank(geocode); + return StringUtils.isBlank(geocode) || !Character.isLetterOrDigit(geocode.charAt(0)); } } diff --git a/main/src/cgeo/geocaching/connector/GCConnector.java b/main/src/cgeo/geocaching/connector/GCConnector.java index f81176e..8419e56 100644 --- a/main/src/cgeo/geocaching/connector/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/GCConnector.java @@ -19,6 +19,19 @@ import java.util.List; public class GCConnector extends AbstractConnector { + private static GCConnector instance; + + private GCConnector() { + // singleton + } + + public static GCConnector getInstance() { + if (instance == null) { + instance = new GCConnector(); + } + return instance; + } + @Override public boolean canHandle(String geocode) { return StringUtils.startsWithIgnoreCase(geocode, "GC"); diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index a0af45c..c1d4586 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -111,13 +111,12 @@ final public class OkapiClient { final JSONArray images = response.getJSONArray(CACHE_IMAGES); if (images != null) { JSONObject imageResponse; - cgImage image; for (int i = 0; i < images.length(); i++) { imageResponse = images.getJSONObject(i); if (imageResponse.getBoolean(CACHE_IMAGE_IS_SPOILER)) { - image = new cgImage(); - image.title = imageResponse.getString(CACHE_IMAGE_CAPTION); - image.url = absoluteUrl(imageResponse.getString(CACHE_IMAGE_URL), cache.getGeocode()); + final String title = imageResponse.getString(CACHE_IMAGE_CAPTION); + final String url = absoluteUrl(imageResponse.getString(CACHE_IMAGE_URL), cache.getGeocode()); + final cgImage image = new cgImage(url, title); if (cache.getSpoilers() == null) { cache.setSpoilers(new ArrayList<cgImage>()); } diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java index e2d3d98..ccea7c8 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheType.java +++ b/main/src/cgeo/geocaching/enumerations/CacheType.java @@ -56,7 +56,7 @@ public enum CacheType { public final static CacheType getById(final String id) { if (id == null) { - return null; + return UNKNOWN; } final CacheType result = CacheType.FIND_BY_ID.get(id.toLowerCase().trim()); if (result == null) { diff --git a/main/src/cgeo/geocaching/enumerations/LogTypeTrackable.java b/main/src/cgeo/geocaching/enumerations/LogTypeTrackable.java index 359e4e8..13b8d03 100644 --- a/main/src/cgeo/geocaching/enumerations/LogTypeTrackable.java +++ b/main/src/cgeo/geocaching/enumerations/LogTypeTrackable.java @@ -23,7 +23,7 @@ public enum LogTypeTrackable { return logType; } } - return null; + return DO_NOTHING; } } diff --git a/main/src/cgeo/geocaching/enumerations/WaypointType.java b/main/src/cgeo/geocaching/enumerations/WaypointType.java index ac1cf1e..9fd783d 100644 --- a/main/src/cgeo/geocaching/enumerations/WaypointType.java +++ b/main/src/cgeo/geocaching/enumerations/WaypointType.java @@ -32,7 +32,11 @@ public enum WaypointType { this.markerId = markerId; } - public static final Map<String, WaypointType> FIND_BY_ID; + /** + * inverse lookup of waypoint IDs<br/> + * non public so that <code>null</code> handling can be handled centrally in the enum type itself + */ + private static final Map<String, WaypointType> FIND_BY_ID; static { final HashMap<String, WaypointType> mapping = new HashMap<String, WaypointType>(); for (WaypointType wt : values()) { @@ -41,4 +45,19 @@ public enum WaypointType { FIND_BY_ID = Collections.unmodifiableMap(mapping); } + /** + * inverse lookup of waypoint IDs<br/> + * here the <code>null</code> handling shall be done + */ + public static WaypointType findById(final String id) { + if (null == id) { + return WAYPOINT; + } + WaypointType waypointType = FIND_BY_ID.get(id); + if (null == waypointType) { + return WAYPOINT; + } + return waypointType; + } + } diff --git a/main/src/cgeo/geocaching/Go4Cache.java b/main/src/cgeo/geocaching/go4cache/Go4Cache.java index d2ed032..ffd5974 100644 --- a/main/src/cgeo/geocaching/Go4Cache.java +++ b/main/src/cgeo/geocaching/go4cache/Go4Cache.java @@ -1,5 +1,9 @@ -package cgeo.geocaching; +package cgeo.geocaching.go4cache; +import cgeo.geocaching.Parameters; +import cgeo.geocaching.Settings; +import cgeo.geocaching.cgBase; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.GeopointFormatter.Format; import cgeo.geocaching.geopoint.Viewport; @@ -15,6 +19,7 @@ import android.util.Log; import java.text.ParseException; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; @@ -35,7 +40,7 @@ public class Go4Cache extends Thread { final private cgBase base; private static Go4Cache getInstance(final cgeoapplication app) { - if (instance == null) { + if (null == instance) { synchronized(Go4Cache.class) { instance = new Go4Cache(app); instance.start(); @@ -45,6 +50,7 @@ public class Go4Cache extends Thread { } private Go4Cache(final cgeoapplication app) { + super("Go4Cache"); this.app = app; base = cgBase.getInstance(app); setPriority(Thread.MIN_PRIORITY); @@ -77,7 +83,7 @@ public class Go4Cache extends Thread { // If we are too close and we haven't changed our current action, no need // to update our situation. - if (latestCoords != null && latestCoords.distanceTo(currentCoords) < 0.75 && StringUtils.equals(latestAction, currentAction)) { + if (null != latestCoords && latestCoords.distanceTo(currentCoords) < 0.75 && StringUtils.equals(latestAction, currentAction)) { continue; } @@ -94,13 +100,13 @@ public class Go4Cache extends Thread { "ln", lonStr, "a", currentAction, "s", (CryptUtils.sha1(username + "|" + latStr + "|" + lonStr + "|" + currentAction + "|" + CryptUtils.md5("carnero: developing your dreams"))).toLowerCase()); - if (base.version != null) { + if (null != base.version) { params.put("v", base.version); } cgBase.postRequest("http://api.go4cache.com/", params); - // Update our coordinates even if the request was not succesful, as not to hammer the server + // Update our coordinates even if the request was not successful, as not to hammer the server // with invalid requests for every new GPS position. latestCoords = currentCoords; latestAction = currentAction; @@ -119,10 +125,10 @@ public class Go4Cache extends Thread { * the current viewport * @return the list of users present in the viewport */ - public static List<cgUser> getGeocachersInViewport(final String username, final Viewport viewport) { - final List<cgUser> users = new ArrayList<cgUser>(); + public static List<Go4CacheUser> getGeocachersInViewport(final String username, final Viewport viewport) { + final List<Go4CacheUser> users = new ArrayList<Go4CacheUser>(); - if (username == null) { + if (null == username) { return users; } @@ -157,7 +163,7 @@ public class Go4Cache extends Thread { /** * Parse user information from go4cache.com. * - * @param oneUser + * @param user * a JSON object * @return a cgCache user filled with information * @throws JSONException @@ -165,14 +171,13 @@ public class Go4Cache extends Thread { * @throws ParseException * if the date could not be parsed as expected */ - private static cgUser parseUser(final JSONObject oneUser) throws JSONException, ParseException { - final cgUser user = new cgUser(); - final String located = oneUser.getString("located"); - user.located = cgBase.dateSqlIn.parse(located); - user.username = oneUser.getString("user"); - user.coords = new Geopoint(oneUser.getDouble("latitude"), oneUser.getDouble("longitude")); - user.action = oneUser.getString("action"); - user.client = oneUser.getString("client"); - return user; + private static Go4CacheUser parseUser(final JSONObject user) throws JSONException, ParseException { + final String located = user.getString("located"); + final Date userlocated = cgBase.dateSqlIn.parse(located); + final String username = user.getString("user"); + final Geopoint coords = new Geopoint(user.getDouble("latitude"), user.getDouble("longitude")); + final String action = user.getString("action"); + final String client = user.getString("client"); + return new Go4CacheUser(username, coords, userlocated, action, client); } } diff --git a/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java new file mode 100644 index 0000000..931bdaf --- /dev/null +++ b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java @@ -0,0 +1,91 @@ +package cgeo.geocaching.go4cache; + +import cgeo.geocaching.R; +import cgeo.geocaching.geopoint.Geopoint; + +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Go4CacheUser { + private static final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE); + + private final Date located; + private final String username; + private final Geopoint coords; + private final String action; + private final String client; + + private String actionForDisplay; + private String geocode; + + public Go4CacheUser(final String username, final Geopoint coords, final Date located, final String action, final String client) { + this.username = username; + this.coords = coords; + this.located = located; + this.action = action; + this.client = client; + } + + public Date getLocated() { + return located; + } + + public String getUsername() { + return username; + } + + public Geopoint getCoords() { + return coords; + } + + public int getIconId() { + if (null == client) { + return -1; + } + if (client.equalsIgnoreCase("c:geo")) { + return R.drawable.client_cgeo; + } else if (client.equalsIgnoreCase("preCaching")) { + return R.drawable.client_precaching; + } else if (client.equalsIgnoreCase("Handy Geocaching")) { + return R.drawable.client_handygeocaching; + } + return -1; + } + + private void getGeocodeAndAction() { + final Matcher matcherGeocode = patternGeocode.matcher(action.trim()); + + geocode = ""; + if (0 == action.length() || action.equalsIgnoreCase("pending")) { + actionForDisplay = "Looking around"; + } else if (action.equalsIgnoreCase("tweeting")) { + actionForDisplay = "Tweeting"; + } else if (matcherGeocode.find()) { + if (null != matcherGeocode.group(1)) { + geocode = matcherGeocode.group(1).trim().toUpperCase(); + } + if (null != matcherGeocode.group(3)) { + actionForDisplay = "Heading to " + geocode + " (" + matcherGeocode.group(3).trim() + ")"; + } else { + actionForDisplay = "Heading to " + geocode; + } + } else { + actionForDisplay = action; + } + } + + public String getAction() { + if (null == actionForDisplay) { + getGeocodeAndAction(); + } + return actionForDisplay; + } + + public String getGeocode() { + if (null == geocode) { + getGeocodeAndAction(); + } + return geocode; + } +} diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 85e916c..f59ddf0 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1,6 +1,5 @@ package cgeo.geocaching.maps; -import cgeo.geocaching.Go4Cache; import cgeo.geocaching.R; import cgeo.geocaching.Settings; import cgeo.geocaching.Settings.mapSourceEnum; @@ -12,7 +11,6 @@ import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSearch; import cgeo.geocaching.cgUpdateDir; import cgeo.geocaching.cgUpdateLoc; -import cgeo.geocaching.cgUser; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.cgeocaches; @@ -22,6 +20,8 @@ import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.Viewport; +import cgeo.geocaching.go4cache.Go4Cache; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapActivityImpl; @@ -156,7 +156,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory /** List of caches in the viewport */ private List<cgCache> caches = new ArrayList<cgCache>(); /** List of users in the viewport */ - private List<cgUser> users = new ArrayList<cgUser>(); + private List<Go4CacheUser> users = new ArrayList<Go4CacheUser>(); private List<cgCoord> coordinates = new ArrayList<cgCoord>(); // storing for offline private ProgressDialog waitDialog = null; @@ -372,7 +372,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory final double latitudeIntent = extras.getDouble(EXTRAS_LATITUDE); final double longitudeIntent = extras.getDouble(EXTRAS_LONGITUDE); coordsIntent = new Geopoint(latitudeIntent, longitudeIntent); - waypointTypeIntent = WaypointType.FIND_BY_ID.get(extras.getString(EXTRAS_WPTTYPE)); + waypointTypeIntent = WaypointType.findById(extras.getString(EXTRAS_WPTTYPE)); mapStateIntent = extras.getIntArray(EXTRAS_MAPSTATE); mapTitle = extras.getString(EXTRAS_MAP_TITLE); @@ -1529,9 +1529,9 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory */ private class DisplayUsersThread extends DoThread { - private List<cgUser> users = null; + private List<Go4CacheUser> users = null; - public DisplayUsersThread(List<cgUser> usersIn, long centerLatIn, long centerLonIn, long spanLatIn, long spanLonIn) { + public DisplayUsersThread(List<Go4CacheUser> usersIn, long centerLatIn, long centerLonIn, long spanLatIn, long spanLonIn) { super(centerLatIn, centerLonIn, spanLatIn, spanLonIn); setName("Display Users"); users = usersIn; @@ -1553,12 +1553,12 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory int counter = 0; OtherCachersOverlayItemImpl item = null; - for (cgUser userOne : users) { + for (Go4CacheUser userOne : users) { if (stop) { return; } - if (userOne.coords == null) { + if (userOne.getCoords() == null) { continue; } diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index 40da6f2..f6e3660 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -311,7 +311,7 @@ public class CachesOverlay extends AbstractItemizedOverlay { } else { dialog.setTitle("waypoint"); - String waypointL10N = cgBase.waypointTypes.get(WaypointType.FIND_BY_ID.get(coordinate.getTypeSpec())); + String waypointL10N = cgBase.waypointTypes.get(WaypointType.findById(coordinate.getTypeSpec())); if (waypointL10N == null) { waypointL10N = cgBase.waypointTypes.get(WaypointType.WAYPOINT); } diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java index 33274ba..8498b29 100644 --- a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java +++ b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java @@ -1,9 +1,8 @@ package cgeo.geocaching.maps; -import cgeo.geocaching.R; import cgeo.geocaching.Settings; -import cgeo.geocaching.cgUser; import cgeo.geocaching.cgeodetail; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl; import cgeo.geocaching.maps.interfaces.MapProjectionImpl; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -21,14 +20,11 @@ import android.util.Log; import java.util.ArrayList; import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class OtherCachersOverlay extends AbstractItemizedOverlay { private List<OtherCachersOverlayItemImpl> items = new ArrayList<OtherCachersOverlayItemImpl>(); private Context context = null; - private final Pattern patternGeocode = Pattern.compile("^(GC[A-Z0-9]+)(\\: ?(.+))?$", Pattern.CASE_INSENSITIVE); public OtherCachersOverlay(ItemizedOverlayImpl ovlImplIn, Context contextIn) { super(ovlImplIn); @@ -71,45 +67,20 @@ public class OtherCachersOverlay extends AbstractItemizedOverlay { } final OtherCachersOverlayItemImpl item = items.get(index); - final cgUser user = item.getUser(); + final Go4CacheUser user = item.getUser(); // set action - String action = null; - String geocode = null; - final Matcher matcherGeocode = patternGeocode.matcher(user.action.trim()); - - if (user.action.length() == 0 || user.action.equalsIgnoreCase("pending")) { - action = "Looking around"; - } else if (user.action.equalsIgnoreCase("tweeting")) { - action = "Tweeting"; - } else if (matcherGeocode.find()) { - if (matcherGeocode.group(1) != null) { - geocode = matcherGeocode.group(1).trim().toUpperCase(); - } - if (matcherGeocode.group(3) != null) { - action = "Heading to " + geocode + " (" + matcherGeocode.group(3).trim() + ")"; - } else { - action = "Heading to " + geocode; - } - } else { - action = user.action; - } + String action = user.getAction(); + String geocode = user.getGeocode(); // set icon - int icon = -1; - if (user.client.equalsIgnoreCase("c:geo")) { - icon = R.drawable.client_cgeo; - } else if (user.client.equalsIgnoreCase("preCaching")) { - icon = R.drawable.client_precaching; - } else if (user.client.equalsIgnoreCase("Handy Geocaching")) { - icon = R.drawable.client_handygeocaching; - } + int icon = user.getIconId(); final AlertDialog.Builder dialog = new AlertDialog.Builder(context); if (icon > -1) { dialog.setIcon(icon); } - dialog.setTitle(user.username); + dialog.setTitle(user.getUsername()); dialog.setMessage(action); dialog.setCancelable(true); if (StringUtils.isNotBlank(geocode)) { diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java b/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java index 55f6837..d4ac68b 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleMapFactory.java @@ -2,9 +2,9 @@ package cgeo.geocaching.maps.google; import cgeo.geocaching.R; import cgeo.geocaching.cgCoord; -import cgeo.geocaching.cgUser; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapFactory; @@ -43,7 +43,7 @@ public class GoogleMapFactory implements MapFactory { } @Override - public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, cgUser userOne) { + public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) { GoogleOtherCachersOverlayItem baseItem = new GoogleOtherCachersOverlayItem(context, userOne); return baseItem; } diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java index f6fbcec..ac8e725 100644 --- a/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/google/GoogleOtherCachersOverlayItem.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.google; import cgeo.geocaching.R; -import cgeo.geocaching.cgUser; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; import com.google.android.maps.GeoPoint; @@ -12,10 +12,10 @@ import android.graphics.drawable.Drawable; public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl { private Context context = null; - private cgUser user = null; + private Go4CacheUser user = null; - public GoogleOtherCachersOverlayItem(Context contextIn, cgUser userIn) { - super(new GeoPoint(userIn.coords.getLatitudeE6(), userIn.coords.getLongitudeE6()), userIn.username, ""); + public GoogleOtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { + super(new GeoPoint(userIn.getCoords().getLatitudeE6(), userIn.getCoords().getLongitudeE6()), userIn.getUsername(), ""); context = contextIn; user = userIn; @@ -25,7 +25,7 @@ public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherC public Drawable getMarker(int state) { Drawable marker = null; - if (user != null && user.located != null && user.located.getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { + if (user != null && user.getLocated() != null && user.getLocated().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { marker = context.getResources().getDrawable(R.drawable.user_location_active); } else { marker = context.getResources().getDrawable(R.drawable.user_location); @@ -38,7 +38,7 @@ public class GoogleOtherCachersOverlayItem extends OverlayItem implements OtherC return marker; } - public cgUser getUser() { + public Go4CacheUser getUser() { return user; } } diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java b/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java index 814703c..3bc6b8f 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java +++ b/main/src/cgeo/geocaching/maps/interfaces/MapFactory.java @@ -1,9 +1,9 @@ package cgeo.geocaching.maps.interfaces; import cgeo.geocaching.cgCoord; -import cgeo.geocaching.cgUser; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4CacheUser; import android.app.Activity; import android.content.Context; @@ -28,6 +28,6 @@ public interface MapFactory { public CachesOverlayItemImpl getCachesOverlayItem(final cgCoord coordinate, final CacheType type); public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, - cgUser userOne); + Go4CacheUser userOne); } diff --git a/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java b/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java index 43fc58e..cc611ed 100644 --- a/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java +++ b/main/src/cgeo/geocaching/maps/interfaces/OtherCachersOverlayItemImpl.java @@ -1,6 +1,6 @@ package cgeo.geocaching.maps.interfaces; -import cgeo.geocaching.cgUser; +import cgeo.geocaching.go4cache.Go4CacheUser; /** * Common functions of the provider-specific @@ -11,5 +11,5 @@ import cgeo.geocaching.cgUser; */ public interface OtherCachersOverlayItemImpl extends OverlayItemImpl { - public cgUser getUser(); + public Go4CacheUser getUser(); } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java index dabd91b..3499c1d 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapFactory.java @@ -2,9 +2,9 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; import cgeo.geocaching.cgCoord; -import cgeo.geocaching.cgUser; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapFactory; @@ -42,7 +42,7 @@ public class MapsforgeMapFactory implements MapFactory { } @Override - public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, cgUser userOne) { + public OtherCachersOverlayItemImpl getOtherCachersOverlayItemBase(Context context, Go4CacheUser userOne) { MapsforgeOtherCachersOverlayItem baseItem = new MapsforgeOtherCachersOverlayItem(context, userOne); return baseItem; } diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java index 6a83c16..f2cae3a 100644 --- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java +++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOtherCachersOverlayItem.java @@ -1,7 +1,7 @@ package cgeo.geocaching.maps.mapsforge; import cgeo.geocaching.R; -import cgeo.geocaching.cgUser; +import cgeo.geocaching.go4cache.Go4CacheUser; import cgeo.geocaching.maps.interfaces.OtherCachersOverlayItemImpl; import org.mapsforge.android.maps.GeoPoint; @@ -12,10 +12,10 @@ import android.graphics.drawable.Drawable; public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements OtherCachersOverlayItemImpl { private Context context = null; - private cgUser user = null; + private Go4CacheUser user = null; - public MapsforgeOtherCachersOverlayItem(Context contextIn, cgUser userIn) { - super(new GeoPoint(userIn.coords.getLatitudeE6(), userIn.coords.getLongitudeE6()), userIn.username, ""); + public MapsforgeOtherCachersOverlayItem(Context contextIn, Go4CacheUser userIn) { + super(new GeoPoint(userIn.getCoords().getLatitudeE6(), userIn.getCoords().getLongitudeE6()), userIn.getUsername(), ""); context = contextIn; user = userIn; @@ -25,7 +25,7 @@ public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements Oth public Drawable getMarker(int state) { Drawable marker = null; - if (user != null && user.located != null && user.located.getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { + if (user != null && user.getLocated() != null && user.getLocated().getTime() >= (System.currentTimeMillis() - (20 * 60 * 1000))) { marker = context.getResources().getDrawable(R.drawable.user_location_active); } else { marker = context.getResources().getDrawable(R.drawable.user_location); @@ -38,7 +38,7 @@ public class MapsforgeOtherCachersOverlayItem extends OverlayItem implements Oth return marker; } - public cgUser getUser() { + public Go4CacheUser getUser() { return user; } } |
