Move stlye url and access token to property
Remove fragment stuff (for now)
This commit is contained in:
@@ -17,11 +17,6 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.mapbox.mapboxgl.app.FragmentActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.mapbox.mapboxgl.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
public class FragmentActivity extends Activity {
|
||||
|
||||
//
|
||||
// Static members
|
||||
//
|
||||
|
||||
// Tag used for logging
|
||||
private static final String TAG = "FragmentActivity";
|
||||
|
||||
//
|
||||
// Lifecycle events
|
||||
//
|
||||
|
||||
// Called when activity is created
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.v(TAG, "onCreate");
|
||||
|
||||
// Load the layout
|
||||
setContentView(R.layout.activity_fragment);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,9 @@ public class MainActivity extends Activity {
|
||||
setContentView(R.layout.activity_main);
|
||||
mMapView = (MapView) findViewById(R.id.map);
|
||||
|
||||
// Load the API key
|
||||
mMapView.setAccessToken("pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ");
|
||||
|
||||
// Need to pass on any saved state to the map
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="${packageName}.${activityClass}" >
|
||||
|
||||
<fragment
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
class="com.mapbox.mapboxgl.lib.MapFragment"
|
||||
android:id="@+id/map_fragment" />
|
||||
|
||||
</merge>
|
||||
@@ -1,150 +0,0 @@
|
||||
package com.mapbox.mapboxgl.lib;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Bundle;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class MapFragment extends Fragment {
|
||||
|
||||
//
|
||||
// Static members
|
||||
//
|
||||
|
||||
// Tag used for logging
|
||||
private static final String TAG = "MapFragment";
|
||||
|
||||
// The map
|
||||
private MapView mMapView;
|
||||
|
||||
// The style attrs to load into the map
|
||||
AttributeSet mAttrs;
|
||||
|
||||
//
|
||||
// Lifecycle events
|
||||
//
|
||||
|
||||
// Called when the fragment is created
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
Log.v(TAG, "onCreateView");
|
||||
|
||||
// Create the map
|
||||
mMapView = new MapView(getActivity());
|
||||
|
||||
// Load the attributes
|
||||
TypedArray typedArray = getActivity().obtainStyledAttributes(mAttrs,
|
||||
R.styleable.MapFragment, 0, 0);
|
||||
try {
|
||||
double centerLongitude = typedArray.getFloat(
|
||||
R.styleable.MapFragment_centerLongitude, 0.0f);
|
||||
double centerLatitude = typedArray.getFloat(
|
||||
R.styleable.MapFragment_centerLatitude, 0.0f);
|
||||
LonLat centerCoordinate = new LonLat(centerLongitude,
|
||||
centerLatitude);
|
||||
mMapView.setCenterCoordinate(centerCoordinate);
|
||||
mMapView.setDirection(typedArray.getFloat(
|
||||
R.styleable.MapFragment_direction, 0.0f));
|
||||
mMapView.setZoomLevel(typedArray.getFloat(
|
||||
R.styleable.MapFragment_zoomLevel, 0.0f));
|
||||
mMapView.setZoomEnabled(typedArray.getBoolean(
|
||||
R.styleable.MapFragment_zoomEnabled, true));
|
||||
mMapView.setScrollEnabled(typedArray.getBoolean(
|
||||
R.styleable.MapFragment_scrollEnabled, true));
|
||||
mMapView.setRotateEnabled(typedArray.getBoolean(
|
||||
R.styleable.MapFragment_rotateEnabled, true));
|
||||
mMapView.setDebugActive(typedArray.getBoolean(
|
||||
R.styleable.MapFragment_debugActive, false));
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
|
||||
// Need to pass on any saved state to the map
|
||||
mMapView.onCreate(savedInstanceState);
|
||||
|
||||
// Return the map as the root view
|
||||
return mMapView;
|
||||
}
|
||||
|
||||
// Called when the fragment is destroyed
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
Log.v(TAG, "onDestroyView");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onDestroy();
|
||||
mMapView = null;
|
||||
}
|
||||
|
||||
// Called to load any fragment attributes set in the activity's layout
|
||||
@Override
|
||||
public void onInflate(Activity activity, AttributeSet attrs,
|
||||
Bundle savedInstanceState) {
|
||||
super.onInflate(activity, attrs, savedInstanceState);
|
||||
Log.v(TAG, "onInflate");
|
||||
|
||||
// TODO seems this is called before onCreateView
|
||||
// Kinda strange, is it supposed to be like this?
|
||||
// Need to keep a copy of these and pass on to MapView later
|
||||
|
||||
mAttrs = attrs;
|
||||
}
|
||||
|
||||
// Called when the fragment is visible
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Log.v(TAG, "onStart");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onStart();
|
||||
}
|
||||
|
||||
// Called when the fragment is invisible
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Log.v(TAG, "onStop");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onStop();
|
||||
}
|
||||
|
||||
// Called when the fragment is in the background
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Log.v(TAG, "onPause");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onPause();
|
||||
}
|
||||
|
||||
// Called when the fragment is no longer in the background
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.v(TAG, "onResume");
|
||||
|
||||
// Need to pass on to view
|
||||
mMapView.onResume();
|
||||
}
|
||||
|
||||
// Called before fragment is destroyed
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
Log.v(TAG, "onSaveInstanceState");
|
||||
|
||||
// Need to retrieve any saved state from the map
|
||||
mMapView.onSaveInstanceState(outState);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import android.graphics.PointF;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.Debug;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
@@ -50,6 +49,8 @@ public class MapView extends SurfaceView {
|
||||
private static final String STATE_SCROLL_ENABLED = "scrollEnabled";
|
||||
private static final String STATE_ROTATE_ENABLED = "rotateEnabled";
|
||||
private static final String STATE_DEBUG_ACTIVE = "debugActive";
|
||||
private static final String STATE_STYLE_URL = "styleUrl";
|
||||
private static final String STATE_ACCESS_TOKEN = "accessToken";
|
||||
|
||||
//
|
||||
// Instance members
|
||||
@@ -58,12 +59,6 @@ public class MapView extends SurfaceView {
|
||||
// Used to call JNI NativeMapView
|
||||
private NativeMapView mNativeMapView;
|
||||
|
||||
// Used to style the map
|
||||
private String mStyleUrl;
|
||||
|
||||
// Used to load map tiles
|
||||
private String mAccessToken;
|
||||
|
||||
// Used to handle DPI scaling
|
||||
private float mScreenDensity = 1.0f;
|
||||
|
||||
@@ -79,8 +74,6 @@ public class MapView extends SurfaceView {
|
||||
// Used to track trackball long presses
|
||||
private TrackballLongPressTimeOut mCurrentTrackballLongPressTimeOut;
|
||||
|
||||
// Used to check connection status
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
private ConnectivityReceiver mConnectivityReceiver;
|
||||
|
||||
// Holds the context
|
||||
@@ -93,6 +86,7 @@ public class MapView extends SurfaceView {
|
||||
private boolean mZoomEnabled = true;
|
||||
private boolean mScrollEnabled = true;
|
||||
private boolean mRotateEnabled = true;
|
||||
private String mStyleUrl = "asset://styles/styles/bright-v6.json";
|
||||
|
||||
//
|
||||
// Constructors
|
||||
@@ -141,15 +135,9 @@ public class MapView extends SurfaceView {
|
||||
String dataPath = context.getFilesDir().getAbsolutePath();
|
||||
String apkPath = context.getPackageCodePath();
|
||||
|
||||
// Load the map style and API key
|
||||
//mStyleUrl = "https://mapbox.github.io/mapbox-gl-styles/styles/bright-v6.json";
|
||||
mStyleUrl = "asset://styles/styles/bright-v6.json";
|
||||
mAccessToken = "pk.eyJ1IjoibGpiYWRlIiwiYSI6IlJSQ0FEZ2MifQ.7mE4aOegldh3595AG9dxpQ";
|
||||
|
||||
// Create the NativeMapView
|
||||
mNativeMapView = new NativeMapView(this, cachePath, dataPath, apkPath);
|
||||
mNativeMapView.setStyleURL(mStyleUrl);
|
||||
mNativeMapView.setAccessToken(mAccessToken);
|
||||
mNativeMapView.setStyleUrl(mStyleUrl);
|
||||
|
||||
// Load the attributes
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs,
|
||||
@@ -174,6 +162,10 @@ public class MapView extends SurfaceView {
|
||||
R.styleable.MapView_rotateEnabled, true));
|
||||
setDebugActive(typedArray.getBoolean(
|
||||
R.styleable.MapView_debugActive, false));
|
||||
setStyleUrl(typedArray.getString(
|
||||
R.styleable.MapView_styleUrl));
|
||||
setAccessToken(typedArray.getString(
|
||||
R.styleable.MapView_accessToken));
|
||||
} finally {
|
||||
typedArray.recycle();
|
||||
}
|
||||
@@ -207,9 +199,9 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
// Check current connection status
|
||||
mConnectivityManager = (ConnectivityManager)context.getSystemService(
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo();
|
||||
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
|
||||
boolean isConnected = (activeNetwork != null) &&
|
||||
activeNetwork.isConnectedOrConnecting();
|
||||
onConnectivityChanged(isConnected);
|
||||
@@ -326,6 +318,23 @@ public class MapView extends SurfaceView {
|
||||
mNativeMapView.toggleDebug();
|
||||
}
|
||||
|
||||
public void setStyleUrl(String url) {
|
||||
mStyleUrl = url;
|
||||
mNativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
public String getStyleUrl() {
|
||||
return mStyleUrl;
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
mNativeMapView.setAccessToken(accessToken);
|
||||
}
|
||||
|
||||
public String getAccessToken() {
|
||||
return mNativeMapView.getAccessToken();
|
||||
}
|
||||
|
||||
//
|
||||
// Style methods
|
||||
//
|
||||
@@ -334,12 +343,11 @@ public class MapView extends SurfaceView {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// TODO seems like JSON simple may be better since it implements Map
|
||||
// interface
|
||||
// TODO seems like JSON simple may be better since it implements Map interface
|
||||
// Other candidates: fastjson, json-smart, fossnova json,
|
||||
public JSONObject getRawStyle() {
|
||||
try {
|
||||
return new JSONObject(mNativeMapView.getStyleJSON());
|
||||
return new JSONObject(mNativeMapView.getStyleJson());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
@@ -347,7 +355,7 @@ public class MapView extends SurfaceView {
|
||||
}
|
||||
|
||||
public void setRawStyle(JSONObject style) {
|
||||
mNativeMapView.setStyleJSON(style.toString());
|
||||
mNativeMapView.setStyleJson(style.toString());
|
||||
}
|
||||
|
||||
public void getStyleOrderedLayerNames() {
|
||||
@@ -397,6 +405,8 @@ public class MapView extends SurfaceView {
|
||||
setRotateEnabled(savedInstanceState
|
||||
.getBoolean(STATE_ROTATE_ENABLED));
|
||||
setDebugActive(savedInstanceState.getBoolean(STATE_DEBUG_ACTIVE));
|
||||
setStyleUrl(savedInstanceState.getString(STATE_STYLE_URL));
|
||||
setAccessToken(savedInstanceState.getString(STATE_ACCESS_TOKEN));
|
||||
}
|
||||
|
||||
mNativeMapView.initializeDisplay();
|
||||
@@ -415,6 +425,8 @@ public class MapView extends SurfaceView {
|
||||
outState.putBoolean(STATE_SCROLL_ENABLED, isScrollEnabled());
|
||||
outState.putBoolean(STATE_ROTATE_ENABLED, isRotateEnabled());
|
||||
outState.putBoolean(STATE_DEBUG_ACTIVE, isDebugActive());
|
||||
outState.putString(STATE_STYLE_URL, getStyleUrl());
|
||||
outState.putString(STATE_ACCESS_TOKEN, getAccessToken());
|
||||
}
|
||||
|
||||
// Called when we need to clean up
|
||||
|
||||
@@ -172,10 +172,6 @@ class NativeMapView {
|
||||
nativeResize(mNativeMapViewPtr, width, height, ratio, fbWidth, fbHeight);
|
||||
}
|
||||
|
||||
/*public void Set<StyleSource> getActiveSources() {
|
||||
return nativeGetActiveSources(mNativeMapViewPtr);
|
||||
}*/
|
||||
|
||||
public void setAppliedClasses(List<String> classes) {
|
||||
nativeSetAppliedClasses(mNativeMapViewPtr, classes);
|
||||
}
|
||||
@@ -198,20 +194,20 @@ class NativeMapView {
|
||||
durationMilliseconds);
|
||||
}
|
||||
|
||||
public void setStyleURL(String url) {
|
||||
nativeSetStyleURL(mNativeMapViewPtr, url);
|
||||
public void setStyleUrl(String url) {
|
||||
nativeSetStyleUrl(mNativeMapViewPtr, url);
|
||||
}
|
||||
|
||||
public void setStyleJSON(String newStyleJSON) {
|
||||
setStyleJSON(newStyleJSON, "");
|
||||
public void setStyleJson(String newStyleJson) {
|
||||
setStyleJson(newStyleJson, "");
|
||||
}
|
||||
|
||||
public void setStyleJSON(String newStyleJSON, String base) {
|
||||
nativeSetStyleJSON(mNativeMapViewPtr, newStyleJSON, base);
|
||||
public void setStyleJson(String newStyleJson, String base) {
|
||||
nativeSetStyleJson(mNativeMapViewPtr, newStyleJson, base);
|
||||
}
|
||||
|
||||
public String getStyleJSON() {
|
||||
return nativeGetStyleJSON(mNativeMapViewPtr);
|
||||
public String getStyleJson() {
|
||||
return nativeGetStyleJson(mNativeMapViewPtr);
|
||||
}
|
||||
|
||||
public void setAccessToken(String accessToken) {
|
||||
@@ -452,8 +448,6 @@ class NativeMapView {
|
||||
private native void nativeResize(long nativeMapViewPtr, int width,
|
||||
int height, float ratio, int fbWidth, int fbHeight);
|
||||
|
||||
//private native void Set<StyleSource> nativeGetActiveSources(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeSetAppliedClasses(long nativeMapViewPtr,
|
||||
List<String> classes);
|
||||
|
||||
@@ -462,12 +456,12 @@ class NativeMapView {
|
||||
private native void nativeSetDefaultTransitionDuration(
|
||||
long nativeMapViewPtr, long durationMilliseconds);
|
||||
|
||||
private native void nativeSetStyleURL(long nativeMapViewPtr, String url);
|
||||
private native void nativeSetStyleUrl(long nativeMapViewPtr, String url);
|
||||
|
||||
private native void nativeSetStyleJSON(long nativeMapViewPtr,
|
||||
String newStyleJSON, String base);
|
||||
private native void nativeSetStyleJson(long nativeMapViewPtr,
|
||||
String newStyleJson, String base);
|
||||
|
||||
private native String nativeGetStyleJSON(long nativeMapViewPtr);
|
||||
private native String nativeGetStyleJson(long nativeMapViewPtr);
|
||||
|
||||
private native void nativeSetAccessToken(long nativeMapViewPtr, String accessToken);
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
<attr name="scrollEnabled" format="boolean" />
|
||||
<attr name="rotateEnabled" format="boolean" />
|
||||
<attr name="debugActive" format="boolean" />
|
||||
<attr name="styleUrl" format="string" />
|
||||
<attr name="accessToken" format="string" />
|
||||
|
||||
<declare-styleable name="MapView">
|
||||
<attr name="centerLongitude" />
|
||||
@@ -17,16 +19,7 @@
|
||||
<attr name="scrollEnabled" />
|
||||
<attr name="rotateEnabled" />
|
||||
<attr name="debugActive" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="MapFragment">
|
||||
<attr name="centerLongitude" />
|
||||
<attr name="centerLatitude" />
|
||||
<attr name="zoomLevel" />
|
||||
<attr name="direction" />
|
||||
<attr name="zoomEnabled" />
|
||||
<attr name="scrollEnabled" />
|
||||
<attr name="rotateEnabled" />
|
||||
<attr name="debugActive" />
|
||||
<attr name="styleUrl" />
|
||||
<attr name="accessToken" />
|
||||
</declare-styleable>
|
||||
</resources>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user