diff --git a/ApiDemos/app/build.gradle b/ApiDemos/app/build.gradle index eb4b4e7e..6e0b3ee3 100644 --- a/ApiDemos/app/build.gradle +++ b/ApiDemos/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion "23.0.2" defaultConfig { applicationId "com.example.mapdemo" @@ -22,6 +22,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.0.1' - compile 'com.google.android.gms:play-services:8.1.0' + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.google.android.gms:play-services-maps:8.4.0' } diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/GroundOverlayDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/GroundOverlayDemoActivity.java index f5d17f84..06842fca 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/GroundOverlayDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/GroundOverlayDemoActivity.java @@ -29,6 +29,7 @@ import com.google.android.gms.maps.model.LatLng; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; +import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; @@ -39,16 +40,22 @@ import java.util.List; * This shows how to add a ground overlay to a map. */ public class GroundOverlayDemoActivity extends AppCompatActivity - implements OnSeekBarChangeListener, OnMapReadyCallback { + implements OnSeekBarChangeListener, OnMapReadyCallback, + GoogleMap.OnGroundOverlayClickListener { private static final int TRANSPARENCY_MAX = 100; private static final LatLng NEWARK = new LatLng(40.714086, -74.228697); + private static final LatLng NEAR_NEWARK = + new LatLng(NEWARK.latitude - 0.001, NEWARK.longitude - 0.025); + private final List mImages = new ArrayList(); private GroundOverlay mGroundOverlay; + private GroundOverlay mGroundOverlayRotated; + private SeekBar mTransparencyBar; private int mCurrentEntry = 0; @@ -69,13 +76,24 @@ public class GroundOverlayDemoActivity extends AppCompatActivity @Override public void onMapReady(GoogleMap map) { + // Register a listener to respond to clicks on GroundOverlays. + map.setOnGroundOverlayClickListener(this); + map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11)); mImages.clear(); mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922)); mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny)); - mCurrentEntry = 0; + // Add a small, rotated overlay that is clickable by default + // (set by the initial state of the checkbox.) + mGroundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions() + .image(mImages.get(1)).anchor(0, 1) + .position(NEAR_NEWARK, 4300f, 3025f) + .bearing(30) + .clickable(((CheckBox) findViewById(R.id.toggleClickability)).isChecked())); + + // Add a large overlay at Newark on top of the smaller overlay. mGroundOverlay = map.addGroundOverlay(new GroundOverlayOptions() .image(mImages.get(mCurrentEntry)).anchor(0, 1) .position(NEWARK, 8600f, 6500f)); @@ -106,4 +124,24 @@ public class GroundOverlayDemoActivity extends AppCompatActivity mCurrentEntry = (mCurrentEntry + 1) % mImages.size(); mGroundOverlay.setImage(mImages.get(mCurrentEntry)); } + + /** + * Toggles the visibility between 100% and 50% when a {@link GroundOverlay} is clicked. + */ + @Override + public void onGroundOverlayClick(GroundOverlay groundOverlay) { + // Toggle transparency value between 0.0f and 0.5f. Initial default value is 0.0f. + mGroundOverlayRotated.setTransparency(0.5f - mGroundOverlayRotated.getTransparency()); + } + + /** + * Toggles the clickability of the smaller, rotated overlay based on the state of the View that + * triggered this call. + * This callback is defined on the CheckBox in the layout for this Activity. + */ + public void toggleClickability(View view) { + if (mGroundOverlayRotated != null) { + mGroundOverlayRotated.setClickable(((CheckBox) view).isChecked()); + } + } } diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java index 76547330..840606df 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java @@ -20,6 +20,8 @@ import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter; import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener; +import com.google.android.gms.maps.GoogleMap.OnInfoWindowCloseListener; +import com.google.android.gms.maps.GoogleMap.OnInfoWindowLongClickListener; import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener; import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener; import com.google.android.gms.maps.OnMapReadyCallback; @@ -64,7 +66,9 @@ public class MarkerDemoActivity extends AppCompatActivity implements OnInfoWindowClickListener, OnMarkerDragListener, OnSeekBarChangeListener, - OnMapReadyCallback { + OnMapReadyCallback, + OnInfoWindowLongClickListener, + OnInfoWindowCloseListener { private static final LatLng BRISBANE = new LatLng(-27.47093, 153.0235); @@ -230,6 +234,8 @@ public class MarkerDemoActivity extends AppCompatActivity implements mMap.setOnMarkerClickListener(this); mMap.setOnInfoWindowClickListener(this); mMap.setOnMarkerDragListener(this); + mMap.setOnInfoWindowCloseListener(this); + mMap.setOnInfoWindowLongClickListener(this); // Override the default content description on the view, for accessibility mode. // Ideally this string would be localised. @@ -417,6 +423,16 @@ public class MarkerDemoActivity extends AppCompatActivity implements Toast.makeText(this, "Click Info Window", Toast.LENGTH_SHORT).show(); } + @Override + public void onInfoWindowClose(Marker marker) { + Toast.makeText(this, "Close Info Window", Toast.LENGTH_SHORT).show(); + } + + @Override + public void onInfoWindowLongClick(Marker marker) { + Toast.makeText(this, "Info Window long click", Toast.LENGTH_SHORT).show(); + } + @Override public void onMarkerDragStart(Marker marker) { mTopText.setText("onMarkerDragStart"); @@ -431,4 +447,5 @@ public class MarkerDemoActivity extends AppCompatActivity implements public void onMarkerDrag(Marker marker) { mTopText.setText("onMarkerDrag. Current Position: " + marker.getPosition()); } + } diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/PolygonDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/PolygonDemoActivity.java index 2e5e0150..6f9585e5 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/PolygonDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/PolygonDemoActivity.java @@ -27,6 +27,8 @@ import com.google.android.gms.maps.model.PolygonOptions; import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; @@ -49,12 +51,16 @@ public class PolygonDemoActivity extends AppCompatActivity private Polygon mMutablePolygon; + private Polygon mClickablePolygonWithHoles; + private SeekBar mColorBar; private SeekBar mAlphaBar; private SeekBar mWidthBar; + private CheckBox mClickabilityCheckbox; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -72,6 +78,8 @@ public class PolygonDemoActivity extends AppCompatActivity mWidthBar.setMax(WIDTH_MAX); mWidthBar.setProgress(10); + mClickabilityCheckbox = (CheckBox) findViewById(R.id.toggleClickability); + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); @@ -84,16 +92,19 @@ public class PolygonDemoActivity extends AppCompatActivity map.setContentDescription("Google Map with polygons."); // Create a rectangle with two rectangular holes. - map.addPolygon(new PolygonOptions() + mClickablePolygonWithHoles = map.addPolygon(new PolygonOptions() .addAll(createRectangle(new LatLng(-20, 130), 5, 5)) .addHole(createRectangle(new LatLng(-22, 128), 1, 1)) .addHole(createRectangle(new LatLng(-18, 133), 0.5, 1.5)) .fillColor(Color.CYAN) .strokeColor(Color.BLUE) - .strokeWidth(5)); + .strokeWidth(5) + .clickable(mClickabilityCheckbox.isChecked())); // Create a rectangle centered at Sydney. - PolygonOptions options = new PolygonOptions().addAll(createRectangle(SYDNEY, 5, 8)); + PolygonOptions options = new PolygonOptions() + .addAll(createRectangle(SYDNEY, 5, 8)) + .clickable(mClickabilityCheckbox.isChecked()); int fillColor = Color.HSVToColor( mAlphaBar.getProgress(), new float[]{mColorBar.getProgress(), 1, 1}); @@ -102,12 +113,29 @@ public class PolygonDemoActivity extends AppCompatActivity .strokeColor(Color.BLACK) .fillColor(fillColor)); + // Create another polygon that overlaps the previous two. + // Clickability defaults to false, so this one won't accept clicks. + map.addPolygon(new PolygonOptions() + .addAll(createRectangle(new LatLng(-27, 140), 10, 7)) + .fillColor(Color.WHITE) + .strokeColor(Color.BLACK)); + mColorBar.setOnSeekBarChangeListener(this); mAlphaBar.setOnSeekBarChangeListener(this); mWidthBar.setOnSeekBarChangeListener(this); // Move the map so that it is centered on the mutable polygon. map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY)); + + // Add a listener for polygon clicks that changes the clicked polygon's stroke color. + map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() { + @Override + public void onPolygonClick(Polygon polygon) { + // Flip the r, g and b components of the polygon's stroke color. + int strokeColor = polygon.getStrokeColor() ^ 0x00ffffff; + polygon.setStrokeColor(strokeColor); + } + }); } /** @@ -149,4 +177,18 @@ public class PolygonDemoActivity extends AppCompatActivity mMutablePolygon.setStrokeWidth(progress); } } -} + + /** + * Toggles the clickability of two polygons based on the state of the View that triggered this + * call. + * This callback is defined on the CheckBox in the layout for this Activity. + */ + public void toggleClickability(View view) { + if (mClickablePolygonWithHoles != null) { + mClickablePolygonWithHoles.setClickable(((CheckBox) view).isChecked()); + } + if (mMutablePolygon != null) { + mMutablePolygon.setClickable(((CheckBox) view).isChecked()); + } + } +} \ No newline at end of file diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/PolylineDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/PolylineDemoActivity.java index 64077bce..841517ee 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/PolylineDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/PolylineDemoActivity.java @@ -27,6 +27,8 @@ import com.google.android.gms.maps.model.PolylineOptions; import android.graphics.Color; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.CheckBox; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; @@ -60,12 +62,16 @@ public class PolylineDemoActivity extends AppCompatActivity private Polyline mMutablePolyline; + private Polyline mClickablePolyline; + private SeekBar mColorBar; private SeekBar mAlphaBar; private SeekBar mWidthBar; + private CheckBox mClickabilityCheckbox; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,6 +89,8 @@ public class PolylineDemoActivity extends AppCompatActivity mWidthBar.setMax(WIDTH_MAX); mWidthBar.setProgress(10); + mClickabilityCheckbox = (CheckBox) findViewById(R.id.toggleClickability); + SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); @@ -99,11 +107,12 @@ public class PolylineDemoActivity extends AppCompatActivity .add(MELBOURNE, ADELAIDE, PERTH)); // A geodesic polyline that goes around the world. - map.addPolyline((new PolylineOptions()) + mClickablePolyline = map.addPolyline((new PolylineOptions()) .add(LHR, AKL, LAX, JFK, LHR) .width(5) .color(Color.BLUE) - .geodesic(true)); + .geodesic(true) + .clickable(mClickabilityCheckbox.isChecked())); // Rectangle centered at Sydney. This polyline will be mutable. int radius = 5; @@ -117,7 +126,8 @@ public class PolylineDemoActivity extends AppCompatActivity mAlphaBar.getProgress(), new float[]{mColorBar.getProgress(), 1, 1}); mMutablePolyline = map.addPolyline(options .color(color) - .width(mWidthBar.getProgress())); + .width(mWidthBar.getProgress()) + .clickable(mClickabilityCheckbox.isChecked())); mColorBar.setOnSeekBarChangeListener(this); mAlphaBar.setOnSeekBarChangeListener(this); @@ -125,6 +135,16 @@ public class PolylineDemoActivity extends AppCompatActivity // Move the map so that it is centered on the mutable polyline. map.moveCamera(CameraUpdateFactory.newLatLng(SYDNEY)); + + // Add a listener for polyline clicks that changes the clicked polyline's color. + map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() { + @Override + public void onPolylineClick(Polyline polyline) { + // Flip the values of the r, g and b components of the polyline's color. + int strokeColor = polyline.getColor() ^ 0x00ffffff; + polyline.setColor(strokeColor); + } + }); } @Override @@ -154,4 +174,18 @@ public class PolylineDemoActivity extends AppCompatActivity mMutablePolyline.setWidth(progress); } } -} + + /** + * Toggles the clickability of two polylines based on the state of the View that triggered this + * call. + * This callback is defined on the CheckBox in the layout for this Activity. + */ + public void toggleClickability(View view) { + if (mClickablePolyline != null) { + mClickablePolyline.setClickable(((CheckBox) view).isChecked()); + } + if (mMutablePolyline != null) { + mMutablePolyline.setClickable(((CheckBox) view).isChecked()); + } + } +} \ No newline at end of file diff --git a/ApiDemos/app/src/main/res/layout/ground_overlay_demo.xml b/ApiDemos/app/src/main/res/layout/ground_overlay_demo.xml index cebd8f55..30d78fad 100644 --- a/ApiDemos/app/src/main/res/layout/ground_overlay_demo.xml +++ b/ApiDemos/app/src/main/res/layout/ground_overlay_demo.xml @@ -18,12 +18,14 @@ android:layout_height="match_parent" android:orientation="vertical"> - + android:background="@color/white" + android:padding="5dp"> - + android:layout_height="wrap_content" + android:layout_toEndOf="@+id/transparency_text" + android:layout_toRightOf="@+id/transparency_text" /> - - - - - + android:layout_below="@+id/transparencySeekBar" + android:onClick="switchImage" + android:text="@string/switch_image" /> + + -