diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2012-11-19 07:15:47 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2012-11-19 07:15:47 +0100 |
| commit | c49a772303401f6996ce7b80899f167310193a14 (patch) | |
| tree | d017a0357c5c6d51b4b39041cbd9fcd759b44397 /main/src/cgeo/geocaching/compatibility | |
| parent | 095423b24064c35037d4b7d6aea423b1652f7a82 (diff) | |
| download | cgeo-c49a772303401f6996ce7b80899f167310193a14.zip cgeo-c49a772303401f6996ce7b80899f167310193a14.tar.gz cgeo-c49a772303401f6996ce7b80899f167310193a14.tar.bz2 | |
#2083: target level 17 changes
* set level 17 as target in manifest (level 4 still supported)
* refactor compatibility classes
* move deprecated code into compatibility classes
Diffstat (limited to 'main/src/cgeo/geocaching/compatibility')
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel11Emulation.java (renamed from main/src/cgeo/geocaching/compatibility/AndroidLevel11Dummy.java) | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel13.java | 31 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java | 33 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel8.java | 20 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java | 16 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java | 30 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java | 1 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/compatibility/Compatibility.java | 51 |
9 files changed, 151 insertions, 46 deletions
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel11Dummy.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel11Emulation.java index 9c2bb8c..6a23ed5 100644 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel11Dummy.java +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel11Emulation.java @@ -3,9 +3,9 @@ package cgeo.geocaching.compatibility; import android.app.Activity; /** - * dummy class which has no functionality in the level 11 API + * implement level 11 API using older methods */ -public class AndroidLevel11Dummy implements AndroidLevel11Interface { +public class AndroidLevel11Emulation implements AndroidLevel11Interface { @Override public void invalidateOptionsMenu(final Activity activity) { diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java new file mode 100644 index 0000000..4eac205 --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel13.java @@ -0,0 +1,31 @@ +package cgeo.geocaching.compatibility; + +import cgeo.geocaching.cgeoapplication; + +import android.annotation.TargetApi; +import android.content.Context; +import android.graphics.Point; +import android.view.WindowManager; + +@TargetApi(value = 13) +public class AndroidLevel13 implements AndroidLevel13Interface { + + @Override + public int getDisplayWidth() { + return getDisplaySize().x; + } + + @Override + public Point getDisplaySize() { + Point dimensions = new Point(); + ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)) + .getDefaultDisplay().getSize(dimensions); + return dimensions; + } + + @Override + public int getDisplayHeight() { + return getDisplaySize().y; + } + +} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java new file mode 100644 index 0000000..2257d83 --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Emulation.java @@ -0,0 +1,33 @@ +package cgeo.geocaching.compatibility; + +import cgeo.geocaching.cgeoapplication; + +import android.content.Context; +import android.graphics.Point; +import android.view.Display; +import android.view.WindowManager; + +@SuppressWarnings("deprecation") +public class AndroidLevel13Emulation implements AndroidLevel13Interface { + + @Override + public int getDisplayWidth() { + return getDisplay().getWidth(); + } + + @Override + public int getDisplayHeight() { + return getDisplay().getHeight(); + } + + @Override + public Point getDisplaySize() { + final Display display = getDisplay(); + return new Point(display.getWidth(), display.getHeight()); + } + + private static Display getDisplay() { + return ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)) + .getDefaultDisplay(); + } +} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java new file mode 100644 index 0000000..f4e1975 --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel13Interface.java @@ -0,0 +1,11 @@ +package cgeo.geocaching.compatibility; + +import android.graphics.Point; + +public interface AndroidLevel13Interface { + int getDisplayWidth(); + + int getDisplayHeight(); + + Point getDisplaySize(); +} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java index ea5a795..a388adb 100644 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java @@ -6,6 +6,7 @@ import android.annotation.TargetApi; import android.app.Activity; import android.app.backup.BackupManager; import android.view.Display; +import android.view.Surface; @TargetApi(8) public class AndroidLevel8 implements AndroidLevel8Interface { @@ -21,4 +22,23 @@ public class AndroidLevel8 implements AndroidLevel8Interface { Log.i("Requesting settings backup with settings manager"); BackupManager.dataChanged(name); } + + @Override + public int getRotationOffset(final Activity activity) { + try { + final int rotation = getRotation(activity); + if (rotation == Surface.ROTATION_90) { + return 90; + } else if (rotation == Surface.ROTATION_180) { + return 180; + } else if (rotation == Surface.ROTATION_270) { + return 270; + } + } catch (final Exception e) { + // This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException + Log.e("Cannot call getRotation()", e); + } + + return 0; + } } diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java deleted file mode 100644 index d0ab911..0000000 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Dummy.java +++ /dev/null @@ -1,16 +0,0 @@ -package cgeo.geocaching.compatibility; - -import android.app.Activity; - -public class AndroidLevel8Dummy implements AndroidLevel8Interface { - - @Override - public int getRotation(final Activity activity) { - return 0; - } - - @Override - public void dataChanged(final String name) { - // do nothing - } -} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java new file mode 100644 index 0000000..197993d --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java @@ -0,0 +1,30 @@ +package cgeo.geocaching.compatibility; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.res.Configuration; +import android.view.Display; + +@TargetApi(value = 7) +public class AndroidLevel8Emulation implements AndroidLevel8Interface { + + @Override + public int getRotation(final Activity activity) { + return 0; + } + + @Override + public void dataChanged(final String name) { + // do nothing + } + + @Override + public int getRotationOffset(Activity activity) { + final Display display = activity.getWindowManager().getDefaultDisplay(); + final int rotation = display.getOrientation(); + if (rotation == Configuration.ORIENTATION_LANDSCAPE) { + return 90; + } + return 0; + } +} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java index b1c4f81..761c23a 100644 --- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java @@ -6,4 +6,5 @@ public interface AndroidLevel8Interface { public int getRotation(final Activity activity); public void dataChanged(final String name); + public int getRotationOffset(final Activity activity); }
\ 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 0821655..05a3331 100644 --- a/main/src/cgeo/geocaching/compatibility/Compatibility.java +++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java @@ -8,11 +8,9 @@ import org.apache.commons.lang3.reflect.MethodUtils; import android.app.Activity; import android.content.Intent; -import android.content.res.Configuration; +import android.graphics.Point; import android.os.Build; import android.text.InputType; -import android.view.Display; -import android.view.Surface; import android.widget.EditText; public final class Compatibility { @@ -23,19 +21,26 @@ public final class Compatibility { private final static AndroidLevel8Interface level8; private final static AndroidLevel11Interface level11; + private final static AndroidLevel13Interface level13; static { if (isLevel8) { level8 = new AndroidLevel8(); } else { - level8 = new AndroidLevel8Dummy(); + level8 = new AndroidLevel8Emulation(); } if (sdkVersion >= 11) { level11 = new AndroidLevel11(); } else { - level11 = new AndroidLevel11Dummy(); + level11 = new AndroidLevel11Emulation(); + } + if (sdkVersion >= 13) { + level13 = new AndroidLevel13(); + } + else { + level13 = new AndroidLevel13Emulation(); } } @@ -47,29 +52,7 @@ public final class Compatibility { * @return the adjusted direction, in the [0, 360[ range */ public static float getDirectionNow(final float directionNowPre, final Activity activity) { - float offset = 0; - if (isLevel8) { - try { - final int rotation = level8.getRotation(activity); - if (rotation == Surface.ROTATION_90) { - offset = 90; - } else if (rotation == Surface.ROTATION_180) { - offset = 180; - } else if (rotation == Surface.ROTATION_270) { - offset = 270; - } - } catch (final Exception e) { - // This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException - Log.e("Cannot call getRotation()", e); - } - } else { - final Display display = activity.getWindowManager().getDefaultDisplay(); - final int rotation = display.getOrientation(); - if (rotation == Configuration.ORIENTATION_LANDSCAPE) { - offset = 90; - } - } - return AngleUtils.normalize(directionNowPre + offset); + return AngleUtils.normalize(directionNowPre + level8.getRotationOffset(activity)); } public static void dataChanged(final String name) { @@ -113,4 +96,16 @@ public final class Compatibility { level11.invalidateOptionsMenu(activity); } + public static int getDisplayWidth() { + return level13.getDisplayWidth(); + } + + public static int getDisplayHeight() { + return level13.getDisplayHeight(); + } + + public static Point getDisplaySize() { + return level13.getDisplaySize(); + } + } |
