diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src/main')
11 files changed, 194 insertions, 7 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml index 14066123d3..1ec0116047 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml @@ -873,6 +873,17 @@ android:value=".activity.FeatureOverviewActivity" /> </activity> + <activity + android:name=".activity.maplayout.RecyclerViewActivity" + android:description="@string/description_recyclerview" + android:label="@string/activity_recyclerview"> + <meta-data + android:name="@string/category" + android:value="@string/category_maplayout" /> + <meta-data + android:name="android.support.PARENT_ACTIVITY" + android:value=".activity.FeatureOverviewActivity" /> + </activity> <!-- For Instrumentation tests --> <activity android:name=".activity.style.RuntimeStyleTestActivity" diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java index e3af101a8d..c7d45a879a 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java @@ -33,6 +33,7 @@ public class MapChangeActivity extends AppCompatActivity { mapView.addOnDidFinishLoadingStyleListener(() -> Timber.v("OnDidFinishLoadingStyle")); mapView.addOnDidFinishRenderingFrameListener(fully -> Timber.v("OnDidFinishRenderingFrame: fully: %s", fully)); mapView.addOnDidFinishRenderingMapListener(fully -> Timber.v("OnDidFinishRenderingMap: fully: %s", fully)); + mapView.addOnDidBecomeIdleListener(() -> Timber.v("OnDidBecomeIdle")); mapView.addOnSourceChangedListener(sourceId -> Timber.v("OnSourceChangedListener: source with id: %s", sourceId)); mapView.addOnWillStartLoadingMapListener(() -> Timber.v("OnWillStartLoadingMap")); mapView.addOnWillStartRenderingFrameListener(() -> Timber.v("OnWillStartRenderingFrame")); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/RecyclerViewActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/RecyclerViewActivity.kt new file mode 100644 index 0000000000..d35c977df0 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/RecyclerViewActivity.kt @@ -0,0 +1,148 @@ +package com.mapbox.mapboxsdk.testapp.activity.maplayout + +import android.annotation.SuppressLint +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.support.v7.widget.LinearLayoutManager +import android.support.v7.widget.RecyclerView +import android.view.LayoutInflater +import android.view.ViewGroup +import android.widget.TextView +import com.mapbox.mapboxsdk.maps.MapView +import com.mapbox.mapboxsdk.testapp.R +import kotlinx.android.synthetic.main.activity_recyclerview.* + +/** + * TestActivity showcasing how to integrate a MapView in a RecyclerView. + * <p> + * It requires calling the correct lifecycle methods when detaching and attaching the View to + * the RecyclerView with onViewAttachedToWindow and onViewDetachedFromWindow. + * </p> + */ +@SuppressLint("ClickableViewAccessibility") +class RecyclerViewActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_recyclerview) + recyclerView.layoutManager = LinearLayoutManager(this) + recyclerView.adapter = ItemAdapter(LayoutInflater.from(this), savedInstanceState) + } + + override fun onSaveInstanceState(outState: Bundle?) { + super.onSaveInstanceState(outState) + // to save state, we need to call MapView#onSaveInstanceState + (recyclerView.adapter as ItemAdapter).onSaveInstanceState(outState) + } + + override fun onLowMemory() { + super.onLowMemory() + // to release memory, we need to call MapView#onLowMemory + (recyclerView.adapter as ItemAdapter).onLowMemory() + } + + override fun onDestroy() { + super.onDestroy() + // to perform cleanup, we need to call MapView#onDestroy + (recyclerView.adapter as ItemAdapter).onDestroy() + } + + class ItemAdapter(private val inflater: LayoutInflater, val savedInstanceState: Bundle?) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { + + private val items = listOf( + "one", "two", "three", MapItem(), "four", "five", "six", "seven", "eight", "nine", "ten", + "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", + "nineteen", "twenty", "twenty-one" + ) + + private var mapHolder: MapHolder? = null + + companion object { + const val TYPE_MAP = 0 + const val TYPE_TEXT = 1 + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return if (viewType == TYPE_MAP) { + val mapView = inflater.inflate(R.layout.item_map, parent, false) as MapView + mapHolder = MapHolder(mapView, savedInstanceState) + return mapHolder as MapHolder + } else { + TextHolder(inflater.inflate(android.R.layout.simple_list_item_1, parent, false) as TextView) + } + } + + override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) { + super.onViewAttachedToWindow(holder) + if (holder is MapHolder) { + val mapView = holder.mapView + mapView.onStart() + mapView.onResume() + } + } + + override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) { + super.onViewDetachedFromWindow(holder) + if (holder is MapHolder) { + val mapView = holder.mapView + mapView.onPause() + mapView.onStop() + } + } + + override fun getItemCount(): Int { + return items.count() + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + if (holder.itemViewType == TYPE_TEXT) { + val textHolder = holder as TextHolder + textHolder.bind(items[position] as String) + } + } + + override fun getItemViewType(position: Int): Int { + return if (items[position] is MapItem) { + TYPE_MAP + } else { + TYPE_TEXT + } + } + + fun onSaveInstanceState(savedInstanceState: Bundle?){ + savedInstanceState?.let { + mapHolder?.mapView?.onSaveInstanceState(it) + } + } + + fun onLowMemory() { + mapHolder?.mapView?.onLowMemory() + } + + fun onDestroy() { + mapHolder?.mapView?.let { + it.onPause() + it.onStop() + it.onDestroy() + } + } + + class MapItem + class MapHolder(val mapView: MapView, bundle: Bundle?) : RecyclerView.ViewHolder(mapView) { + init { + mapView.onCreate(bundle) + mapView.setOnTouchListener { view, motionEvent -> + // Disallow the touch request for recyclerView scroll + view.parent.requestDisallowInterceptTouchEvent(true) + mapView.onTouchEvent(motionEvent) + true + } + } + } + class TextHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) { + fun bind(item: String) { + textView.text = item + } + } + } +} diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java index 9f1e7b9956..f98cffecc9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/snapshot/MapSnapshotterActivity.java @@ -27,7 +27,6 @@ public class MapSnapshotterActivity extends AppCompatActivity { private GridLayout grid; private List<MapSnapshotter> snapshotters = new ArrayList<>(); - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -69,7 +68,7 @@ public class MapSnapshotterActivity extends AppCompatActivity { // Optionally the style .withStyle((column + row) % 2 == 0 ? Style.MAPBOX_STREETS : Style.DARK) - .withLocalIdeographFontFamily("sans-serif"); + .withLocalIdeographFontFamily("sans-serif"); // Optionally the visible region if (row % 2 == 0) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml index 51442894e1..3da56d1c82 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_multi_map.xml @@ -24,7 +24,7 @@ mapbox:mapbox_cameraTargetLat="38.913187" mapbox:mapbox_cameraTargetLng="-77.032546" mapbox:mapbox_cameraZoom="12" - mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" /> + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v11" /> <!-- SF --> <fragment @@ -36,7 +36,7 @@ mapbox:mapbox_cameraTargetLat="37.775732" mapbox:mapbox_cameraTargetLng="-122.413985" mapbox:mapbox_cameraZoom="13" - mapbox:mapbox_styleUrl="mapbox://styles/mapbox/outdoors-v10" /> + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/outdoors-v11" /> </LinearLayout> <LinearLayout @@ -56,7 +56,7 @@ mapbox:mapbox_cameraTargetLat="12.97913" mapbox:mapbox_cameraTargetLng="77.59188" mapbox:mapbox_cameraZoom="14" - mapbox:mapbox_styleUrl="mapbox://styles/mapbox/light-v9" /> + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/light-v10" /> <!-- Ayacucho --> <fragment @@ -68,6 +68,6 @@ mapbox:mapbox_cameraTargetLat="-13.155980" mapbox:mapbox_cameraTargetLng="-74.217134" mapbox:mapbox_cameraZoom="15" - mapbox:mapbox_styleUrl="mapbox://styles/mapbox/dark-v9" /> + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/dark-v10" /> </LinearLayout> </LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_recyclerview.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_recyclerview.xml new file mode 100644 index 0000000000..7d57f112b7 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_recyclerview.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <android.support.v7.widget.RecyclerView + android:id="@+id/recyclerView" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + +</android.support.constraint.ConstraintLayout>
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_dialog_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_dialog_map.xml index b8ea3d847e..9e5312f067 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_dialog_map.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/fragment_dialog_map.xml @@ -12,6 +12,6 @@ mapbox:mapbox_cameraTargetLat="47.6077" mapbox:mapbox_cameraTargetLng="-122.3421" mapbox:mapbox_cameraZoom="11" - mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v10" /> + mapbox:mapbox_styleUrl="mapbox://styles/mapbox/streets-v11" /> </LinearLayout> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map.xml new file mode 100644 index 0000000000..c4c17a25ff --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<com.mapbox.mapboxsdk.maps.MapView + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@id/mapView" + android:layout_width="match_parent" + android:layout_height="256dp" + app:mapbox_cameraTargetLat="45.38301927899065" + app:mapbox_cameraTargetLng="8.63525390625" + app:mapbox_renderTextureMode="true" + app:mapbox_cameraZoom="7" + app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml index 67447bce74..abd46d4c8c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml @@ -76,4 +76,5 @@ <string name="description_location_modes">Showcases location render and tracking modes</string> <string name="description_location_fragment">Uses LocationComponent in a Fragment</string> <string name="description_location_manual">Force location updates and don\'t rely on the engine</string> + <string name="description_recyclerview">Show a MapView as a recyclerView item</string> </resources> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml index a0525171a5..faa994e978 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml @@ -48,6 +48,8 @@ <item name="mapbox_accuracyColor">#FF82C6</item> <item name="mapbox_elevation">0dp</item> + <item name="mapbox_compassAnimationEnabled">false</item> + <item name="mapbox_accuracyAnimationEnabled">false</item> </style> </resources> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml index efd7476c4d..dd7900478b 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml @@ -76,4 +76,5 @@ <string name="activity_location_modes">Location Modes Activity</string> <string name="activity_location_fragment">Location Fragment</string> <string name="activity_location_manual">Manual Location updates</string> + <string name="activity_recyclerview">RecyclerView</string> </resources>
\ No newline at end of file |