Skip to content

Commit

Permalink
Add Android demo activity
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilsnd committed Aug 29, 2024
1 parent c0bb223 commit e55cdbd
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,18 @@
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity> <!-- Telemetry -->
<activity
android:name="org.maplibre.android.testapp.activity.telemetry.ObserverActivity"
android:description="@string/description_observer_activity"
android:exported="true"
android:label="@string/activity_observer_activity" >
<meta-data
android:name="@string/category"
android:value="@string/category_telemetry" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity> <!-- TextureView -->
<activity
android:name=".activity.textureview.TextureViewDebugModeActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package org.maplibre.android.testapp.activity.telemetry

import android.app.ActivityManager
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.MapLibre
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.Style
import org.maplibre.android.tile.TileOperation
import org.maplibre.android.testapp.R
import org.maplibre.android.testapp.styles.TestStyles
import timber.log.Timber
import java.util.*
import kotlin.time.TimeMark
import kotlin.time.TimeSource
import kotlin.time.TimeSource.Monotonic
import org.maplibre.android.log.Logger
import org.maplibre.android.log.Logger.INFO

/**
* Test activity showcasing logging observer actions from the core
*/
class ObserverActivity : AppCompatActivity(),
MapView.OnPreCompileShaderListener,
MapView.OnPostCompileShaderListener,
MapView.OnTileActionListener,
MapView.OnGlyphsLoadedListener,
MapView.OnGlyphsRequestedListener,
MapView.OnSpriteLoadedListener,
MapView.OnSpriteRequestedListener {
private lateinit var mapView: MapView

companion object {
const val TAG = "ObserverActivity"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map_simple)
mapView = findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
mapView.addOnPreCompileShaderListener(this)
mapView.addOnPostCompileShaderListener(this)
mapView.addOnTileActionListener(this)
mapView.addOnGlyphsLoadedListener(this)
mapView.addOnGlyphsRequestedListener(this)
mapView.addOnSpriteLoadedListener(this)
mapView.addOnSpriteRequestedListener(this)
mapView.getMapAsync {
it.setStyle(
Style.Builder().fromUri(TestStyles.getPredefinedStyleWithFallback("Streets"))
)
}
}

private val shaderTimes: HashMap<String, TimeMark> = HashMap()

public 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) {
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) {
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) {
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) {
Logger.i(TAG, "The sprite $id has been requested from $url")
}

public 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) {
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")
TileOperation.RequestedFromNetwork -> Logger.i(TAG, "Requesting tile ${tile} from the network")
TileOperation.LoadFromCache -> Logger.i(TAG, "Loading tile ${tile}, requested from the cache")
TileOperation.LoadFromNetwork -> Logger.i(TAG, "Loading tile ${tile}, requested from the network")
TileOperation.StartParse -> Logger.i(TAG, "Parsing tile ${tile}")
TileOperation.EndParse -> Logger.i(TAG, "Completed parsing tile ${tile}")
TileOperation.Error -> Logger.e(TAG, "An error occured during proccessing for tile ${tile}")
TileOperation.Cancelled -> Logger.i(TAG, "Pending work on tile ${tile} was cancelled")
TileOperation.NullOp -> Logger.e(TAG, "An unknown tile operation was emitted for tile ${tile}")
}
}

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

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

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

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

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

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

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="category_style">Styling</string>
<string name="category_features">Features</string>
<string name="category_storage">Storage</string>
<string name="category_telemetry">Telemetry</string>
<string name="category_textureview">Texture View</string>
<string name="category_location">Location</string>
<string name="category_integration">_Integration</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<string name="description_map_snapshotter_local_style">Show how to load a local style with a Snapshot</string>
<string name="description_camera_animator">Use Android SDK Animators to animate camera position changes</string>
<string name="description_symbol_generator">Use Android SDK Views as symbols</string>
<string name="description_observer_activity">Use map observers to log telemetry information</string>
<string name="description_textureview_debug">Use TextureView to render the map</string>
<string name="description_textureview_resize">Resize a map rendered on a TextureView</string>
<string name="description_textureview_animate">Animate a map rendered on a TextureView</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<string name="activity_map_snapshotter_local_style">Map Snapshot with local style</string>
<string name="activity_camera_animator">Animator animation</string>
<string name="activity_symbol_generator">SymbolGenerator</string>
<string name="activity_observer_activity">Log map observer telemetry</string>
<string name="activity_textureview_debug">TextureView debug</string>
<string name="activity_textureview_resize">TextureView resize</string>
<string name="activity_textureview_animate">TextureView animation</string>
Expand Down

0 comments on commit e55cdbd

Please sign in to comment.