Add Style URL Activity to Android Test App (#4170)

This commit is contained in:
Andrew Calcutt
2026-03-12 22:34:24 -04:00
committed by GitHub
parent 5107c6cc0b
commit fdc58f04ac
5 changed files with 149 additions and 0 deletions

View File

@@ -686,6 +686,18 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.style.StyleUrlActivity"
android:description="@string/description_style_url"
android:exported="true"
android:label="@string/activity_style_url">
<meta-data
android:name="@string/category"
android:value="@string/category_style" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.style.CustomSpriteActivity"
android:description="@string/description_custom_sprite"

View File

@@ -0,0 +1,100 @@
package org.maplibre.android.testapp.activity.style
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import org.maplibre.android.maps.MapLibreMap
import org.maplibre.android.maps.MapView
import org.maplibre.android.maps.Style
import org.maplibre.android.testapp.R
import org.maplibre.android.testapp.styles.TestStyles
/**
* Activity to demonstrate loading a style dynamically from a URL.
*/
class StyleUrlActivity : AppCompatActivity() {
private lateinit var mapView: MapView
private var mapLibreMap: MapLibreMap? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_style_url)
val urlInput = findViewById<AutoCompleteTextView>(R.id.urlAutoCompleteTextView)
val loadButton = findViewById<Button>(R.id.loadButton)
mapView = findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState)
val styles = arrayOf(
TestStyles.DEMOTILES,
TestStyles.AMERICANA,
TestStyles.OPENFREEMAP_LIBERTY,
TestStyles.OPENFREEMAP_BRIGHT,
TestStyles.AWS_OPEN_DATA_STANDARD_LIGHT,
TestStyles.PROTOMAPS_LIGHT,
TestStyles.PROTOMAPS_DARK,
TestStyles.PROTOMAPS_GRAYSCALE,
TestStyles.PROTOMAPS_WHITE,
TestStyles.PROTOMAPS_BLACK
)
val adapter = ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, styles)
urlInput.setAdapter(adapter)
urlInput.setOnClickListener {
urlInput.showDropDown()
}
mapView.getMapAsync { map ->
mapLibreMap = map
map.setStyle(Style.Builder().fromUri(urlInput.text.toString()))
}
loadButton.setOnClickListener {
val url = urlInput.text.toString()
if (url.isNotEmpty()) {
mapLibreMap?.setStyle(Style.Builder().fromUri(url)) {
Toast.makeText(this, "Style loaded", Toast.LENGTH_SHORT).show()
}
}
}
}
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 onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onDestroy() {
super.onDestroy()
mapView.onDestroy()
}
}

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<AutoCompleteTextView
android:id="@+id/urlAutoCompleteTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter or pick Style URL"
android:inputType="textUri"
android:completionThreshold="1"
android:text="https://demotiles.maplibre.org/style.json" />
<Button
android:id="@+id/loadButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load" />
</LinearLayout>
<org.maplibre.android.maps.MapView
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@@ -55,6 +55,7 @@
<string name="description_visibility_map">Changes visibility of map and view parent</string>
<string name="description_add_remove_markers">Change Symbol icon when zoom levels changes</string>
<string name="description_style_file">Use a local file as the style</string>
<string name="description_style_url">Load a map style dynamically from a URL</string>
<string name="description_map_in_dialog">Display a map inside a dialog fragment</string>
<string name="description_circle_layer">Show bus stops and route in Singapore</string>
<string name="description_collection_style_change">Verify that updating the GeoJsonSource across style changes allows for smooth transitions</string>

View File

@@ -40,6 +40,7 @@
<string name="activity_circle_layer">Circle layer</string>
<string name="activity_collection_style_change">Collection updates on style changes</string>
<string name="activity_style_file">Local Style file</string>
<string name="activity_style_url">Style URL</string>
<string name="activity_geojson_clustering">GeoJson Clustering</string>
<string name="activity_geojson_realtime">Add live realtime data</string>
<string name="activity_print">Print a map</string>