Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - update snapshot activity example with idle listener, conv…
Browse files Browse the repository at this point in the history
…ert to kotlin
  • Loading branch information
tobrun committed Apr 1, 2019
1 parent 2cfdd1a commit 4731f88
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 126 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.mapbox.mapboxsdk.testapp.activity.imagegenerator

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.testapp.R
import kotlinx.android.synthetic.main.activity_snapshot.*
import timber.log.Timber

/**
* Test activity showcasing the Snapshot API to create and display a bitmap of the current shown Map.
*/
class SnapshotActivity : AppCompatActivity(), OnMapReadyCallback {

private lateinit var mapboxMap: MapboxMap

private val idleListener = object : MapView.OnDidBecomeIdleListener {
override fun onDidBecomeIdle() {
mapView.removeOnDidBecomeIdleListener(this)
mapboxMap.snapshot { snapshot ->
imageView.setImageBitmap(snapshot)
mapView.addOnDidBecomeIdleListener(this)
}
}
}

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_snapshot)
mapView.onCreate(savedInstanceState)
mapView.getMapAsync(this)
}

override fun onMapReady(map: MapboxMap) {
mapboxMap = map
mapboxMap.setStyle(Style.Builder().fromUrl(Style.OUTDOORS)) { mapView.addOnDidBecomeIdleListener(idleListener) }
}

override fun onStart() {
super.onStart()
mapView.onStart()
}

override fun onResume() {
super.onResume()
mapView.onResume()
}

override fun onPause() {
super.onPause()
mapboxMap.snapshot {
Timber.e("Regression test for https://github.com/mapbox/mapbox-gl-native/pull/11358")
}
mapView.onPause()
}

override fun onStop() {
super.onStop()
mapView.onStop()
}

public override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}

override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}

public override fun onDestroy() {
super.onDestroy()
mapView.removeOnDidBecomeIdleListener(idleListener)
mapView.onDestroy()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
Expand All @@ -27,15 +26,4 @@

</LinearLayout>

<android.support.design.widget.FloatingActionButton
android:id="@id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add_a_photo_black"
app:backgroundTint="@android:color/white"/>

</RelativeLayout>

0 comments on commit 4731f88

Please sign in to comment.