From 31c14c9d7a54d0759d081017fd7ac06796c2efe7 Mon Sep 17 00:00:00 2001 From: Katherine Allen Date: Mon, 15 Jan 2018 15:20:33 +1100 Subject: [PATCH] adding kotlin marker demo and associated files. New commit as I accidentally pushed the previous one before it was completed. --- .../example/kotlindemos/DemoDetailsList.kt | 1 + .../example/kotlindemos/MarkerDemoActivity.kt | 23 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt index 03109440..7a19206a 100644 --- a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt +++ b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt @@ -25,5 +25,6 @@ class DemoDetailsList { DemoDetails(R.string.markers_demo_label, R.string.markers_demo_description, MarkerDemoActivity::class.java) ) + } } \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt index 13e23a31..b101cc2f 100644 --- a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt +++ b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/MarkerDemoActivity.kt @@ -84,6 +84,8 @@ class MarkerDemoActivity : OnInfoWindowCloseListener, OnMapAndViewReadyListener.OnGlobalLayoutAndMapReadyListener { + private val TAG = MarkerDemoActivity::class.java.name + /** This is ok to be lateinit as it is initialised in onMapReady */ private lateinit var map: GoogleMap @@ -116,8 +118,6 @@ class MarkerDemoActivity : private val random = Random() - private val TAG = MarkerDemoActivity::class.java.name - /** Demonstrates customizing the info window and/or its contents. */ internal inner class CustomInfoWindowAdapter : InfoWindowAdapter { @@ -187,7 +187,7 @@ class MarkerDemoActivity : super.onCreate(savedInstanceState) setContentView(R.layout.marker_demo) - topText = findViewById(R.id.top_text) + topText = findViewById(R.id.top_text) rotationBar = findViewById(R.id.rotationSeekBar).apply { max = 360 @@ -196,7 +196,7 @@ class MarkerDemoActivity : /** Called when the Rotation progress bar is moved */ override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { val rotation = seekBar?.progress?.toFloat() - checkReadyThen { markerRainbow.map { it.rotation = rotation ?: 0F } } + checkReadyThen { markerRainbow.map { it.rotation = rotation ?: 0f } } } override fun onStartTrackingTouch(p0: SeekBar?) { @@ -210,9 +210,7 @@ class MarkerDemoActivity : } ) } - - - flatBox = findViewById(R.id.flat) + flatBox = findViewById(R.id.flat) options = findViewById(R.id.custom_info_window_options).apply { setOnCheckedChangeListener { _, _ -> @@ -234,8 +232,8 @@ class MarkerDemoActivity : */ override fun onMapReady(googleMap: GoogleMap?) { - // exit early if the map was not initialised properly - if (googleMap == null) return + // return early if the map was not initialised properly + map = googleMap ?: return // create bounds that encompass every location we reference val boundsBuilder = LatLngBounds.Builder() @@ -243,7 +241,7 @@ class MarkerDemoActivity : places.keys.map { place -> boundsBuilder.include(places.getValue(place)) } val bounds = boundsBuilder.build() - map = googleMap.apply { + with(map) { // Hide the zoom controls as the button panel will cover it. uiSettings.isZoomControlsEnabled = false @@ -338,7 +336,6 @@ class MarkerDemoActivity : ) } - // place markers for each of the defined locations placeDetailsMap.keys.map { with(placeDetailsMap.getValue(it)) { @@ -402,11 +399,13 @@ class MarkerDemoActivity : } /** Called when the Clear button is clicked. */ + @Suppress("UNUSED_PARAMETER") fun onClearMap(view: View) { checkReadyThen { map.clear() } } /** Called when the Reset button is clicked. */ + @Suppress("UNUSED_PARAMETER") fun onResetMap(view: View) { checkReadyThen { map.clear() @@ -415,11 +414,11 @@ class MarkerDemoActivity : } /** Called when the Flat check box is checked or unchecked */ + @Suppress("UNUSED_PARAMETER") fun onToggleFlat(view: View) { checkReadyThen { markerRainbow.map { marker -> marker.isFlat = flatBox.isChecked } } } - // // Marker related listeners. //