Skip to content

Commit da59043

Browse files
authored
chore: Add StreetViewPanoramaViewDemoActivity in Kotlin (googlemaps-samples#209)
Also apply following changes to Java version: * Refactor variables to remove Hungarian notation * Add missing annotation
1 parent ae0de4b commit da59043

File tree

5 files changed

+107
-15
lines changed

5 files changed

+107
-15
lines changed

ApiDemos/java/app/src/gms/java/com/example/mapdemo/StreetViewPanoramaViewDemoActivity.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.os.Bundle;
2323
import android.view.ViewGroup.LayoutParams;
2424

25+
import androidx.annotation.NonNull;
2526
import androidx.appcompat.app.AppCompatActivity;
2627

2728
/**
@@ -32,7 +33,7 @@ public class StreetViewPanoramaViewDemoActivity extends AppCompatActivity {
3233
// George St, Sydney
3334
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
3435

35-
private StreetViewPanoramaView mStreetViewPanoramaView;
36+
private StreetViewPanoramaView streetViewPanoramaView;
3637

3738
private static final String STREETVIEW_BUNDLE_KEY = "StreetViewBundleKey";
3839

@@ -45,48 +46,48 @@ protected void onCreate(Bundle savedInstanceState) {
4546
options.position(SYDNEY);
4647
}
4748

48-
mStreetViewPanoramaView = new StreetViewPanoramaView(this, options);
49-
addContentView(mStreetViewPanoramaView,
49+
streetViewPanoramaView = new StreetViewPanoramaView(this, options);
50+
addContentView(streetViewPanoramaView,
5051
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
5152

5253
// *** IMPORTANT ***
5354
// StreetViewPanoramaView requires that the Bundle you pass contain _ONLY_
5455
// StreetViewPanoramaView SDK objects or sub-Bundles.
55-
Bundle mStreetViewBundle = null;
56+
Bundle streetViewBundle = null;
5657
if (savedInstanceState != null) {
57-
mStreetViewBundle = savedInstanceState.getBundle(STREETVIEW_BUNDLE_KEY);
58+
streetViewBundle = savedInstanceState.getBundle(STREETVIEW_BUNDLE_KEY);
5859
}
59-
mStreetViewPanoramaView.onCreate(mStreetViewBundle);
60+
streetViewPanoramaView.onCreate(streetViewBundle);
6061
}
6162

6263
@Override
6364
protected void onResume() {
64-
mStreetViewPanoramaView.onResume();
65+
streetViewPanoramaView.onResume();
6566
super.onResume();
6667
}
6768

6869
@Override
6970
protected void onPause() {
70-
mStreetViewPanoramaView.onPause();
71+
streetViewPanoramaView.onPause();
7172
super.onPause();
7273
}
7374

7475
@Override
7576
protected void onDestroy() {
76-
mStreetViewPanoramaView.onDestroy();
77+
streetViewPanoramaView.onDestroy();
7778
super.onDestroy();
7879
}
7980

8081
@Override
81-
public void onSaveInstanceState(Bundle outState) {
82+
public void onSaveInstanceState(@NonNull Bundle outState) {
8283
super.onSaveInstanceState(outState);
8384

84-
Bundle mStreetViewBundle = outState.getBundle(STREETVIEW_BUNDLE_KEY);
85-
if (mStreetViewBundle == null) {
86-
mStreetViewBundle = new Bundle();
87-
outState.putBundle(STREETVIEW_BUNDLE_KEY, mStreetViewBundle);
85+
Bundle streetViewBundle = outState.getBundle(STREETVIEW_BUNDLE_KEY);
86+
if (streetViewBundle == null) {
87+
streetViewBundle = new Bundle();
88+
outState.putBundle(STREETVIEW_BUNDLE_KEY, streetViewBundle);
8889
}
8990

90-
mStreetViewPanoramaView.onSaveInstanceState(mStreetViewBundle);
91+
streetViewPanoramaView.onSaveInstanceState(streetViewBundle);
9192
}
9293
}

ApiDemos/kotlin/app/src/gms/java/com/example/kotlindemos/DemoDetailsList.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class DemoDetailsList {
6161
R.string.street_view_panorama_events_demo_label,
6262
R.string.street_view_panorama_events_demo_details,
6363
StreetViewPanoramaEventsDemoActivity::class.java),
64+
DemoDetails(
65+
R.string.street_view_panorama_view_demo_label,
66+
R.string.street_view_panorama_view_demo_details,
67+
StreetViewPanoramaViewDemoActivity::class.java
68+
),
6469
DemoDetails(R.string.tags_demo_label, R.string.tags_demo_details,
6570
TagsDemoActivity::class.java),
6671
DemoDetails(R.string.ui_settings_demo_label, R.string.ui_settings_demo_details,
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.example.kotlindemos
15+
16+
import android.os.Bundle
17+
import android.view.ViewGroup
18+
import androidx.appcompat.app.AppCompatActivity
19+
import com.google.android.gms.maps.StreetViewPanoramaOptions
20+
import com.google.android.gms.maps.StreetViewPanoramaView
21+
import com.google.android.gms.maps.model.LatLng
22+
23+
/**
24+
* This shows how to create a simple activity with streetview
25+
*/
26+
class StreetViewPanoramaViewDemoActivity : AppCompatActivity() {
27+
private lateinit var streetViewPanoramaView: StreetViewPanoramaView
28+
29+
override fun onCreate(savedInstanceState: Bundle?) {
30+
super.onCreate(savedInstanceState)
31+
val options = StreetViewPanoramaOptions()
32+
savedInstanceState ?: options.position(SYDNEY)
33+
streetViewPanoramaView = StreetViewPanoramaView(this, options)
34+
addContentView(
35+
streetViewPanoramaView,
36+
ViewGroup.LayoutParams(
37+
ViewGroup.LayoutParams.MATCH_PARENT,
38+
ViewGroup.LayoutParams.MATCH_PARENT
39+
)
40+
)
41+
42+
// *** IMPORTANT ***
43+
// StreetViewPanoramaView requires that the Bundle you pass contain _ONLY_
44+
// StreetViewPanoramaView SDK objects or sub-Bundles.
45+
streetViewPanoramaView.onCreate(savedInstanceState?.getBundle(STREETVIEW_BUNDLE_KEY))
46+
}
47+
48+
override fun onResume() {
49+
streetViewPanoramaView.onResume()
50+
super.onResume()
51+
}
52+
53+
override fun onPause() {
54+
streetViewPanoramaView.onPause()
55+
super.onPause()
56+
}
57+
58+
override fun onDestroy() {
59+
streetViewPanoramaView.onDestroy()
60+
super.onDestroy()
61+
}
62+
63+
public override fun onSaveInstanceState(outState: Bundle) {
64+
super.onSaveInstanceState(outState)
65+
var streetViewBundle = outState.getBundle(STREETVIEW_BUNDLE_KEY)
66+
if (streetViewBundle == null) {
67+
streetViewBundle = Bundle()
68+
outState.putBundle(
69+
STREETVIEW_BUNDLE_KEY,
70+
streetViewBundle
71+
)
72+
}
73+
streetViewPanoramaView.onSaveInstanceState(streetViewBundle)
74+
}
75+
76+
companion object {
77+
// George St, Sydney
78+
private val SYDNEY = LatLng(-33.87365, 151.20689)
79+
private const val STREETVIEW_BUNDLE_KEY = "StreetViewBundleKey"
80+
}
81+
}

ApiDemos/kotlin/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
6262
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
6363
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
64+
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
6465
</application>
6566

6667
</manifest>

ApiDemos/kotlin/app/src/main/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
<string name="tap_screen">tap screen</string>
169169
<string name="long_press_screen">long press screen</string>
170170

171+
<!-- StreetView PanoramaView Demo -->
172+
<string name="street_view_panorama_view_demo_label">Street View Panorama View</string>
173+
<string name="street_view_panorama_view_demo_details">Standard Street View Panorama using a View.</string>
174+
171175
<!-- Tags Demo -->
172176
<string name="tags_demo_label">Tags</string>
173177
<string name="tags_demo_details">Demonstrates how to get and set tags on API objects.</string>

0 commit comments

Comments
 (0)