[android] - add zMediaOverlay configuration, add bottom sheet test setup

This commit is contained in:
Tobrun Van Nuland
2017-07-24 18:46:23 +02:00
committed by Tobrun
parent 93ba48a3a4
commit c5a5b40837
11 changed files with 418 additions and 7 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -75,6 +75,9 @@
<!-- Deprecated to use TextureView-->
<public name="mapbox_renderTextureMode" type="attr" />
<public name="mapbox_enableTilePrefetch" type="attr" />
<public name="mapbox_enableZMediaOverlay" type="attr" />
<!-- Exposed content descriptions -->
<public name="mapbox_logoContentDescription" type="string" />

View File

@@ -118,6 +118,7 @@
<attr name="mapbox_renderTextureMode" format="boolean"/>
<attr name="mapbox_enableTilePrefetch" format="boolean"/>
<attr name="mapbox_enableZMediaOverlay" format="boolean"/>
</declare-styleable>

View File

@@ -682,7 +682,13 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity"/>
</activity>
<activity android:name=".activity.maplayout.BottomSheetActivity"
android:description="@string/description_bottom_sheet"
android:label="@string/activity_bottom_sheet">
<meta-data
android:name="@string/category"
android:value="@string/category_basic"/>
</activity>
<!-- For Instrumentation tests -->
<activity

View File

@@ -50,7 +50,7 @@ public class SupportMapFragmentActivity extends AppCompatActivity implements OnM
.zoom(11)
.build());
mapFragment = SupportMapFragment.newInstance();
mapFragment = SupportMapFragment.newInstance(options);
transaction.add(R.id.fragment_container, mapFragment, "com.mapbox.map");
transaction.commit();

View File

@@ -0,0 +1,285 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
import android.content.Context;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
public class BottomSheetActivity extends AppCompatActivity {
private static final String TAG_MAIN_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.main";
private static final String TAG_BOTTOM_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.bottom";
private boolean bottomSheetFragmentAdded;
private int mapViewCounter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_sheet);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
findViewById(R.id.fabFragment).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addMapFragment();
}
});
findViewById(R.id.fabBottomSheet).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleBottomSheetMapFragment();
}
});
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
bottomSheetBehavior.setPeekHeight((int) (64 * getResources().getDisplayMetrics().density));
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
toggleBottomSheetMapFragment();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
super.onBackPressed();
if (mapViewCounter > 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();
}
}
}

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</vector>

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@color/primaryDark"
app:behavior_hideable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@color/white"
android:text="^"
android:textSize="22sp"
tools:ignore="HardcodedText"/>
<FrameLayout
android:id="@+id/fragment_container_bottom"
android:layout_width="match_parent"
android:layout_height="186dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabBottomSheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/primary"
android:src="@drawable/ic_refresh"
app:layout_anchor="@id/bottom_sheet"
app:layout_anchorGravity="top|end"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:clipToPadding="false"
android:paddingBottom="8dp"
app:layout_anchor="@id/fabBottomSheet"
app:layout_anchorGravity="top">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white"
app:backgroundTint="@color/accent"/>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@@ -62,6 +62,7 @@
<string name="activity_fill_extrusion_layer">Fill extrusions</string>
<string name="activity_building_fill_extrusion_layer">Building layer</string>
<string name="activity_animated_image_source">Animated Image Source</string>
<string name="activity_bottom_sheet">Bottom sheet</string>
<!--Description-->
<string name="description_user_location_tracking">Tracks the location of the user</string>
@@ -123,6 +124,7 @@
<string name="description_fill_extrusion_layer">Shows how to add 3D extruded shapes</string>
<string name="description_building_fill_extrusion_layer">Shows how to show 3D extruded buildings</string>
<string name="description_animated_image_source">Shows how to animate georeferenced images</string>
<string name="description_bottom_sheet">Show 2 MapView on screen with a bottom sheet</string>
<!--Categories-->
<string name="category">category</string>