This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - update snapshot activity example with idle listener, conv…
…ert to kotlin
- Loading branch information
Showing
3 changed files
with
80 additions
and
126 deletions.
There are no files selected for viewing
114 changes: 0 additions & 114 deletions
114
.../src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
...pp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters