diff --git a/ApiDemos/java/app/src/gms/java/com/example/mapdemo/EventsDemoActivity.java b/ApiDemos/java/app/src/gms/java/com/example/mapdemo/EventsDemoActivity.java index e05a4de9..78534c17 100644 --- a/ApiDemos/java/app/src/gms/java/com/example/mapdemo/EventsDemoActivity.java +++ b/ApiDemos/java/app/src/gms/java/com/example/mapdemo/EventsDemoActivity.java @@ -35,17 +35,17 @@ public class EventsDemoActivity extends AppCompatActivity implements OnMapClickListener, OnMapLongClickListener, OnCameraIdleListener, OnMapReadyCallback { - private TextView mTapTextView; - private TextView mCameraTextView; - private GoogleMap mMap; + private TextView tapTextView; + private TextView cameraTextView; + private GoogleMap map; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.events_demo); - mTapTextView = (TextView) findViewById(R.id.tap_text); - mCameraTextView = (TextView) findViewById(R.id.camera_text); + tapTextView = findViewById(R.id.tap_text); + cameraTextView = findViewById(R.id.camera_text); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); @@ -54,24 +54,24 @@ public class EventsDemoActivity extends AppCompatActivity @Override public void onMapReady(GoogleMap map) { - mMap = map; - mMap.setOnMapClickListener(this); - mMap.setOnMapLongClickListener(this); - mMap.setOnCameraIdleListener(this); + this.map = map; + this.map.setOnMapClickListener(this); + this.map.setOnMapLongClickListener(this); + this.map.setOnCameraIdleListener(this); } @Override public void onMapClick(LatLng point) { - mTapTextView.setText("tapped, point=" + point); + tapTextView.setText("tapped, point=" + point); } @Override public void onMapLongClick(LatLng point) { - mTapTextView.setText("long pressed, point=" + point); + tapTextView.setText("long pressed, point=" + point); } @Override public void onCameraIdle() { - mCameraTextView.setText(mMap.getCameraPosition().toString()); + cameraTextView.setText(map.getCameraPosition().toString()); } } diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt index 4532dcc4..afa58fa4 100644 --- a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt @@ -31,6 +31,10 @@ class DemoDetailsList { DemoDetails(R.string.close_info_window_demo_label, R.string.close_info_window_demo_details, CloseInfoWindowDemoActivity::class.java), + DemoDetails( + R.string.events_demo_label, + R.string.events_demo_details, + EventsDemoActivity::class.java), DemoDetails(R.string.layers_demo_label, R.string.layers_demo_description, LayersDemoActivity::class.java), DemoDetails(R.string.lite_demo_label, R.string.lite_demo_details, diff --git a/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/EventsDemoActivity.kt b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/EventsDemoActivity.kt new file mode 100644 index 00000000..1996cd3b --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/EventsDemoActivity.kt @@ -0,0 +1,64 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.example.kotlindemos + +import android.os.Bundle +import android.widget.TextView +import androidx.appcompat.app.AppCompatActivity +import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.GoogleMap.* +import com.google.android.gms.maps.OnMapReadyCallback +import com.google.android.gms.maps.SupportMapFragment +import com.google.android.gms.maps.model.LatLng + +/** + * This shows how to listen to some [GoogleMap] events. + */ +class EventsDemoActivity : AppCompatActivity(), OnMapClickListener, + OnMapLongClickListener, OnCameraIdleListener, OnMapReadyCallback { + + private lateinit var tapTextView: TextView + private lateinit var cameraTextView: TextView + private lateinit var map: GoogleMap + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.events_demo) + tapTextView = findViewById(R.id.tap_text) + cameraTextView = findViewById(R.id.camera_text) + val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment? + mapFragment?.getMapAsync(this) + } + + override fun onMapReady(googleMap: GoogleMap?) { + // return early if the map was not initialised properly + map = googleMap ?: return + map.setOnMapClickListener(this) + map.setOnMapLongClickListener(this) + map.setOnCameraIdleListener(this) + } + + override fun onMapClick(point: LatLng) { + tapTextView.text = "tapped, point=$point" + } + + override fun onMapLongClick(point: LatLng) { + tapTextView.text = "long pressed, point=$point" + } + + override fun onCameraIdle() { + if(!::map.isInitialized) return + cameraTextView.text = map.cameraPosition.toString() + } +} \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/gms/res/layout/events_demo.xml b/ApiDemos/kotlin/app/src/gms/res/layout/events_demo.xml new file mode 100644 index 00000000..acf55de0 --- /dev/null +++ b/ApiDemos/kotlin/app/src/gms/res/layout/events_demo.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + diff --git a/ApiDemos/kotlin/app/src/main/AndroidManifest.xml b/ApiDemos/kotlin/app/src/main/AndroidManifest.xml index 7f1d543e..4a577f69 100644 --- a/ApiDemos/kotlin/app/src/main/AndroidManifest.xml +++ b/ApiDemos/kotlin/app/src/main/AndroidManifest.xml @@ -63,6 +63,7 @@ + \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/main/res/values/strings.xml b/ApiDemos/kotlin/app/src/main/res/values/strings.xml index c335207a..d25420bc 100644 --- a/ApiDemos/kotlin/app/src/main/res/values/strings.xml +++ b/ApiDemos/kotlin/app/src/main/res/values/strings.xml @@ -49,6 +49,12 @@ Close Info Window Demo Demonstrates how to close the info window when the currently selected marker is retapped. + + Events + Demonstrates event handling. + Move the camera + Tap or long press on the map + Buildings Hybrid