aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2011-11-29 21:41:32 +0100
committerBananeweizen <bananeweizen@gmx.de>2011-11-29 21:41:32 +0100
commit5001dbaf1f0cbd8460655fe98ff0e78da78808cb (patch)
tree6e66e3649fe69c930a76ed4585fd4395be284ca6
parentc6f8ba139da6e82c668dbc86964d99c5139fdb92 (diff)
downloadcgeo-5001dbaf1f0cbd8460655fe98ff0e78da78808cb.zip
cgeo-5001dbaf1f0cbd8460655fe98ff0e78da78808cb.tar.gz
cgeo-5001dbaf1f0cbd8460655fe98ff0e78da78808cb.tar.bz2
first refactoring of cgGeo, see #355
* removes mainly unnecessary variables and methods of cgGeo * next refactoring will remove all cgGeo/cgDirection instances in activies
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java4
-rw-r--r--main/src/cgeo/geocaching/Settings.java1
-rw-r--r--main/src/cgeo/geocaching/cgDirection.java10
-rw-r--r--main/src/cgeo/geocaching/cgGeo.java50
-rw-r--r--main/src/cgeo/geocaching/cgeo.java2
-rw-r--r--main/src/cgeo/geocaching/cgeoadvsearch.java2
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java27
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java8
-rw-r--r--main/src/cgeo/geocaching/cgeonavigate.java4
-rw-r--r--main/src/cgeo/geocaching/cgeopoint.java2
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java2
-rw-r--r--main/src/cgeo/geocaching/cgeowaypoint.java4
-rw-r--r--main/src/cgeo/geocaching/cgeowaypointadd.java4
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java10
14 files changed, 41 insertions, 89 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index aecf46b..8e06636 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -148,7 +148,7 @@ public class CacheDetailActivity extends AbstractActivity {
setTitle(res.getString(R.string.cache));
if (geolocation == null) {
- geolocation = app.startGeo(this, locationUpdater, 0, 0);
+ geolocation = app.startGeo(locationUpdater);
}
String geocode = null;
@@ -261,7 +261,7 @@ public class CacheDetailActivity extends AbstractActivity {
super.onResume();
if (geolocation == null) {
- geolocation = app.startGeo(this, locationUpdater, 0, 0);
+ geolocation = app.startGeo(locationUpdater);
}
if (refreshOnResume) {
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java
index aa5b659..7218d50 100644
--- a/main/src/cgeo/geocaching/Settings.java
+++ b/main/src/cgeo/geocaching/Settings.java
@@ -833,5 +833,4 @@ public final class Settings {
public static int getVersion() {
return sharedPrefs.getInt(KEY_VERSION, 0);
}
-
}
diff --git a/main/src/cgeo/geocaching/cgDirection.java b/main/src/cgeo/geocaching/cgDirection.java
index 7b1ad60..7eeceb4 100644
--- a/main/src/cgeo/geocaching/cgDirection.java
+++ b/main/src/cgeo/geocaching/cgDirection.java
@@ -10,7 +10,6 @@ import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
public class cgDirection {
- private cgDirection dir = null;
private Context context = null;
private SensorManager sensorManager = null;
private cgeoSensorListener sensorListener = null;
@@ -22,11 +21,10 @@ public class cgDirection {
context = contextIn;
dirUpdate = dirUpdateIn;
sensorListener = new cgeoSensorListener();
+ initDir();
}
- public void initDir() {
- dir = this;
-
+ private void initDir() {
if (sensorManager == null) {
sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
}
@@ -43,7 +41,7 @@ public class cgDirection {
dirUpdate = dirUpdateIn;
if (dirUpdate != null && directionNow != null) {
- dirUpdate.updateDir(dir);
+ dirUpdate.updateDir(this);
}
}
@@ -68,7 +66,7 @@ public class cgDirection {
directionNow = Compatibility.getDirectionNow(event.values[0], (Activity) context);
if (dirUpdate != null && directionNow != null) {
- dirUpdate.updateDir(dir);
+ dirUpdate.updateDir(cgDirection.this);
}
}
}
diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java
index 828a31e..3384e04 100644
--- a/main/src/cgeo/geocaching/cgGeo.java
+++ b/main/src/cgeo/geocaching/cgGeo.java
@@ -5,7 +5,6 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.go4cache.Go4Cache;
import android.content.Context;
-import android.content.SharedPreferences;
import android.location.GpsSatellite;
import android.location.GpsStatus;
import android.location.Location;
@@ -18,16 +17,11 @@ import java.util.Iterator;
public class cgGeo {
- private Context context = null;
- private cgeoapplication app = null;
private LocationManager geoManager = null;
private cgUpdateLoc geoUpdate = null;
- private SharedPreferences prefs = null;
private cgeoGeoListener geoNetListener = null;
private cgeoGeoListener geoGpsListener = null;
private cgeoGpsStatusListener geoGpsStatusListener = null;
- private Integer time = 0;
- private Integer distance = 0;
private Location locGps = null;
private Location locNet = null;
private long locGpsLast = 0L;
@@ -41,29 +35,9 @@ public class cgGeo {
public Float accuracyNow = null;
public Integer satellitesVisible = null;
public Integer satellitesFixed = null;
- public double distanceNow = 0d;
- public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, int timeIn, int distanceIn) {
- context = contextIn;
- app = appIn;
+ public cgGeo(cgUpdateLoc geoUpdateIn) {
geoUpdate = geoUpdateIn;
- time = timeIn;
- distance = distanceIn;
-
- if (prefs == null) {
- prefs = context.getSharedPreferences(Settings.preferences, 0);
- }
- distanceNow = prefs.getFloat("dst", 0f);
- if (Double.isNaN(distanceNow)) {
- distanceNow = 0d;
- }
- if (distanceNow == 0f) {
- final SharedPreferences.Editor prefsEdit = context.getSharedPreferences(Settings.preferences, 0).edit();
- if (prefsEdit != null) {
- prefsEdit.putLong("dst-since", System.currentTimeMillis());
- prefsEdit.commit();
- }
- }
geoNetListener = new cgeoGeoListener();
geoNetListener.setProvider(LocationManager.NETWORK_PROVIDER);
@@ -72,9 +46,11 @@ public class cgGeo {
geoGpsListener.setProvider(LocationManager.GPS_PROVIDER);
geoGpsStatusListener = new cgeoGpsStatusListener();
+
+ initGeo();
}
- public void initGeo() {
+ private void initGeo() {
location = null;
locationProvider = LocationProviderType.LAST;
coordsNow = null;
@@ -86,7 +62,7 @@ public class cgGeo {
satellitesFixed = 0;
if (geoManager == null) {
- geoManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
+ geoManager = (LocationManager) cgeoapplication.getInstance().getSystemService(Context.LOCATION_SERVICE);
}
lastLoc();
@@ -96,13 +72,13 @@ public class cgGeo {
geoManager.addGpsStatusListener(geoGpsStatusListener);
try {
- geoManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, geoNetListener);
+ geoManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, geoNetListener);
} catch (Exception e) {
Log.w(Settings.tag, "There is no NETWORK location provider");
}
try {
- geoManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, time, distance, geoGpsListener);
+ geoManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, geoGpsListener);
} catch (Exception e) {
Log.w(Settings.tag, "There is no GPS location provider");
}
@@ -118,12 +94,6 @@ public class cgGeo {
if (geoManager != null) {
geoManager.removeGpsStatusListener(geoGpsStatusListener);
}
-
- final SharedPreferences.Editor prefsEdit = context.getSharedPreferences(Settings.preferences, 0).edit();
- if (prefsEdit != null && !Double.isNaN(distanceNow)) {
- prefsEdit.putFloat("dst", (float) distanceNow);
- prefsEdit.commit();
- }
}
public void replaceUpdate(cgUpdateLoc geoUpdateIn) {
@@ -309,7 +279,7 @@ public class cgGeo {
}
coordsNow = new Geopoint(location.getLatitude(), location.getLongitude());
- app.setLastLoc(coordsNow);
+ cgeoapplication.getInstance().setLastCoords(coordsNow);
if (location.hasAltitude() && locationProvider != LocationProviderType.LAST) {
altitudeNow = location.getAltitude() + Settings.getAltCorrection();
@@ -338,8 +308,6 @@ public class cgGeo {
final float dst = coordsBefore.distanceTo(coordsNow);
if (dst > 0.005) {
- distanceNow += dst;
-
coordsBefore = coordsNow;
}
} else if (coordsBefore == null) { // values aren't initialized
@@ -357,7 +325,7 @@ public class cgGeo {
}
public void lastLoc() {
- assign(app.getLastCoords());
+ assign(cgeoapplication.getInstance().getLastCoords());
Location lastGps = geoManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index b5901f1..00cc877 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -449,7 +449,7 @@ public class cgeo extends AbstractActivity {
(new cleanDatabase()).start();
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
navType = (TextView) findViewById(R.id.nav_type);
diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java
index 90f0402..b7a8458 100644
--- a/main/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/main/src/cgeo/geocaching/cgeoadvsearch.java
@@ -144,7 +144,7 @@ public class cgeoadvsearch extends AbstractActivity {
Settings.getLogin();
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
((Button) findViewById(R.id.buttonLatitude)).setOnClickListener(new findByCoordsAction());
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index 110766f..cabf2de 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -65,15 +65,8 @@ public class cgeoapplication extends Application {
public void onTerminate() {
Log.d(Settings.tag, "Terminating c:geo...");
- if (geo != null) {
- geo.closeGeo();
- geo = null;
- }
-
- if (dir != null) {
- dir.closeDir();
- dir = null;
- }
+ cleanGeo();
+ cleanDir();
if (storage != null) {
storage.clean();
@@ -140,10 +133,9 @@ public class cgeoapplication extends Application {
return storage.status();
}
- public cgGeo startGeo(Context context, cgUpdateLoc geoUpdate, int time, int distance) {
+ public cgGeo startGeo(cgUpdateLoc geoUpdate) {
if (geo == null) {
- geo = new cgGeo(context, this, geoUpdate, time, distance);
- geo.initGeo();
+ geo = new cgGeo(geoUpdate);
Log.i(Settings.tag, "Location service started");
}
@@ -176,9 +168,7 @@ public class cgeoapplication extends Application {
}
if (!geoInUse && geo != null) {
- geo.closeGeo();
- geo = null;
-
+ cleanGeo();
Log.i(Settings.tag, "Location service stopped");
}
}
@@ -187,7 +177,6 @@ public class cgeoapplication extends Application {
public cgDirection startDir(Context context, cgUpdateDir dirUpdate) {
if (dir == null) {
dir = new cgDirection(context, dirUpdate);
- dir.initDir();
Log.i(Settings.tag, "Direction service started");
}
@@ -220,9 +209,7 @@ public class cgeoapplication extends Application {
}
if (!dirInUse && dir != null) {
- dir.closeDir();
- dir = null;
-
+ cleanDir();
Log.i(Settings.tag, "Direction service stopped");
}
}
@@ -667,7 +654,7 @@ public class cgeoapplication extends Application {
return storage.saveLogs(geocode, list, false);
}
- public void setLastLoc(final Geopoint coords) {
+ public void setLastCoords(final Geopoint coords) {
lastCoords = coords;
}
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index f2fff10..381c386 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -377,7 +377,7 @@ public class cgeocaches extends AbstractListActivity {
}
if (geo == null) {
- geo = app.startGeo(cgeocaches.this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(cgeocaches.this, dirUpdate);
@@ -1462,7 +1462,7 @@ public class cgeocaches extends AbstractListActivity {
private void init() {
// sensor & geolocation manager
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(this, dirUpdate);
@@ -1515,7 +1515,7 @@ public class cgeocaches extends AbstractListActivity {
}
if (geo == null) {
- geo = app.startGeo(cgeocaches.this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(cgeocaches.this, dirUpdate);
@@ -1671,7 +1671,7 @@ public class cgeocaches extends AbstractListActivity {
}
if (geo == null) {
- geo = app.startGeo(cgeocaches.this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(cgeocaches.this, dirUpdate);
diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java
index 0a3b1a1..9b0e653 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -81,7 +81,7 @@ public class cgeonavigate extends AbstractActivity {
// sensor & geolocation manager
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(this, dirUpdate);
@@ -139,7 +139,7 @@ public class cgeonavigate extends AbstractActivity {
// sensor & geolocation manager
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(this, dirUpdate);
diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java
index c33de0c..e1d69b7 100644
--- a/main/src/cgeo/geocaching/cgeopoint.java
+++ b/main/src/cgeo/geocaching/cgeopoint.java
@@ -258,7 +258,7 @@ public class cgeopoint extends AbstractActivity {
private void init() {
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
latButton = (Button) findViewById(R.id.buttonLatitude);
diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java
index 2820448..56c3e55 100644
--- a/main/src/cgeo/geocaching/cgeopopup.java
+++ b/main/src/cgeo/geocaching/cgeopopup.java
@@ -196,7 +196,7 @@ public class cgeopopup extends AbstractActivity {
private void init() {
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
app.setAction(geocode);
diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java
index ec2547e..9534594 100644
--- a/main/src/cgeo/geocaching/cgeowaypoint.java
+++ b/main/src/cgeo/geocaching/cgeowaypoint.java
@@ -156,7 +156,7 @@ public class cgeowaypoint extends AbstractActivity {
}
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
@@ -171,7 +171,7 @@ public class cgeowaypoint extends AbstractActivity {
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (waitDialog == null) {
diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java
index a9bf9e8..eb4c01e 100644
--- a/main/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/main/src/cgeo/geocaching/cgeowaypointadd.java
@@ -91,7 +91,7 @@ public class cgeowaypointadd extends AbstractActivity {
setTitle("waypoint");
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
// get parameters
@@ -148,7 +148,7 @@ public class cgeowaypointadd extends AbstractActivity {
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (id > 0) {
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index c93c532..6ffdd63 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -242,7 +242,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
@@ -257,7 +257,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
@@ -307,7 +307,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
ActivityMixin.setTitle(activity, res.getString(R.string.map_map));
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
@@ -417,7 +417,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
app.setAction(StringUtils.defaultIfBlank(geocodeIntent, null));
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
@@ -642,7 +642,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, 0, 0);
+ geo = app.startGeo(geoUpdate);
}
if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);