diff options
Diffstat (limited to 'main/src/cgeo/geocaching/compatibility')
4 files changed, 61 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel19.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel19.java new file mode 100644 index 0000000..ed4849f --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel19.java @@ -0,0 +1,25 @@ +package cgeo.geocaching.compatibility; + +import android.annotation.TargetApi; +import android.app.Activity; +import android.content.Intent; + +@TargetApi(19) +public class AndroidLevel19 implements AndroidLevel19Interface { + + @Override + public void importGpxFromStorageAccessFramework(final Activity activity, final int requestCode) { + // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file browser. + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + + // Filter to only show results that can be "opened", such as a file (as opposed to a list + // of contacts or timezones) + intent.addCategory(Intent.CATEGORY_OPENABLE); + + // Mime type based filter, we use "*/*" as GPX does not have a good mime type anyway + intent.setType("*/*"); + + activity.startActivityForResult(intent, requestCode); + } + +} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel19Emulation.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel19Emulation.java new file mode 100644 index 0000000..99f140f --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel19Emulation.java @@ -0,0 +1,12 @@ +package cgeo.geocaching.compatibility; + +import android.app.Activity; + +public class AndroidLevel19Emulation implements AndroidLevel19Interface { + + @Override + public void importGpxFromStorageAccessFramework(Activity activity, int requestCode) { + // do nothing + } + +} diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel19Interface.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel19Interface.java new file mode 100644 index 0000000..9a27cd8 --- /dev/null +++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel19Interface.java @@ -0,0 +1,7 @@ +package cgeo.geocaching.compatibility; + +import android.app.Activity; + +public interface AndroidLevel19Interface { + void importGpxFromStorageAccessFramework(Activity activity, final int requestCode); +} diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java index 48454ef..31c9e31 100644 --- a/main/src/cgeo/geocaching/compatibility/Compatibility.java +++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java @@ -5,6 +5,7 @@ import cgeo.geocaching.utils.AngleUtils; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.reflect.MethodUtils; +import org.eclipse.jdt.annotation.NonNull; import android.app.Activity; import android.content.Intent; @@ -24,33 +25,22 @@ public final class Compatibility { private final static AndroidLevel8Interface level8; private final static AndroidLevel11Interface level11; private final static AndroidLevel13Interface level13; + private final static AndroidLevel19Interface level19; static { - if (isLevel8) { - level8 = new AndroidLevel8(); - } - else { - level8 = new AndroidLevel8Emulation(); - } - if (sdkVersion >= 11) { - level11 = new AndroidLevel11(); - } - else { - level11 = new AndroidLevel11Emulation(); - } - if (sdkVersion >= 13) { - level13 = new AndroidLevel13(); - } - else { - level13 = new AndroidLevel13Emulation(); - } + level8 = isLevel8 ? new AndroidLevel8() : new AndroidLevel8Emulation(); + level11 = sdkVersion >= 11 ? new AndroidLevel11() : new AndroidLevel11Emulation(); + level13 = sdkVersion >= 13 ? new AndroidLevel13() : new AndroidLevel13Emulation(); + level19 = sdkVersion >= 19 ? new AndroidLevel19() : new AndroidLevel19Emulation(); } /** * Add 90, 180 or 270 degrees to the given rotation. * - * @param directionNowPre the direction in degrees before adjustment - * @param activity the activity whose rotation is used to adjust the direction + * @param directionNowPre + * the direction in degrees before adjustment + * @param activity + * the activity whose rotation is used to adjust the direction * @return the adjusted direction, in the [0, 360[ range */ public static float getDirectionNow(final float directionNowPre, final Activity activity) { @@ -110,4 +100,11 @@ public final class Compatibility { return level8.getExternalPictureDir(); } + public static void importGpxFromStorageAccessFramework(final @NonNull Activity activity, int requestCodeImportGpx) { + level19.importGpxFromStorageAccessFramework(activity, requestCodeImportGpx); + } + + public static boolean isStorageAccessFrameworkAvailable() { + return sdkVersion >= 19; + } } |
