Skip to content

Commit b27512a

Browse files
chore: Generate V3 samples (googlemaps-samples#243)
1 parent 8bb3e6f commit b27512a

28 files changed

+1803
-241
lines changed

ApiDemos/java/app/src/v3/java/com/example/mapdemo/CameraDemoActivity.java

Lines changed: 83 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222

2323
package com.example.mapdemo;
2424

25+
import android.graphics.Color;
26+
import android.os.Bundle;
27+
import android.util.Log;
28+
import android.view.View;
29+
import android.widget.CompoundButton;
30+
import android.widget.SeekBar;
31+
import android.widget.Toast;
32+
33+
import androidx.appcompat.app.AppCompatActivity;
34+
2535
import com.google.android.libraries.maps.CameraUpdate;
2636
import com.google.android.libraries.maps.CameraUpdateFactory;
2737
import com.google.android.libraries.maps.GoogleMap;
@@ -36,26 +46,17 @@
3646
import com.google.android.libraries.maps.model.LatLng;
3747
import com.google.android.libraries.maps.model.PolylineOptions;
3848

39-
import android.graphics.Color;
40-
import android.os.Bundle;
41-
import android.util.Log;
42-
import android.view.View;
43-
import android.widget.CompoundButton;
44-
import android.widget.SeekBar;
45-
import android.widget.Toast;
46-
47-
import androidx.appcompat.app.AppCompatActivity;
48-
4949
/**
5050
* This shows how to change the camera position for the map.
5151
*/
52+
// [START maps_camera_events]
5253
public class CameraDemoActivity extends AppCompatActivity implements
5354
OnCameraMoveStartedListener,
5455
OnCameraMoveListener,
5556
OnCameraMoveCanceledListener,
5657
OnCameraIdleListener,
5758
OnMapReadyCallback {
58-
59+
// [START_EXCLUDE silent]
5960
private static final String TAG = CameraDemoActivity.class.getName();
6061

6162
/**
@@ -77,60 +78,67 @@ public class CameraDemoActivity extends AppCompatActivity implements
7778
.bearing(0)
7879
.tilt(25)
7980
.build();
81+
// [END_EXCLUDE]
8082

81-
private GoogleMap mMap;
82-
83-
private CompoundButton mAnimateToggle;
84-
private CompoundButton mCustomDurationToggle;
85-
private SeekBar mCustomDurationBar;
83+
private GoogleMap map;
84+
// [START_EXCLUDE silent]
85+
private CompoundButton animateToggle;
86+
private CompoundButton customDurationToggle;
87+
private SeekBar customDurationBar;
8688
private PolylineOptions currPolylineOptions;
8789
private boolean isCanceled = false;
90+
// [END_EXCLUDE]
8891

8992
@Override
9093
protected void onCreate(Bundle savedInstanceState) {
9194
super.onCreate(savedInstanceState);
9295
setContentView(R.layout.camera_demo);
93-
94-
mAnimateToggle = (CompoundButton) findViewById(R.id.animate);
95-
mCustomDurationToggle = (CompoundButton) findViewById(R.id.duration_toggle);
96-
mCustomDurationBar = (SeekBar) findViewById(R.id.duration_bar);
96+
// [START_EXCLUDE silent]
97+
animateToggle = findViewById(R.id.animate);
98+
customDurationToggle = findViewById(R.id.duration_toggle);
99+
customDurationBar = findViewById(R.id.duration_bar);
97100

98101
updateEnabledState();
102+
// [END_EXCLUDE]
99103

100104
SupportMapFragment mapFragment =
101105
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
102106
mapFragment.getMapAsync(this);
103107
}
104108

109+
// [START_EXCLUDE silent]
105110
@Override
106111
protected void onResume() {
107112
super.onResume();
108113
updateEnabledState();
109114
}
115+
// [END_EXCLUDE]
110116

111117
@Override
112-
public void onMapReady(GoogleMap map) {
113-
mMap = map;
114-
115-
mMap.setOnCameraIdleListener(this);
116-
mMap.setOnCameraMoveStartedListener(this);
117-
mMap.setOnCameraMoveListener(this);
118-
mMap.setOnCameraMoveCanceledListener(this);
119-
118+
public void onMapReady(GoogleMap googleMap) {
119+
map = googleMap;
120+
121+
map.setOnCameraIdleListener(this);
122+
map.setOnCameraMoveStartedListener(this);
123+
map.setOnCameraMoveListener(this);
124+
map.setOnCameraMoveCanceledListener(this);
125+
// [START_EXCLUDE silent]
120126
// We will provide our own zoom controls.
121-
mMap.getUiSettings().setZoomControlsEnabled(false);
122-
mMap.getUiSettings().setMyLocationButtonEnabled(true);
127+
map.getUiSettings().setZoomControlsEnabled(false);
128+
map.getUiSettings().setMyLocationButtonEnabled(true);
129+
// [END_EXCLUDE]
123130

124131
// Show Sydney
125-
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.87365, 151.20689), 10));
132+
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.87365, 151.20689), 10));
126133
}
127134

135+
// [START_EXCLUDE silent]
128136
/**
129137
* When the map is not ready the CameraUpdateFactory cannot be used. This should be called on
130138
* all entry points that call methods on the Google Maps API.
131139
*/
132140
private boolean checkReady() {
133-
if (mMap == null) {
141+
if (map == null) {
134142
Toast.makeText(this, R.string.map_not_ready, Toast.LENGTH_SHORT).show();
135143
return false;
136144
}
@@ -179,7 +187,7 @@ public void onStopAnimation(View view) {
179187
return;
180188
}
181189

182-
mMap.stopAnimation();
190+
map.stopAnimation();
183191
}
184192

185193
/**
@@ -212,7 +220,7 @@ public void onTiltMore(View view) {
212220
return;
213221
}
214222

215-
CameraPosition currentCameraPosition = mMap.getCameraPosition();
223+
CameraPosition currentCameraPosition = map.getCameraPosition();
216224
float currentTilt = currentCameraPosition.tilt;
217225
float newTilt = currentTilt + 10;
218226

@@ -232,7 +240,7 @@ public void onTiltLess(View view) {
232240
return;
233241
}
234242

235-
CameraPosition currentCameraPosition = mMap.getCameraPosition();
243+
CameraPosition currentCameraPosition = map.getCameraPosition();
236244

237245
float currentTilt = currentCameraPosition.tilt;
238246

@@ -307,9 +315,9 @@ public void onToggleCustomDuration(View view) {
307315
* Update the enabled state of the custom duration controls.
308316
*/
309317
private void updateEnabledState() {
310-
mCustomDurationToggle.setEnabled(mAnimateToggle.isChecked());
311-
mCustomDurationBar
312-
.setEnabled(mAnimateToggle.isChecked() && mCustomDurationToggle.isChecked());
318+
customDurationToggle.setEnabled(animateToggle.isChecked());
319+
customDurationBar
320+
.setEnabled(animateToggle.isChecked() && customDurationToggle.isChecked());
313321
}
314322

315323
private void changeCamera(CameraUpdate update) {
@@ -321,79 +329,101 @@ private void changeCamera(CameraUpdate update) {
321329
* animate toggle button.
322330
*/
323331
private void changeCamera(CameraUpdate update, CancelableCallback callback) {
324-
if (mAnimateToggle.isChecked()) {
325-
if (mCustomDurationToggle.isChecked()) {
326-
int duration = mCustomDurationBar.getProgress();
332+
if (animateToggle.isChecked()) {
333+
if (customDurationToggle.isChecked()) {
334+
int duration = customDurationBar.getProgress();
327335
// The duration must be strictly positive so we make it at least 1.
328-
mMap.animateCamera(update, Math.max(duration, 1), callback);
336+
map.animateCamera(update, Math.max(duration, 1), callback);
329337
} else {
330-
mMap.animateCamera(update, callback);
338+
map.animateCamera(update, callback);
331339
}
332340
} else {
333-
mMap.moveCamera(update);
341+
map.moveCamera(update);
334342
}
335343
}
344+
// [END_EXCLUDE]
336345

337346
@Override
338347
public void onCameraMoveStarted(int reason) {
348+
// [START_EXCLUDE silent]
339349
if (!isCanceled) {
340-
mMap.clear();
350+
map.clear();
341351
}
352+
// [END_EXCLUDE]
342353

343354
String reasonText = "UNKNOWN_REASON";
355+
// [START_EXCLUDE silent]
344356
currPolylineOptions = new PolylineOptions().width(5);
357+
// [END_EXCLUDE]
345358
switch (reason) {
346359
case OnCameraMoveStartedListener.REASON_GESTURE:
360+
// [START_EXCLUDE silent]
347361
currPolylineOptions.color(Color.BLUE);
362+
// [END_EXCLUDE]
348363
reasonText = "GESTURE";
349364
break;
350365
case OnCameraMoveStartedListener.REASON_API_ANIMATION:
366+
// [START_EXCLUDE silent]
351367
currPolylineOptions.color(Color.RED);
368+
// [END_EXCLUDE]
352369
reasonText = "API_ANIMATION";
353370
break;
354371
case OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION:
372+
// [START_EXCLUDE silent]
355373
currPolylineOptions.color(Color.GREEN);
374+
// [END_EXCLUDE]
356375
reasonText = "DEVELOPER_ANIMATION";
357376
break;
358377
}
359-
Log.i(TAG, "onCameraMoveStarted(" + reasonText + ")");
378+
Log.d(TAG, "onCameraMoveStarted(" + reasonText + ")");
379+
// [START_EXCLUDE silent]
360380
addCameraTargetToPath();
381+
// [END_EXCLUDE]
361382
}
362383

363384
@Override
364385
public void onCameraMove() {
386+
// [START_EXCLUDE silent]
365387
// When the camera is moving, add its target to the current path we'll draw on the map.
366388
if (currPolylineOptions != null) {
367389
addCameraTargetToPath();
368390
}
369-
Log.i(TAG, "onCameraMove");
391+
// [END_EXCLUDE]
392+
Log.d(TAG, "onCameraMove");
370393
}
371394

372395
@Override
373396
public void onCameraMoveCanceled() {
397+
// [START_EXCLUDE silent]
374398
// When the camera stops moving, add its target to the current path, and draw it on the map.
375399
if (currPolylineOptions != null) {
376400
addCameraTargetToPath();
377-
mMap.addPolyline(currPolylineOptions);
401+
map.addPolyline(currPolylineOptions);
378402
}
379403
isCanceled = true; // Set to clear the map when dragging starts again.
380404
currPolylineOptions = null;
381-
Log.i(TAG, "onCameraMoveCancelled");
405+
// [END_EXCLUDE]
406+
Log.d(TAG, "onCameraMoveCancelled");
382407
}
383408

384409
@Override
385410
public void onCameraIdle() {
411+
// [START_EXCLUDE silent]
386412
if (currPolylineOptions != null) {
387413
addCameraTargetToPath();
388-
mMap.addPolyline(currPolylineOptions);
414+
map.addPolyline(currPolylineOptions);
389415
}
390416
currPolylineOptions = null;
391417
isCanceled = false; // Set to *not* clear the map when dragging starts again.
392-
Log.i(TAG, "onCameraIdle");
418+
// [END_EXCLUDE]
419+
Log.d(TAG, "onCameraIdle");
393420
}
394421

422+
// [START_EXCLUDE silent]
395423
private void addCameraTargetToPath() {
396-
LatLng target = mMap.getCameraPosition().target;
424+
LatLng target = map.getCameraPosition().target;
397425
currPolylineOptions.add(target);
398426
}
399-
}
427+
// [END_EXCLUDE]
428+
}
429+
// [END maps_camera_events]

ApiDemos/java/app/src/v3/java/com/example/mapdemo/EventsDemoActivity.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ public class EventsDemoActivity extends AppCompatActivity
4242
implements OnMapClickListener, OnMapLongClickListener, OnCameraIdleListener,
4343
OnMapReadyCallback {
4444

45-
private TextView mTapTextView;
46-
private TextView mCameraTextView;
47-
private GoogleMap mMap;
45+
private TextView tapTextView;
46+
private TextView cameraTextView;
47+
private GoogleMap map;
4848

4949
@Override
5050
protected void onCreate(Bundle savedInstanceState) {
5151
super.onCreate(savedInstanceState);
5252
setContentView(R.layout.events_demo);
5353

54-
mTapTextView = (TextView) findViewById(R.id.tap_text);
55-
mCameraTextView = (TextView) findViewById(R.id.camera_text);
54+
tapTextView = findViewById(R.id.tap_text);
55+
cameraTextView = findViewById(R.id.camera_text);
5656

5757
SupportMapFragment mapFragment =
5858
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
@@ -61,24 +61,24 @@ protected void onCreate(Bundle savedInstanceState) {
6161

6262
@Override
6363
public void onMapReady(GoogleMap map) {
64-
mMap = map;
65-
mMap.setOnMapClickListener(this);
66-
mMap.setOnMapLongClickListener(this);
67-
mMap.setOnCameraIdleListener(this);
64+
this.map = map;
65+
this.map.setOnMapClickListener(this);
66+
this.map.setOnMapLongClickListener(this);
67+
this.map.setOnCameraIdleListener(this);
6868
}
6969

7070
@Override
7171
public void onMapClick(LatLng point) {
72-
mTapTextView.setText("tapped, point=" + point);
72+
tapTextView.setText("tapped, point=" + point);
7373
}
7474

7575
@Override
7676
public void onMapLongClick(LatLng point) {
77-
mTapTextView.setText("long pressed, point=" + point);
77+
tapTextView.setText("long pressed, point=" + point);
7878
}
7979

8080
@Override
8181
public void onCameraIdle() {
82-
mCameraTextView.setText(mMap.getCameraPosition().toString());
82+
cameraTextView.setText(map.getCameraPosition().toString());
8383
}
8484
}

0 commit comments

Comments
 (0)