Add action journal (#3409)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
@@ -17,7 +17,7 @@ abstract class BaseLayerTest : AppCenter() {
|
||||
|
||||
fun before() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
nativeMapView = NativeMapView(context, false, null, null, NativeMapViewTest.DummyRenderer(context))
|
||||
nativeMapView = NativeMapView(context, null, null, NativeMapViewTest.DummyRenderer(context))
|
||||
nativeMapView.resizeView(WIDTH, HEIGHT)
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,10 @@ class NativeMapViewTest : AppCenter() {
|
||||
fun before() {
|
||||
val context = InstrumentationRegistry.getInstrumentation().context
|
||||
val apiKey = MapLibre.getApiKey()
|
||||
val options = NativeMapOptions(2.0f, false)
|
||||
|
||||
MapLibre.getInstance(context, apiKey, WellKnownTileServer.MapTiler)
|
||||
nativeMapView = NativeMapView(context, 2.0f, false, null, null, DummyRenderer(context))
|
||||
nativeMapView = NativeMapView(context, options, null, null, DummyRenderer(context))
|
||||
nativeMapView.resizeView(WIDTH, HEIGHT)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.maplibre.android.testapp.activity.events
|
||||
import android.app.ActivityManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import org.maplibre.android.MapLibre
|
||||
@@ -18,7 +19,11 @@ import kotlin.time.TimeSource
|
||||
import kotlin.time.TimeSource.Monotonic
|
||||
import org.maplibre.android.log.Logger
|
||||
import org.maplibre.android.log.Logger.INFO
|
||||
import org.maplibre.android.maps.MapLibreMap
|
||||
|
||||
|
||||
|
||||
// # --8<-- [start:ObserverActivity]
|
||||
/**
|
||||
* Test activity showcasing logging observer actions from the core
|
||||
*/
|
||||
@@ -30,6 +35,8 @@ class ObserverActivity : AppCompatActivity(),
|
||||
MapView.OnGlyphsRequestedListener,
|
||||
MapView.OnSpriteLoadedListener,
|
||||
MapView.OnSpriteRequestedListener {
|
||||
// # --8<-- [end:ObserverActivity]
|
||||
|
||||
private lateinit var mapView: MapView
|
||||
|
||||
companion object {
|
||||
@@ -38,9 +45,11 @@ class ObserverActivity : AppCompatActivity(),
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_map_simple)
|
||||
setContentView(R.layout.activity_map_events)
|
||||
mapView = findViewById(R.id.mapView)
|
||||
mapView.onCreate(savedInstanceState)
|
||||
|
||||
// # --8<-- [start:addListeners]
|
||||
mapView.addOnPreCompileShaderListener(this)
|
||||
mapView.addOnPostCompileShaderListener(this)
|
||||
mapView.addOnTileActionListener(this)
|
||||
@@ -48,44 +57,67 @@ class ObserverActivity : AppCompatActivity(),
|
||||
mapView.addOnGlyphsRequestedListener(this)
|
||||
mapView.addOnSpriteLoadedListener(this)
|
||||
mapView.addOnSpriteRequestedListener(this)
|
||||
// # --8<-- [end:addListeners]
|
||||
|
||||
mapView.getMapAsync {
|
||||
it.setStyle(
|
||||
Style.Builder().fromUri(TestStyles.getPredefinedStyleWithFallback("Streets"))
|
||||
Style.Builder().fromUri(TestStyles.DEMOTILES)
|
||||
)
|
||||
}
|
||||
|
||||
// print and clear action journal
|
||||
val fab = findViewById<View>(R.id.fab)
|
||||
fab?.setOnClickListener { _: View? ->
|
||||
mapView.getMapAsync {
|
||||
printActionJournal(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// # --8<-- [start:printActionJournal]
|
||||
fun printActionJournal(map: MapLibreMap) {
|
||||
// configure using `MapLibreMapOptions.actionJournal*` methods
|
||||
|
||||
Logger.i(TAG,"ActionJournal files: \n${map.actionJournalLogFiles.joinToString("\n")}")
|
||||
Logger.i(TAG,"ActionJournal : \n${map.actionJournalLog.joinToString("\n")}")
|
||||
|
||||
// print only the newest events on each call
|
||||
map.clearActionJournalLog()
|
||||
}
|
||||
// # --8<-- [end:printActionJournal]
|
||||
|
||||
private val shaderTimes: HashMap<String, TimeMark> = HashMap()
|
||||
|
||||
public override fun onPreCompileShader(id: Int, type: Int, defines: String) {
|
||||
// # --8<-- [start:mapEvents]
|
||||
override fun onPreCompileShader(id: Int, type: Int, defines: String) {
|
||||
shaderTimes["${id}-${type}-${defines}"] = TimeSource.Monotonic.markNow()
|
||||
Logger.i(TAG, "A new shader is being compiled, shaderID:${id}, backend type:${type}, program configuration:${defines}")
|
||||
}
|
||||
|
||||
public override fun onPostCompileShader(id: Int, type: Int, defines: String) {
|
||||
override fun onPostCompileShader(id: Int, type: Int, defines: String) {
|
||||
val startTime = shaderTimes.get("${id}-${type}-${defines}")
|
||||
if (startTime != null) {
|
||||
Logger.i(TAG, "A shader has been compiled in ${startTime.elapsedNow()}, shaderID:${id}, backend type:${type}, program configuration:${defines}")
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onGlyphsRequested(fontStack: Array<String>, rangeStart: Int, rangeEnd: Int) {
|
||||
override fun onGlyphsRequested(fontStack: Array<String>, rangeStart: Int, rangeEnd: Int) {
|
||||
Logger.i(TAG, "Glyphs are being requested for the font stack $fontStack, ranging from $rangeStart to $rangeEnd")
|
||||
}
|
||||
|
||||
public override fun onGlyphsLoaded(fontStack: Array<String>, rangeStart: Int, rangeEnd: Int) {
|
||||
override fun onGlyphsLoaded(fontStack: Array<String>, rangeStart: Int, rangeEnd: Int) {
|
||||
Logger.i(TAG, "Glyphs have been loaded for the font stack $fontStack, ranging from $rangeStart to $rangeEnd")
|
||||
}
|
||||
|
||||
public override fun onSpriteRequested(id: String, url: String) {
|
||||
override fun onSpriteRequested(id: String, url: String) {
|
||||
Logger.i(TAG, "The sprite $id has been requested from $url")
|
||||
}
|
||||
|
||||
public override fun onSpriteLoaded(id: String, url: String) {
|
||||
override fun onSpriteLoaded(id: String, url: String) {
|
||||
Logger.i(TAG, "The sprite $id has been loaded from $url")
|
||||
}
|
||||
|
||||
public override fun onTileAction(op: TileOperation, x: Int, y: Int, z: Int, wrap: Int, overscaledZ: Int, sourceID: String) {
|
||||
override fun onTileAction(op: TileOperation, x: Int, y: Int, z: Int, wrap: Int, overscaledZ: Int, sourceID: String) {
|
||||
val tile = "X:${x}, Y:${y}, Z:${z}, Wrap:${wrap}, OverscaledZ:${overscaledZ}, SourceID:${sourceID}"
|
||||
when (op) {
|
||||
TileOperation.RequestedFromCache -> Logger.i(TAG, "Requesting tile ${tile} from the cache")
|
||||
@@ -99,6 +131,7 @@ class ObserverActivity : AppCompatActivity(),
|
||||
TileOperation.NullOp -> Logger.e(TAG, "An unknown tile operation was emitted for tile ${tile}")
|
||||
}
|
||||
}
|
||||
// # --8<-- [end:mapEvents]
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
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"
|
||||
android:id="@+id/coordinator_layout">
|
||||
|
||||
<!-- -8<- [start:MapView] -->
|
||||
<org.maplibre.android.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:maplibre_actionJournalEnabled="true"
|
||||
app:maplibre_actionJournalLogFileSize="1024"
|
||||
app:maplibre_actionJournalLogFileCount="2"/>
|
||||
<!-- -8<- [end:MapView] -->
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_print"
|
||||
app:backgroundTint="@color/accent"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
Reference in New Issue
Block a user