diff options
author | rsudev <rasch@munin-soft.de> | 2014-05-20 23:51:59 +0200 |
---|---|---|
committer | rsudev <rasch@munin-soft.de> | 2014-05-20 23:51:59 +0200 |
commit | 8d40947d9b4d8d9a555cef825bea32ab4ae41ae9 (patch) | |
tree | e4915d14ea893937c34f659fe1dc3dfb67f2f754 | |
parent | bc175b134809716d735b25a656ca3692b524b0fb (diff) | |
parent | a8ace2cabf632d61ba544639301b937a824aef7a (diff) | |
download | cgeo-8d40947d9b4d8d9a555cef825bea32ab4ae41ae9.zip cgeo-8d40947d9b4d8d9a555cef825bea32ab4ae41ae9.tar.gz cgeo-8d40947d9b4d8d9a555cef825bea32ab4ae41ae9.tar.bz2 |
Merge pull request #3880 from schwabe/fix_coords_dialogs
Make Fragment implementation more conforming to the coding guidelines. ...
4 files changed, 82 insertions, 52 deletions
diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java index 279dbd5..8c060e5 100644 --- a/main/src/cgeo/geocaching/EditWaypointActivity.java +++ b/main/src/cgeo/geocaching/EditWaypointActivity.java @@ -48,7 +48,7 @@ import java.util.EnumSet; import java.util.List; @EActivity -public class EditWaypointActivity extends AbstractActionBarActivity { +public class EditWaypointActivity extends AbstractActionBarActivity implements CoordinatesInputDialog.CoordinateUpdate { private static final ArrayList<WaypointType> POSSIBLE_WAYPOINT_TYPES = new ArrayList<WaypointType>(WaypointType.ALL_TYPES_EXCEPT_OWN_AND_ORIGINAL); @ViewById(R.id.buttonLatitude) protected Button buttonLat; @@ -294,17 +294,18 @@ public class EditWaypointActivity extends AbstractActionBarActivity { // button text is blank when creating new waypoint } Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); - CoordinatesInputDialog coordsDialog = new CoordinatesInputDialog(cache, gp, app.currentGeo()); + CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(cache, gp, app.currentGeo()); coordsDialog.setCancelable(true); - coordsDialog.setOnCoordinateUpdate(new CoordinatesInputDialog.CoordinateUpdate() { - @Override - public void update(final Geopoint gp) { - buttonLat.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); - buttonLon.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); - } - }); coordsDialog.show(getSupportFragmentManager(),"wpeditdialog"); } + + + } + + @Override + public void updateCoordinates(Geopoint gp) { + buttonLat.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); + buttonLon.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); } public static final int SUCCESS = 0; diff --git a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java index f92c5df..80812d1 100644 --- a/main/src/cgeo/geocaching/NavigateAnyPointActivity.java +++ b/main/src/cgeo/geocaching/NavigateAnyPointActivity.java @@ -44,7 +44,7 @@ import android.widget.TextView; import java.util.List; -public class NavigateAnyPointActivity extends AbstractActionBarActivity { +public class NavigateAnyPointActivity extends AbstractActionBarActivity implements CoordinatesInputDialog.CoordinateUpdate { @InjectView(R.id.historyList) protected ListView historyListView; @@ -278,18 +278,17 @@ public class NavigateAnyPointActivity extends AbstractActionBarActivity { if (latButton.getText().length() > 0 && lonButton.getText().length() > 0) { gp = new Geopoint(latButton.getText().toString() + " " + lonButton.getText().toString()); } - CoordinatesInputDialog coordsDialog = new CoordinatesInputDialog(null, gp, app.currentGeo()); + CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(null, gp, app.currentGeo()); coordsDialog.setCancelable(true); - coordsDialog.setOnCoordinateUpdate(new CoordinatesInputDialog.CoordinateUpdate() { - @Override - public void update(Geopoint gp) { - latButton.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); - lonButton.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); - changed = true; - } - }); coordsDialog.show(getSupportFragmentManager(),"wpedit_dialog"); } + + } + @Override + public void updateCoordinates(Geopoint gp) { + latButton.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); + lonButton.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); + changed = true; } private static class ChangeDistanceUnit implements OnItemSelectedListener { diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java index 40d6ffe..81dec98 100644 --- a/main/src/cgeo/geocaching/SearchActivity.java +++ b/main/src/cgeo/geocaching/SearchActivity.java @@ -37,7 +37,7 @@ import android.widget.Button; import java.util.Locale; -public class SearchActivity extends AbstractActionBarActivity { +public class SearchActivity extends AbstractActionBarActivity implements CoordinatesInputDialog.CoordinateUpdate { @InjectView(R.id.buttonLatitude) protected Button buttonLatitude; @InjectView(R.id.buttonLongitude) protected Button buttonLongitude; @@ -290,16 +290,15 @@ public class SearchActivity extends AbstractActionBarActivity { } private void updateCoordinates() { - final CoordinatesInputDialog coordsDialog = new CoordinatesInputDialog(null, null, app.currentGeo()); + final CoordinatesInputDialog coordsDialog = CoordinatesInputDialog.getInstance(null, null, app.currentGeo()); coordsDialog.setCancelable(true); - coordsDialog.setOnCoordinateUpdate(new CoordinatesInputDialog.CoordinateUpdate() { - @Override - public void update(final Geopoint gp) { - buttonLatitude.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); - buttonLongitude.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); - } - }); - coordsDialog.show(getSupportFragmentManager(),"wpedit_dialog"); + coordsDialog.show(getSupportFragmentManager(), "wpedit_dialog"); + } + + @Override + public void updateCoordinates(final Geopoint gp) { + buttonLatitude.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE)); + buttonLongitude.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE)); } private void findByCoordsFn() { diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java index 84d4466..00b5abe 100644 --- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java @@ -29,9 +29,9 @@ import android.widget.TextView; public class CoordinatesInputDialog extends DialogFragment { - final private IGeoData geo; - final private Geocache cache; private Geopoint gp; + private Geopoint gpinitial; + private Geopoint cacheCoords; private EditText eLat, eLon; private Button bLat, bLon; @@ -40,22 +40,54 @@ public class CoordinatesInputDialog extends DialogFragment { private TextView tLatSep1, tLatSep2, tLatSep3; private TextView tLonSep1, tLonSep2, tLonSep3; - private CoordinateUpdate cuListener; - private CoordInputFormatEnum currentFormat = null; - public CoordinatesInputDialog(final Geocache cache, final Geopoint gp, final IGeoData geo) { - this.geo = geo; - this.cache = cache; + private static final String GEOPOINT_ARG = "GEOPOINT"; + private static final String GEOPOINT_INTIAL_ARG = "GEOPOINT_INITIAL"; + private static final String CACHECOORDS_ARG = "CACHECOORDS"; + + + public static CoordinatesInputDialog getInstance(final Geocache cache, final Geopoint gp, final IGeoData geo) { + + Bundle args = new Bundle(); if (gp != null) { - this.gp = gp; + args.putParcelable(GEOPOINT_ARG, gp); } else if (geo != null && geo.getCoords() != null) { - this.gp = geo.getCoords(); + args.putParcelable(GEOPOINT_ARG, geo.getCoords()); } else { - this.gp = Geopoint.ZERO; + args.putParcelable(GEOPOINT_ARG, Geopoint.ZERO); } + + if (geo !=null) + args.putParcelable(GEOPOINT_INTIAL_ARG, geo.getCoords()); + + if (cache != null) + args.putParcelable(CACHECOORDS_ARG, cache.getCoords()); + + CoordinatesInputDialog cid = new CoordinatesInputDialog(); + cid.setArguments(args); + return cid; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + gp = getArguments().getParcelable(GEOPOINT_ARG); + gpinitial = getArguments().getParcelable(GEOPOINT_INTIAL_ARG); + cacheCoords = getArguments().getParcelable(CACHECOORDS_ARG); + + if (savedInstanceState != null && savedInstanceState.getParcelable(GEOPOINT_ARG)!=null) + gp = savedInstanceState.getParcelable(GEOPOINT_ARG); + + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + // TODO: if current input is not commited in gp, read the current input into gp + outState.putParcelable(GEOPOINT_ARG, gp); } @Override @@ -117,11 +149,13 @@ public class CoordinatesInputDialog extends DialogFragment { final Button buttonCurrent = (Button) v.findViewById(R.id.current); buttonCurrent.setOnClickListener(new CurrentListener()); final Button buttonCache = (Button) v.findViewById(R.id.cache); - if (cache != null) { + + if (cacheCoords != null) { buttonCache.setOnClickListener(new CacheListener()); } else { buttonCache.setVisibility(View.GONE); } + final Button buttonDone = (Button) v.findViewById(R.id.done); buttonDone.setOnClickListener(new InputDoneListener()); @@ -403,8 +437,8 @@ public class CoordinatesInputDialog extends DialogFragment { // Start new format with an acceptable value: either the current one // entered by the user, else our current coordinates, else (0,0). if (!areCurrentCoordinatesValid(false)) { - if (geo != null && geo.getCoords() != null) { - gp = geo.getCoords(); + if (gpinitial != null) { + gp = gpinitial; } else { gp = Geopoint.ZERO; } @@ -426,13 +460,13 @@ public class CoordinatesInputDialog extends DialogFragment { @Override public void onClick(View v) { - if (geo == null || geo.getCoords() == null) { + if (gpinitial == null) { final AbstractActivity activity = (AbstractActivity) getActivity(); activity.showToast(activity.getResources().getString(R.string.err_point_unknown_position)); return; } - gp = geo.getCoords(); + gp = gpinitial; updateGUI(); } } @@ -441,17 +475,18 @@ public class CoordinatesInputDialog extends DialogFragment { @Override public void onClick(View v) { - if (cache == null || cache.getCoords() == null) { + if (cacheCoords == null) { final AbstractActivity activity = (AbstractActivity) getActivity(); activity.showToast(activity.getResources().getString(R.string.err_location_unknown)); return; } - gp = cache.getCoords(); + gp = cacheCoords; updateGUI(); } } + private class InputDoneListener implements View.OnClickListener { @Override @@ -460,18 +495,14 @@ public class CoordinatesInputDialog extends DialogFragment { return; } if (gp != null) { - cuListener.update(gp); + ((CoordinateUpdate) getActivity()).updateCoordinates(gp); } dismiss(); } } - public void setOnCoordinateUpdate(CoordinateUpdate cu) { - cuListener = cu; - } - public interface CoordinateUpdate { - public void update(final Geopoint gp); + public void updateCoordinates(final Geopoint gp); } } |