mirror of
https://github.com/googlemaps/android-samples.git
synced 2026-01-18 14:07:37 +00:00
chore: Add SplitStreetViewPanoramaAndMapDemoActivity in Kotlin (#203)
Also update Java example to not use Hungarian notation
This commit is contained in:
parent
7fdbaa234f
commit
b2c83b643e
@ -44,9 +44,9 @@ public class SplitStreetViewPanoramaAndMapDemoActivity extends AppCompatActivity
|
||||
// George St, Sydney
|
||||
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
|
||||
|
||||
private StreetViewPanorama mStreetViewPanorama;
|
||||
private StreetViewPanorama streetViewPanorama;
|
||||
|
||||
private Marker mMarker;
|
||||
private Marker marker;
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
@ -67,13 +67,13 @@ public class SplitStreetViewPanoramaAndMapDemoActivity extends AppCompatActivity
|
||||
new OnStreetViewPanoramaReadyCallback() {
|
||||
@Override
|
||||
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
|
||||
mStreetViewPanorama = panorama;
|
||||
mStreetViewPanorama.setOnStreetViewPanoramaChangeListener(
|
||||
streetViewPanorama = panorama;
|
||||
streetViewPanorama.setOnStreetViewPanoramaChangeListener(
|
||||
SplitStreetViewPanoramaAndMapDemoActivity.this);
|
||||
// Only need to set the position once as the streetview fragment will maintain
|
||||
// its state.
|
||||
if (savedInstanceState == null) {
|
||||
mStreetViewPanorama.setPosition(SYDNEY);
|
||||
streetViewPanorama.setPosition(SYDNEY);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -85,7 +85,7 @@ public class SplitStreetViewPanoramaAndMapDemoActivity extends AppCompatActivity
|
||||
public void onMapReady(GoogleMap map) {
|
||||
map.setOnMarkerDragListener(SplitStreetViewPanoramaAndMapDemoActivity.this);
|
||||
// Creates a draggable marker. Long press to drag.
|
||||
mMarker = map.addMarker(new MarkerOptions()
|
||||
marker = map.addMarker(new MarkerOptions()
|
||||
.position(markerPosition)
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman))
|
||||
.draggable(true));
|
||||
@ -96,13 +96,13 @@ public class SplitStreetViewPanoramaAndMapDemoActivity extends AppCompatActivity
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(MARKER_POSITION_KEY, mMarker.getPosition());
|
||||
outState.putParcelable(MARKER_POSITION_KEY, marker.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStreetViewPanoramaChange(StreetViewPanoramaLocation location) {
|
||||
if (location != null) {
|
||||
mMarker.setPosition(location.position);
|
||||
marker.setPosition(location.position);
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class SplitStreetViewPanoramaAndMapDemoActivity extends AppCompatActivity
|
||||
|
||||
@Override
|
||||
public void onMarkerDragEnd(Marker marker) {
|
||||
mStreetViewPanorama.setPosition(marker.getPosition(), 150);
|
||||
streetViewPanorama.setPosition(marker.getPosition(), 150);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -45,6 +45,10 @@ class DemoDetailsList {
|
||||
R.string.street_view_panorama_navigation_demo_label,
|
||||
R.string.street_view_panorama_navigation_demo_details,
|
||||
StreetViewPanoramaNavigationDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.split_street_view_panorama_and_map_demo_label,
|
||||
R.string.split_street_view_panorama_and_map_demo_details,
|
||||
SplitStreetViewPanoramaAndMapDemoActivity::class.java),
|
||||
DemoDetails(R.string.tags_demo_label, R.string.tags_demo_details,
|
||||
TagsDemoActivity::class.java),
|
||||
DemoDetails(R.string.ui_settings_demo_label, R.string.ui_settings_demo_details,
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
// 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 androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener
|
||||
import com.google.android.gms.maps.StreetViewPanorama
|
||||
import com.google.android.gms.maps.StreetViewPanorama.OnStreetViewPanoramaChangeListener
|
||||
import com.google.android.gms.maps.SupportMapFragment
|
||||
import com.google.android.gms.maps.SupportStreetViewPanoramaFragment
|
||||
import com.google.android.gms.maps.model.*
|
||||
|
||||
/**
|
||||
* This shows how to create a simple activity with streetview and a map
|
||||
*/
|
||||
class SplitStreetViewPanoramaAndMapDemoActivity : AppCompatActivity(),
|
||||
OnMarkerDragListener, OnStreetViewPanoramaChangeListener {
|
||||
var streetViewPanorama: StreetViewPanorama? = null
|
||||
var marker: Marker? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.split_street_view_panorama_and_map_demo)
|
||||
val markerPosition = savedInstanceState?.getParcelable(MARKER_POSITION_KEY) ?: SYDNEY
|
||||
|
||||
val streetViewPanoramaFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.streetviewpanorama) as SupportStreetViewPanoramaFragment?
|
||||
streetViewPanoramaFragment?.getStreetViewPanoramaAsync { panorama ->
|
||||
streetViewPanorama = panorama
|
||||
streetViewPanorama?.setOnStreetViewPanoramaChangeListener(
|
||||
this@SplitStreetViewPanoramaAndMapDemoActivity
|
||||
)
|
||||
// Only need to set the position once as the streetview fragment will maintain
|
||||
// its state.
|
||||
savedInstanceState ?: streetViewPanorama?.setPosition(SYDNEY)
|
||||
}
|
||||
val mapFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
|
||||
mapFragment?.getMapAsync { map ->
|
||||
map.setOnMarkerDragListener(this@SplitStreetViewPanoramaAndMapDemoActivity)
|
||||
// Creates a draggable marker. Long press to drag.
|
||||
marker = map.addMarker(
|
||||
MarkerOptions()
|
||||
.position(markerPosition)
|
||||
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman))
|
||||
.draggable(true)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putParcelable(
|
||||
MARKER_POSITION_KEY,
|
||||
marker?.position
|
||||
)
|
||||
}
|
||||
|
||||
override fun onStreetViewPanoramaChange(location: StreetViewPanoramaLocation) {
|
||||
marker?.position = location.position
|
||||
}
|
||||
|
||||
override fun onMarkerDragStart(marker: Marker) {}
|
||||
override fun onMarkerDragEnd(marker: Marker) {
|
||||
streetViewPanorama?.setPosition(marker.position, 150)
|
||||
}
|
||||
|
||||
override fun onMarkerDrag(marker: Marker) {}
|
||||
|
||||
companion object {
|
||||
private const val MARKER_POSITION_KEY = "MarkerPosition"
|
||||
|
||||
// George St, Sydney
|
||||
private val SYDNEY = LatLng(-33.87365, 151.20689)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright (C) 2012 The Android Open Source Project
|
||||
|
||||
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.
|
||||
--><!-- This can go anywhere in your layout. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:map="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/map_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/map_container2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5"
|
||||
android:orientation="vertical">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/streetviewpanorama"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5"
|
||||
class="com.google.android.gms.maps.SupportStreetViewPanoramaFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5"
|
||||
class="com.google.android.gms.maps.SupportMapFragment"
|
||||
map:cameraTargetLat="-33.87365"
|
||||
map:cameraTargetLng="151.20689"
|
||||
map:cameraZoom="15" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@ -57,6 +57,7 @@
|
||||
<activity android:name=".TagsDemoActivity"/>
|
||||
<activity android:name=".UiSettingsDemoActivity" />
|
||||
<activity android:name=".VisibleRegionDemoActivity"/>
|
||||
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
BIN
ApiDemos/kotlin/app/src/main/res/drawable-hdpi/pegman.png
Normal file
BIN
ApiDemos/kotlin/app/src/main/res/drawable-hdpi/pegman.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
ApiDemos/kotlin/app/src/main/res/drawable-mdpi/pegman.png
Normal file
BIN
ApiDemos/kotlin/app/src/main/res/drawable-mdpi/pegman.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
ApiDemos/kotlin/app/src/main/res/drawable-xhdpi/pegman.png
Normal file
BIN
ApiDemos/kotlin/app/src/main/res/drawable-xhdpi/pegman.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
ApiDemos/kotlin/app/src/main/res/drawable-xxhdpi/pegman.png
Normal file
BIN
ApiDemos/kotlin/app/src/main/res/drawable-xxhdpi/pegman.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@ -143,6 +143,10 @@
|
||||
<string name="go_to_san_francisco">Go to San Francisco</string>
|
||||
<string name="go_to_santorini">Go to Santorini</string>
|
||||
|
||||
<!-- Split StreetView Panorama and Map Demo -->
|
||||
<string name="split_street_view_panorama_and_map_demo_label">Street View Panorama and Map</string>
|
||||
<string name="split_street_view_panorama_and_map_demo_details">Demonstrates how to show a Street View panorama and map.</string>
|
||||
|
||||
<!-- Tags Demo -->
|
||||
<string name="tags_demo_label">Tags</string>
|
||||
<string name="tags_demo_details">Demonstrates how to get and set tags on API objects.</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user