[android] #5968 - add support for a layout editor preview, show a drawable and some overlain items

This commit is contained in:
Tobrun
2016-08-12 12:22:20 -04:00
parent d4271d993e
commit 834ff765c0
3 changed files with 52 additions and 9 deletions

View File

@@ -185,25 +185,23 @@ public class MapView extends FrameLayout {
}
private void initialize(@NonNull Context context, @NonNull MapboxMapOptions options) {
if (isInEditMode()) {
// if we are in an editor mode we show an image of a map
LayoutInflater.from(context).inflate(R.layout.mapview_preview, this);
return;
}
mInitialLoad = true;
mOnMapReadyCallbackList = new ArrayList<>();
mOnMapChangedListener = new CopyOnWriteArrayList<>();
mMapboxMap = new MapboxMap(this);
mIcons = new ArrayList<>();
View view = LayoutInflater.from(context).inflate(R.layout.mapview_internal, this);
if (!isInEditMode()) {
setWillNotDraw(false);
}
setWillNotDraw(false);
// Reference the TextureView
SurfaceView surfaceView = (SurfaceView) view.findViewById(R.id.surfaceView);
// Check if we are in Android Studio UI editor to avoid error in layout preview
if (isInEditMode()) {
return;
}
mNativeMapView = new NativeMapView(this);
// Ensure this view is interactable
@@ -1506,6 +1504,10 @@ public class MapView extends FrameLayout {
// Called when view is hidden and shown
@Override
protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
if (isInEditMode()) {
return;
}
// Required by ZoomButtonController (from Android SDK documentation)
if (mMapboxMap.getUiSettings().isZoomControlsEnabled() && (visibility != View.VISIBLE)) {
mZoomButtonsController.setVisible(false);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/mapview_preview" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="@dimen/eight_dp"
android:layout_marginLeft="@dimen/eight_dp"
android:contentDescription="@string/mapboxIconContentDescription"
android:src="@drawable/attribution_logo" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/seven_dp"
android:layout_marginLeft="@dimen/seventy_six_dp"
android:background="@drawable/bg_default_selector"
android:clickable="true"
android:contentDescription="@string/attributionsIconContentDescription"
android:src="@drawable/ic_info_outline_24dp_selector" />
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:src="@drawable/compass" />
</RelativeLayout>