diff --git a/android/cpp/jni.cpp b/android/cpp/jni.cpp index ec9283b87..37ed35f77 100644 --- a/android/cpp/jni.cpp +++ b/android/cpp/jni.cpp @@ -813,9 +813,9 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { { "nativeSetAppliedClasses", "(JLjava/util/List;)V", reinterpret_cast(&nativeSetAppliedClasses) }, { "nativeGetAppliedClasses", "(J)Ljava/util/List;", reinterpret_cast(&nativeGetAppliedClasses) }, { "nativeSetDefaultTransitionDuration", "(JJ)V", reinterpret_cast(&nativeSetDefaultTransitionDuration) }, - { "nativeSetStyleURL", "(JLjava/lang/String;)V", reinterpret_cast(&nativeSetStyleURL) }, - { "nativeSetStyleJSON", "(JLjava/lang/String;Ljava/lang/String;)V", reinterpret_cast(&nativeSetStyleJSON) }, - { "nativeGetStyleJSON", "(J)Ljava/lang/String;", reinterpret_cast(&nativeGetStyleJSON) }, + { "nativeSetStyleUrl", "(JLjava/lang/String;)V", reinterpret_cast(&nativeSetStyleURL) }, + { "nativeSetStyleJson", "(JLjava/lang/String;Ljava/lang/String;)V", reinterpret_cast(&nativeSetStyleJSON) }, + { "nativeGetStyleJson", "(J)Ljava/lang/String;", reinterpret_cast(&nativeGetStyleJSON) }, { "nativeSetAccessToken", "(JLjava/lang/String;)V", reinterpret_cast(&nativeSetAccessToken) }, { "nativeGetAccessToken", "(J)Ljava/lang/String;", reinterpret_cast(&nativeGetAccessToken) }, { "nativeCancelTransitions", "(J)V", reinterpret_cast(&nativeCancelTransitions) }, diff --git a/android/java/app/src/main/AndroidManifest.xml b/android/java/app/src/main/AndroidManifest.xml index 80a39ed4b..5b73a63ff 100644 --- a/android/java/app/src/main/AndroidManifest.xml +++ b/android/java/app/src/main/AndroidManifest.xml @@ -17,11 +17,6 @@ - - diff --git a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/FragmentActivity.java b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/FragmentActivity.java deleted file mode 100644 index 1b27ca2fd..000000000 --- a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/FragmentActivity.java +++ /dev/null @@ -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); - } -} diff --git a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java index acc899500..2166b7dd1 100644 --- a/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java +++ b/android/java/app/src/main/java/com/mapbox/mapboxgl/app/MainActivity.java @@ -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); } diff --git a/android/java/app/src/main/res/layout/activity_fragment.xml b/android/java/app/src/main/res/layout/activity_fragment.xml deleted file mode 100644 index 6310106fc..000000000 --- a/android/java/app/src/main/res/layout/activity_fragment.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapFragment.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapFragment.java deleted file mode 100644 index 1263ac56e..000000000 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapFragment.java +++ /dev/null @@ -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); - } -} diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index 45eeda4e8..530d563dc 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -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 diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java index fc525a594..7d24abf44 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java @@ -172,10 +172,6 @@ class NativeMapView { nativeResize(mNativeMapViewPtr, width, height, ratio, fbWidth, fbHeight); } - /*public void Set getActiveSources() { - return nativeGetActiveSources(mNativeMapViewPtr); - }*/ - public void setAppliedClasses(List 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 nativeGetActiveSources(long nativeMapViewPtr); - private native void nativeSetAppliedClasses(long nativeMapViewPtr, List 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); diff --git a/android/java/lib/src/main/res/values/attrs.xml b/android/java/lib/src/main/res/values/attrs.xml index b42f729c9..191e7d000 100644 --- a/android/java/lib/src/main/res/values/attrs.xml +++ b/android/java/lib/src/main/res/values/attrs.xml @@ -7,6 +7,8 @@ + + @@ -17,16 +19,7 @@ - - - - - - - - - - - + + diff --git a/android/java/lib/src/main/res/values/strings.xml b/android/java/lib/src/main/res/values/strings.xml deleted file mode 100644 index f11f7450a..000000000 --- a/android/java/lib/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -