15
15
16
16
package com .example .mapdemo ;
17
17
18
- import com .google .android .gms .maps .OnStreetViewPanoramaReadyCallback ;
18
+ import android .graphics .Point ;
19
+ import android .os .Bundle ;
20
+ import android .widget .TextView ;
21
+
22
+ import androidx .appcompat .app .AppCompatActivity ;
23
+
19
24
import com .google .android .gms .maps .StreetViewPanorama ;
20
25
import com .google .android .gms .maps .StreetViewPanorama .OnStreetViewPanoramaCameraChangeListener ;
21
26
import com .google .android .gms .maps .StreetViewPanorama .OnStreetViewPanoramaChangeListener ;
27
32
import com .google .android .gms .maps .model .StreetViewPanoramaLocation ;
28
33
import com .google .android .gms .maps .model .StreetViewPanoramaOrientation ;
29
34
30
- import android .graphics .Point ;
31
- import android .os .Bundle ;
32
- import android .widget .TextView ;
33
-
34
- import androidx .appcompat .app .AppCompatActivity ;
35
-
36
35
/**
37
36
* This shows how to listen to some {@link StreetViewPanorama} events.
38
37
*/
@@ -43,94 +42,91 @@ public class StreetViewPanoramaEventsDemoActivity extends AppCompatActivity
43
42
// George St, Sydney
44
43
private static final LatLng SYDNEY = new LatLng (-33.87365 , 151.20689 );
45
44
46
- private StreetViewPanorama mStreetViewPanorama ;
45
+ private StreetViewPanorama streetViewPanorama ;
47
46
48
- private TextView mPanoChangeTimesTextView ;
47
+ private TextView panoChangeTimesTextView ;
49
48
50
- private TextView mPanoCameraChangeTextView ;
49
+ private TextView panoCameraChangeTextView ;
51
50
52
- private TextView mPanoClickTextView ;
51
+ private TextView panoClickTextView ;
53
52
54
- private TextView mPanoLongClickTextView ;
53
+ private TextView panoLongClickTextView ;
55
54
56
- private int mPanoChangeTimes = 0 ;
55
+ private int panoChangeTimes = 0 ;
57
56
58
- private int mPanoCameraChangeTimes = 0 ;
57
+ private int panoCameraChangeTimes = 0 ;
59
58
60
- private int mPanoClickTimes = 0 ;
59
+ private int panoClickTimes = 0 ;
61
60
62
- private int mPanoLongClickTimes = 0 ;
61
+ private int panoLongClickTimes = 0 ;
63
62
64
63
@ Override
65
64
protected void onCreate (final Bundle savedInstanceState ) {
66
65
super .onCreate (savedInstanceState );
67
66
setContentView (R .layout .street_view_panorama_events_demo );
68
67
69
- mPanoChangeTimesTextView = ( TextView ) findViewById (R .id .change_pano );
70
- mPanoCameraChangeTextView = ( TextView ) findViewById (R .id .change_camera );
71
- mPanoClickTextView = ( TextView ) findViewById (R .id .click_pano );
72
- mPanoLongClickTextView = ( TextView ) findViewById (R .id .long_click_pano );
68
+ panoChangeTimesTextView = findViewById (R .id .change_pano );
69
+ panoCameraChangeTextView = findViewById (R .id .change_camera );
70
+ panoClickTextView = findViewById (R .id .click_pano );
71
+ panoLongClickTextView = findViewById (R .id .long_click_pano );
73
72
74
73
SupportStreetViewPanoramaFragment streetViewPanoramaFragment =
75
74
(SupportStreetViewPanoramaFragment )
76
75
getSupportFragmentManager ().findFragmentById (R .id .streetviewpanorama );
77
76
streetViewPanoramaFragment .getStreetViewPanoramaAsync (
78
- new OnStreetViewPanoramaReadyCallback () {
79
- @ Override
80
- public void onStreetViewPanoramaReady (StreetViewPanorama panorama ) {
81
- mStreetViewPanorama = panorama ;
82
- mStreetViewPanorama .setOnStreetViewPanoramaChangeListener (
83
- StreetViewPanoramaEventsDemoActivity .this );
84
- mStreetViewPanorama .setOnStreetViewPanoramaCameraChangeListener (
85
- StreetViewPanoramaEventsDemoActivity .this );
86
- mStreetViewPanorama .setOnStreetViewPanoramaClickListener (
87
- StreetViewPanoramaEventsDemoActivity .this );
88
- mStreetViewPanorama .setOnStreetViewPanoramaLongClickListener (
89
- StreetViewPanoramaEventsDemoActivity .this );
90
-
91
- // Only set the panorama to SYDNEY on startup (when no panoramas have been
92
- // loaded which is when the savedInstanceState is null).
93
- if (savedInstanceState == null ) {
94
- mStreetViewPanorama .setPosition (SYDNEY );
95
- }
77
+ panorama -> {
78
+ streetViewPanorama = panorama ;
79
+ streetViewPanorama .setOnStreetViewPanoramaChangeListener (
80
+ StreetViewPanoramaEventsDemoActivity .this );
81
+ streetViewPanorama .setOnStreetViewPanoramaCameraChangeListener (
82
+ StreetViewPanoramaEventsDemoActivity .this );
83
+ streetViewPanorama .setOnStreetViewPanoramaClickListener (
84
+ StreetViewPanoramaEventsDemoActivity .this );
85
+ streetViewPanorama .setOnStreetViewPanoramaLongClickListener (
86
+ StreetViewPanoramaEventsDemoActivity .this );
87
+
88
+ // Only set the panorama to SYDNEY on startup (when no panoramas have been
89
+ // loaded which is when the savedInstanceState is null).
90
+ if (savedInstanceState == null ) {
91
+ streetViewPanorama .setPosition (SYDNEY );
96
92
}
97
93
});
98
94
}
99
95
100
96
@ Override
101
97
public void onStreetViewPanoramaChange (StreetViewPanoramaLocation location ) {
102
98
if (location != null ) {
103
- mPanoChangeTimesTextView .setText ("Times panorama changed=" + ++mPanoChangeTimes );
99
+ panoChangeTimesTextView .setText ("Times panorama changed=" + ++panoChangeTimes );
104
100
}
105
101
}
106
102
107
103
@ Override
108
104
public void onStreetViewPanoramaCameraChange (StreetViewPanoramaCamera camera ) {
109
- mPanoCameraChangeTextView .setText ("Times camera changed=" + ++mPanoCameraChangeTimes );
105
+ panoCameraChangeTextView .setText ("Times camera changed=" + ++panoCameraChangeTimes );
110
106
}
111
107
112
108
@ Override
113
109
public void onStreetViewPanoramaClick (StreetViewPanoramaOrientation orientation ) {
114
- Point point = mStreetViewPanorama .orientationToPoint (orientation );
110
+ Point point = streetViewPanorama .orientationToPoint (orientation );
115
111
if (point != null ) {
116
- mPanoClickTimes ++;
117
- mPanoClickTextView .setText (
118
- "Times clicked=" + mPanoClickTimes + " : " + point .toString ());
119
- mStreetViewPanorama .animateTo (
112
+ panoClickTimes ++;
113
+ panoClickTextView .setText (
114
+ "Times clicked=" + panoClickTimes + " : " + point .toString ());
115
+ streetViewPanorama .animateTo (
120
116
new StreetViewPanoramaCamera .Builder ()
121
117
.orientation (orientation )
122
- .zoom (mStreetViewPanorama .getPanoramaCamera ().zoom )
118
+ .zoom (streetViewPanorama .getPanoramaCamera ().zoom )
123
119
.build (), 1000 );
124
120
}
125
121
}
126
122
127
123
@ Override
128
124
public void onStreetViewPanoramaLongClick (StreetViewPanoramaOrientation orientation ) {
129
- Point point = mStreetViewPanorama .orientationToPoint (orientation );
125
+ Point point = streetViewPanorama .orientationToPoint (orientation );
130
126
if (point != null ) {
131
- mPanoLongClickTimes ++;
132
- mPanoLongClickTextView .setText (
133
- "Times long clicked=" + mPanoLongClickTimes + " : " + point .toString ());
127
+ panoLongClickTimes ++;
128
+ panoLongClickTextView .setText (
129
+ "Times long clicked=" + panoLongClickTimes + " : " + point .toString ());
134
130
}
135
131
}
136
132
}
0 commit comments