mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
Merge branch 'github/master'
This commit is contained in:
commit
8be3a02361
@ -23,5 +23,5 @@ dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'com.google.android.gms:play-services-maps:8.4.0'
|
||||
compile 'com.google.android.gms:play-services-maps:9.2.0'
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ package com.example.mapdemo;
|
||||
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.GoogleMap.OnCircleClickListener;
|
||||
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
|
||||
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
@ -34,6 +35,7 @@ import android.location.Location;
|
||||
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;
|
||||
|
||||
@ -46,17 +48,12 @@ import java.util.List;
|
||||
*/
|
||||
public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarChangeListener,
|
||||
OnMarkerDragListener, OnMapLongClickListener, OnMapReadyCallback {
|
||||
|
||||
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
|
||||
|
||||
private static final double DEFAULT_RADIUS = 1000000;
|
||||
|
||||
public static final double RADIUS_OF_EARTH_METERS = 6371009;
|
||||
|
||||
private static final int WIDTH_MAX = 50;
|
||||
|
||||
private static final int HUE_MAX = 360;
|
||||
|
||||
private static final int ALPHA_MAX = 255;
|
||||
|
||||
private GoogleMap mMap;
|
||||
@ -64,26 +61,18 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
private List<DraggableCircle> mCircles = new ArrayList<DraggableCircle>(1);
|
||||
|
||||
private SeekBar mColorBar;
|
||||
|
||||
private SeekBar mAlphaBar;
|
||||
|
||||
private SeekBar mWidthBar;
|
||||
|
||||
private int mStrokeColor;
|
||||
|
||||
private int mFillColor;
|
||||
private CheckBox mClickabilityCheckbox;
|
||||
|
||||
private class DraggableCircle {
|
||||
|
||||
private final Marker centerMarker;
|
||||
|
||||
private final Marker radiusMarker;
|
||||
|
||||
private final Circle circle;
|
||||
|
||||
private double radius;
|
||||
|
||||
public DraggableCircle(LatLng center, double radius) {
|
||||
public DraggableCircle(LatLng center, double radius, boolean clickable) {
|
||||
this.radius = radius;
|
||||
centerMarker = mMap.addMarker(new MarkerOptions()
|
||||
.position(center)
|
||||
@ -98,10 +87,11 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
.radius(radius)
|
||||
.strokeWidth(mWidthBar.getProgress())
|
||||
.strokeColor(mStrokeColor)
|
||||
.fillColor(mFillColor));
|
||||
.fillColor(mFillColor)
|
||||
.clickable(clickable));
|
||||
}
|
||||
|
||||
public DraggableCircle(LatLng center, LatLng radiusLatLng) {
|
||||
public DraggableCircle(LatLng center, LatLng radiusLatLng, boolean clickable) {
|
||||
this.radius = toRadiusMeters(center, radiusLatLng);
|
||||
centerMarker = mMap.addMarker(new MarkerOptions()
|
||||
.position(center)
|
||||
@ -116,7 +106,8 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
.radius(radius)
|
||||
.strokeWidth(mWidthBar.getProgress())
|
||||
.strokeColor(mStrokeColor)
|
||||
.fillColor(mFillColor));
|
||||
.fillColor(mFillColor)
|
||||
.clickable(clickable));
|
||||
}
|
||||
|
||||
public boolean onMarkerMoved(Marker marker) {
|
||||
@ -138,6 +129,10 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
circle.setFillColor(mFillColor);
|
||||
circle.setStrokeColor(mStrokeColor);
|
||||
}
|
||||
|
||||
public void setClickable(boolean clickable) {
|
||||
circle.setClickable(clickable);
|
||||
}
|
||||
}
|
||||
|
||||
/** Generate LatLng of radius marker */
|
||||
@ -174,6 +169,8 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
SupportMapFragment mapFragment =
|
||||
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
|
||||
mapFragment.getMapAsync(this);
|
||||
|
||||
mClickabilityCheckbox = (CheckBox) findViewById(R.id.toggleClickability);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,11 +190,22 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
mAlphaBar.getProgress(), new float[]{mColorBar.getProgress(), 1, 1});
|
||||
mStrokeColor = Color.BLACK;
|
||||
|
||||
DraggableCircle circle = new DraggableCircle(SYDNEY, DEFAULT_RADIUS);
|
||||
DraggableCircle circle =
|
||||
new DraggableCircle(SYDNEY, DEFAULT_RADIUS, mClickabilityCheckbox.isChecked());
|
||||
mCircles.add(circle);
|
||||
|
||||
// Move the map so that it is centered on the initial circle
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, 4.0f));
|
||||
|
||||
// Set up the click listener for the circle.
|
||||
map.setOnCircleClickListener(new OnCircleClickListener() {
|
||||
@Override
|
||||
public void onCircleClick(Circle circle) {
|
||||
// Flip the r, g and b components of the circle's stroke color.
|
||||
int strokeColor = circle.getStrokeColor() ^ 0x00ffffff;
|
||||
circle.setStrokeColor(strokeColor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -256,7 +264,17 @@ public class CircleDemoActivity extends AppCompatActivity implements OnSeekBarCh
|
||||
view.getHeight() * 3 / 4, view.getWidth() * 3 / 4));
|
||||
|
||||
// ok create it
|
||||
DraggableCircle circle = new DraggableCircle(point, radiusLatLng);
|
||||
DraggableCircle circle =
|
||||
new DraggableCircle(point, radiusLatLng, mClickabilityCheckbox.isChecked());
|
||||
mCircles.add(circle);
|
||||
}
|
||||
}
|
||||
|
||||
public void toggleClickability(View view) {
|
||||
boolean clickable = ((CheckBox) view).isChecked();
|
||||
// Set each of the circles to be clickable or not, based on the
|
||||
// state of the checkbox.
|
||||
for (DraggableCircle draggableCircle : mCircles) {
|
||||
draggableCircle.setClickable(clickable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -411,6 +411,12 @@ public class MarkerDemoActivity extends AppCompatActivity implements
|
||||
marker.setAlpha(mRandom.nextFloat());
|
||||
}
|
||||
|
||||
// Markers have a z-index that is settable and gettable.
|
||||
float zIndex = marker.getZIndex() + 1.0f;
|
||||
marker.setZIndex(zIndex);
|
||||
Toast.makeText(this, marker.getTitle() + " z-index set to " + zIndex,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
mLastSelectedMarker = marker;
|
||||
// We return false to indicate that we have not consumed the event and that we wish
|
||||
// for the default behavior to occur (which is for the camera to move such that the
|
||||
@ -425,7 +431,7 @@ public class MarkerDemoActivity extends AppCompatActivity implements
|
||||
|
||||
@Override
|
||||
public void onInfoWindowClose(Marker marker) {
|
||||
Toast.makeText(this, "Close Info Window", Toast.LENGTH_SHORT).show();
|
||||
//Toast.makeText(this, "Close Info Window", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -28,6 +28,8 @@ 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;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@ -36,19 +38,27 @@ import java.util.Locale;
|
||||
/**
|
||||
* This demonstrates how to add a tile overlay to a map.
|
||||
*/
|
||||
public class TileOverlayDemoActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
public class TileOverlayDemoActivity extends AppCompatActivity
|
||||
implements OnSeekBarChangeListener, OnMapReadyCallback {
|
||||
|
||||
private static final int TRANSPARENCY_MAX = 100;
|
||||
|
||||
/** This returns moon tiles. */
|
||||
private static final String MOON_MAP_URL_FORMAT =
|
||||
"http://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw/%d/%d/%d.jpg";
|
||||
|
||||
private TileOverlay mMoonTiles;
|
||||
private SeekBar mTransparencyBar;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.tile_overlay_demo);
|
||||
|
||||
mTransparencyBar = (SeekBar) findViewById(R.id.transparencySeekBar);
|
||||
mTransparencyBar.setMax(TRANSPARENCY_MAX);
|
||||
mTransparencyBar.setProgress(0);
|
||||
|
||||
SupportMapFragment mapFragment =
|
||||
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
|
||||
mapFragment.getMapAsync(this);
|
||||
@ -75,6 +85,7 @@ public class TileOverlayDemoActivity extends AppCompatActivity implements OnMapR
|
||||
};
|
||||
|
||||
mMoonTiles = map.addTileOverlay(new TileOverlayOptions().tileProvider(tileProvider));
|
||||
mTransparencyBar.setOnSeekBarChangeListener(this);
|
||||
}
|
||||
|
||||
public void setFadeIn(View v) {
|
||||
@ -83,4 +94,19 @@ public class TileOverlayDemoActivity extends AppCompatActivity implements OnMapR
|
||||
}
|
||||
mMoonTiles.setFadeIn(((CheckBox) v).isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (mMoonTiles != null) {
|
||||
mMoonTiles.setTransparency((float) progress / (float) TRANSPARENCY_MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,11 +58,27 @@
|
||||
|
||||
<SeekBar android:id="@+id/widthSeekBar" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/toggleClickability"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="true"
|
||||
android:onClick="toggleClickability"
|
||||
android:text="@string/clickable"/>
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
class="com.google.android.gms.maps.SupportMapFragment" />
|
||||
class="com.google.android.gms.maps.SupportMapFragment"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -40,5 +40,17 @@
|
||||
android:checked="true"
|
||||
android:onClick="setFadeIn"
|
||||
android:text="@string/fade_in" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/transparency"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/transparencySeekBar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
@ -2,10 +2,11 @@
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.5.0'
|
||||
classpath 'com.android.tools.build:gradle:2.1.0'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
@ -14,6 +15,7 @@ buildscript {
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#Wed Oct 07 13:01:26 AEDT 2015
|
||||
#Mon Jun 20 10:42:35 AEST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
Google Maps Android API v2 Samples
|
||||
===================================
|
||||
|
||||
Samples that use the [Google Maps Android API v2](https://developers.google.com/maps/documentation/android/).
|
||||
Samples demonstrating how to use
|
||||
[Google Maps Android API v2](https://developers.google.com/maps/documentation/android/).
|
||||
|
||||
This repo contains the following sample:
|
||||
|
||||
@ -49,7 +50,7 @@ https://github.com/googlemaps/android-samples/issues
|
||||
Patches are encouraged, and may be submitted according to the instructions in
|
||||
CONTRIBUTING.md.
|
||||
|
||||

|
||||

|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user