diff --git a/VacationTracker/app/build.gradle b/VacationTracker/app/build.gradle
index b0de220..eb6b954 100755
--- a/VacationTracker/app/build.gradle
+++ b/VacationTracker/app/build.gradle
@@ -21,8 +21,9 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.google.android.gms:play-services-maps:9.0.2'
+ compile 'com.google.android.gms:play-services-location:9.0.2'
+ testCompile 'junit:junit:4.12'
}
diff --git a/VacationTracker/app/src/debug/res/values/google_maps_api.xml b/VacationTracker/app/src/debug/res/values/google_maps_api.xml
new file mode 100644
index 0000000..b38266e
--- /dev/null
+++ b/VacationTracker/app/src/debug/res/values/google_maps_api.xml
@@ -0,0 +1,19 @@
+
+
+ AIzaSyCE6rGd2a6lAS3z9sSRs1O46KqT3FKwD6s
+
diff --git a/VacationTracker/app/src/main/AndroidManifest.xml b/VacationTracker/app/src/main/AndroidManifest.xml
index 1f2bc3f..08edc8d 100755
--- a/VacationTracker/app/src/main/AndroidManifest.xml
+++ b/VacationTracker/app/src/main/AndroidManifest.xml
@@ -2,13 +2,21 @@
+
+
+
-
+
+
@@ -18,6 +26,18 @@
+
+
+
-
+
\ No newline at end of file
diff --git a/VacationTracker/app/src/main/java/edu/rosehulman/vacationtracker/MainActivity.java b/VacationTracker/app/src/main/java/edu/rosehulman/vacationtracker/MainActivity.java
index 1722485..de99e27 100755
--- a/VacationTracker/app/src/main/java/edu/rosehulman/vacationtracker/MainActivity.java
+++ b/VacationTracker/app/src/main/java/edu/rosehulman/vacationtracker/MainActivity.java
@@ -2,22 +2,46 @@
import android.app.Dialog;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.location.Address;
+import android.location.Geocoder;
import android.os.Bundle;
+import android.support.v4.app.ActivityCompat;
import android.support.v4.app.DialogFragment;
+import android.support.v4.graphics.ColorUtils;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
+import android.widget.Toast;
import android.widget.ToggleButton;
+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.LatLng;
+import com.google.android.gms.maps.model.MarkerOptions;
+import com.google.android.gms.maps.model.Polygon;
+import com.google.android.gms.maps.model.PolygonOptions;
+
+import java.io.IOException;
+import java.util.List;
public class
-MainActivity extends AppCompatActivity {
+MainActivity extends AppCompatActivity implements OnMapReadyCallback {
+
+ private static final int RC_PERMISSIONS = 1;
+ private GoogleMap mMap;
+
+ List mStateBoundaries;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -25,9 +49,86 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
+ // Obtain the SupportMapFragment and get notified when the map is ready to be used.
+ SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
+ .findFragmentById(R.id.map);
+ mapFragment.getMapAsync(this);
+
+ mStateBoundaries = Utils.getStateBoundaries(this);
+ }
+
+ /**
+ * Manipulates the map once available.
+ * This callback is triggered 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 case,
+ * we just add a marker near Sydney, Australia.
+ * If Google Play services is not installed on the device, the user will be prompted to install
+ * it inside the SupportMapFragment. This method will only be triggered once the user has
+ * installed Google Play services and returned to the app.
+ */
+ @Override
+ public void onMapReady(GoogleMap googleMap) {
+ mMap = googleMap;
+
+ // Add a marker in Sydney and move the camera
+ LatLng terreHaute = new LatLng(39.465542, -87.375924);
+
+ mMap.addMarker(new MarkerOptions().position(terreHaute).title("Terre Haute"));
+ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(terreHaute, 5.0f));
+ //mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
+
+ mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
+ @Override
+ public void onMapLongClick(LatLng latLng) {
+ createMarker(latLng);
+ }
+ });
+ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
+ || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
+ mMap.setMyLocationEnabled(true);
+ } else {
+ Toast.makeText(MainActivity.this, "No location permission", Toast.LENGTH_SHORT).show();
+ ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, RC_PERMISSIONS);
+ }
+ // Add state boundaries
+ for (StateBoundary sb : mStateBoundaries) {
+ int fillColor = sb.getColor();
+ int alpha = 10; // Make almost transparent (hidden) for now.
+ fillColor = ColorUtils.setAlphaComponent(fillColor, alpha);
+
+ mMap.addPolygon(new PolygonOptions()
+ .addAll(sb.getVertices())
+ .fillColor(fillColor)
+ .strokeWidth(1.0f)
+ .clickable(true));
+ }
+
+ mMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
+ @Override
+ public void onPolygonClick(Polygon polygon) {
+ int fillColor = polygon.getFillColor();
+ Log.d(Constants.TAG, String.format("Before toggle: %x", fillColor));
+ // Toggle alpha on/off. But doesn't store in model.
+ int alpha = Color.alpha(fillColor) > 10 ? 10 : 95;
+ fillColor = ColorUtils.setAlphaComponent(fillColor, alpha);
+ Log.d(Constants.TAG, String.format("After toggle: %x", fillColor));
+ polygon.setFillColor(fillColor);
+ }
+ });
+ }
+
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ if (requestCode == RC_PERMISSIONS) {
+ try {
+ mMap.setMyLocationEnabled(true);
+ } catch (SecurityException se) {
+ Toast.makeText(MainActivity.this, "Don't have security permission to add location", Toast.LENGTH_SHORT).show();
+ }
+ }
}
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
@@ -62,7 +163,7 @@ public void onClick(DialogInterface dialog, int which) {
String snippet = editTextSnippet.getText().toString();
// TODO: Add a marker at that location.
-
+ mMap.addMarker(new MarkerOptions().position(latLng).title(title).snippet(snippet));
}
});
builder.create().show();
@@ -88,7 +189,15 @@ public void onClick(DialogInterface dialog, int which) {
}
private void goToPlace(String locationName, float zoomLevel) {
- // TODO: find this place using the GeoCoder and go there.
-
+ // DONE: find this place using the GeoCoder and go there.
+ Geocoder geocoder = new Geocoder(this);
+ List addresses = null;
+ try {
+ addresses = geocoder.getFromLocationName(locationName, 1);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ LatLng placeLocation = new LatLng(addresses.get(0).getLatitude(), addresses.get(0).getLongitude());
+ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(placeLocation, zoomLevel));
}
}
diff --git a/VacationTracker/app/src/main/res/layout/activity_main.xml b/VacationTracker/app/src/main/res/layout/activity_main.xml
index 568a1ce..8316e7e 100755
--- a/VacationTracker/app/src/main/res/layout/activity_main.xml
+++ b/VacationTracker/app/src/main/res/layout/activity_main.xml
@@ -21,6 +21,6 @@
-
+
diff --git a/VacationTracker/app/src/main/res/layout/activity_maps.xml b/VacationTracker/app/src/main/res/layout/activity_maps.xml
new file mode 100644
index 0000000..30f9a2c
--- /dev/null
+++ b/VacationTracker/app/src/main/res/layout/activity_maps.xml
@@ -0,0 +1,11 @@
+
diff --git a/VacationTracker/app/src/main/res/layout/content_main.xml b/VacationTracker/app/src/main/res/layout/content_main.xml
deleted file mode 100755
index c18b5ba..0000000
--- a/VacationTracker/app/src/main/res/layout/content_main.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
diff --git a/VacationTracker/app/src/release/res/values/google_maps_api.xml b/VacationTracker/app/src/release/res/values/google_maps_api.xml
new file mode 100644
index 0000000..fa88c61
--- /dev/null
+++ b/VacationTracker/app/src/release/res/values/google_maps_api.xml
@@ -0,0 +1,22 @@
+
+
+
+ YOUR_KEY_HERE
+
+