[android] #2462 refactored ApiAccess token setup
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
android:value="9724157045ff7d083492c6d9ae03e60e8609d461" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.mapbox.accessToken"
|
||||
android:name="com.mapbox.AccessToken"
|
||||
android:value="" />
|
||||
|
||||
</application>
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.widget.TextView;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
import com.mapbox.mapboxsdk.views.MapView;
|
||||
|
||||
public class InfoWindowAdapterActivity extends AppCompatActivity {
|
||||
@@ -35,7 +36,7 @@ public class InfoWindowAdapterActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.secondMapView);
|
||||
mMapView.setAccessToken(Util.getAccessToken(this));
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
mMapView.setStyleUrl(MapView.StyleUrls.MAPBOX_STREETS);
|
||||
mMapView.setInfoWindowAdapter(new MapView.InfoWindowAdapter() {
|
||||
|
||||
@@ -30,6 +30,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.utils.ApiAccess;
|
||||
import com.mapbox.mapboxsdk.views.MapView;
|
||||
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
@@ -100,7 +101,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
mMapView = (MapView) findViewById(R.id.mainMapView);
|
||||
mMapView.setAccessToken(Util.getAccessToken(this));
|
||||
mMapView.setAccessToken(ApiAccess.getToken(this));
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
mMapView.setOnFpsChangedListener(new MyOnFpsChangedListener());
|
||||
|
||||
@@ -63,36 +63,4 @@ public class Util {
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// TODO move this to SDK
|
||||
public static String getAccessToken(Context context) {
|
||||
String accessToken = getReleaseAccessToken(context);
|
||||
if (TextUtils.isEmpty(accessToken)) {
|
||||
accessToken = getDevelopmentAccessToken(context);
|
||||
}
|
||||
// TODO add validation + throw exception
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
// TODO move this to SDK
|
||||
private static String getReleaseAccessToken(Context context){
|
||||
try {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
|
||||
return appInfo.metaData.getString("com.mapbox.accessToken");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to load AccessToken: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO move this to SDK
|
||||
private static String getDevelopmentAccessToken(Context context) {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().openRawResource(R.raw.token)));
|
||||
return reader.readLine();
|
||||
}catch (IOException e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user