summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-03-15 11:25:03 +0100
committerTobrun <tobrun@mapbox.com>2019-03-22 18:39:29 +0100
commit5ea450b14bb84950f80bda3eeb9873fdbd736fc7 (patch)
treef28c0e6a4334881f5c94b2675bbf593208cef0d1 /platform/android
parent03db58cdc1f1f31034863020f205f5c5696bfa8b (diff)
downloadqtlocation-mapboxgl-5ea450b14bb84950f80bda3eeb9873fdbd736fc7.tar.gz
[android] - add GLSurfaceView RecylerView example to test for regressions
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml19
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt155
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/RecyclerViewActivity.kt151
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/TextureRecyclerViewActivity.kt15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_gl.xml10
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_texture.xml (renamed from platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map.xml)0
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml3
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml3
8 files changed, 199 insertions, 157 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index d8eb81a972..fbba6a4927 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -895,9 +895,20 @@
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
- android:name=".activity.maplayout.RecyclerViewActivity"
- android:description="@string/description_recyclerview"
- android:label="@string/activity_recyclerview">
+ android:name=".activity.maplayout.TextureRecyclerViewActivity"
+ android:description="@string/description_recyclerview_textureview"
+ android:label="@string/activity_recyclerview_textureview">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_maplayout" />
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".activity.FeatureOverviewActivity" />
+ </activity>
+ <activity
+ android:name=".activity.maplayout.GLSurfaceRecyclerViewActivity"
+ android:description="@string/description_recyclerview_glsurfaceview"
+ android:label="@string/activity_recyclerview_glsurfaceview">
<meta-data
android:name="@string/category"
android:value="@string/category_maplayout" />
@@ -907,7 +918,7 @@
</activity>
<activity
android:name=".activity.fragment.NestedViewPagerActivity"
- android:description="@string/description_recyclerview"
+ android:description="@string/description_nested_viewpager"
android:label="@string/activity_nested_viewpager">
<meta-data
android:name="@string/category"
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt
new file mode 100644
index 0000000000..5acf356696
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/GLSurfaceRecyclerViewActivity.kt
@@ -0,0 +1,155 @@
+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.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+import kotlinx.android.synthetic.main.activity_recyclerview.*
+
+/**
+ * TestActivity showcasing how to integrate a GLSurfaceView 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")
+open class GLSurfaceRecyclerViewActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_recyclerview)
+ recyclerView.layoutManager = LinearLayoutManager(this)
+ recyclerView.adapter = ItemAdapter(this, 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()
+ }
+
+ open fun getMapItemLayoutId(): Int {
+ return R.layout.item_map_gl
+ }
+
+ class ItemAdapter(private val activity: GLSurfaceRecyclerViewActivity, 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(activity.getMapItemLayoutId(), parent, false) as MapView
+ mapView.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS) }
+ 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/maplayout/RecyclerViewActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/RecyclerViewActivity.kt
deleted file mode 100644
index 9989d1b137..0000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/RecyclerViewActivity.kt
+++ /dev/null
@@ -1,151 +0,0 @@
-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.maps.OnMapReadyCallback
-import com.mapbox.mapboxsdk.maps.Style
-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
- mapView.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS) }
- 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/maplayout/TextureRecyclerViewActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/TextureRecyclerViewActivity.kt
new file mode 100644
index 0000000000..895389bc1e
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/TextureRecyclerViewActivity.kt
@@ -0,0 +1,15 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.annotation.SuppressLint
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * TestActivity showcasing how to integrate a TexureView MapView in a RecyclerView.
+ */
+@SuppressLint("ClickableViewAccessibility")
+class TextureRecyclerViewActivity : GLSurfaceRecyclerViewActivity() {
+
+ override fun getMapItemLayoutId() : Int{
+ return R.layout.item_map_texture
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_gl.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_gl.xml
new file mode 100644
index 0000000000..850399e355
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_gl.xml
@@ -0,0 +1,10 @@
+<?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_cameraZoom="7"/>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_texture.xml
index 3224b73477..3224b73477 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_map_texture.xml
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 21ebeaabd5..cd4130c44a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -78,6 +78,7 @@
<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_location_activation_builder">Use LocationComponentActivationOptions to set options</string>
- <string name="description_recyclerview">Show a MapView as a recyclerView item</string>
+ <string name="description_recyclerview_textureview">Show a TextureView MapView as a recyclerView item</string>
+ <string name="description_recyclerview_glsurfaceview">Show a GLSurfaceView MapView as a recyclerView item</string>
<string name="description_nested_viewpager">Show a MapView inside a viewpager inside a recyclerView</string>
</resources>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index 26f56f29b1..07ba2b7afd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -78,6 +78,7 @@
<string name="activity_location_fragment">Location Fragment</string>
<string name="activity_location_manual">Manual Location updates</string>
<string name="activity_location_activation_builder">Build Location Activation</string>
- <string name="activity_recyclerview">RecyclerView</string>
+ <string name="activity_recyclerview_textureview">RecyclerView TextureView</string>
+ <string name="activity_recyclerview_glsurfaceview">RecyclerView GLSurfaceView</string>
<string name="activity_nested_viewpager">Nested ViewPager</string>
</resources> \ No newline at end of file