diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2014-05-11 18:16:31 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2014-05-11 18:16:31 +0200 |
commit | 7bcf0e177f4b8f731fd205ac0baee9a65154091e (patch) | |
tree | dd1c33824125cecaff2de2f23f31e157f9bf2185 /main/src | |
parent | 2279eca9ebb25bd6306acf4502e969c47756c958 (diff) | |
download | cgeo-7bcf0e177f4b8f731fd205ac0baee9a65154091e.zip cgeo-7bcf0e177f4b8f731fd205ac0baee9a65154091e.tar.gz cgeo-7bcf0e177f4b8f731fd205ac0baee9a65154091e.tar.bz2 |
refactoring: avoid activity references
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/SearchActivity.java | 42 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/settings/SettingsActivity.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java | 22 |
3 files changed, 40 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/SearchActivity.java b/main/src/cgeo/geocaching/SearchActivity.java index 2a37e27..d3bb2d8 100644 --- a/main/src/cgeo/geocaching/SearchActivity.java +++ b/main/src/cgeo/geocaching/SearchActivity.java @@ -174,8 +174,20 @@ public class SearchActivity extends AbstractActivity { } private void init() { - buttonLatitude.setOnClickListener(new FindByCoordsAction()); - buttonLongitude.setOnClickListener(new FindByCoordsAction()); + buttonLatitude.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + updateCoordinates(); + } + }); + buttonLongitude.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + updateCoordinates(); + } + }); buttonSearchCoords.setOnClickListener(new View.OnClickListener() { @@ -277,21 +289,17 @@ public class SearchActivity extends AbstractActivity { } } - private class FindByCoordsAction implements OnClickListener { - - @Override - public void onClick(final View arg0) { - final CoordinatesInputDialog coordsDialog = new CoordinatesInputDialog(SearchActivity.this, 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(); - } + private void updateCoordinates() { + final CoordinatesInputDialog coordsDialog = new CoordinatesInputDialog(SearchActivity.this, 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(); } private void findByCoordsFn() { diff --git a/main/src/cgeo/geocaching/settings/SettingsActivity.java b/main/src/cgeo/geocaching/settings/SettingsActivity.java index dc1a39d..d4d9722 100644 --- a/main/src/cgeo/geocaching/settings/SettingsActivity.java +++ b/main/src/cgeo/geocaching/settings/SettingsActivity.java @@ -62,7 +62,7 @@ public class SettingsActivity extends PreferenceActivity { * directory and preference key in onActivityResult() easily just by knowing * the result code. */ - private enum DirChooserType { + private static enum DirChooserType { GPX_IMPORT_DIR(1, R.string.pref_gpxImportDir, Environment.getExternalStorageDirectory().getPath() + "/gpx", false), GPX_EXPORT_DIR(2, R.string.pref_gpxExportDir, diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java index b2ce11a..67b8923 100644 --- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java +++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java @@ -1,17 +1,18 @@ package cgeo.geocaching.ui.dialog; import cgeo.geocaching.Geocache; -import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.R; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.geopoint.GeopointFormatter; +import cgeo.geocaching.sensors.IGeoData; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.settings.Settings.CoordInputFormatEnum; import cgeo.geocaching.utils.EditUtils; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; import android.os.Bundle; import android.text.Editable; @@ -25,9 +26,11 @@ import android.widget.EditText; import android.widget.Spinner; import android.widget.TextView; +import java.lang.ref.WeakReference; + public class CoordinatesInputDialog extends NoTitleDialog { - final private AbstractActivity context; + final private WeakReference<AbstractActivity> context; final private IGeoData geo; final private Geocache cache; private Geopoint gp; @@ -43,9 +46,9 @@ public class CoordinatesInputDialog extends NoTitleDialog { private CoordInputFormatEnum currentFormat = null; - public CoordinatesInputDialog(final AbstractActivity context, final Geocache cache, final Geopoint gp, final IGeoData geo) { + public CoordinatesInputDialog(final @NonNull AbstractActivity context, final Geocache cache, final Geopoint gp, final IGeoData geo) { super(context, ActivityMixin.getDialogTheme()); - this.context = context; + this.context = new WeakReference<AbstractActivity>(context); this.geo = geo; this.cache = cache; @@ -66,7 +69,7 @@ public class CoordinatesInputDialog extends NoTitleDialog { final Spinner spinner = (Spinner) findViewById(R.id.spinnerCoordinateFormats); final ArrayAdapter<CharSequence> adapter = - ArrayAdapter.createFromResource(context, + ArrayAdapter.createFromResource(context.get(), R.array.waypoint_coordinate_formats, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); @@ -371,7 +374,8 @@ public class CoordinatesInputDialog extends NoTitleDialog { // Signaled and returned below } if (signalError) { - context.showToast(context.getResources().getString(R.string.err_parse_lat_lon)); + final AbstractActivity activity = context.get(); + activity.showToast(activity.getResources().getString(R.string.err_parse_lat_lon)); } return false; } @@ -423,7 +427,8 @@ public class CoordinatesInputDialog extends NoTitleDialog { @Override public void onClick(View v) { if (geo == null || geo.getCoords() == null) { - context.showToast(context.getResources().getString(R.string.err_point_unknown_position)); + final AbstractActivity activity = context.get(); + activity.showToast(activity.getResources().getString(R.string.err_point_unknown_position)); return; } @@ -437,7 +442,8 @@ public class CoordinatesInputDialog extends NoTitleDialog { @Override public void onClick(View v) { if (cache == null || cache.getCoords() == null) { - context.showToast(context.getResources().getString(R.string.err_location_unknown)); + final AbstractActivity activity = context.get(); + activity.showToast(activity.getResources().getString(R.string.err_location_unknown)); return; } |