forked from googlemaps-samples/android-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes unnecessary parentheses in an if statement.
Change-Id: I835957dbe9f8df3927489f3608d48ca6c8e2713d
- Loading branch information
1 parent
9aecf0f
commit 3bc9ac3
Showing
27 changed files
with
659 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
/play-services-maps-10.2.0 | ||
/app/libs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 25 | ||
buildToolsVersion "25.0.0" | ||
defaultConfig { | ||
applicationId "com.example.polygons" | ||
minSdkVersion 15 | ||
targetSdkVersion 25 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
resValue "string", "google_maps_key", (project.findProperty("GOOGLE_MAPS_API_KEY") ?: "") | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
|
||
repositories { | ||
maven { url "/Users/sarahmaddox/Development/devrelgit-projects/tut-polygons/maps/tutorials/Polygons/app/libs/"} | ||
} | ||
|
||
dependencies { | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:25.1.0' | ||
compile 'com.google.android.gms:play-services-maps:10.2.0' | ||
} | ||
|
||
dependencies { | ||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { | ||
exclude group: 'com.android.support', module: 'support-annotations' | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/sarahmaddox/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.polygons"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<meta-data | ||
android:name="com.google.android.gms.version" | ||
android:value="@integer/google_play_services_version" /> | ||
|
||
<!-- | ||
The API key for Google Maps-based APIs. | ||
--> | ||
<meta-data | ||
android:name="com.google.android.geo.API_KEY" | ||
android:value="@string/google_maps_key" /> | ||
|
||
<activity | ||
android:name="com.example.polygons.PolygonActivity" | ||
android:label="@string/title_activity_maps"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
228 changes: 228 additions & 0 deletions
228
tutorials/Polygons/app/src/main/java/com/example/polygons/PolygonActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
package com.example.polygons; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.Toast; | ||
|
||
import com.google.android.gms.maps.CameraUpdateFactory; | ||
import com.google.android.gms.maps.GoogleMap; | ||
import com.google.android.gms.maps.OnMapReadyCallback; | ||
import com.google.android.gms.maps.SupportMapFragment; | ||
import com.google.android.gms.maps.model.BitmapDescriptorFactory; | ||
import com.google.android.gms.maps.model.CustomCap; | ||
import com.google.android.gms.maps.model.Dash; | ||
import com.google.android.gms.maps.model.Dot; | ||
import com.google.android.gms.maps.model.Gap; | ||
import com.google.android.gms.maps.model.JointType; | ||
import com.google.android.gms.maps.model.LatLng; | ||
import com.google.android.gms.maps.model.PatternItem; | ||
import com.google.android.gms.maps.model.Polygon; | ||
import com.google.android.gms.maps.model.PolygonOptions; | ||
import com.google.android.gms.maps.model.Polyline; | ||
import com.google.android.gms.maps.model.PolylineOptions; | ||
import com.google.android.gms.maps.model.RoundCap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.example.polygons.R.id.map; | ||
|
||
/** | ||
* An activity that displays a Google map with polygons to represent areas, and | ||
* polylines to represent paths or routes. | ||
*/ | ||
public class PolygonActivity extends AppCompatActivity implements | ||
OnMapReadyCallback, | ||
GoogleMap.OnPolygonClickListener, | ||
GoogleMap.OnPolylineClickListener { | ||
|
||
private static final int PATTERN_GAP_LENGTH = 20; | ||
private static final int PATTERN_DASH_LENGTH = 20; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
// Retrieve the content view that renders the map. | ||
setContentView(R.layout.activity_maps); | ||
|
||
// Get the SupportMapFragment and request notification | ||
// when the map is ready to be used. | ||
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() | ||
.findFragmentById(map); | ||
mapFragment.getMapAsync(this); | ||
} | ||
|
||
/** | ||
* Manipulates the map when it's available. | ||
* The API invokes this callback when the map is ready to be used. | ||
* This is where we can add markers or lines, add listeners or move the camera. | ||
* In this tutorial, we add polylines and polygons to represent routes and areas on the map. | ||
*/ | ||
@Override | ||
public void onMapReady(GoogleMap googleMap) { | ||
|
||
// Add polylines to the map. | ||
// Polylines are useful to show a route or some other connection between points. | ||
Polyline polyline1 = googleMap.addPolyline((new PolylineOptions()) | ||
.clickable(true) | ||
.add(new LatLng(-35.016, 143.321), | ||
new LatLng(-34.747, 145.592), | ||
new LatLng(-34.364, 147.891), | ||
new LatLng(-33.501, 150.217), | ||
new LatLng(-32.306, 149.248), | ||
new LatLng(-32.491, 147.309))); | ||
// Store a data object with the polyline, used here to indicate an arbitrary type. | ||
polyline1.setTag("A"); | ||
// Style the polyline. | ||
stylePolyline(polyline1); | ||
|
||
Polyline polyline2 = googleMap.addPolyline((new PolylineOptions()) | ||
.clickable(true) | ||
.add(new LatLng(-29.501, 119.700), | ||
new LatLng(-27.456, 119.672), | ||
new LatLng(-25.971, 124.187), | ||
new LatLng(-28.081, 126.555), | ||
new LatLng(-28.848, 124.229), | ||
new LatLng(-28.215, 123.938))); | ||
polyline2.setTag("B"); | ||
stylePolyline(polyline2); | ||
|
||
// Add polygons to indicate areas on the map. | ||
Polygon polygon1 = googleMap.addPolygon((new PolygonOptions()) | ||
.clickable(true) | ||
.add(new LatLng(-27.457, 153.040), | ||
new LatLng(-33.852, 151.211), | ||
new LatLng(-37.813, 144.962), | ||
new LatLng(-34.928, 138.599))); | ||
// Store a data object with the polygon, used here to indicate an arbitrary type. | ||
polygon1.setTag("alpha"); | ||
// Style the polygon. | ||
stylePolygon(polygon1); | ||
|
||
Polygon polygon2 = googleMap.addPolygon((new PolygonOptions()) | ||
.clickable(true) | ||
.add(new LatLng(-31.673, 128.892), | ||
new LatLng(-31.952, 115.857), | ||
new LatLng(-17.785, 122.258), | ||
new LatLng(-12.4258, 130.7932))); | ||
polygon2.setTag("beta"); | ||
stylePolygon(polygon2); | ||
|
||
// Position the map's camera near Alice Springs in the center of Australia, | ||
// and set the zoom factor so most of Australia shows on the screen. | ||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-23.684, 133.903), 4)); | ||
|
||
// Set listeners for click events. | ||
googleMap.setOnPolygonClickListener(this); | ||
googleMap.setOnPolylineClickListener(this); | ||
} | ||
|
||
/** | ||
* Styles the polyline, based on type. | ||
* @param polyline The polyline object that needs styling. | ||
*/ | ||
private void stylePolyline(Polyline polyline) { | ||
String type = ""; | ||
// Get the data object stored with the polyline. | ||
if (polyline.getTag() != null) { | ||
type = polyline.getTag().toString(); | ||
} | ||
|
||
switch (type) { | ||
// If no type is given, allow the API to use the default. | ||
case "A": | ||
// Use a custom bitmap as the cap at one end of the line. | ||
polyline.setEndCap( | ||
new CustomCap(BitmapDescriptorFactory.fromResource(R.drawable.ic_arrow_black_48dp), | ||
16)); | ||
break; | ||
case "B": | ||
// Use a round cap at the end of the line. | ||
polyline.setEndCap(new RoundCap()); | ||
break; | ||
} | ||
|
||
polyline.setStartCap(new RoundCap()); | ||
polyline.setWidth(12); | ||
polyline.setColor(0xff000000); | ||
polyline.setJointType((JointType.ROUND)); | ||
} | ||
|
||
/** | ||
* Styles the polygon, based on type. | ||
* @param polygon The polygon object that needs styling. | ||
*/ | ||
private void stylePolygon(Polygon polygon) { | ||
String type = ""; | ||
// Get the data object stored with the polygon. | ||
if (polygon.getTag() != null) { | ||
type = polygon.getTag().toString(); | ||
} | ||
|
||
List<PatternItem> patterns = new ArrayList<>(); | ||
int strokeColor = 0xff000000; | ||
int fillColor = 0xffffffff; | ||
|
||
switch (type) { | ||
// If no type is given, allow the API to use the default. | ||
case "alpha": | ||
// Create a stroke pattern of dashes, and define colors. | ||
patterns.add(new Gap(PATTERN_GAP_LENGTH)); | ||
patterns.add(new Dash(PATTERN_DASH_LENGTH)); | ||
strokeColor = 0xff388E3C; | ||
fillColor = 0xff81C784; | ||
break; | ||
case "beta": | ||
// Create a stroke pattern of dots and dashes, and define colors. | ||
patterns.add(new Dot()); | ||
patterns.add(new Gap(PATTERN_GAP_LENGTH)); | ||
patterns.add(new Dash(PATTERN_DASH_LENGTH)); | ||
patterns.add(new Gap(PATTERN_GAP_LENGTH)); | ||
strokeColor = 0xffF57F17; | ||
fillColor = 0xffF9A825; | ||
break; | ||
} | ||
|
||
polygon.setStrokePattern(patterns); | ||
polygon.setStrokeWidth(8); | ||
polygon.setStrokeColor(strokeColor); | ||
polygon.setFillColor(fillColor); | ||
} | ||
|
||
/** | ||
* Listens for clicks on a polygon. | ||
* @param polygon The polygon object that the user has clicked. | ||
*/ | ||
@Override | ||
public void onPolygonClick(Polygon polygon) { | ||
// Flip the values of the r, g and b components of the polygon's color. | ||
int color = polygon.getStrokeColor() ^ 0x00ffffff; | ||
polygon.setStrokeColor(color); | ||
color = polygon.getFillColor() ^ 0x00ffffff; | ||
polygon.setFillColor(color); | ||
|
||
Toast.makeText(this, "Area type " + polygon.getTag().toString(), Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
/** | ||
* Listens for clicks on a polyline. | ||
* @param polyline The polyline object that the user has clicked. | ||
*/ | ||
@Override | ||
public void onPolylineClick(Polyline polyline) { | ||
// Flip from solid stroke to dotted stroke pattern. | ||
Dot dot = new Dot(); | ||
List<PatternItem> patterns = new ArrayList<>(); | ||
if (polyline.getPattern() == null || !polyline.getPattern().contains(dot)) { | ||
patterns.add(new Gap(PATTERN_GAP_LENGTH)); | ||
patterns.add(dot); | ||
polyline.setPattern(patterns); | ||
} else { | ||
// The default pattern is a solid stroke. | ||
polyline.setPattern(null); | ||
} | ||
|
||
Toast.makeText(this, "Route type " + polyline.getTag().toString(), | ||
Toast.LENGTH_SHORT).show(); | ||
} | ||
} |
Binary file added
BIN
+240 Bytes
tutorials/Polygons/app/src/main/res/drawable-hdpi/ic_arrow_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+200 Bytes
tutorials/Polygons/app/src/main/res/drawable-mdpi/ic_arrow_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+304 Bytes
tutorials/Polygons/app/src/main/res/drawable-xhdpi/ic_arrow_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+413 Bytes
tutorials/Polygons/app/src/main/res/drawable-xxhdpi/ic_arrow_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+732 Bytes
tutorials/Polygons/app/src/main/res/drawable-xxxhdpi/ic_arrow_black_48dp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<fragment xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/map" | ||
android:name="com.google.android.gms.maps.SupportMapFragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context="com.example.polygons.PolygonActivity" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<resources> | ||
<string name="app_name">Polygons</string> | ||
<string name="title_activity_maps">Polygons</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.2.3' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
Oops, something went wrong.