aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2014-05-17 06:17:42 +0200
committerBananeweizen <bananeweizen@gmx.de>2014-05-17 06:17:42 +0200
commit7bf8d33c30e731fe7728bc9275a84919718b334d (patch)
treeb8aaa0c60b06bfb5229b527b486ccdb7148b034a
parentf1ce7876f01fceed22b51e1576b75042daf8d18c (diff)
downloadcgeo-7bf8d33c30e731fe7728bc9275a84919718b334d.zip
cgeo-7bf8d33c30e731fe7728bc9275a84919718b334d.tar.gz
cgeo-7bf8d33c30e731fe7728bc9275a84919718b334d.tar.bz2
minor code cleanups
-rw-r--r--main/src/cgeo/calendar/CalendarAddon.java5
-rw-r--r--main/src/cgeo/contacts/ContactsAddon.java5
-rw-r--r--main/src/cgeo/geocaching/Geocache.java3
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java4
-rw-r--r--main/src/cgeo/geocaching/compatibility/Compatibility.java28
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java24
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java1
-rw-r--r--main/src/cgeo/geocaching/connector/gc/IconDecoder.java2
-rw-r--r--main/src/cgeo/geocaching/connector/gc/Tile.java5
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java11
-rw-r--r--main/src/cgeo/geocaching/sensors/DirectionProvider.java40
11 files changed, 57 insertions, 71 deletions
diff --git a/main/src/cgeo/calendar/CalendarAddon.java b/main/src/cgeo/calendar/CalendarAddon.java
index 117fb9a..4a672fa 100644
--- a/main/src/cgeo/calendar/CalendarAddon.java
+++ b/main/src/cgeo/calendar/CalendarAddon.java
@@ -18,6 +18,11 @@ import android.net.Uri;
import java.util.Date;
public class CalendarAddon {
+
+ private CalendarAddon() {
+ // utility class
+ }
+
public static boolean isAvailable() {
return ProcessUtils.isIntentAvailable(ICalendar.INTENT, Uri.parse(ICalendar.URI_SCHEME + "://" + ICalendar.URI_HOST));
}
diff --git a/main/src/cgeo/contacts/ContactsAddon.java b/main/src/cgeo/contacts/ContactsAddon.java
index f2498ea..7165a77 100644
--- a/main/src/cgeo/contacts/ContactsAddon.java
+++ b/main/src/cgeo/contacts/ContactsAddon.java
@@ -8,6 +8,11 @@ import android.content.Intent;
import android.net.Uri;
public class ContactsAddon {
+
+ private ContactsAddon() {
+ // utility class
+ }
+
public static void openContactCard(Activity context, String userName) {
final Parameters params = new Parameters(
IContacts.PARAM_NAME, userName
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 8836115..a88ceca 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -35,6 +35,7 @@ import cgeo.geocaching.utils.MatcherWrapper;
import cgeo.geocaching.utils.UncertainProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.collections4.Predicate;
@@ -43,6 +44,7 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+
import rx.Scheduler;
import rx.Subscription;
import rx.functions.Action0;
@@ -157,7 +159,6 @@ public class Geocache implements ICache, IWaypoint {
private final EnumSet<StorageLocation> storageLocation = EnumSet.of(StorageLocation.HEAP);
private boolean finalDefined = false;
private boolean logPasswordRequired = false;
- // private int zoomlevel = Tile.ZOOMLEVEL_MIN - 1;
private static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+");
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java
index da988aa..024bf37 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigonApp.java
@@ -23,8 +23,8 @@ class NavigonApp extends AbstractPointNavigationApp {
/*
* Long/Lat are float values in decimal degree format (+-DDD.DDDDD).
* Example:
- * intent.putExtra(INTENT_EXTRA_KEY_LATITUDE, 46.12345f);
- * intent.putExtra(INTENT_EXTRA_KEY_LONGITUDE, 23.12345f);
+ * intent.putExtra(INTENT_EXTRA_KEY_LATITUDE, 46.12345f)
+ * intent.putExtra(INTENT_EXTRA_KEY_LONGITUDE, 23.12345f)
*/
intent.putExtra(INTENT_EXTRA_KEY_LATITUDE, (float) point.getLatitude());
intent.putExtra(INTENT_EXTRA_KEY_LONGITUDE, (float) point.getLongitude());
diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java
index a293cfd..887bb32 100644
--- a/main/src/cgeo/geocaching/compatibility/Compatibility.java
+++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java
@@ -8,35 +8,39 @@ import android.os.Build;
public final class Compatibility {
- private final static int sdkVersion = Build.VERSION.SDK_INT;
+ private static final int SDK_VERSION = Build.VERSION.SDK_INT;
- private final static AndroidLevel11Interface level11;
- private final static AndroidLevel13Interface level13;
- private final static AndroidLevel19Interface level19;
+ private static final AndroidLevel11Interface LEVEL_11;
+ private static final AndroidLevel13Interface LEVEL_13;
+ private static final AndroidLevel19Interface LEVEL_19;
static {
- level11 = sdkVersion >= 11 ? new AndroidLevel11() : new AndroidLevel11Emulation();
- level13 = sdkVersion >= 13 ? new AndroidLevel13() : new AndroidLevel13Emulation();
- level19 = sdkVersion >= 19 ? new AndroidLevel19() : new AndroidLevel19Emulation();
+ LEVEL_11 = SDK_VERSION >= 11 ? new AndroidLevel11() : new AndroidLevel11Emulation();
+ LEVEL_13 = SDK_VERSION >= 13 ? new AndroidLevel13() : new AndroidLevel13Emulation();
+ LEVEL_19 = SDK_VERSION >= 19 ? new AndroidLevel19() : new AndroidLevel19Emulation();
+ }
+
+ private Compatibility() {
+ // utility class
}
public static void invalidateOptionsMenu(final Activity activity) {
- level11.invalidateOptionsMenu(activity);
+ LEVEL_11.invalidateOptionsMenu(activity);
}
public static int getDisplayWidth() {
- return level13.getDisplayWidth();
+ return LEVEL_13.getDisplayWidth();
}
public static Point getDisplaySize() {
- return level13.getDisplaySize();
+ return LEVEL_13.getDisplaySize();
}
public static void importGpxFromStorageAccessFramework(final @NonNull Activity activity, int requestCodeImportGpx) {
- level19.importGpxFromStorageAccessFramework(activity, requestCodeImportGpx);
+ LEVEL_19.importGpxFromStorageAccessFramework(activity, requestCodeImportGpx);
}
public static boolean isStorageAccessFrameworkAvailable() {
- return sdkVersion >= 19;
+ return SDK_VERSION >= 19;
}
}
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index dc2408f..dd81507 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -146,30 +146,6 @@ public class GCMap {
throw new JSONException("No data inside JSON");
}
- /*
- * Optimization: the grid can get ignored. The keys are the grid position in the format x_y
- * It's not used at the moment due to optimizations
- * But maybe we need it some day...
- *
- * // attach all keys with the cache positions in the tile
- * Map<String, UTFGridPosition> keyPositions = new HashMap<String, UTFGridPosition>(); // JSON key, (x/y) in
- * grid
- * for (int y = 0; y < grid.length(); y++) {
- * String rowUTF8 = grid.getString(y);
- * if (rowUTF8.length() != (UTFGrid.GRID_MAXX + 1)) {
- * throw new JSONException("Grid has wrong size");
- * }
- *
- * for (int x = 0; x < UTFGrid.GRID_MAXX; x++) {
- * char c = rowUTF8.charAt(x);
- * if (c != ' ') {
- * short id = UTFGrid.getUTFGridId(c);
- * keyPositions.put(keys.getString(id), new UTFGridPosition(x, y));
- * }
- * }
- * }
- */
-
// iterate over the data and construct all caches in this tile
Map<String, List<UTFGridPosition>> positions = new HashMap<String, List<UTFGridPosition>>(); // JSON id as key
Map<String, List<UTFGridPosition>> singlePositions = new HashMap<String, List<UTFGridPosition>>(); // JSON id as key
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index 4d3580c..4ae03bf 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -144,7 +144,6 @@ public abstract class GCParser {
while (matcherGuidAndDisabled.find()) {
if (matcherGuidAndDisabled.groupCount() > 0) {
- //cache.setGuid(matcherGuidAndDisabled.group(1));
if (matcherGuidAndDisabled.group(2) != null) {
cache.setName(Html.fromHtml(matcherGuidAndDisabled.group(2).trim()).toString());
}
diff --git a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
index c7b470a..c6a2afc 100644
--- a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
+++ b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java
@@ -35,7 +35,7 @@ public abstract class IconDecoder {
return false; //out of image position
}
- int numberOfDetections = 7; //for level 12 and 13;
+ int numberOfDetections = 7; //for level 12 and 13
if (zoomlevel < 12) {
numberOfDetections = 5;
}
diff --git a/main/src/cgeo/geocaching/connector/gc/Tile.java b/main/src/cgeo/geocaching/connector/gc/Tile.java
index ca70111..d7b3a48 100644
--- a/main/src/cgeo/geocaching/connector/gc/Tile.java
+++ b/main/src/cgeo/geocaching/connector/gc/Tile.java
@@ -9,6 +9,7 @@ import cgeo.geocaching.utils.LeastRecentlyUsedSet;
import cgeo.geocaching.utils.Log;
import ch.boye.httpclientandroidlib.HttpResponse;
+
import org.eclipse.jdt.annotation.NonNull;
import android.graphics.Bitmap;
@@ -88,10 +89,6 @@ public class Tile {
*
*/
private static int calcY(final Geopoint origin, final int zoomlevel) {
-
- // double latRad = Math.toRadians(origin.getLatitude());
- // return (int) ((1 - (Math.log(Math.tan(latRad) + (1 / Math.cos(latRad))) / Math.PI)) / 2 * numberOfTiles);
-
// Optimization from Bing
double sinLatRad = Math.sin(Math.toRadians(origin.getLatitude()));
// The cut of the fractional part instead of rounding to the nearest integer is intentional and part of the algorithm
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index 1655343..bb34114 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -556,15 +556,14 @@ public final class Geopoint implements ICoordinates, Parcelable {
* Gets distance in meters (workaround for 4.2.1 JIT bug).
*/
public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
- double earthRadius = 6372.8; // for haversine use R = 6372.8 km instead of 6371 km
+ // for haversine use R = 6372.8 km instead of 6371 km
+ double earthRadius = 6372.8;
double dLat = toRadians(lat2 - lat1);
double dLon = toRadians(lon2 - lon1);
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
- //double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
- //return R * c * 1000;
- // simplify haversine:
+ // simplify haversine
return (2 * earthRadius * 1000 * Math.asin(Math.sqrt(a)));
}
@@ -582,8 +581,8 @@ public final class Geopoint implements ICoordinates, Parcelable {
}
/**
- * Check whether a lo bngitudeuilt from user supplied data is valid. We accept both E180/W180.
- *
+ * Check whether a longitude from user supplied data is valid. We accept both E180/W180.
+ *
* @return <tt>true</tt> if the longitude looks valid, <tt>false</tt> otherwise
*/
public static boolean isValidLongitude(final double longitude) {
diff --git a/main/src/cgeo/geocaching/sensors/DirectionProvider.java b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
index 13fcc82..ed5d76a 100644
--- a/main/src/cgeo/geocaching/sensors/DirectionProvider.java
+++ b/main/src/cgeo/geocaching/sensors/DirectionProvider.java
@@ -21,9 +21,13 @@ import android.view.WindowManager;
public class DirectionProvider {
- private static final BehaviorSubject<Float> subject = BehaviorSubject.create(0.0f);
+ private static final BehaviorSubject<Float> SUBJECT = BehaviorSubject.create(0.0f);
- private static final WindowManager windowManager = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
+ private static final WindowManager WINDOW_MANAGER = (WindowManager) CgeoApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
+
+ private DirectionProvider() {
+ // utility class
+ }
static class Listener implements SensorEventListener, StartableHandlerThread.Callback {
@@ -33,22 +37,17 @@ public class DirectionProvider {
@Override
public void onSensorChanged(final SensorEvent event) {
- subject.onNext(event.values[0]);
+ SUBJECT.onNext(event.values[0]);
}
@Override
public void onAccuracyChanged(final Sensor sensor, final int accuracy) {
- /*
- * There is a bug in Android, which apparently causes this method to be called every
- * time the sensor _value_ changed, even if the _accuracy_ did not change. So logging
- * this event leads to the log being flooded with multiple entries _per second_,
- * which I experienced when running cgeo in a building (with GPS and network being
- * unreliable).
- *
- * See for example https://code.google.com/p/android/issues/detail?id=14792
- */
-
- //Log.i(Settings.tag, "Compass' accuracy is low (" + accuracy + ")");
+ /*
+ * There is a bug in Android, which apparently causes this method to be called every
+ * time the sensor _value_ changed, even if the _accuracy_ did not change. Do not have any code in here.
+ *
+ * See for example https://code.google.com/p/android/issues/detail?id=14792
+ */
}
@Override
@@ -99,18 +98,19 @@ public class DirectionProvider {
}
- private static final StartableHandlerThread handlerThread =
+ private static final StartableHandlerThread HANDLER_THREAD =
new StartableHandlerThread("DirectionProvider thread", Process.THREAD_PRIORITY_BACKGROUND, new Listener());
static {
- handlerThread.start();
+ HANDLER_THREAD.start();
}
- static public Observable<Float> create(final Context context) {
+
+ public static Observable<Float> create(final Context context) {
return Observable.create(new OnSubscribe<Float>() {
@Override
public void call(final Subscriber<? super Float> subscriber) {
- handlerThread.start(subscriber, context);
- subject.subscribe(subscriber);
+ HANDLER_THREAD.start(subscriber, context);
+ SUBJECT.subscribe(subscriber);
}
});
}
@@ -131,7 +131,7 @@ public class DirectionProvider {
}
private static int getRotationOffset() {
- switch (windowManager.getDefaultDisplay().getRotation()) {
+ switch (WINDOW_MANAGER.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
return 90;
case Surface.ROTATION_180: