aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2012-02-17 18:13:02 +0100
committerBananeweizen <Bananeweizen@gmx.de>2012-02-17 18:13:02 +0100
commit5241b730a8a3d3650b9b6f0352f74c090e258afe (patch)
treee81d968c2c4de4a5f66109c158d6e92a7f624049 /main/src/cgeo/geocaching
parent9649d1c0fc401be51432c7e23943c5cb40679954 (diff)
downloadcgeo-5241b730a8a3d3650b9b6f0352f74c090e258afe.zip
cgeo-5241b730a8a3d3650b9b6f0352f74c090e258afe.tar.gz
cgeo-5241b730a8a3d3650b9b6f0352f74c090e258afe.tar.bz2
refactoring: remove reflection from compatibility package
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8.java6
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java14
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java9
-rw-r--r--main/src/cgeo/geocaching/compatibility/Compatibility.java30
4 files changed, 34 insertions, 25 deletions
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
index 259cb5c..6d01e55 100644
--- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
@@ -7,14 +7,14 @@ import android.app.backup.BackupManager;
import android.util.Log;
import android.view.Display;
-public class AndroidLevel8 {
+public class AndroidLevel8 implements AndroidLevel8Interface {
- static public int getRotation(final Activity activity) {
+ public int getRotation(final Activity activity) {
Display display = activity.getWindowManager().getDefaultDisplay();
return display.getRotation();
}
- static public void dataChanged(final String name) {
+ public void dataChanged(final String name) {
Log.i(Settings.tag, "Requesting settings backup with settings manager");
BackupManager.dataChanged(name);
}
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java
new file mode 100644
index 0000000..664b55b
--- /dev/null
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java
@@ -0,0 +1,14 @@
+package cgeo.geocaching.compatibility;
+
+import android.app.Activity;
+
+public class AndroidLevel8Dummy implements AndroidLevel8Interface {
+
+ public int getRotation(final Activity activity) {
+ return 0;
+ }
+
+ public void dataChanged(final String name) {
+ // do nothing
+ }
+}
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java
new file mode 100644
index 0000000..b1c4f81
--- /dev/null
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java
@@ -0,0 +1,9 @@
+package cgeo.geocaching.compatibility;
+
+import android.app.Activity;
+
+public interface AndroidLevel8Interface {
+ public int getRotation(final Activity activity);
+ public void dataChanged(final String name);
+
+} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java
index b6d1061..409f837 100644
--- a/main/src/cgeo/geocaching/compatibility/Compatibility.java
+++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java
@@ -14,28 +14,21 @@ import android.view.Display;
import android.view.Surface;
import android.widget.EditText;
-import java.lang.reflect.Method;
-
public final class Compatibility {
private final static int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
private final static boolean isLevel8 = sdkVersion >= 8;
private final static boolean isLevel5 = sdkVersion >= 5;
- private static Method dataChangedMethod = null;
- private static Method getRotationMethod = null;
- private static AndroidLevel11Interface level11;
+ private final static AndroidLevel8Interface level8;
+ private final static AndroidLevel11Interface level11;
static {
if (isLevel8) {
- try {
- final Class<?> cl = Class.forName("cgeo.geocaching.compatibility.AndroidLevel8");
- dataChangedMethod = cl.getDeclaredMethod("dataChanged", String.class);
- getRotationMethod = cl.getDeclaredMethod("getRotation", Activity.class);
- } catch (final Exception e) {
- // Exception can be ClassNotFoundException, SecurityException or NoSuchMethodException
- Log.e(Settings.tag, "Cannot load AndroidLevel8 class", e);
- }
+ level8 = new AndroidLevel8();
+ }
+ else {
+ level8 = new AndroidLevel8Dummy();
}
if (sdkVersion >= 11) {
level11 = new AndroidLevel11();
@@ -49,7 +42,7 @@ public final class Compatibility {
final Activity activity) {
if (isLevel8) {
try {
- final int rotation = (Integer) getRotationMethod.invoke(null, activity);
+ final int rotation = level8.getRotation(activity);
if (rotation == Surface.ROTATION_90) {
return directionNowPre + 90;
} else if (rotation == Surface.ROTATION_180) {
@@ -81,14 +74,7 @@ public final class Compatibility {
}
public static void dataChanged(final String name) {
- if (isLevel8) {
- try {
- dataChangedMethod.invoke(null, name);
- } catch (final Exception e) {
- // This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException
- Log.e(Settings.tag, "Cannot call dataChanged()", e);
- }
- }
+ level8.dataChanged(name);
}
public static void disableSuggestions(EditText edit) {