Fixed the address search dialog, & disabled map when not in use

This commit is contained in:
2014-09-01 11:13:57 -04:00
parent c6c6f1819b
commit 00b90b4331
3 changed files with 35 additions and 27 deletions

View File

@@ -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<String> list = new ArrayList<String>();
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();
}

View File

@@ -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) {
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);
enableMap(false);
}
// mMap.addCircle(mRadiusOverlay.getCircleOptions());
//
// mMap.setDoubleTapZoonEnabled(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);