summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidModuleBase/src
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2018-07-17 15:05:53 +0200
committertobrun <tobrun.van.nuland@gmail.com>2018-07-23 17:58:17 +0200
commitf400615dc87c5583d5faabbb61287155ee500971 (patch)
treed4a48e709f389cafcc80bc969fe4e2f4152f1de6 /platform/android/MapboxGLAndroidModuleBase/src
parent681e0141de63d0d5a545e87c40216163b2d63fc6 (diff)
downloadqtlocation-mapboxgl-upstream/tvn-http-module.tar.gz
[android] - modularise used http clientupstream/tvn-http-module
Diffstat (limited to 'platform/android/MapboxGLAndroidModuleBase/src')
-rw-r--r--platform/android/MapboxGLAndroidModuleBase/src/main/AndroidManifest.xml1
-rw-r--r--platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java159
-rw-r--r--platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java57
-rw-r--r--platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestResponder.java7
-rw-r--r--platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/utils/ApplicationContextWrapper.java20
5 files changed, 244 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidModuleBase/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidModuleBase/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..1ac48e6903
--- /dev/null
+++ b/platform/android/MapboxGLAndroidModuleBase/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest package="com.mapbox.mapboxsdk.module"/>
diff --git a/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
new file mode 100644
index 0000000000..640c70282c
--- /dev/null
+++ b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java
@@ -0,0 +1,159 @@
+package com.mapbox.mapboxsdk.constants;
+
+import java.util.Locale;
+
+/**
+ * MapboxConstants exposes Mapbox related constants
+ */
+public class MapboxConstants {
+
+ /**
+ * Default Locale for data processing (ex: String.toLowerCase(MAPBOX_LOCALE, "foo"))
+ */
+ public static final Locale MAPBOX_LOCALE = Locale.US;
+
+ /**
+ * Key used to switch storage to external in AndroidManifest.xml
+ */
+ public static final String KEY_META_DATA_SET_STORAGE_EXTERNAL = "com.mapbox.SetStorageExternal";
+
+ /**
+ * Default value for KEY_META_DATA_SET_STORAGE_EXTERNAL (default is internal storage)
+ */
+ public static final boolean DEFAULT_SET_STORAGE_EXTERNAL = false;
+
+ /**
+ * Unmeasured state
+ */
+ public static final float UNMEASURED = -1f;
+
+ /**
+ * Default animation time
+ */
+ public static final int ANIMATION_DURATION = 300;
+
+ /**
+ * Default short animation time
+ */
+ public static final int ANIMATION_DURATION_SHORT = 150;
+
+ /**
+ * Animation time of a fling gesture
+ */
+ public static final long ANIMATION_DURATION_FLING_BASE = ANIMATION_DURATION_SHORT;
+
+ /**
+ * Velocity threshold for a fling gesture
+ */
+ public static final long VELOCITY_THRESHOLD_IGNORE_FLING = 1000;
+
+ /**
+ * Value by which the default rotation threshold will be increased when scaling
+ */
+ public static final float ROTATION_THRESHOLD_INCREASE_WHEN_SCALING = 25f;
+
+ /**
+ * Time within which user needs to lift fingers for velocity animation to start.
+ */
+ public static final long SCHEDULED_ANIMATION_TIMEOUT = 150L;
+
+ /**
+ * Minimum angular velocity for rotation animation
+ */
+ public static final float MINIMUM_ANGULAR_VELOCITY = 1.5f;
+
+ /**
+ * Maximum angular velocity for rotation animation
+ */
+ public static final float MAXIMUM_ANGULAR_VELOCITY = 20f;
+
+ /**
+ * Factor to calculate tilt change based on pixel change during shove gesture.
+ */
+ public static final float SHOVE_PIXEL_CHANGE_FACTOR = 0.1f;
+
+ /**
+ * The currently supported minimum zoom level.
+ */
+ public static final float MINIMUM_ZOOM = 0.0f;
+
+ /**
+ * The currently supported maximum zoom level.
+ */
+ public static final float MAXIMUM_ZOOM = 25.5f;
+
+ /**
+ * The currently supported maximum tilt value.
+ */
+ public static final double MAXIMUM_TILT = 60;
+
+ /**
+ * The currently supported minimum tilt value.
+ */
+ public static final double MINIMUM_TILT = 0;
+
+ /**
+ * The currently supported maximum direction
+ */
+ public static final double MAXIMUM_DIRECTION = 360;
+
+ /**
+ * The currently supported minimum direction
+ */
+ public static final double MINIMUM_DIRECTION = 0;
+
+ /**
+ * The currently used minimum scale factor to clamp to when a quick zoom gesture occurs
+ */
+ public static final float MINIMUM_SCALE_FACTOR_CLAMP = 0.00f;
+
+ /**
+ * The currently used maximum scale factor to clamp to when a quick zoom gesture occurs
+ */
+ public static final float MAXIMUM_SCALE_FACTOR_CLAMP = 0.15f;
+
+ /**
+ * Fragment Argument Key for MapboxMapOptions
+ */
+ public static final String FRAG_ARG_MAPBOXMAPOPTIONS = "MapboxMapOptions";
+
+ // Save instance state keys
+ public static final String STATE_HAS_SAVED_STATE = "mapbox_savedState";
+ public static final String STATE_CAMERA_POSITION = "mapbox_cameraPosition";
+ public static final String STATE_ZOOM_ENABLED = "mapbox_zoomEnabled";
+ public static final String STATE_SCROLL_ENABLED = "mapbox_scrollEnabled";
+ public static final String STATE_ROTATE_ENABLED = "mapbox_rotateEnabled";
+ public static final String STATE_TILT_ENABLED = "mapbox_tiltEnabled";
+ public static final String STATE_ZOOM_CONTROLS_ENABLED = "mapbox_zoomControlsEnabled";
+ public static final String STATE_DOUBLE_TAP_ENABLED = "mapbox_doubleTapEnabled";
+ public static final String STATE_DEBUG_ACTIVE = "mapbox_debugActive";
+ public static final String STATE_STYLE_URL = "mapbox_styleUrl";
+ public static final String STATE_COMPASS_ENABLED = "mapbox_compassEnabled";
+ public static final String STATE_COMPASS_GRAVITY = "mapbox_compassGravity";
+ public static final String STATE_COMPASS_MARGIN_LEFT = "mapbox_compassMarginLeft";
+ public static final String STATE_COMPASS_MARGIN_TOP = "mapbox_compassMarginTop";
+ public static final String STATE_COMPASS_MARGIN_RIGHT = "mapbox_compassMarginRight";
+ public static final String STATE_COMPASS_MARGIN_BOTTOM = "mapbox_compassMarginBottom";
+ public static final String STATE_COMPASS_FADE_WHEN_FACING_NORTH = "mapbox_compassFade";
+ public static final String STATE_COMPASS_IMAGE_BITMAP = "mapbox_compassImage";
+ public static final String STATE_LOGO_GRAVITY = "mapbox_logoGravity";
+ public static final String STATE_LOGO_MARGIN_LEFT = "mapbox_logoMarginLeft";
+ public static final String STATE_LOGO_MARGIN_TOP = "mapbox_logoMarginTop";
+ public static final String STATE_LOGO_MARGIN_RIGHT = "mapbox_logoMarginRight";
+ public static final String STATE_LOGO_MARGIN_BOTTOM = "mapbox_logoMarginBottom";
+ public static final String STATE_LOGO_ENABLED = "mapbox_logoEnabled";
+ public static final String STATE_ATTRIBUTION_GRAVITY = "mapbox_attrGravity";
+ public static final String STATE_ATTRIBUTION_MARGIN_LEFT = "mapbox_attrMarginLeft";
+ public static final String STATE_ATTRIBUTION_MARGIN_TOP = "mapbox_attrMarginTop";
+ public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "mapbox_attrMarginRight";
+ public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom";
+ public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled";
+ public static final String STATE_DESELECT_MARKER_ON_TAP = "mapbox_deselectMarkerOnTap";
+ public static final String STATE_USER_FOCAL_POINT = "mapbox_userFocalPoint";
+ public static final String STATE_SCALE_ANIMATION_ENABLED = "mapbox_scaleAnimationEnabled";
+ public static final String STATE_ROTATE_ANIMATION_ENABLED = "mapbox_rotateAnimationEnabled";
+ public static final String STATE_FLING_ANIMATION_ENABLED = "mapbox_flingAnimationEnabled";
+ public static final String STATE_INCREASE_ROTATE_THRESHOLD = "mapbox_increaseRotateThreshold";
+ public static final String STATE_INCREASE_SCALE_THRESHOLD = "mapbox_increaseScaleThreshold";
+
+}
diff --git a/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
new file mode 100644
index 0000000000..072a45b0de
--- /dev/null
+++ b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequest.java
@@ -0,0 +1,57 @@
+package com.mapbox.mapboxsdk.http;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.support.annotation.NonNull;
+import com.mapbox.mapboxsdk.utils.ApplicationContextWrapper;
+
+public abstract class HttpRequest {
+
+ static final int CONNECTION_ERROR = 0;
+ static final int TEMPORARY_ERROR = 1;
+ static final int PERMANENT_ERROR = 2;
+
+ public abstract void executeRequest(HttpRequestResponder httpRequest, long nativePtr, String resourceUrl,
+ String etag, String modified);
+
+ public abstract void cancelRequest();
+
+ //
+ // Utility methods
+ //
+
+ static String getApplicationIdentifier() {
+ ApplicationContextWrapper contextWrapper = ApplicationContextWrapper.getInstance(null);
+ Context context = contextWrapper.getBaseContext();
+ if(context == null){
+ throw new RuntimeException("Mapbox.java not correctly initialized");
+ }
+ return getApplicationIdentifier(context);
+ }
+
+ private static String getApplicationIdentifier(@NonNull Context context){
+ try {
+ PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
+ return String.format("%s/%s (%s)", context.getPackageName(), packageInfo.versionName, packageInfo.versionCode);
+ } catch (Exception exception) {
+ return "";
+ }
+ }
+
+ String buildResourceUrl(String host, String resourceUrl, int querySize) {
+ if (isValidMapboxEndpoint(host)) {
+ if (querySize == 0) {
+ resourceUrl = resourceUrl + "?";
+ } else {
+ resourceUrl = resourceUrl + "&";
+ }
+ resourceUrl = resourceUrl + "events=true";
+ }
+ return resourceUrl;
+ }
+
+ private boolean isValidMapboxEndpoint(String host) {
+ return host.equals("mapbox.com") || host.endsWith(".mapbox.com") || host.equals("mapbox.cn")
+ || host.endsWith(".mapbox.cn");
+ }
+}
diff --git a/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestResponder.java b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestResponder.java
new file mode 100644
index 0000000000..e4659e0955
--- /dev/null
+++ b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/http/HttpRequestResponder.java
@@ -0,0 +1,7 @@
+package com.mapbox.mapboxsdk.http;
+
+public interface HttpRequestResponder {
+ void onResponse(int responseCode, String eTag, String lastModified, String cacheControl, String expires,
+ String retryAfter, String xRateLimitReset, byte[] body);
+ void handleFailure(int type, String errorMessage);
+}
diff --git a/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/utils/ApplicationContextWrapper.java b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/utils/ApplicationContextWrapper.java
new file mode 100644
index 0000000000..8981a0f2e2
--- /dev/null
+++ b/platform/android/MapboxGLAndroidModuleBase/src/main/java/com/mapbox/mapboxsdk/utils/ApplicationContextWrapper.java
@@ -0,0 +1,20 @@
+package com.mapbox.mapboxsdk.utils;
+
+import android.content.Context;
+import android.content.ContextWrapper;
+
+public class ApplicationContextWrapper extends ContextWrapper {
+
+ private static ApplicationContextWrapper instance;
+
+ public static synchronized ApplicationContextWrapper getInstance(Context context) {
+ if (instance == null) {
+ instance = new ApplicationContextWrapper(context);
+ }
+ return instance;
+ }
+
+ private ApplicationContextWrapper(Context base) {
+ super(base.getApplicationContext());
+ }
+}