summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src')
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml12
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/NestedViewPagerActivity.kt162
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_viewpager.xml17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml1
5 files changed, 192 insertions, 1 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index 1ec0116047..d6dca8664a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -872,7 +872,6 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
-
<activity
android:name=".activity.maplayout.RecyclerViewActivity"
android:description="@string/description_recyclerview"
@@ -884,6 +883,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
+ <activity
+ android:name=".activity.fragment.NestedViewPagerActivity"
+ android:description="@string/description_recyclerview"
+ android:label="@string/activity_nested_viewpager">
+ <meta-data
+ android:name="@string/category"
+ android:value="@string/category_fragment" />
+ <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/fragment/NestedViewPagerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/NestedViewPagerActivity.kt
new file mode 100644
index 0000000000..ee8a78750f
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/NestedViewPagerActivity.kt
@@ -0,0 +1,162 @@
+package com.mapbox.mapboxsdk.testapp.activity.fragment
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.support.v4.app.Fragment
+import android.support.v4.app.FragmentManager
+import android.support.v4.app.FragmentStatePagerAdapter
+import android.support.v4.view.ViewPager
+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.View
+import android.view.ViewGroup
+import android.widget.TextView
+import com.mapbox.mapboxsdk.camera.CameraPosition
+import com.mapbox.mapboxsdk.constants.Style
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.MapboxMapOptions
+import com.mapbox.mapboxsdk.maps.SupportMapFragment
+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 NestedViewPagerActivity : AppCompatActivity() {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_recyclerview)
+ recyclerView.layoutManager = LinearLayoutManager(this)
+ recyclerView.adapter = ItemAdapter(LayoutInflater.from(this), supportFragmentManager)
+ }
+
+ class ItemAdapter(private val inflater: LayoutInflater, private val fragmentManager: FragmentManager) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
+
+ private val items = listOf(
+ "one", "two", "three", ViewPagerItem(), "four", "five", "six", "seven", "eight", "nine", "ten",
+ "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
+ "nineteen", "twenty", "twenty-one"
+ )
+
+ private var mapHolder: ViewPagerHolder? = null
+
+ companion object {
+ const val TYPE_VIEWPAGER = 0
+ const val TYPE_TEXT = 1
+ }
+
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
+ return if (viewType == TYPE_VIEWPAGER) {
+ val viewPager = inflater.inflate(R.layout.item_viewpager, parent, false) as ViewPager
+ mapHolder = ViewPagerHolder(viewPager, fragmentManager)
+ return mapHolder as ViewPagerHolder
+ } else {
+ TextHolder(inflater.inflate(android.R.layout.simple_list_item_1, parent, false) as TextView)
+ }
+ }
+
+ 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 ViewPagerItem) {
+ TYPE_VIEWPAGER
+ } else {
+ TYPE_TEXT
+ }
+ }
+
+ class TextHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) {
+ fun bind(item: String) {
+ textView.text = item
+ }
+ }
+
+ class ViewPagerItem
+ class ViewPagerHolder(private val viewPager: ViewPager, fragmentManager: FragmentManager) : RecyclerView.ViewHolder(viewPager) {
+ init {
+ viewPager.adapter = MapPagerAdapter(fragmentManager)
+ viewPager.setOnTouchListener { view, motionEvent ->
+ // Disallow the touch request for recyclerView scroll
+ view.parent.requestDisallowInterceptTouchEvent(true)
+ viewPager.onTouchEvent(motionEvent)
+ false
+ }
+ }
+ }
+
+ class MapPagerAdapter(fm: FragmentManager?) : FragmentStatePagerAdapter(fm) {
+
+ override fun getItem(position: Int): Fragment {
+ val options = MapboxMapOptions()
+ options.textureMode(true)
+ options.doubleTapGesturesEnabled(false)
+ options.rotateGesturesEnabled(false)
+ options.tiltGesturesEnabled(false)
+ options.scrollGesturesEnabled(false)
+ options.zoomGesturesEnabled(false)
+ when (position) {
+ 0 -> {
+ options.styleUrl(Style.MAPBOX_STREETS)
+ options.camera(CameraPosition.Builder().target(LatLng(34.920526, 102.634774)).zoom(3.0).build())
+ return SupportMapFragment.newInstance(options)
+ }
+ 1 -> {
+ return EmptyFragment.newInstance()
+ }
+ 2 -> {
+ options.styleUrl(Style.DARK)
+ options.camera(CameraPosition.Builder().target(LatLng(62.326440, 92.764913)).zoom(3.0).build())
+ return SupportMapFragment.newInstance(options)
+ }
+ 3 -> {
+ return EmptyFragment.newInstance()
+ }
+ 4 -> {
+ options.styleUrl(Style.SATELLITE)
+ options.camera(CameraPosition.Builder().target(LatLng(-25.007786, 133.623852)).zoom(3.0).build())
+ return SupportMapFragment.newInstance(options)
+ }
+ 5 -> {
+ return EmptyFragment.newInstance()
+ }
+ }
+ throw IllegalAccessError()
+ }
+
+ override fun getCount(): Int {
+ return 6
+ }
+ }
+
+ class EmptyFragment : Fragment() {
+ companion object {
+ fun newInstance(): EmptyFragment {
+ return EmptyFragment()
+ }
+ }
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
+ val textView = TextView(inflater.context)
+ textView.text = "This is an empty Fragment"
+ return textView
+ }
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_viewpager.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_viewpager.xml
new file mode 100644
index 0000000000..9a0c882602
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/item_viewpager.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.mapbox.mapboxsdk.testapp.view.MapViewPager
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:id="@+id/viewpager"
+ android:layout_width="match_parent"
+ android:layout_height="256dp">
+
+ <android.support.v4.view.PagerTabStrip
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top"
+ android:paddingBottom="4dp"
+ android:paddingTop="4dp"/>
+
+</com.mapbox.mapboxsdk.testapp.view.MapViewPager>
+
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index abd46d4c8c..1256e42756 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -77,4 +77,5 @@
<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>
+ <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 dd7900478b..2408f7dcdb 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -77,4 +77,5 @@
<string name="activity_location_fragment">Location Fragment</string>
<string name="activity_location_manual">Manual Location updates</string>
<string name="activity_recyclerview">RecyclerView</string>
+ <string name="activity_nested_viewpager">Nested ViewPager</string>
</resources> \ No newline at end of file