summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobrun <tobrun.van.nuland@gmail.com>2019-03-22 09:37:21 +0100
committerTobrun <tobrun@mapbox.com>2019-03-25 15:22:29 +0100
commit7dea381161006e00b007ab01e491acc7166bd075 (patch)
tree6aec44f348d8876ca50f804bce1b951eb239a1d8
parente7c9d3ca55fc74cf0ca978b48797549d5a0a4812 (diff)
downloadqtlocation-mapboxgl-7dea381161006e00b007ab01e491acc7166bd075.tar.gz
[android] - revert onDismiss workaround, refactor tests, adress review
comments
-rw-r--r--circle.yml4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt59
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt16
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt18
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt18
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt15
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt4
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/ViewPagerActivity.kt88
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java34
-rw-r--r--platform/android/scripts/exclude-activity-gen.json3
13 files changed, 155 insertions, 153 deletions
diff --git a/circle.yml b/circle.yml
index 87de7109ac..b47281cf26 100644
--- a/circle.yml
+++ b/circle.yml
@@ -15,8 +15,8 @@ workflows:
- android-arm-template:
name: android-gnustl-arm-v7
stl: gnustl_shared
- firebase_device_id: "m0"
- firebase_device_os: "18"
+ firebase_device_id: "cheryl"
+ firebase_device_os: "25"
image: android-ndk-r17c:1d5db0eb34
abi: arm-v7
- android-release:
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt
index 4d39b55a25..be57fb3e2d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/BaseIntegrationTest.kt
@@ -1,60 +1,31 @@
package com.mapbox.mapboxsdk.integration
+import android.content.Context
import android.content.Intent
+import android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP
import android.support.test.InstrumentationRegistry
import android.support.test.uiautomator.*
-import org.hamcrest.CoreMatchers
-import org.hamcrest.MatcherAssert
import org.junit.Before
-const val LAUNCH_TIMEOUT = 2500L
-private const val TEST_APP_PACKAGE = "com.mapbox.mapboxsdk.testapp"
-
abstract class BaseIntegrationTest {
protected lateinit var device: UiDevice
@Before
open fun beforeTest() {
- // Initialize UiDevice instance
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
-
- // Start from the home screen
- device.pressHome()
-
- // Wait for launcher
- val launcherPackage: String = device.launcherPackageName
- MatcherAssert.assertThat(launcherPackage, CoreMatchers.notNullValue())
- device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT)
-
- // Launch the app
- val context = InstrumentationRegistry.getInstrumentation().context
- val intent = context.packageManager.getLaunchIntentForPackage(TEST_APP_PACKAGE).apply {
- // Clear out any previous instances
- addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
- }
- context.startActivity(intent)
-
- // Wait for the app to appear
- device.wait(
- Until.hasObject(By.pkg(TEST_APP_PACKAGE).depth(0)),
- LAUNCH_TIMEOUT
- )
- }
-
- fun openFeature(featureName: String) {
- scrollRecyclerViewTo(featureName)
- device.findObject(UiSelector().text(featureName)).clickAndWaitForNewWindow()
- device.waitForIdle(LAUNCH_TIMEOUT)
- }
-
- fun scrollRecyclerViewTo(recycleItem: String) {
- val appView = UiScrollable(UiSelector().scrollable(true))
- appView.scrollIntoView(UiSelector().text(recycleItem))
- }
-
- fun pressHomeReturnWithRecentApps(){
- device.pressRecentApps()
- device.findObject(UiSelector().text(InstrumentationRegistry.getTargetContext().getString(InstrumentationRegistry.getTargetContext().applicationInfo.labelRes))).click()
}
+}
+
+fun UiDevice.launchActivity(context: Context, clazz: Class<*>) {
+ val applicationPackage = InstrumentationRegistry.getTargetContext().packageName
+ val intent = Intent(context, clazz)
+ intent.addFlags(FLAG_ACTIVITY_SINGLE_TOP)
+ InstrumentationRegistry.getContext().startActivity(intent)
+ wait(Until.hasObject(By.pkg(applicationPackage).depth(0)), 5000)
+}
+
+fun UiDevice.scrollRecyclerViewTo(recycleItem: String) {
+ val appView = UiScrollable(UiSelector().scrollable(true))
+ appView.scrollIntoView(UiSelector().text(recycleItem))
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt
index 9eb03bd1c5..e57e1d1abd 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/FragmentBackStackTest.kt
@@ -1,9 +1,13 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.UiSelector
+import com.mapbox.mapboxsdk.testapp.activity.fragment.FragmentBackStackActivity
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -13,21 +17,19 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class FragmentBackStackTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("Backstack Map Fragment")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<FragmentBackStackActivity> = ActivityTestRule(FragmentBackStackActivity::class.java)
@Test
@LargeTest
fun backPressedOnBackStackResumed(){
device.waitForIdle()
clickReplaceFragmentButton()
+ device.pressHome()
device.waitForIdle()
- pressHomeReturnWithRecentApps()
- device.waitForIdle()
+ device.launchActivity(activityRule.activity.applicationContext, FragmentBackStackActivity::class.java)
backPressBackStack()
+ device.waitForIdle()
}
private fun clickReplaceFragmentButton(){
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt
index 07fea012eb..755c5fc560 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReopenTest.kt
@@ -1,27 +1,29 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
-import org.junit.Before
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+
/**
* Regression test that validates reopening an Activity with a GLSurfaceView
*/
@RunWith(AndroidJUnit4::class)
class GLSurfaceViewReopenTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("Simple Map")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)
@Test
@LargeTest
fun reopenSimpleMapActivity() {
- pressHomeReturnWithRecentApps()
device.waitForIdle()
+ device.pressHome()
+ device.waitForIdle()
+ device.launchActivity(activityRule.activity.applicationContext, SimpleMapActivity::class.java)
}
-} \ No newline at end of file
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt
index 95f05566c3..945fac677e 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/GLSurfaceViewReuseTest.kt
@@ -1,8 +1,12 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -12,19 +16,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class GLSurfaceViewReuseTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("RecyclerView GLSurfaceView")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<GLSurfaceRecyclerViewActivity> = ActivityTestRule(GLSurfaceRecyclerViewActivity::class.java)
@Test
@LargeTest
- fun scrollRecylerView() {
+ fun scrollRecyclerView() {
device.waitForIdle()
- scrollRecyclerViewTo("Twenty-one")
+ device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
- scrollRecyclerViewTo("One")
+ device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt
index b79303a1a8..941b7ea8dc 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/OrientationChangeTest.kt
@@ -1,19 +1,20 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class OrientationChangeTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("Simple Map")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<SimpleMapActivity> = ActivityTestRule(SimpleMapActivity::class.java)
@Test
@LargeTest
@@ -25,5 +26,9 @@ class OrientationChangeTest : BaseIntegrationTest() {
device.setOrientationRight()
device.waitForIdle()
device.setOrientationNatural()
+ device.setOrientationLeft()
+ device.setOrientationNatural()
+ device.setOrientationRight()
+ device.setOrientationNatural()
}
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt
index 3de8ece8c3..cc171ca905 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReopenTest.kt
@@ -1,8 +1,13 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
+import com.mapbox.mapboxsdk.testapp.activity.textureview.TextureViewDebugModeActivity
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.Thread.sleep
@@ -13,17 +18,15 @@ import java.lang.Thread.sleep
@RunWith(AndroidJUnit4::class)
class TextureViewReopenTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("TextureView debug")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<TextureViewDebugModeActivity> = ActivityTestRule(TextureViewDebugModeActivity::class.java)
@Test
@LargeTest
fun reopenTextureViewDebugActivity() {
- pressHomeReturnWithRecentApps()
device.waitForIdle()
- sleep(LAUNCH_TIMEOUT)
+ device.pressHome()
+ device.waitForIdle()
+ device.launchActivity(activityRule.activity.applicationContext, TextureViewDebugModeActivity::class.java)
}
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt
index 6053e696d6..5c3d66c462 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/TextureViewReuseTest.kt
@@ -1,8 +1,12 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.TextureRecyclerViewActivity
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -12,18 +16,16 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class TextureViewReuseTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("RecyclerView TextureView")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<TextureRecyclerViewActivity> = ActivityTestRule(TextureRecyclerViewActivity::class.java)
@Test
@LargeTest
- fun scrollRecylerView() {
- scrollRecyclerViewTo("Twenty-one")
+ fun scrollRecyclerView() {
+ device.waitForIdle()
+ device.scrollRecyclerViewTo("Twenty-one")
device.waitForIdle()
- scrollRecyclerViewTo("One")
+ device.scrollRecyclerViewTo("One")
device.waitForIdle()
}
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt
index 9f4b7591b6..b918801296 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/integration/ViewPagerScrollTest.kt
@@ -1,9 +1,13 @@
package com.mapbox.mapboxsdk.integration
import android.support.test.filters.LargeTest
+import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.test.uiautomator.UiSelector
+import com.mapbox.mapboxsdk.testapp.activity.fragment.ViewPagerActivity
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.GLSurfaceRecyclerViewActivity
import org.junit.Before
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -13,20 +17,17 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ViewPagerScrollTest : BaseIntegrationTest() {
- @Before
- override fun beforeTest() {
- super.beforeTest()
- openFeature("ViewPager")
- }
+ @get:Rule
+ var activityRule: ActivityTestRule<ViewPagerActivity> = ActivityTestRule(ViewPagerActivity::class.java)
@Test
@LargeTest
fun scrollViewPager() {
- for (i in 1..5) {
+ for (i in 1..4) {
clickTab(i)
}
- for (i in 4 downTo 0) {
+ for (i in 3 downTo 0) {
clickTab(i)
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt
index 418191e91a..2731b20db7 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/fragment/MapDialogFragmentTest.kt
@@ -10,6 +10,7 @@ import android.support.test.runner.AndroidJUnit4
import com.mapbox.mapboxsdk.testapp.R
import com.mapbox.mapboxsdk.testapp.action.WaitAction
import com.mapbox.mapboxsdk.testapp.activity.maplayout.MapInDialogActivity
+import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -25,9 +26,10 @@ class MapDialogFragmentTest {
var activityRule: ActivityTestRule<MapInDialogActivity> = ActivityTestRule(MapInDialogActivity::class.java)
@Test
+ @Ignore
fun openCloseDialog() {
onView(withId(R.id.button_open_dialog)).perform(click())
- onView(withId(R.id.mapView)).perform(WaitAction(2500))
+ Thread.sleep(2500)
Espresso.pressBack()
}
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/ViewPagerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/ViewPagerActivity.kt
index 8312661ebd..77e2e1370d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/ViewPagerActivity.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/ViewPagerActivity.kt
@@ -26,46 +26,84 @@ class ViewPagerActivity : AppCompatActivity() {
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
super.onRestoreInstanceState(savedInstanceState)
- val currentPosition = viewPager!!.currentItem
- for (i in 0 until FRAGMENT_COUNT) {
- if (Math.abs(i - currentPosition) <= 1) {
- viewPager.adapter?.instantiateItem(viewPager, 0)
- break
- }
+
+ val currentPosition = viewPager.currentItem
+ var mapFragment: SupportMapFragment
+
+ if (Math.abs(0 - currentPosition) <= 1) {
+ mapFragment = viewPager.adapter?.instantiateItem(viewPager, 0) as SupportMapFragment
+ mapFragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS) }
+ }
+
+ if (Math.abs(1 - currentPosition) <= 1) {
+ mapFragment = viewPager.adapter?.instantiateItem(viewPager, 1) as SupportMapFragment
+ mapFragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.DARK) }
+ }
+
+ if (Math.abs(2 - currentPosition) <= 1) {
+ mapFragment = viewPager.adapter?.instantiateItem(viewPager, 2) as SupportMapFragment
+ mapFragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.SATELLITE) }
+ }
+
+ if (Math.abs(3 - currentPosition) <= 1) {
+ mapFragment = viewPager.adapter?.instantiateItem(viewPager, 3) as SupportMapFragment
+ mapFragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.SATELLITE) }
+ }
+
+ if (Math.abs(4 - currentPosition) <= 1) {
+ mapFragment = viewPager.adapter?.instantiateItem(viewPager, 4) as SupportMapFragment
+ mapFragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.SATELLITE) }
}
}
internal class MapFragmentAdapter(fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) {
override fun getCount(): Int {
- return FRAGMENT_COUNT
+ return NUM_ITEMS
}
- override fun getItem(position: Int): Fragment {
- return when (position) {
- 0 -> createFragment(Style.MAPBOX_STREETS, LatLng(34.920526, 102.634774))
- 1 -> createFragment(Style.DARK, LatLng(62.326440, 92.764913))
- 2 -> createFragment(Style.SATELLITE, LatLng(-25.007786, 133.623852))
- 3 -> createFragment(Style.LIGHT, LatLng(-19.922070, -43.939676))
- 4 -> createFragment(Style.OUTDOORS, LatLng(46.881020, 9.098098))
- else -> createFragment(Style.TRAFFIC_DAY, LatLng(40.722517, -74.000029))
- }
- }
+ override fun getItem(position: Int): Fragment? {
+ var fragment: SupportMapFragment? = null
+ val options = MapboxMapOptions()
+ options.textureMode(true)
- private fun createFragment(@Style.StyleUrl style: String, latLng: LatLng): Fragment {
- val options = MapboxMapOptions().camera(CameraPosition.Builder().target(latLng).zoom(3.0).build())
- val fragment = SupportMapFragment.newInstance(options)
- fragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(style) }
+ when (position) {
+ 0 -> {
+ options.camera(CameraPosition.Builder().target(LatLng(34.920526, 102.634774)).zoom(3.0).build())
+ fragment = SupportMapFragment.newInstance(options)
+ fragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.MAPBOX_STREETS) }
+ }
+ 1 -> {
+ options.camera(CameraPosition.Builder().target(LatLng(62.326440, 92.764913)).zoom(3.0).build())
+ fragment = SupportMapFragment.newInstance(options)
+ fragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.DARK) }
+ }
+ 2 -> {
+ options.camera(CameraPosition.Builder().target(LatLng(-25.007786, 133.623852)).zoom(3.0).build())
+ fragment = SupportMapFragment.newInstance(options)
+ fragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.SATELLITE) }
+ }
+ 3 -> {
+ options.camera(CameraPosition.Builder().target(LatLng(62.326440, 92.764913)).zoom(3.0).build())
+ fragment = SupportMapFragment.newInstance(options)
+ fragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.LIGHT) }
+ }
+ 4 -> {
+ options.camera(CameraPosition.Builder().target(LatLng(34.920526, 102.634774)).zoom(3.0).build())
+ fragment = SupportMapFragment.newInstance(options)
+ fragment.getMapAsync { mapboxMap -> mapboxMap.setStyle(Style.TRAFFIC_NIGHT) }
+ }
+ }
return fragment
}
override fun getPageTitle(position: Int): CharSequence? {
return "Page $position"
}
- }
- companion object {
- const val FRAGMENT_COUNT = 6
+ companion object {
+
+ private val NUM_ITEMS = 5
+ }
}
}
-
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
index c9a9377885..18092ce372 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
@@ -1,6 +1,5 @@
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@@ -17,9 +16,6 @@ import com.mapbox.mapboxsdk.testapp.R;
/**
* Test activity showcasing showing a Map inside of a DialogFragment.
- * <p>
- * Uses the deprecated TextureView API to workaround the issue of seeing a grey background before the gl surface.
- * </p>
*/
public class MapInDialogActivity extends AppCompatActivity {
@@ -64,23 +60,6 @@ public class MapInDialogActivity extends AppCompatActivity {
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.OUTDOORS));
}
- @NonNull
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- return new Dialog(getActivity(), getTheme()) {
- @Override
- public void dismiss() {
- if (mapView != null && !mapView.isDestroyed()) {
- mapView.onPause();
- mapView.onStop();
- mapView.onDestroy();
- mapView = null;
- }
- super.dismiss();
- }
- };
- }
-
@Override
public void onStart() {
super.onStart();
@@ -96,25 +75,20 @@ public class MapInDialogActivity extends AppCompatActivity {
@Override
public void onPause() {
super.onPause();
- if (mapView != null) {
- mapView.onPause();
- }
+ mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
- if (mapView != null) {
- mapView.onStop();
- }
+ mapView.onStop();
}
@Override
public void onDestroyView() {
super.onDestroyView();
- if (mapView != null) {
- mapView.onDestroy();
- }
+ mapView.onDestroy();
+ mapView = null;
}
@Override
diff --git a/platform/android/scripts/exclude-activity-gen.json b/platform/android/scripts/exclude-activity-gen.json
index 9e0a1d154f..47c437bd23 100644
--- a/platform/android/scripts/exclude-activity-gen.json
+++ b/platform/android/scripts/exclude-activity-gen.json
@@ -48,5 +48,6 @@
"EspressoTestActivity",
"ChangeResourcesCachePathActivity",
"EspressoTestActivity",
- "FragmentBackStackActivity"
+ "FragmentBackStackActivity",
+ "ChildFragmentMapInDialogActivity"
]