diff --git a/platform/android/MapboxGLAndroidSDK/gradle.properties b/platform/android/MapboxGLAndroidSDK/gradle.properties index 078fdbc80..ff6e2f61d 100644 --- a/platform/android/MapboxGLAndroidSDK/gradle.properties +++ b/platform/android/MapboxGLAndroidSDK/gradle.properties @@ -17,4 +17,4 @@ POM_PACKAGING=aar # Only build native dependencies for the current ABI # See https://code.google.com/p/android/issues/detail?id=221098#c20 -android.buildOnlyTargetAbi=true +android.buildOnlyTargetAbi=true \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 1f31e3b5a..848a898f9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -133,7 +133,7 @@ public class MapView extends FrameLayout { } else { getViewTreeObserver().removeGlobalOnLayoutListener(this); } - initialiseDrawingSurface(mapboxMapOptions.getTextureMode()); + initialiseDrawingSurface(mapboxMapOptions); } }); } @@ -229,13 +229,14 @@ public class MapView extends FrameLayout { } } - private void initialiseDrawingSurface(boolean textureMode) { - if (textureMode) { + private void initialiseDrawingSurface(MapboxMapOptions mapboxMapOptions) { + if (mapboxMapOptions.getTextureMode()) { TextureView textureView = new TextureView(getContext()); textureView.setSurfaceTextureListener(new SurfaceTextureListener()); addView(textureView, 0); } else { SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView); + surfaceView.setZOrderMediaOverlay(mapboxMapOptions.getRenderSurfaceOnTop()); surfaceView.getHolder().addCallback(new SurfaceCallback()); surfaceView.setVisibility(View.VISIBLE); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 4301d6437..94e2fbcf3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -81,6 +81,7 @@ public class MapboxMapOptions implements Parcelable { private int myLocationAccuracyAlpha; private float myLocationAccuracyThreshold; private boolean prefetchesTiles = true; + private boolean zMediaOverlay = false; private String apiBaseUrl; @@ -156,6 +157,7 @@ public class MapboxMapOptions implements Parcelable { apiBaseUrl = in.readString(); textureMode = in.readByte() != 0; prefetchesTiles = in.readByte() != 0; + zMediaOverlay = in.readByte() != 0; } static Bitmap getBitmapFromDrawable(Drawable drawable) { @@ -301,6 +303,8 @@ public class MapboxMapOptions implements Parcelable { typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_renderTextureMode, false)); mapboxMapOptions.setPrefetchesTiles( typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableTilePrefetch, true)); + mapboxMapOptions.renderSurfaceOnTop( + typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_enableZMediaOverlay, false)); } finally { typedArray.recycle(); } @@ -718,7 +722,6 @@ public class MapboxMapOptions implements Parcelable { /** * Enable tile pre-fetching. Loads tiles at a lower zoom-level to pre-render * a low resolution preview while more detailed tiles are loaded. - * * Enabled by default * * @param enable true to enable @@ -739,6 +742,25 @@ public class MapboxMapOptions implements Parcelable { return prefetchesTiles; } + + /** + * Set the flag to render the map surface on top of another surface. + * + * @param renderOnTop true if this map is shown on top of another one, false if bottom. + */ + public void renderSurfaceOnTop(boolean renderOnTop) { + this.zMediaOverlay = renderOnTop; + } + + /** + * Get the flag to render the map surface on top of another surface. + * + * @return true if this map is + */ + public boolean getRenderSurfaceOnTop() { + return zMediaOverlay; + } + /** * Get the current configured API endpoint base URL. * @@ -1123,6 +1145,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeString(apiBaseUrl); dest.writeByte((byte) (textureMode ? 1 : 0)); dest.writeByte((byte) (prefetchesTiles ? 1 : 0)); + dest.writeByte((byte) (zMediaOverlay ? 1 : 0)); } @Override @@ -1249,6 +1272,10 @@ public class MapboxMapOptions implements Parcelable { if (prefetchesTiles != options.prefetchesTiles) { return false; } + if (zMediaOverlay != options.zMediaOverlay) { + return false; + } + return false; } @@ -1296,6 +1323,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (textureMode ? 1 : 0); result = 31 * result + (style != null ? style.hashCode() : 0); result = 31 * result + (prefetchesTiles ? 1 : 0); + result = 31 * result + (zMediaOverlay ? 1 : 0); return result; } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index f30cb7c27..3decd6ead 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -75,6 +75,9 @@ + + + diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index a7ef78d69..281fe8afe 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -118,6 +118,7 @@ + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 93ac4101d..9ef85be75 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -682,7 +682,13 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activity.FeatureOverviewActivity"/> - + + + 0) { + mapViewCounter--; + Toast.makeText(this, "Amount of main map fragments: " + mapViewCounter, Toast.LENGTH_SHORT).show(); + } + } + + private void addMapFragment() { + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + MainMapFragment mainMapFragment = MainMapFragment.newInstance(mapViewCounter); + if (mapViewCounter == 0) { + fragmentTransaction.add(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT); + } else { + fragmentTransaction.replace(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT); + } + fragmentTransaction.addToBackStack(null); + fragmentTransaction.commit(); + mapViewCounter++; + Toast.makeText(this, "Amount of main map fragments: " + mapViewCounter, Toast.LENGTH_SHORT).show(); + } + + private void toggleBottomSheetMapFragment() { + if (!bottomSheetFragmentAdded) { + addBottomSheetMapFragment(); + } else { + removeBottomSheetFragment(); + } + bottomSheetFragmentAdded = !bottomSheetFragmentAdded; + } + + private void addBottomSheetMapFragment() { + FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); + fragmentTransaction.add(R.id.fragment_container_bottom, BottomSheetFragment.newInstance(), TAG_BOTTOM_FRAGMENT); + fragmentTransaction.commit(); + } + + private void removeBottomSheetFragment() { + Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_BOTTOM_FRAGMENT); + if (fragment != null) { + getSupportFragmentManager().beginTransaction().remove(fragment).commit(); + } + } + + public static class MainMapFragment extends Fragment implements OnMapReadyCallback { + + private static final String[] STYLES = new String[] { + Style.MAPBOX_STREETS, + Style.SATELLITE_STREETS, + Style.LIGHT, + Style.DARK, + Style.SATELLITE, + Style.OUTDOORS + }; + + private MapView map; + + public static MainMapFragment newInstance(int mapCounter) { + MainMapFragment mapFragment = new MainMapFragment(); + MapboxMapOptions mapboxMapOptions = new MapboxMapOptions(); + mapboxMapOptions.styleUrl(STYLES[Math.min(Math.max(mapCounter, 0), STYLES.length - 1)]); + mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions)); + return mapFragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + Context context = inflater.getContext(); + return map = new MapView(context, MapFragmentUtils.resolveArgs(context, getArguments())); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + map.onCreate(savedInstanceState); + map.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap mapboxMap) { + Location location = mapboxMap.getMyLocation(); + if (location != null) { + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15)); + } + } + + @Override + public void onStart() { + super.onStart(); + map.onStart(); + } + + @Override + public void onResume() { + super.onResume(); + map.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + map.onPause(); + } + + @Override + public void onStop() { + super.onStop(); + map.onStop(); + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + map.onSaveInstanceState(outState); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + map.onLowMemory(); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + map.onDestroy(); + } + } + + public static class BottomSheetFragment extends Fragment implements OnMapReadyCallback { + + private MapView map; + + public static BottomSheetFragment newInstance() { + BottomSheetFragment mapFragment = new BottomSheetFragment(); + MapboxMapOptions mapboxMapOptions = new MapboxMapOptions(); + mapboxMapOptions.locationEnabled(true); + mapboxMapOptions.renderSurfaceOnTop(true); + mapboxMapOptions.styleUrl(Style.LIGHT); + mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions)); + return mapFragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + Context context = inflater.getContext(); + return map = new MapView(context, MapFragmentUtils.resolveArgs(context, getArguments())); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + map.onCreate(savedInstanceState); + map.getMapAsync(this); + } + + @Override + public void onMapReady(MapboxMap mapboxMap) { + Location location = mapboxMap.getMyLocation(); + if (location != null) { + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location), 15)); + } + } + + @Override + public void onStart() { + super.onStart(); + map.onStart(); + } + + @Override + public void onResume() { + super.onResume(); + map.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + map.onPause(); + } + + @Override + public void onStop() { + super.onStop(); + map.onStop(); + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + map.onSaveInstanceState(outState); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + map.onLowMemory(); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + map.onDestroy(); + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_add_white.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_add_white.xml new file mode 100644 index 000000000..cd5c04578 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/drawable/ic_add_white.xml @@ -0,0 +1,9 @@ + + + diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_bottom_sheet.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_bottom_sheet.xml new file mode 100644 index 000000000..cbb440d92 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_bottom_sheet.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml index 09f0c307a..671dccbd2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/strings.xml @@ -62,6 +62,7 @@ Fill extrusions Building layer Animated Image Source + Bottom sheet Tracks the location of the user @@ -123,6 +124,7 @@ Shows how to add 3D extruded shapes Shows how to show 3D extruded buildings Shows how to animate georeferenced images + Show 2 MapView on screen with a bottom sheet category