diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/CameraDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/CameraDemoActivity.java index beaa94b31..5a5c9984b 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/CameraDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/CameraDemoActivity.java @@ -20,13 +20,20 @@ import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.CancelableCallback; +import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener; +import com.google.android.gms.maps.GoogleMap.OnCameraMoveCanceledListener; +import com.google.android.gms.maps.GoogleMap.OnCameraMoveListener; +import com.google.android.gms.maps.GoogleMap.OnCameraMoveStartedListener; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.PolylineOptions; +import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.View; import android.widget.CompoundButton; import android.widget.SeekBar; @@ -35,7 +42,14 @@ /** * This shows how to change the camera position for the map. */ -public class CameraDemoActivity extends AppCompatActivity implements OnMapReadyCallback { +public class CameraDemoActivity extends AppCompatActivity implements + OnCameraMoveStartedListener, + OnCameraMoveListener, + OnCameraMoveCanceledListener, + OnCameraIdleListener, + OnMapReadyCallback { + + private static final String TAG = CameraDemoActivity.class.getName(); /** * The amount by which to scroll the camera. Note that this amount is in raw pixels, not dp @@ -60,10 +74,10 @@ public class CameraDemoActivity extends AppCompatActivity implements OnMapReadyC private GoogleMap mMap; private CompoundButton mAnimateToggle; - private CompoundButton mCustomDurationToggle; - private SeekBar mCustomDurationBar; + private PolylineOptions currPolylineOptions; + private boolean isCanceled = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -91,8 +105,14 @@ protected void onResume() { public void onMapReady(GoogleMap map) { mMap = map; + mMap.setOnCameraIdleListener(this); + mMap.setOnCameraMoveStartedListener(this); + mMap.setOnCameraMoveListener(this); + mMap.setOnCameraMoveCanceledListener(this); + // We will provide our own zoom controls. mMap.getUiSettings().setZoomControlsEnabled(false); + mMap.getUiSettings().setMyLocationButtonEnabled(true); // Show Sydney mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-33.87365, 151.20689), 10)); @@ -306,4 +326,67 @@ private void changeCamera(CameraUpdate update, CancelableCallback callback) { mMap.moveCamera(update); } } -} + + @Override + public void onCameraMoveStarted(int reason) { + if (!isCanceled) { + mMap.clear(); + } + + String reasonText = "UNKNOWN_REASON"; + currPolylineOptions = new PolylineOptions().width(5); + switch (reason) { + case OnCameraMoveStartedListener.REASON_GESTURE: + currPolylineOptions.color(Color.BLUE); + reasonText = "GESTURE"; + break; + case OnCameraMoveStartedListener.REASON_API_ANIMATION: + currPolylineOptions.color(Color.RED); + reasonText = "API_ANIMATION"; + break; + case OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION: + currPolylineOptions.color(Color.GREEN); + reasonText = "DEVELOPER_ANIMATION"; + break; + } + Log.i(TAG, "onCameraMoveStarted(" + reasonText + ")"); + addCameraTargetToPath(); + } + + @Override + public void onCameraMove() { + // When the camera is moving, add its target to the current path we'll draw on the map. + if (currPolylineOptions != null) { + addCameraTargetToPath(); + } + Log.i(TAG, "onCameraMove"); + } + + @Override + public void onCameraMoveCanceled() { + // When the camera stops moving, add its target to the current path, and draw it on the map. + if (currPolylineOptions != null) { + addCameraTargetToPath(); + mMap.addPolyline(currPolylineOptions); + } + isCanceled = true; // Set to clear the map when dragging starts again. + currPolylineOptions = null; + Log.i(TAG, "onCameraMoveCancelled"); + } + + @Override + public void onCameraIdle() { + if (currPolylineOptions != null) { + addCameraTargetToPath(); + mMap.addPolyline(currPolylineOptions); + } + currPolylineOptions = null; + isCanceled = false; // Set to *not* clear the map when dragging starts again. + Log.i(TAG, "onCameraIdle"); + } + + private void addCameraTargetToPath() { + LatLng target = mMap.getCameraPosition().target; + currPolylineOptions.add(target); + } +} \ No newline at end of file diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/DemoDetailsList.java b/ApiDemos/app/src/main/java/com/example/mapdemo/DemoDetailsList.java index a7997220d..c5db391dd 100755 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/DemoDetailsList.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/DemoDetailsList.java @@ -32,6 +32,9 @@ private DemoDetailsList() { new DemoDetails(R.string.camera_demo_label, R.string.camera_demo_description, CameraDemoActivity.class), + new DemoDetails(R.string.camera_clamping_demo_label, + R.string.camera_clamping_demo_description, + CameraClampingDemoActivity.class), new DemoDetails(R.string.circle_demo_label, R.string.circle_demo_description, CircleDemoActivity.class), diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/EventsDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/EventsDemoActivity.java index b84f2d389..d715b434a 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/EventsDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/EventsDemoActivity.java @@ -17,12 +17,11 @@ package com.example.mapdemo; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener; +import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener; import com.google.android.gms.maps.GoogleMap.OnMapClickListener; import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; -import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import android.os.Bundle; @@ -33,12 +32,12 @@ * This shows how to listen to some {@link GoogleMap} events. */ public class EventsDemoActivity extends AppCompatActivity - implements OnMapClickListener, OnMapLongClickListener, OnCameraChangeListener, + implements OnMapClickListener, OnMapLongClickListener, OnCameraIdleListener, OnMapReadyCallback { private TextView mTapTextView; - private TextView mCameraTextView; + private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { @@ -55,9 +54,10 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onMapReady(GoogleMap map) { - map.setOnMapClickListener(this); - map.setOnMapLongClickListener(this); - map.setOnCameraChangeListener(this); + mMap = map; + mMap.setOnMapClickListener(this); + mMap.setOnMapLongClickListener(this); + mMap.setOnCameraIdleListener(this); } @Override @@ -71,7 +71,7 @@ public void onMapLongClick(LatLng point) { } @Override - public void onCameraChange(final CameraPosition position) { - mCameraTextView.setText(position.toString()); + public void onCameraIdle() { + mCameraTextView.setText(mMap.getCameraPosition().toString()); } } diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/VisibleRegionDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/VisibleRegionDemoActivity.java index fdd97540e..e6b8a52fd 100755 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/VisibleRegionDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/VisibleRegionDemoActivity.java @@ -18,10 +18,9 @@ import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; -import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener; +import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; -import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.MarkerOptions; @@ -85,11 +84,11 @@ public void onMapReady(GoogleMap map) { mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SFO, 18)); // Add a marker to the Opera House. mMap.addMarker(new MarkerOptions().position(SOH).title("Sydney Opera House")); - // Add a camera change listener. - mMap.setOnCameraChangeListener(new OnCameraChangeListener() { + // Add a camera idle listener. + mMap.setOnCameraIdleListener(new OnCameraIdleListener() { @Override - public void onCameraChange(CameraPosition pos) { - mMessageView.setText("CameraChangeListener: " + pos); + public void onCameraIdle() { + mMessageView.setText("CameraChangeListener: " + mMap.getCameraPosition()); } }); } @@ -138,8 +137,7 @@ public void setMorePadding(View view) { if (!checkReady()) { return; } - View mapView = ((SupportMapFragment) - getSupportFragmentManager().findFragmentById(R.id.map)).getView(); + View mapView = (getSupportFragmentManager().findFragmentById(R.id.map)).getView(); int left = 150; int top = 0; int right = mapView.getWidth() / 3;