summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2015-11-12 13:20:57 +0100
committerTobrun <tobrun.van.nuland@gmail.com>2015-11-13 08:52:32 +0100
commit569399c1ae6cf4796eca1101e0d80e5b315db2c4 (patch)
tree0d32c3475cbed523db5933d758cf50745694e046 /android
parentf9ebe54a6336431af98ebfb428d28a0513b2522d (diff)
downloadqtlocation-mapboxgl-569399c1ae6cf4796eca1101e0d80e5b315db2c4.tar.gz
[android] #2989 - moved access token to test app
[android] #2989 - gitignoring config.xml [android] #2989 - move token file, rename [android] #2989 fixing gitignore, renaming config file
Diffstat (limited to 'android')
-rw-r--r--android/.gitignore2
-rw-r--r--android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java34
-rw-r--r--android/MapboxGLAndroidSDK/src/main/res/raw/token.txt1
-rw-r--r--android/MapboxGLAndroidSDKTestApp/build.gradle17
-rw-r--r--android/MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml4
5 files changed, 14 insertions, 44 deletions
diff --git a/android/.gitignore b/android/.gitignore
index 173ce20c94..57cd31fea2 100644
--- a/android/.gitignore
+++ b/android/.gitignore
@@ -21,7 +21,7 @@ MapboxGLAndroidSDK/src/main/assets/
local.properties
# Token file
-MapboxGLAndroidSDKTestApp/src/main/res/raw/token.txt
+MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml
# Twitter Fabric / Crashlytics
fabric.properties
diff --git a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java
index 354bb01855..180144a44e 100644
--- a/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java
+++ b/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ApiAccess.java
@@ -5,15 +5,9 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-import android.text.TextUtils;
-import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
/**
* {@code ApiAccess} provides a method to load the Mapbox access token.
*/
@@ -32,29 +26,19 @@ public final class ApiAccess {
*/
@Nullable
public static String getToken(@NonNull Context context) {
- String accessToken = getReleaseToken(context);
- if (TextUtils.isEmpty(accessToken)) {
- accessToken = getDevelopmentToken(context);
- }
- return accessToken;
- }
-
- private static String getReleaseToken(@NonNull Context context) {
try {
+ // read out AndroidManifest
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
- return appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
+ String token = appInfo.metaData.getString(MapboxConstants.KEY_META_DATA_MANIFEST);
+ if (token == null || token.isEmpty()) {
+ throw new IllegalArgumentException();
+ }
+ return token;
} catch (Exception e) {
- return null;
- }
- }
-
- private static String getDevelopmentToken(@NonNull Context context) {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(R.raw.token)));
- return reader.readLine();
- } catch (IOException e) {
- return null;
+ // use fallback on string resource, used for development
+ int tokenResId = context.getResources().getIdentifier("access_token", "string", context.getPackageName());
+ return tokenResId != 0 ? context.getString(tokenResId) : null;
}
}
}
diff --git a/android/MapboxGLAndroidSDK/src/main/res/raw/token.txt b/android/MapboxGLAndroidSDK/src/main/res/raw/token.txt
deleted file mode 100644
index ec747fa47d..0000000000
--- a/android/MapboxGLAndroidSDK/src/main/res/raw/token.txt
+++ /dev/null
@@ -1 +0,0 @@
-null \ No newline at end of file
diff --git a/android/MapboxGLAndroidSDKTestApp/build.gradle b/android/MapboxGLAndroidSDKTestApp/build.gradle
index fbfc00376f..7283d2d067 100644
--- a/android/MapboxGLAndroidSDKTestApp/build.gradle
+++ b/android/MapboxGLAndroidSDKTestApp/build.gradle
@@ -15,23 +15,6 @@ apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'checkstyle'
-task accessToken {
- def rawDir = new File("MapboxGLAndroidSDK/src/main/res/raw")
- rawDir.mkdirs()
- def tokenFile = new File("MapboxGLAndroidSDK/src/main/res/raw/token.txt")
- if (!tokenFile.exists()) {
- String token = "$System.env.MAPBOX_ACCESS_TOKEN"
- if (token == null) {
- throw new InvalidUserDataException("You must set the MAPBOX_ACCESS_TOKEN environment variable.")
- }
- tokenFile.write(token)
- }
-}
-
-gradle.projectsEvaluated {
- preBuild.dependsOn('accessToken')
-}
-
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
diff --git a/android/MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml
new file mode 100644
index 0000000000..02305f1feb
--- /dev/null
+++ b/android/MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="access_token">null</string>
+</resources> \ No newline at end of file