diff --git a/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/SearchDialog.java b/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/SearchDialog.java index c29ebf0..c742dcc 100644 --- a/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/SearchDialog.java +++ b/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/SearchDialog.java @@ -23,6 +23,7 @@ import org.RickBarrette.android.LocationRinger.Log; import org.RickBarrette.android.LocationRinger.R; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import java.io.IOException; import java.util.ArrayList; @@ -77,7 +78,7 @@ public class SearchDialog extends Dialog implements android.view.View.OnClickLis final ArrayList list = new ArrayList(); try { for (int i = 0; i < mResults.length(); i++) - list.add(mResults.getJSONObject(i).getString("address")); + list.add(mResults.getJSONObject(i).getString("formatted_address")); } catch (final JSONException e) { e.printStackTrace(); return null; @@ -96,8 +97,8 @@ public class SearchDialog extends Dialog implements android.view.View.OnClickLis private LatLng getCoords(final int index) { Log.d(TAG, "getCoords()"); try { - final JSONArray coords = mResults.getJSONObject(index).getJSONObject("Point").getJSONArray("coordinates"); - return new LatLng(coords.getDouble(1), coords.getDouble(0)); + final JSONObject coords = mResults.getJSONObject(index).getJSONObject("geometry").getJSONObject("location"); + return new LatLng(coords.getDouble("lat"), coords.getDouble("lng")); } catch (final JSONException e) { e.printStackTrace(); } diff --git a/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/fragments/LocationInformationFragment.java b/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/fragments/LocationInformationFragment.java index fefc182..d800141 100644 --- a/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/fragments/LocationInformationFragment.java +++ b/LocationRinger/src/org/RickBarrette/android/LocationRinger/ui/fragments/LocationInformationFragment.java @@ -87,10 +87,7 @@ public class LocationInformationFragment extends Fragment implements LatLngListe mMap.setOnMapClickListener(null); } -// mMap.setDoubleTapZoonEnabled(isChecked); -// // buttons -// mMap.setBuiltInZoomControls(isChecked); -// mMap.setClickable(isChecked);*/ + enableMap(isChecked); mRadius.setEnabled(isChecked); Toast.makeText(getActivity(), isChecked ? getString(R.string.map_editing_enabled) : getString(R.string.map_editiing_disabled), Toast.LENGTH_SHORT).show(); } @@ -120,6 +117,13 @@ public class LocationInformationFragment extends Fragment implements LatLngListe } } + /** + * Called when the fragment view is being created + * @param inflater + * @param container + * @param savedInstanceState + * @return + */ @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { view = inflater.inflate(R.layout.map_info_fragment, container, false); @@ -131,9 +135,6 @@ public class LocationInformationFragment extends Fragment implements LatLngListe mRadiusTextView = (TextView) view.findViewById(R.id.radius_textview); mRadius.setMax(Constraints.MAX_RADIUS_IN_METERS); - //TODO extend GoogleMap to intercept clicks -// mMap.setClickable(false); - mMapEditToggle = (ToggleButton) view.findViewById(R.id.map_edit_toggle); mMapEditToggle.setChecked(false); mMapEditToggle.setOnCheckedChangeListener(this); @@ -178,9 +179,10 @@ public class LocationInformationFragment extends Fragment implements LatLngListe */ if (isFirstFix) { // mMap.disableGPSProgess(); - if (mMap != null) { - mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPoint, 14)); - } + if (mMap != null) + if(mCircle.getCenter() == new LatLng(0, 0)); + mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mPoint, 14)); + } } // else @@ -218,8 +220,6 @@ public class LocationInformationFragment extends Fragment implements LatLngListe case R.id.radius: mRadiusTextView.setText(GeoUtils.distanceToString(Float.valueOf(progress) / 1000, true)); mCircle.setRadius(progress); - //todo invalidate this shit -// mMap.invalidate(); if (mListener != null) { final ContentValues info = new ContentValues(); info.put(RingerDatabase.KEY_RADIUS, progress); @@ -306,6 +306,7 @@ public class LocationInformationFragment extends Fragment implements LatLngListe */ private void setUpMap() { + //Create the circle overlay and add it to the map final CircleOptions circle = new CircleOptions(); circle.strokeColor(Color.GREEN); circle.fillColor(Color.argb(100, 0, 255, 0)); @@ -313,19 +314,21 @@ public class LocationInformationFragment extends Fragment implements LatLngListe circle.radius(0); mCircle = mMap.addCircle(circle); - if (mCircle.getCenter() != null) { - mMap.moveCamera(CameraUpdateFactory.newLatLng(mCircle.getCenter())); - //todo zoom -// mMap.setZoom(16); - } - - -// mMap.addCircle(mRadiusOverlay.getCircleOptions()); - - // -// mMap.setDoubleTapZoonEnabled(false); + enableMap(false); } + /** + * Enables/Disables the zoom and scroll gestures of the map + * @param isEnabled + */ + private void enableMap(final boolean isEnabled){ + mMap.getUiSettings().setAllGesturesEnabled(isEnabled); + mMap.getUiSettings().setZoomControlsEnabled(isEnabled); + } + /** + * Called when the Map is clicked + * @param point + */ @Override public void onMapClick(LatLng point) { if (point != null) { @@ -348,6 +351,10 @@ public class LocationInformationFragment extends Fragment implements LatLngListe Log.d(TAG, "onLocationSelected() Location was null"); } + /** + * Called when a location is selected in the search dialog + * @param point + */ @Override public void onLocationSelected(LatLng point) { onMapClick(point); diff --git a/location_library b/location_library index ec9fb9a..4ca015c 160000 --- a/location_library +++ b/location_library @@ -1 +1 @@ -Subproject commit ec9fb9aec03ebd3818561472954346687f17576d +Subproject commit 4ca015c7cd52c27f9be199f94d3d721a16a7a2ae