aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java12
-rw-r--r--main/src/cgeo/geocaching/UpdateDirectionCallback.java5
-rw-r--r--main/src/cgeo/geocaching/UpdateLocationCallback.java5
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractListActivity.java5
-rw-r--r--main/src/cgeo/geocaching/cgBase.java16
-rw-r--r--main/src/cgeo/geocaching/cgCache.java13
-rw-r--r--main/src/cgeo/geocaching/cgCacheListAdapter.java1
-rw-r--r--main/src/cgeo/geocaching/cgCacheView.java5
-rw-r--r--main/src/cgeo/geocaching/cgData.java85
-rw-r--r--main/src/cgeo/geocaching/cgDirection.java40
-rw-r--r--main/src/cgeo/geocaching/cgGeo.java276
-rw-r--r--main/src/cgeo/geocaching/cgList.java1
-rw-r--r--main/src/cgeo/geocaching/cgTrackable.java27
-rw-r--r--main/src/cgeo/geocaching/cgUpdateDir.java5
-rw-r--r--main/src/cgeo/geocaching/cgUpdateLoc.java5
-rw-r--r--main/src/cgeo/geocaching/cgeo.java10
-rw-r--r--main/src/cgeo/geocaching/cgeoadvsearch.java6
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java8
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java16
-rw-r--r--main/src/cgeo/geocaching/cgeocoords.java2
-rw-r--r--main/src/cgeo/geocaching/cgeonavigate.java20
-rw-r--r--main/src/cgeo/geocaching/cgeopoint.java6
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java8
-rw-r--r--main/src/cgeo/geocaching/cgeotrackable.java143
-rw-r--r--main/src/cgeo/geocaching/cgeowaypoint.java6
-rw-r--r--main/src/cgeo/geocaching/cgeowaypointadd.java6
-rw-r--r--main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java18
-rw-r--r--main/src/cgeo/geocaching/files/GPXImporter.java3
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java8
-rw-r--r--main/src/cgeo/geocaching/files/LocalStorage.java9
-rw-r--r--main/src/cgeo/geocaching/go4cache/Go4CacheUser.java2
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java26
-rw-r--r--main/src/cgeo/geocaching/network/HtmlImage.java14
33 files changed, 355 insertions, 457 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 2a1e6f9..3f81e3c 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -601,9 +601,9 @@ public class CacheDetailActivity extends AbstractActivity {
progress.dismiss();
}
- private class LocationUpdater extends cgUpdateLoc {
+ private class LocationUpdater implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
@@ -1271,7 +1271,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
if (geolocation != null) {
- locationUpdater.updateLoc(geolocation);
+ locationUpdater.updateLocation(geolocation);
}
return view;
@@ -2015,13 +2015,15 @@ public class CacheDetailActivity extends AbstractActivity {
protected Void doInBackground(Void... params) {
// log count
if (cache != null && cache.getLogCounts() != null) {
- final StringBuilder text = new StringBuilder();
+ final StringBuilder text = new StringBuilder(200);
text.append(res.getString(R.string.cache_log_types));
text.append(": ");
// sort the log counts by type id ascending. that way the FOUND, DNF log types are the first and most visible ones
List<Entry<Integer, Integer>> sortedLogCounts = new ArrayList<Entry<Integer, Integer>>();
- sortedLogCounts.addAll(cache.getLogCounts().entrySet());
+ for (Entry<Integer, Integer> entry : cache.getLogCounts().entrySet()) {
+ sortedLogCounts.add(entry); // don't add these entries using addAll(), the iterator in the EntrySet can go wrong (see Findbugs)
+ }
Collections.sort(sortedLogCounts, new Comparator<Entry<Integer, Integer>>() {
@Override
diff --git a/main/src/cgeo/geocaching/UpdateDirectionCallback.java b/main/src/cgeo/geocaching/UpdateDirectionCallback.java
new file mode 100644
index 0000000..9381917
--- /dev/null
+++ b/main/src/cgeo/geocaching/UpdateDirectionCallback.java
@@ -0,0 +1,5 @@
+package cgeo.geocaching;
+
+public interface UpdateDirectionCallback {
+ public void updateDirection(cgDirection dir);
+}
diff --git a/main/src/cgeo/geocaching/UpdateLocationCallback.java b/main/src/cgeo/geocaching/UpdateLocationCallback.java
new file mode 100644
index 0000000..f0334a1
--- /dev/null
+++ b/main/src/cgeo/geocaching/UpdateLocationCallback.java
@@ -0,0 +1,5 @@
+package cgeo.geocaching;
+
+public interface UpdateLocationCallback {
+ public void updateLocation(cgGeo geo);
+}
diff --git a/main/src/cgeo/geocaching/activity/AbstractListActivity.java b/main/src/cgeo/geocaching/activity/AbstractListActivity.java
index a1c7596..10e73a5 100644
--- a/main/src/cgeo/geocaching/activity/AbstractListActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractListActivity.java
@@ -1,13 +1,10 @@
package cgeo.geocaching.activity;
-import cgeo.geocaching.Settings;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgeoapplication;
import android.app.ListActivity;
-import android.content.Context;
-import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -21,7 +18,6 @@ public abstract class AbstractListActivity extends ListActivity implements
protected cgeoapplication app = null;
protected Resources res = null;
- protected SharedPreferences prefs = null;
protected AbstractListActivity() {
this(null);
@@ -70,7 +66,6 @@ public abstract class AbstractListActivity extends ListActivity implements
// init
res = this.getResources();
app = (cgeoapplication) this.getApplication();
- prefs = getSharedPreferences(Settings.preferences, Context.MODE_PRIVATE);
cgBase.initialize(app);
}
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 56b74a9..77eeff4 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -2071,16 +2071,17 @@ public class cgBase {
}
public static cgTrackable searchTrackable(final String geocode, final String guid, final String id) {
- cgTrackable trackable = new cgTrackable();
-
if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid) && StringUtils.isBlank(id)) {
Log.w(Settings.tag, "cgeoBase.searchTrackable: No geocode nor guid nor id given");
return null;
}
+ cgTrackable trackable = new cgTrackable();
+
final Parameters params = new Parameters();
if (StringUtils.isNotBlank(geocode)) {
params.put("tracker", geocode);
+ trackable.setGeocode(geocode);
} else if (StringUtils.isNotBlank(guid)) {
params.put("guid", guid);
} else if (StringUtils.isNotBlank(id)) {
@@ -2097,7 +2098,7 @@ public class cgBase {
trackable = parseTrackable(page, cgeoapplication.getInstance());
if (trackable == null) {
Log.e(Settings.tag, "cgeoBase.searchTrackable: No trackable parsed");
- return trackable;
+ return null;
}
return trackable;
@@ -2429,8 +2430,13 @@ public class cgBase {
if (name.length() > 82) {
name = name.substring(0, 79) + "...";
}
- String status = "I touched " + name + " (" + trackable.getUrl() + ")!";
- status = Twitter.appendHashTag(status, "cgeo");
+ StringBuilder builder = new StringBuilder("I touched ");
+ builder.append(name);
+ if (trackable.getUrl() != null) {
+ builder.append(" (").append(trackable.getUrl()).append(')');
+ }
+ builder.append('!');
+ String status = Twitter.appendHashTag(builder.toString(), "cgeo");
status = Twitter.appendHashTag(status, "geocaching");
Twitter.postTweet(app, status, null);
}
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index b1d064a..a91737c 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -2,6 +2,7 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.IAbstractActivity;
import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.connector.GCConnector;
import cgeo.geocaching.connector.IConnector;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
@@ -467,8 +468,7 @@ public class cgCache implements ICache {
@Override
public String getCacheId() {
- // TODO: Only valid for GC-cache
- if (StringUtils.isBlank(cacheId)) {
+ if (StringUtils.isBlank(cacheId) && getConnector().equals(GCConnector.getInstance())) {
return CryptUtils.convertToGcBase31(geocode);
}
@@ -645,8 +645,13 @@ public class cgCache implements ICache {
this.nameSp = nameSp;
}
- public void setHidden(Date hidden) {
- this.hidden = hidden;
+ public void setHidden(final Date hidden) {
+ if (hidden == null) {
+ this.hidden = null;
+ }
+ else {
+ this.hidden = new Date(hidden.getTime()); // avoid storing the external reference in this object
+ }
}
public Float getDirection() {
diff --git a/main/src/cgeo/geocaching/cgCacheListAdapter.java b/main/src/cgeo/geocaching/cgCacheListAdapter.java
index 4b8c573..7f67bc6 100644
--- a/main/src/cgeo/geocaching/cgCacheListAdapter.java
+++ b/main/src/cgeo/geocaching/cgCacheListAdapter.java
@@ -343,7 +343,6 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
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.oneCache = (RelativeLayout) v.findViewById(R.id.one_cache);
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);
diff --git a/main/src/cgeo/geocaching/cgCacheView.java b/main/src/cgeo/geocaching/cgCacheView.java
index 6b3b433..39f5a45 100644
--- a/main/src/cgeo/geocaching/cgCacheView.java
+++ b/main/src/cgeo/geocaching/cgCacheView.java
@@ -7,7 +7,6 @@ import android.widget.TextView;
public class cgCacheView {
// layouts & views
- public RelativeLayout oneCache;
public RelativeLayout oneInfo;
public RelativeLayout oneCheckbox;
public CheckBox checkbox;
@@ -21,8 +20,4 @@ public class cgCacheView {
public cgCompassMini direction;
public RelativeLayout dirImgLayout;
public ImageView dirImg;
-
- // status
- public float startX = -1;
- public float prevX = -1;
}
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 715ebed..c70e8c4 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -1671,8 +1671,8 @@ public class cgData {
values.clear();
values.put("geocode", geocode);
values.put("updated", timeStamp);
- values.put("type", pair.getKey().intValue());
- values.put("count", pair.getValue().intValue());
+ values.put("type", pair.getKey());
+ values.put("count", pair.getValue());
databaseRW.insert(dbTableLogCount, null, values);
}
@@ -2015,44 +2015,45 @@ public class cgData {
cgCache cache = new cgCache();
if (cacheColumnIndex == null) {
- cacheColumnIndex = new int[37];
- cacheColumnIndex[0] = cursor.getColumnIndex("updated");
- cacheColumnIndex[1] = cursor.getColumnIndex("reason");
- cacheColumnIndex[2] = cursor.getColumnIndex("detailed");
- cacheColumnIndex[3] = cursor.getColumnIndex("detailedupdate");
- cacheColumnIndex[4] = cursor.getColumnIndex("visiteddate");
- cacheColumnIndex[5] = cursor.getColumnIndex("geocode");
- cacheColumnIndex[6] = cursor.getColumnIndex("cacheid");
- cacheColumnIndex[7] = cursor.getColumnIndex("guid");
- cacheColumnIndex[8] = cursor.getColumnIndex("type");
- cacheColumnIndex[9] = cursor.getColumnIndex("name");
- cacheColumnIndex[10] = cursor.getColumnIndex("own");
- cacheColumnIndex[11] = cursor.getColumnIndex("owner");
- cacheColumnIndex[12] = cursor.getColumnIndex("owner_real");
- cacheColumnIndex[13] = cursor.getColumnIndex("hidden");
- cacheColumnIndex[14] = cursor.getColumnIndex("hint");
- cacheColumnIndex[15] = cursor.getColumnIndex("size");
- cacheColumnIndex[16] = cursor.getColumnIndex("difficulty");
- cacheColumnIndex[17] = cursor.getColumnIndex("direction");
- cacheColumnIndex[18] = cursor.getColumnIndex("distance");
- cacheColumnIndex[19] = cursor.getColumnIndex("terrain");
- cacheColumnIndex[20] = cursor.getColumnIndex("latlon");
- cacheColumnIndex[21] = cursor.getColumnIndex("location");
- cacheColumnIndex[22] = cursor.getColumnIndex("elevation");
- cacheColumnIndex[23] = cursor.getColumnIndex("personal_note");
- cacheColumnIndex[24] = cursor.getColumnIndex("shortdesc");
- cacheColumnIndex[25] = cursor.getColumnIndex("favourite_cnt");
- cacheColumnIndex[26] = cursor.getColumnIndex("rating");
- cacheColumnIndex[27] = cursor.getColumnIndex("votes");
- cacheColumnIndex[28] = cursor.getColumnIndex("myvote");
- cacheColumnIndex[29] = cursor.getColumnIndex("disabled");
- cacheColumnIndex[30] = cursor.getColumnIndex("archived");
- cacheColumnIndex[31] = cursor.getColumnIndex("members");
- cacheColumnIndex[32] = cursor.getColumnIndex("found");
- cacheColumnIndex[33] = cursor.getColumnIndex("favourite");
- cacheColumnIndex[34] = cursor.getColumnIndex("inventoryunknown");
- cacheColumnIndex[35] = cursor.getColumnIndex("onWatchlist");
- cacheColumnIndex[36] = cursor.getColumnIndex("reliable_latlon");
+ int[] local_cci = new int[37]; // use a local variable to avoid having the not yet fully initialized array be visible to other threads
+ local_cci[0] = cursor.getColumnIndex("updated");
+ local_cci[1] = cursor.getColumnIndex("reason");
+ local_cci[2] = cursor.getColumnIndex("detailed");
+ local_cci[3] = cursor.getColumnIndex("detailedupdate");
+ local_cci[4] = cursor.getColumnIndex("visiteddate");
+ local_cci[5] = cursor.getColumnIndex("geocode");
+ local_cci[6] = cursor.getColumnIndex("cacheid");
+ local_cci[7] = cursor.getColumnIndex("guid");
+ local_cci[8] = cursor.getColumnIndex("type");
+ local_cci[9] = cursor.getColumnIndex("name");
+ local_cci[10] = cursor.getColumnIndex("own");
+ local_cci[11] = cursor.getColumnIndex("owner");
+ local_cci[12] = cursor.getColumnIndex("owner_real");
+ local_cci[13] = cursor.getColumnIndex("hidden");
+ local_cci[14] = cursor.getColumnIndex("hint");
+ local_cci[15] = cursor.getColumnIndex("size");
+ local_cci[16] = cursor.getColumnIndex("difficulty");
+ local_cci[17] = cursor.getColumnIndex("direction");
+ local_cci[18] = cursor.getColumnIndex("distance");
+ local_cci[19] = cursor.getColumnIndex("terrain");
+ local_cci[20] = cursor.getColumnIndex("latlon");
+ local_cci[21] = cursor.getColumnIndex("location");
+ local_cci[22] = cursor.getColumnIndex("elevation");
+ local_cci[23] = cursor.getColumnIndex("personal_note");
+ local_cci[24] = cursor.getColumnIndex("shortdesc");
+ local_cci[25] = cursor.getColumnIndex("favourite_cnt");
+ local_cci[26] = cursor.getColumnIndex("rating");
+ local_cci[27] = cursor.getColumnIndex("votes");
+ local_cci[28] = cursor.getColumnIndex("myvote");
+ local_cci[29] = cursor.getColumnIndex("disabled");
+ local_cci[30] = cursor.getColumnIndex("archived");
+ local_cci[31] = cursor.getColumnIndex("members");
+ local_cci[32] = cursor.getColumnIndex("found");
+ local_cci[33] = cursor.getColumnIndex("favourite");
+ local_cci[34] = cursor.getColumnIndex("inventoryunknown");
+ local_cci[35] = cursor.getColumnIndex("onWatchlist");
+ local_cci[36] = cursor.getColumnIndex("reliable_latlon");
+ cacheColumnIndex = local_cci;
}
cache.setUpdated(cursor.getLong(cacheColumnIndex[0]));
@@ -3166,12 +3167,8 @@ public class cgData {
cursor.moveToFirst();
int indexId = cursor.getColumnIndex("_id");
int indexTitle = cursor.getColumnIndex("title");
- int indexUpdated = cursor.getColumnIndex("updated");
-
do {
cgList list = new cgList(cursor.getInt(indexId) + 10, cursor.getString(indexTitle));
- list.updated = cursor.getLong(indexUpdated);
-
result.add(list);
} while (cursor.moveToNext());
}
diff --git a/main/src/cgeo/geocaching/cgDirection.java b/main/src/cgeo/geocaching/cgDirection.java
index 7eeceb4..d985a7b 100644
--- a/main/src/cgeo/geocaching/cgDirection.java
+++ b/main/src/cgeo/geocaching/cgDirection.java
@@ -10,24 +10,18 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class cgDirection {
- private Context context = null;
- private SensorManager sensorManager = null;
- private cgeoSensorListener sensorListener = null;
- private cgUpdateDir dirUpdate = null;
+ private final Context context;
+ private final SensorManager sensorManager;
+ private final SensorListener sensorListener;
+ private UpdateDirectionCallback updateDirectionCallback = null;
public Float directionNow = null;
- public cgDirection(Context contextIn, cgUpdateDir dirUpdateIn) {
+ public cgDirection(Context contextIn, UpdateDirectionCallback callback) {
context = contextIn;
- dirUpdate = dirUpdateIn;
- sensorListener = new cgeoSensorListener();
- initDir();
- }
-
- private void initDir() {
- if (sensorManager == null) {
- sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- }
+ updateDirectionCallback = callback;
+ sensorListener = new SensorListener();
+ sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL);
}
@@ -37,15 +31,18 @@ public class cgDirection {
}
}
- public void replaceUpdate(cgUpdateDir dirUpdateIn) {
- dirUpdate = dirUpdateIn;
+ public void replaceUpdate(UpdateDirectionCallback callback) {
+ updateDirectionCallback = callback;
+ fireDirectionCallback();
+ }
- if (dirUpdate != null && directionNow != null) {
- dirUpdate.updateDir(this);
+ private void fireDirectionCallback() {
+ if (updateDirectionCallback != null && directionNow != null) {
+ updateDirectionCallback.updateDirection(this);
}
}
- private class cgeoSensorListener implements SensorEventListener {
+ private final class SensorListener implements SensorEventListener {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
/*
@@ -64,10 +61,7 @@ public class cgDirection {
@Override
public void onSensorChanged(SensorEvent event) {
directionNow = Compatibility.getDirectionNow(event.values[0], (Activity) context);
-
- if (dirUpdate != null && directionNow != null) {
- dirUpdate.updateDir(cgDirection.this);
- }
+ fireDirectionCallback();
}
}
}
diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java
index 3384e04..19ffdf2 100644
--- a/main/src/cgeo/geocaching/cgGeo.java
+++ b/main/src/cgeo/geocaching/cgGeo.java
@@ -17,166 +17,116 @@ import java.util.Iterator;
public class cgGeo {
- private LocationManager geoManager = null;
- private cgUpdateLoc geoUpdate = null;
- private cgeoGeoListener geoNetListener = null;
- private cgeoGeoListener geoGpsListener = null;
- private cgeoGpsStatusListener geoGpsStatusListener = null;
+ private static final String LAST_LOCATION_PSEUDO_PROVIDER = "last";
+ private final LocationManager geoManager = (LocationManager) cgeoapplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
+ private UpdateLocationCallback updateLocationCallback = null;
+ private final AbstractLocationListener networkListener = new NetworkLocationListener();
+ private final AbstractLocationListener gpsListener = new GpsLocationListener();
+ private final GpsStatusListener gpsStatusListener = new GpsStatusListener();
private Location locGps = null;
private Location locNet = null;
private long locGpsLast = 0L;
public Location location = null;
public LocationProviderType locationProvider = LocationProviderType.LAST;
public Geopoint coordsNow = null;
- public Geopoint coordsBefore = null;
public Double altitudeNow = null;
public Float bearingNow = null;
public Float speedNow = null;
public Float accuracyNow = null;
- public Integer satellitesVisible = null;
- public Integer satellitesFixed = null;
+ public int satellitesVisible = 0;
+ public int satellitesFixed = 0;
- public cgGeo(cgUpdateLoc geoUpdateIn) {
- geoUpdate = geoUpdateIn;
+ public cgGeo() {
+ restoreLastLocation();
- geoNetListener = new cgeoGeoListener();
- geoNetListener.setProvider(LocationManager.NETWORK_PROVIDER);
+ geoManager.addGpsStatusListener(gpsStatusListener);
- geoGpsListener = new cgeoGeoListener();
- geoGpsListener.setProvider(LocationManager.GPS_PROVIDER);
+ for (AbstractLocationListener listener : new AbstractLocationListener[] { networkListener, gpsListener }) {
+ try {
+ geoManager.requestLocationUpdates(listener.locationProvider, 0, 0, listener);
+ } catch (Exception e) {
+ Log.w(Settings.tag, "There is no location provider " + listener.locationProvider);
+ }
+ }
+ }
- geoGpsStatusListener = new cgeoGpsStatusListener();
+ public void closeGeo() {
+ geoManager.removeUpdates(networkListener);
+ geoManager.removeUpdates(gpsListener);
+ geoManager.removeGpsStatusListener(gpsStatusListener);
+ }
- initGeo();
+ public void replaceUpdate(UpdateLocationCallback callback) {
+ updateLocationCallback = callback;
+ fireLocationCallback();
}
- private void initGeo() {
- location = null;
- locationProvider = LocationProviderType.LAST;
- coordsNow = null;
- altitudeNow = null;
- bearingNow = null;
- speedNow = null;
- accuracyNow = null;
- satellitesVisible = 0;
- satellitesFixed = 0;
-
- if (geoManager == null) {
- geoManager = (LocationManager) cgeoapplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
+ private void fireLocationCallback() {
+ if (updateLocationCallback != null) {
+ updateLocationCallback.updateLocation(this);
}
+ }
- lastLoc();
-
- geoNetListener.setProvider(LocationManager.NETWORK_PROVIDER);
- geoGpsListener.setProvider(LocationManager.GPS_PROVIDER);
- geoManager.addGpsStatusListener(geoGpsStatusListener);
+ private abstract class AbstractLocationListener implements LocationListener {
+ private final String locationProvider;
- try {
- geoManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, geoNetListener);
- } catch (Exception e) {
- Log.w(Settings.tag, "There is no NETWORK location provider");
+ protected AbstractLocationListener(String provider) {
+ this.locationProvider = provider;
}
- try {
- geoManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, geoGpsListener);
- } catch (Exception e) {
- Log.w(Settings.tag, "There is no GPS location provider");
+ @Override
+ public void onStatusChanged(String provider, int status, Bundle extras) {
+ // nothing
}
- }
- public void closeGeo() {
- if (geoManager != null && geoNetListener != null) {
- geoManager.removeUpdates(geoNetListener);
- }
- if (geoManager != null && geoGpsListener != null) {
- geoManager.removeUpdates(geoGpsListener);
- }
- if (geoManager != null) {
- geoManager.removeGpsStatusListener(geoGpsStatusListener);
+ @Override
+ public void onProviderDisabled(String provider) {
+ if (provider.equals(locationProvider)) {
+ geoManager.removeUpdates(this);
+ }
}
- }
- public void replaceUpdate(cgUpdateLoc geoUpdateIn) {
- geoUpdate = geoUpdateIn;
-
- if (geoUpdate != null) {
- geoUpdate.updateLoc(this);
+ @Override
+ public void onProviderEnabled(String provider) {
+ // nothing
}
}
- public class cgeoGeoListener implements LocationListener {
-
- public String active = null;
+ private final class GpsLocationListener extends AbstractLocationListener {
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- // nothing
+ public GpsLocationListener() {
+ super(LocationManager.GPS_PROVIDER);
}
@Override
public void onLocationChanged(Location location) {
- if (location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
- locGps = location;
- locGpsLast = System.currentTimeMillis();
- } else if (location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
- locNet = location;
- }
-
+ locGps = location;
+ locGpsLast = System.currentTimeMillis();
selectBest(location.getProvider());
}
+ }
- @Override
- public void onProviderDisabled(String provider) {
- if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
- if (geoManager != null && geoNetListener != null) {
- geoManager.removeUpdates(geoNetListener);
- }
- } else if (provider.equals(LocationManager.GPS_PROVIDER)) {
- if (geoManager != null && geoGpsListener != null) {
- geoManager.removeUpdates(geoGpsListener);
- }
- }
+ private final class NetworkLocationListener extends AbstractLocationListener {
+
+ protected NetworkLocationListener() {
+ super(LocationManager.NETWORK_PROVIDER);
}
@Override
- public void onProviderEnabled(String provider) {
- if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
- if (geoNetListener == null) {
- geoNetListener = new cgeoGeoListener();
- }
- geoNetListener.setProvider(LocationManager.NETWORK_PROVIDER);
- } else if (provider.equals(LocationManager.GPS_PROVIDER)) {
- if (geoGpsListener == null) {
- geoGpsListener = new cgeoGeoListener();
- }
- geoGpsListener.setProvider(LocationManager.GPS_PROVIDER);
- }
+ public void onLocationChanged(Location location) {
+ locNet = location;
+ selectBest(location.getProvider());
}
- public void setProvider(String provider) {
- if (provider.equals(LocationManager.GPS_PROVIDER)) {
- if (geoManager != null && geoManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
- active = provider;
- } else {
- active = null;
- }
- } else if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
- if (geoManager != null && geoManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
- active = provider;
- } else {
- active = null;
- }
- }
- }
}
- public class cgeoGpsStatusListener implements GpsStatus.Listener {
+ private final class GpsStatusListener implements GpsStatus.Listener {
@Override
public void onGpsStatusChanged(int event) {
if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) {
- GpsStatus status = geoManager.getGpsStatus(null);
- Iterator<GpsSatellite> statusIterator = status.getSatellites().iterator();
+ final GpsStatus status = geoManager.getGpsStatus(null);
+ final Iterator<GpsSatellite> statusIterator = status.getSatellites().iterator();
int satellites = 0;
int fixed = 0;
@@ -187,23 +137,14 @@ public class cgGeo {
fixed++;
}
satellites++;
-
- /*
- * satellite signal strength
- * if (sat.usedInFix()) {
- * Log.d(Settings.tag, "Sat #" + satellites + ": " + sat.getSnr() + " FIX");
- * } else {
- * Log.d(Settings.tag, "Sat #" + satellites + ": " + sat.getSnr());
- * }
- */
}
boolean changed = false;
- if (satellitesVisible == null || satellites != satellitesVisible) {
+ if (satellites != satellitesVisible) {
satellitesVisible = satellites;
changed = true;
}
- if (satellitesFixed == null || fixed != satellitesFixed) {
+ if (fixed != satellitesFixed) {
satellitesFixed = fixed;
changed = true;
}
@@ -215,36 +156,23 @@ public class cgGeo {
}
}
- private void selectBest(String initProvider) {
- if (locNet == null && locGps != null) { // we have only GPS
- assign(locGps);
- return;
- }
-
+ private void selectBest(final String signallingProvider) {
if (locNet != null && locGps == null) { // we have only NET
assign(locNet);
- return;
}
-
- if (satellitesFixed > 0) { // GPS seems to be fixed
+ else if ((locNet == null && locGps != null) // we have only GPS
+ || (satellitesFixed > 0) // GPS seems to be fixed
+ || (signallingProvider != null && signallingProvider.equals(LocationManager.GPS_PROVIDER)) // we have new location from GPS
+ || locGpsLast > (System.currentTimeMillis() - 30 * 1000) // GPS was working in last 30 seconds
+ ) {
assign(locGps);
- return;
}
-
- if (initProvider != null && initProvider.equals(LocationManager.GPS_PROVIDER)) { // we have new location from GPS
- assign(locGps);
- return;
+ else {
+ assign(locNet); // nothing else, using NET
}
-
- if (locGpsLast > (System.currentTimeMillis() - 30 * 1000)) { // GPS was working in last 30 seconds
- assign(locGps);
- return;
- }
-
- assign(locNet); // nothing else, using NET
}
- private void assign(final Geopoint coords) {
+ private void assignLastLocation(final Geopoint coords) {
if (coords == null) {
return;
}
@@ -256,12 +184,10 @@ public class cgGeo {
speedNow = 0f;
accuracyNow = 999f;
- if (geoUpdate != null) {
- geoUpdate.updateLoc(this);
- }
+ fireLocationCallback();
}
- private void assign(Location loc) {
+ private void assign(final Location loc) {
if (loc == null) {
locationProvider = LocationProviderType.LAST;
return;
@@ -269,12 +195,12 @@ public class cgGeo {
location = loc;
- String provider = location.getProvider();
+ final String provider = location.getProvider();
if (provider.equals(LocationManager.GPS_PROVIDER)) {
locationProvider = LocationProviderType.GPS;
} else if (provider.equals(LocationManager.NETWORK_PROVIDER)) {
locationProvider = LocationProviderType.NETWORK;
- } else if (provider.equalsIgnoreCase("last")) {
+ } else if (provider.equalsIgnoreCase(LAST_LOCATION_PSEUDO_PROVIDER)) {
locationProvider = LocationProviderType.LAST;
}
@@ -302,49 +228,27 @@ public class cgGeo {
accuracyNow = 999f;
}
- if (locationProvider == LocationProviderType.GPS) {
- // save travelled distance only when location is from GPS
- if (coordsBefore != null) {
- final float dst = coordsBefore.distanceTo(coordsNow);
-
- if (dst > 0.005) {
- coordsBefore = coordsNow;
- }
- } else if (coordsBefore == null) { // values aren't initialized
- coordsBefore = coordsNow;
- }
- }
-
- if (geoUpdate != null) {
- geoUpdate.updateLoc(this);
- }
+ fireLocationCallback();
if (locationProvider == LocationProviderType.GPS || locationProvider == LocationProviderType.NETWORK) {
Go4Cache.signalCoordinates(coordsNow);
}
}
- public void lastLoc() {
- assign(cgeoapplication.getInstance().getLastCoords());
-
- Location lastGps = geoManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
-
- if (lastGps != null) {
- lastGps.setProvider("last");
- assign(lastGps);
+ private void restoreLastLocation() {
+ // restore from last location (stored by app)
+ assignLastLocation(cgeoapplication.getInstance().getLastCoords());
- Log.i(Settings.tag, "Using last location from GPS");
- return;
- }
+ // restore from last location (stored by device sensors)
+ for (String provider : new String[] { LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER }) {
+ final Location lastLocation = geoManager.getLastKnownLocation(provider);
+ if (lastLocation != null) {
+ lastLocation.setProvider(LAST_LOCATION_PSEUDO_PROVIDER);
+ assign(lastLocation);
- Location lastGsm = geoManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
-
- if (lastGsm != null) {
- lastGsm.setProvider("last");
- assign(lastGsm);
-
- Log.i(Settings.tag, "Using last location from NETWORK");
- return;
+ Log.i(Settings.tag, "Using last location from " + provider);
+ break;
+ }
}
}
}
diff --git a/main/src/cgeo/geocaching/cgList.java b/main/src/cgeo/geocaching/cgList.java
index f176129..273f6d8 100644
--- a/main/src/cgeo/geocaching/cgList.java
+++ b/main/src/cgeo/geocaching/cgList.java
@@ -6,7 +6,6 @@ public class cgList {
public int id = 0;
public String title = null;
- public Long updated = null;
public cgList(int idIn, String titleIn) {
id = idIn;
diff --git a/main/src/cgeo/geocaching/cgTrackable.java b/main/src/cgeo/geocaching/cgTrackable.java
index bcf3c83..b8c8958 100644
--- a/main/src/cgeo/geocaching/cgTrackable.java
+++ b/main/src/cgeo/geocaching/cgTrackable.java
@@ -1,6 +1,9 @@
package cgeo.geocaching;
+import org.apache.commons.lang3.StringUtils;
+
import android.text.Html;
+import android.util.Log;
import java.util.ArrayList;
import java.util.Date;
@@ -33,6 +36,16 @@ public class cgTrackable implements ILogable {
private List<cgLog> logs = new ArrayList<cgLog>();
public String getUrl() {
+ if (StringUtils.startsWithIgnoreCase(geocode, "GK")) {
+ String hex = geocode.substring(3);
+ try {
+ int id = Integer.parseInt(hex, 16);
+ return "http://geokrety.org/konkret.php?id=" + id;
+ } catch (NumberFormatException e) {
+ Log.e(Settings.tag, "cgTrackable.getUrl", e);
+ return null;
+ }
+ }
return "http://coord.info/" + geocode.toUpperCase();
}
@@ -85,7 +98,12 @@ public class cgTrackable implements ILogable {
}
public void setReleased(Date released) {
- this.released = released;
+ if (released == null) {
+ this.released = null;
+ }
+ else {
+ this.released = new Date(released.getTime()); // avoid storing external reference in this object
+ }
}
public Float getDistance() {
@@ -188,4 +206,11 @@ public class cgTrackable implements ILogable {
return "???";
}
+
+ public boolean isLoggable() {
+ if (StringUtils.startsWithIgnoreCase(geocode, "GK")) {
+ return false;
+ }
+ return true;
+ }
}
diff --git a/main/src/cgeo/geocaching/cgUpdateDir.java b/main/src/cgeo/geocaching/cgUpdateDir.java
deleted file mode 100644
index 236d7a8..0000000
--- a/main/src/cgeo/geocaching/cgUpdateDir.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package cgeo.geocaching;
-
-abstract public class cgUpdateDir {
- abstract public void updateDir(cgDirection dir);
-}
diff --git a/main/src/cgeo/geocaching/cgUpdateLoc.java b/main/src/cgeo/geocaching/cgUpdateLoc.java
deleted file mode 100644
index 763ca85..0000000
--- a/main/src/cgeo/geocaching/cgUpdateLoc.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package cgeo.geocaching;
-
-abstract public class cgUpdateLoc {
- abstract public void updateLoc(cgGeo geo);
-}
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index 00cc877..0d44ad8 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -51,7 +51,7 @@ public class cgeo extends AbstractActivity {
private Integer version = null;
private cgGeo geo = null;
- private cgUpdateLoc geoUpdate = new update();
+ private UpdateLocationCallback geoUpdate = new update();
private TextView navType = null;
private TextView navAccuracy = null;
private TextView navSatellites = null;
@@ -534,10 +534,10 @@ public class cgeo extends AbstractActivity {
.show();
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
@@ -561,9 +561,9 @@ public class cgeo extends AbstractActivity {
findNearest.setBackgroundResource(R.drawable.main_nearby);
String satellites = null;
- if (geo.satellitesVisible != null && geo.satellitesFixed != null && geo.satellitesFixed > 0) {
+ if (geo.satellitesFixed > 0) {
satellites = res.getString(R.string.loc_sat) + ": " + geo.satellitesFixed + "/" + geo.satellitesVisible;
- } else if (geo.satellitesVisible != null) {
+ } else if (geo.satellitesVisible >= 0) {
satellites = res.getString(R.string.loc_sat) + ": 0/" + geo.satellitesVisible;
} else {
satellites = "";
diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java
index b7a8458..ab4f218 100644
--- a/main/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/main/src/cgeo/geocaching/cgeoadvsearch.java
@@ -31,7 +31,7 @@ public class cgeoadvsearch extends AbstractActivity {
private static final int MENU_SEARCH_OWN_CACHES = 1;
private cgGeo geo = null;
- private cgUpdateLoc geoUpdate = new update();
+ private UpdateLocationCallback geoUpdate = new update();
private EditText latEdit = null;
private EditText lonEdit = null;
private String[] geocodesInCache = null;
@@ -198,10 +198,10 @@ public class cgeoadvsearch extends AbstractActivity {
displayTrackable.setOnClickListener(new findTrackableListener());
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index cabf2de..839d365 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -37,7 +37,6 @@ public class cgeoapplication extends Application {
final private Map<String, cgCache> cachesCache = new HashMap<String, cgCache>(); // caching caches into memory
public boolean firstRun = true; // c:geo is just launched
public boolean showLoginToast = true; //login toast shown just once.
- public boolean warnedLanguage = false; // user was warned about different language settings on geocaching.com
private boolean databaseCleaned = false; // database was cleaned
private static cgeoapplication instance;
@@ -133,10 +132,9 @@ public class cgeoapplication extends Application {
return storage.status();
}
- public cgGeo startGeo(cgUpdateLoc geoUpdate) {
+ public cgGeo startGeo(UpdateLocationCallback geoUpdate) {
if (geo == null) {
- geo = new cgGeo(geoUpdate);
-
+ geo = new cgGeo();
Log.i(Settings.tag, "Location service started");
}
@@ -174,7 +172,7 @@ public class cgeoapplication extends Application {
}
}
- public cgDirection startDir(Context context, cgUpdateDir dirUpdate) {
+ public cgDirection startDir(Context context, UpdateDirectionCallback dirUpdate) {
if (dir == null) {
dir = new cgDirection(context, dirUpdate);
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index 381c386..8505252 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -164,8 +164,8 @@ public class cgeocaches extends AbstractListActivity {
private Float northHeading = 0f;
private cgGeo geo = null;
private cgDirection dir = null;
- private cgUpdateLoc geoUpdate = new update();
- private cgUpdateDir dirUpdate = new UpdateDirection();
+ private UpdateLocationCallback geoUpdate = new update();
+ private UpdateDirectionCallback dirUpdate = new UpdateDirection();
private String title = "";
private int detailTotal = 0;
private int detailProgress = 0;
@@ -1477,10 +1477,10 @@ public class cgeocaches extends AbstractListActivity {
setAdapter();
if (geo != null) {
- geoUpdate.updateLoc(geo);
+ geoUpdate.updateLocation(geo);
}
if (dir != null) {
- dirUpdate.updateDir(dir);
+ dirUpdate.updateDirection(dir);
}
}
@@ -1745,10 +1745,10 @@ public class cgeocaches extends AbstractListActivity {
threadR.start();
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
@@ -1779,10 +1779,10 @@ public class cgeocaches extends AbstractListActivity {
}
}
- private class UpdateDirection extends cgUpdateDir {
+ private class UpdateDirection implements UpdateDirectionCallback {
@Override
- public void updateDir(cgDirection dir) {
+ public void updateDirection(cgDirection dir) {
if (!Settings.isLiveList()) {
return;
}
diff --git a/main/src/cgeo/geocaching/cgeocoords.java b/main/src/cgeo/geocaching/cgeocoords.java
index c0c0c0f..83d694c 100644
--- a/main/src/cgeo/geocaching/cgeocoords.java
+++ b/main/src/cgeo/geocaching/cgeocoords.java
@@ -285,6 +285,8 @@ public class cgeocoords extends Dialog {
case 'W':
button.setText("E");
break;
+ default:
+ break;
}
calc(true);
}
diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java
index 9b0e653..ac9118e 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -35,8 +35,8 @@ public class cgeonavigate extends AbstractActivity {
private PowerManager pm = null;
private cgGeo geo = null;
private cgDirection dir = null;
- private cgUpdateLoc geoUpdate = new update();
- private cgUpdateDir dirUpdate = new UpdateDirection();
+ private UpdateLocationCallback geoUpdate = new update();
+ private UpdateDirectionCallback dirUpdate = new UpdateDirection();
private Geopoint dstCoords = null;
private float cacheHeading = 0;
private Float northHeading = null;
@@ -117,10 +117,10 @@ public class cgeonavigate extends AbstractActivity {
setDestCoords();
if (geo != null) {
- geoUpdate.updateLoc(geo);
+ geoUpdate.updateLocation(geo);
}
if (dir != null) {
- dirUpdate.updateDir(dir);
+ dirUpdate.updateDirection(dir);
}
// get textviews once
@@ -335,10 +335,10 @@ public class cgeonavigate extends AbstractActivity {
headingView.setText(String.format("%.0f", cacheHeading) + "°");
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
@@ -353,9 +353,9 @@ public class cgeonavigate extends AbstractActivity {
if (geo.coordsNow != null) {
String satellites = null;
- if (geo.satellitesVisible != null && geo.satellitesFixed != null && geo.satellitesFixed > 0) {
+ if (geo.satellitesFixed > 0) {
satellites = res.getString(R.string.loc_sat) + ": " + geo.satellitesFixed + "/" + geo.satellitesVisible;
- } else if (geo.satellitesVisible != null) {
+ } else if (geo.satellitesVisible >= 0) {
satellites = res.getString(R.string.loc_sat) + ": 0/" + geo.satellitesVisible;
} else {
satellites = "";
@@ -400,10 +400,10 @@ public class cgeonavigate extends AbstractActivity {
}
}
- private class UpdateDirection extends cgUpdateDir {
+ private class UpdateDirection implements UpdateDirectionCallback {
@Override
- public void updateDir(cgDirection dir) {
+ public void updateDirection(cgDirection dir) {
if (dir == null || dir.directionNow == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java
index e1d69b7..9b8d1bb 100644
--- a/main/src/cgeo/geocaching/cgeopoint.java
+++ b/main/src/cgeo/geocaching/cgeopoint.java
@@ -85,7 +85,7 @@ public class cgeopoint extends AbstractActivity {
}
private cgGeo geo = null;
- private cgUpdateLoc geoUpdate = new update();
+ private UpdateLocationCallback geoUpdate = new update();
private Button latButton = null;
private Button lonButton = null;
private boolean changed = false;
@@ -457,10 +457,10 @@ public class cgeopoint extends AbstractActivity {
finish();
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java
index 56c3e55..908b895 100644
--- a/main/src/cgeo/geocaching/cgeopopup.java
+++ b/main/src/cgeo/geocaching/cgeopopup.java
@@ -37,7 +37,7 @@ public class cgeopopup extends AbstractActivity {
private String geocode = null;
private cgCache cache = null;
private cgGeo geo = null;
- private cgUpdateLoc geoUpdate = new update();
+ private UpdateLocationCallback geoUpdate = new update();
private ProgressDialog storeDialog = null;
private ProgressDialog dropDialog = null;
private TextView cacheDistance = null;
@@ -454,7 +454,7 @@ public class cgeopopup extends AbstractActivity {
}
if (geo != null) {
- geoUpdate.updateLoc(geo);
+ geoUpdate.updateLocation(geo);
}
}
@@ -499,10 +499,10 @@ public class cgeopopup extends AbstractActivity {
super.onPause();
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java
index a7a93e4..dd0f358 100644
--- a/main/src/cgeo/geocaching/cgeotrackable.java
+++ b/main/src/cgeo/geocaching/cgeotrackable.java
@@ -30,6 +30,8 @@ import java.net.URLEncoder;
import java.util.Arrays;
public class cgeotrackable extends AbstractActivity {
+ private static final int MENU_LOG_TOUCH = 1;
+ private static final int MENU_BROWSER_TRACKABLE = 2;
public cgTrackable trackable = null;
public String geocode = null;
public String name = null;
@@ -38,14 +40,11 @@ public class cgeotrackable extends AbstractActivity {
private String contextMenuUser = null;
private LayoutInflater inflater = null;
private ProgressDialog waitDialog = null;
+ protected LinearLayout detailsList;
private Handler loadTrackableHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
- RelativeLayout itemLayout;
- TextView itemName;
- TextView itemValue;
-
if (trackable != null && StringUtils.isNotBlank(trackable.getError())) {
showToast(res.getString(R.string.err_tb_details_download) + " " + trackable.getError() + ".");
@@ -79,7 +78,7 @@ public class cgeotrackable extends AbstractActivity {
}
((ScrollView) findViewById(R.id.details_list_box)).setVisibility(View.VISIBLE);
- LinearLayout detailsList = (LinearLayout) findViewById(R.id.details_list);
+ detailsList = (LinearLayout) findViewById(R.id.details_list);
// actiobar icon
if (StringUtils.isNotBlank(trackable.getIconUrl())) {
@@ -89,66 +88,32 @@ public class cgeotrackable extends AbstractActivity {
}
// trackable name
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_name));
- if (StringUtils.isNotBlank(trackable.getName())) {
- itemValue.setText(Html.fromHtml(trackable.getName()).toString());
- } else {
- itemValue.setText(res.getString(R.string.trackable_unknown));
- }
- detailsList.addView(itemLayout);
+ addDetail(R.string.trackable_name, StringUtils.isNotBlank(trackable.getName()) ? Html.fromHtml(trackable.getName()).toString() : res.getString(R.string.trackable_unknown));
// trackable type
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
String tbType = null;
if (StringUtils.isNotBlank(trackable.getType())) {
tbType = Html.fromHtml(trackable.getType()).toString();
} else {
tbType = res.getString(R.string.trackable_unknown);
}
- itemName.setText(res.getString(R.string.trackable_type));
- itemValue.setText(tbType);
- detailsList.addView(itemLayout);
+ addDetail(R.string.trackable_type, tbType);
// trackable geocode
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_code));
- itemValue.setText(trackable.getGeocode().toUpperCase());
- detailsList.addView(itemLayout);
+ addDetail(R.string.trackable_code, trackable.getGeocode().toUpperCase());
// trackable owner
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_owner));
+ TextView owner = addDetail(R.string.trackable_owner, res.getString(R.string.trackable_unknown));
if (StringUtils.isNotBlank(trackable.getOwner())) {
- itemValue.setText(Html.fromHtml(trackable.getOwner()), TextView.BufferType.SPANNABLE);
- itemLayout.setOnClickListener(new userActions());
- } else {
- itemValue.setText(res.getString(R.string.trackable_unknown));
+ owner.setText(Html.fromHtml(trackable.getOwner()), TextView.BufferType.SPANNABLE);
+ owner.setOnClickListener(new userActions());
}
- detailsList.addView(itemLayout);
// trackable spotted
if (StringUtils.isNotBlank(trackable.getSpottedName()) ||
trackable.getSpottedType() == cgTrackable.SPOTTED_UNKNOWN ||
trackable.getSpottedType() == cgTrackable.SPOTTED_OWNER
) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_spotted));
String text = null;
if (trackable.getSpottedType() == cgTrackable.SPOTTED_CACHE) {
@@ -163,10 +128,10 @@ public class cgeotrackable extends AbstractActivity {
text = "N/A";
}
- itemValue.setText(text);
- itemLayout.setClickable(true);
+ TextView spotted = addDetail(R.string.trackable_spotted, text);
+ spotted.setClickable(true);
if (cgTrackable.SPOTTED_CACHE == trackable.getSpottedType()) {
- itemLayout.setOnClickListener(new View.OnClickListener() {
+ spotted.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent cacheIntent = new Intent(cgeotrackable.this, CacheDetailActivity.class);
cacheIntent.putExtra("guid", trackable.getSpottedGuid());
@@ -175,44 +140,24 @@ public class cgeotrackable extends AbstractActivity {
}
});
} else if (cgTrackable.SPOTTED_USER == trackable.getSpottedType()) {
- itemLayout.setOnClickListener(new userActions());
- //activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?guid=" + trackable.spottedGuid)));
+ spotted.setOnClickListener(new userActions());
}
-
- detailsList.addView(itemLayout);
}
// trackable origin
if (StringUtils.isNotBlank(trackable.getOrigin())) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_origin));
- itemValue.setText(Html.fromHtml(trackable.getOrigin()), TextView.BufferType.SPANNABLE);
- detailsList.addView(itemLayout);
+ TextView origin = addDetail(R.string.trackable_origin, "");
+ origin.setText(Html.fromHtml(trackable.getOrigin()), TextView.BufferType.SPANNABLE);
}
// trackable released
if (trackable.getReleased() != null) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_released));
- itemValue.setText(cgBase.formatDate(trackable.getReleased().getTime()));
- detailsList.addView(itemLayout);
+ addDetail(R.string.trackable_released, cgBase.formatDate(trackable.getReleased().getTime()));
}
// trackable distance
if (trackable.getDistance() != null) {
- itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
- itemName = (TextView) itemLayout.findViewById(R.id.name);
- itemValue = (TextView) itemLayout.findViewById(R.id.value);
-
- itemName.setText(res.getString(R.string.trackable_distance));
- itemValue.setText(cgBase.getHumanDistance(trackable.getDistance()));
- detailsList.addView(itemLayout);
+ addDetail(R.string.trackable_distance, cgBase.getHumanDistance(trackable.getDistance()));
}
// trackable goal
@@ -362,17 +307,17 @@ public class cgeotrackable extends AbstractActivity {
return;
}
+ String message;
if (StringUtils.isNotBlank(name)) {
- waitDialog = ProgressDialog.show(this, Html.fromHtml(name).toString(), res.getString(R.string.trackable_details_loading), true);
+ message = Html.fromHtml(name).toString();
} else if (StringUtils.isNotBlank(geocode)) {
- waitDialog = ProgressDialog.show(this, geocode.toUpperCase(), res.getString(R.string.trackable_details_loading), true);
+ message = geocode.toUpperCase();
} else {
- waitDialog = ProgressDialog.show(this, res.getString(R.string.trackable), res.getString(R.string.trackable_details_loading), true);
+ message = res.getString(R.string.trackable);
}
- waitDialog.setCancelable(true);
+ waitDialog = ProgressDialog.show(this, message, res.getString(R.string.trackable_details_loading), true, true);
- loadTrackable thread;
- thread = new loadTrackable(loadTrackableHandler, geocode, guid, id);
+ loadTrackable thread = new loadTrackable(loadTrackableHandler, geocode, guid, id);
thread.start();
}
@@ -427,26 +372,31 @@ public class cgeotrackable extends AbstractActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- menu.add(0, 1, 0, res.getString(R.string.trackable_log_touch)).setIcon(android.R.drawable.ic_menu_agenda); // log touch
-
- menu.add(0, 2, 0, res.getString(R.string.trackable_browser_open)).setIcon(android.R.drawable.ic_menu_info_details); // browser
+ menu.add(0, MENU_LOG_TOUCH, 0, res.getString(R.string.trackable_log_touch)).setIcon(android.R.drawable.ic_menu_agenda); // log touch
+ menu.add(0, MENU_BROWSER_TRACKABLE, 0, res.getString(R.string.trackable_browser_open)).setIcon(android.R.drawable.ic_menu_info_details); // browser
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case 1:
+ case MENU_LOG_TOUCH:
logTouch();
return true;
- case 2:
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/track/details.aspx?tracker=" + trackable.getGeocode())));
+ case MENU_BROWSER_TRACKABLE:
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(trackable.getUrl())));
return true;
}
-
return false;
}
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ menu.findItem(MENU_LOG_TOUCH).setEnabled(trackable.isLoggable());
+ menu.findItem(MENU_BROWSER_TRACKABLE).setEnabled(StringUtils.isNotBlank(trackable.getUrl()));
+ return super.onPrepareOptionsMenu(menu);
+ }
+
private class loadTrackable extends Thread {
private Handler handler = null;
@@ -471,8 +421,13 @@ public class cgeotrackable extends AbstractActivity {
@Override
public void run() {
- trackable = cgBase.searchTrackable(geocode, guid, id);
- handler.sendMessage(new Message());
+ if (trackable == null || trackable.isLoggable()) {
+ trackable = cgBase.searchTrackable(geocode, guid, id);
+ } else {
+ // for non TB trackables, we should just use what we have in the database
+ trackable = cgeoapplication.getInstance().getTrackableByGeocode(geocode);
+ }
+ handler.sendMessage(Message.obtain());
}
}
@@ -549,6 +504,18 @@ public class cgeotrackable extends AbstractActivity {
startActivity(logTouchIntent);
}
+ private TextView addDetail(int labelResourceId, String value) {
+ RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null);
+ TextView labelView = (TextView) layout.findViewById(R.id.name);
+ TextView valueView = (TextView) layout.findViewById(R.id.value);
+
+ labelView.setText(res.getString(labelResourceId));
+ valueView.setText(value);
+ detailsList.addView(layout);
+
+ return valueView;
+ }
+
private class tbIconThread extends Thread {
String url = null;
Handler handler = null;
diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java
index 9534594..06e279d 100644
--- a/main/src/cgeo/geocaching/cgeowaypoint.java
+++ b/main/src/cgeo/geocaching/cgeowaypoint.java
@@ -35,7 +35,7 @@ public class cgeowaypoint extends AbstractActivity {
private int id = -1;
private ProgressDialog waitDialog = null;
private cgGeo geo = null;
- private cgUpdateLoc geoUpdate = new update();
+ private UpdateLocationCallback geoUpdate = new update();
private Handler loadWaypointHandler = new Handler() {
@Override
@@ -279,10 +279,10 @@ public class cgeowaypoint extends AbstractActivity {
}
}
- private static class update extends cgUpdateLoc {
+ private static class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
// nothing
}
}
diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java
index eb4c01e..8d795b0 100644
--- a/main/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/main/src/cgeo/geocaching/cgeowaypointadd.java
@@ -30,7 +30,7 @@ public class cgeowaypointadd extends AbstractActivity {
private String geocode = null;
private int id = -1;
private cgGeo geo = null;
- private cgUpdateLoc geoUpdate = new update();
+ private UpdateLocationCallback geoUpdate = new update();
private ProgressDialog waitDialog = null;
private cgWaypoint waypoint = null;
private WaypointType type = WaypointType.OWN;
@@ -188,10 +188,10 @@ public class cgeowaypointadd extends AbstractActivity {
super.onPause();
}
- private class update extends cgUpdateLoc {
+ private class update implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null || geo.coordsNow == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
index b894c70..83d6487 100644
--- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
+++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java
@@ -1,6 +1,7 @@
package cgeo.geocaching.connector.opencaching;
import cgeo.geocaching.Parameters;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgImage;
@@ -20,6 +21,7 @@ import org.json.JSONObject;
import android.net.Uri;
import android.text.Html;
+import android.util.Log;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -112,8 +114,7 @@ final public class OkapiClient {
return caches;
}
} catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(Settings.tag, "OkapiClient.parseCaches", e);
}
return null;
}
@@ -173,8 +174,7 @@ final public class OkapiClient {
cache.setHidden(parseDate(response.getString(CACHE_HIDDEN)));
} catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(Settings.tag, "OkapiClient.parseCache", e);
}
return cache;
}
@@ -215,10 +215,8 @@ final public class OkapiClient {
}
result.add(log);
} catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(Settings.tag, "OkapiClient.parseLogs", e);
}
-
}
return result;
}
@@ -239,8 +237,7 @@ final public class OkapiClient {
try {
return ISO8601DATEFORMAT.parse(strippedDate);
} catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(Settings.tag, "OkapiClient.parseDate", e);
}
return null;
}
@@ -257,8 +254,7 @@ final public class OkapiClient {
try {
size = response.getDouble("size");
} catch (JSONException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(Settings.tag, "OkapiClient.getCacheSize", e);
}
switch ((int) Math.round(size)) {
case 1:
diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java
index ab3f869..a021af0 100644
--- a/main/src/cgeo/geocaching/files/GPXImporter.java
+++ b/main/src/cgeo/geocaching/files/GPXImporter.java
@@ -371,6 +371,9 @@ public class GPXImporter {
fromActivity.showShortToast(res.getString(R.string.gpx_import_canceled));
importFinished();
break;
+
+ default:
+ break;
}
}
};
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index bfdb1a9..94140e6 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -613,8 +613,11 @@ public abstract class GPXParser extends FileParser {
// waypoint.cache.travelbugs
final Element gcTBs = gcCache.getChild(nsGC, "travelbugs");
+ // waypoint.cache.travelbug
+ final Element gcTB = gcTBs.getChild(nsGC, "travelbug");
+
// waypoint.cache.travelbugs.travelbug
- gcTBs.getChild(nsGC, "travelbug").setStartElementListener(new StartElementListener() {
+ gcTB.setStartElementListener(new StartElementListener() {
@Override
public void start(Attributes attrs) {
@@ -630,9 +633,6 @@ public abstract class GPXParser extends FileParser {
}
});
- // waypoint.cache.travelbug
- final Element gcTB = gcTBs.getChild(nsGC, "travelbug");
-
gcTB.setEndElementListener(new EndElementListener() {
@Override
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java
index edfb93a..c127e89 100644
--- a/main/src/cgeo/geocaching/files/LocalStorage.java
+++ b/main/src/cgeo/geocaching/files/LocalStorage.java
@@ -180,13 +180,20 @@ public class LocalStorage {
public static boolean copy(final File source, final File destination) {
destination.getParentFile().mkdirs();
- InputStream input;
+ InputStream input = null;
OutputStream output;
try {
input = new FileInputStream(source);
output = new FileOutputStream(destination);
} catch (FileNotFoundException e) {
Log.e(Settings.tag, "LocalStorage.copy: could not open file", e);
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e1) {
+ // ignore
+ }
+ }
return false;
}
diff --git a/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java
index 94399bd..5bdc209 100644
--- a/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java
+++ b/main/src/cgeo/geocaching/go4cache/Go4CacheUser.java
@@ -26,7 +26,7 @@ public class Go4CacheUser {
public Go4CacheUser(final String username, final Geopoint coords, final Date date, final String action, final String client) {
this.username = username;
this.coords = coords;
- this.date = date;
+ this.date = new Date(date.getTime());
this.action = action;
this.client = client;
}
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 6ffdd63..f354374 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -2,14 +2,14 @@ package cgeo.geocaching.maps;
import cgeo.geocaching.R;
import cgeo.geocaching.Settings;
+import cgeo.geocaching.UpdateDirectionCallback;
+import cgeo.geocaching.UpdateLocationCallback;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgCoord;
import cgeo.geocaching.cgDirection;
import cgeo.geocaching.cgGeo;
import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgUpdateDir;
-import cgeo.geocaching.cgUpdateLoc;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.cgeocaches;
@@ -99,8 +99,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
private cgeoapplication app = null;
private cgGeo geo = null;
private cgDirection dir = null;
- private cgUpdateLoc geoUpdate = new UpdateLoc();
- private cgUpdateDir dirUpdate = new UpdateDir();
+ private UpdateLocationCallback geoUpdate = new UpdateLoc();
+ private UpdateDirectionCallback dirUpdate = new UpdateDir();
// from intent
private boolean fromDetailIntent = false;
private cgSearch searchIntent = null;
@@ -347,10 +347,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
// start location and directory services
if (geo != null) {
- geoUpdate.updateLoc(geo);
+ geoUpdate.updateLocation(geo);
}
if (dir != null) {
- dirUpdate.updateDir(dir);
+ dirUpdate.updateDirection(dir);
}
// get parameters
@@ -423,10 +423,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
dir = app.startDir(activity, dirUpdate);
}
- geoUpdate.updateLoc(geo);
+ geoUpdate.updateLocation(geo);
if (dir != null) {
- dirUpdate.updateDir(dir);
+ dirUpdate.updateDirection(dir);
}
startTimer();
@@ -524,7 +524,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
menu.add(0, MENU_MAP_LIVE, 0, res.getString(R.string.map_live_disable)).setIcon(R.drawable.ic_menu_refresh);
menu.add(0, MENU_STORE_CACHES, 0, res.getString(R.string.caches_store_offline)).setIcon(android.R.drawable.ic_menu_set_as).setEnabled(false);
- menu.add(0, MENU_TRAIL_MODE, 0, res.getString(R.string.map_trail_hide)).setIcon(android.R.drawable.ic_menu_recent_history);
+ menu.add(0, MENU_TRAIL_MODE, 0, res.getString(R.string.map_trail_hide)).setIcon(R.drawable.ic_menu_trail);
menu.add(0, MENU_CIRCLE_MODE, 0, res.getString(R.string.map_circles_hide)).setIcon(R.drawable.ic_menu_circle);
menu.add(0, MENU_AS_LIST, 0, res.getString(R.string.map_as_list)).setIcon(android.R.drawable.ic_menu_agenda);
@@ -756,10 +756,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
// class: update location
- private class UpdateLoc extends cgUpdateLoc {
+ private class UpdateLoc implements UpdateLocationCallback {
@Override
- public void updateLoc(cgGeo geo) {
+ public void updateLocation(cgGeo geo) {
if (geo == null) {
return;
}
@@ -803,10 +803,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
// class: update direction
- private class UpdateDir extends cgUpdateDir {
+ private class UpdateDir implements UpdateDirectionCallback {
@Override
- public void updateDir(cgDirection dir) {
+ public void updateDirection(cgDirection dir) {
if (dir == null || dir.directionNow == null) {
return;
}
diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java
index ca9aa05..7c02c32 100644
--- a/main/src/cgeo/geocaching/network/HtmlImage.java
+++ b/main/src/cgeo/geocaching/network/HtmlImage.java
@@ -176,7 +176,13 @@ public class HtmlImage implements Html.ImageGetter {
} else {
final String host = ConnectorFactory.getConnector(geocode).getHost();
if (StringUtils.isNotEmpty(host)) {
- return "http://" + host + url;
+ StringBuilder builder = new StringBuilder("http://");
+ builder.append(host);
+ if (!StringUtils.startsWith(url, "/")) {
+ builder.append('/');
+ }
+ builder.append(url);
+ return builder.toString();
}
}
} catch (Exception e) {
@@ -205,15 +211,13 @@ public class HtmlImage implements Html.ImageGetter {
fis = new FileInputStream(file);
BitmapFactory.decodeStream(fis, null, options);
} catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(Settings.tag, "HtmlImage.setSampleSize", e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // ignore
}
}
}