aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2014-05-19 22:29:05 +0200
committerArne Schwabe <arne@rfc2549.org>2014-05-19 22:30:06 +0200
commitac1160a81eec2e2e58bd275896a8fd2316690675 (patch)
treed5b83120b048dc5011cf55c56180bf4e43b9c0b6 /main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
parent35d75d9a7600fe1c7c3467e898e84f1ef9d09215 (diff)
downloadcgeo-ac1160a81eec2e2e58bd275896a8fd2316690675.zip
cgeo-ac1160a81eec2e2e58bd275896a8fd2316690675.tar.gz
cgeo-ac1160a81eec2e2e58bd275896a8fd2316690675.tar.bz2
Convert DateDialog and CoordinateInputDialog to DialogFragments, closes #3852
Diffstat (limited to 'main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java')
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java85
1 files changed, 45 insertions, 40 deletions
diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
index 67b8923..b4d1292 100644
--- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
@@ -14,10 +14,14 @@ import cgeo.geocaching.utils.EditUtils;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import android.app.Dialog;
import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
import android.text.Editable;
import android.text.TextWatcher;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
@@ -28,9 +32,8 @@ import android.widget.TextView;
import java.lang.ref.WeakReference;
-public class CoordinatesInputDialog extends NoTitleDialog {
+public class CoordinatesInputDialog extends DialogFragment {
- final private WeakReference<AbstractActivity> context;
final private IGeoData geo;
final private Geocache cache;
private Geopoint gp;
@@ -46,9 +49,8 @@ public class CoordinatesInputDialog extends NoTitleDialog {
private CoordInputFormatEnum currentFormat = null;
- public CoordinatesInputDialog(final @NonNull AbstractActivity context, final Geocache cache, final Geopoint gp, final IGeoData geo) {
- super(context, ActivityMixin.getDialogTheme());
- this.context = new WeakReference<AbstractActivity>(context);
+ public CoordinatesInputDialog(final Geocache cache, final Geopoint gp, final IGeoData geo) {
+
this.geo = geo;
this.cache = cache;
@@ -62,14 +64,13 @@ public class CoordinatesInputDialog extends NoTitleDialog {
}
@Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.coordinatesinput_dialog);
+ public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
+ getDialog().setTitle(R.string.cache_coordinates);
- final Spinner spinner = (Spinner) findViewById(R.id.spinnerCoordinateFormats);
+ View v = inflater.inflate(R.layout.coordinatesinput_dialog, container, false);
+ final Spinner spinner = (Spinner) v.findViewById(R.id.spinnerCoordinateFormats);
final ArrayAdapter<CharSequence> adapter =
- ArrayAdapter.createFromResource(context.get(),
+ ArrayAdapter.createFromResource(getActivity(),
R.array.waypoint_coordinate_formats,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@@ -77,25 +78,25 @@ public class CoordinatesInputDialog extends NoTitleDialog {
spinner.setSelection(Settings.getCoordInputFormat().ordinal());
spinner.setOnItemSelectedListener(new CoordinateFormatListener());
- bLat = (Button) findViewById(R.id.ButtonLat);
- eLat = (EditText) findViewById(R.id.latitude);
- eLatDeg = (EditText) findViewById(R.id.EditTextLatDeg);
- eLatMin = (EditText) findViewById(R.id.EditTextLatMin);
- eLatSec = (EditText) findViewById(R.id.EditTextLatSec);
- eLatSub = (EditText) findViewById(R.id.EditTextLatSecFrac);
- tLatSep1 = (TextView) findViewById(R.id.LatSeparator1);
- tLatSep2 = (TextView) findViewById(R.id.LatSeparator2);
- tLatSep3 = (TextView) findViewById(R.id.LatSeparator3);
-
- bLon = (Button) findViewById(R.id.ButtonLon);
- eLon = (EditText) findViewById(R.id.longitude);
- eLonDeg = (EditText) findViewById(R.id.EditTextLonDeg);
- eLonMin = (EditText) findViewById(R.id.EditTextLonMin);
- eLonSec = (EditText) findViewById(R.id.EditTextLonSec);
- eLonSub = (EditText) findViewById(R.id.EditTextLonSecFrac);
- tLonSep1 = (TextView) findViewById(R.id.LonSeparator1);
- tLonSep2 = (TextView) findViewById(R.id.LonSeparator2);
- tLonSep3 = (TextView) findViewById(R.id.LonSeparator3);
+ bLat = (Button) v.findViewById(R.id.ButtonLat);
+ eLat = (EditText) v.findViewById(R.id.latitude);
+ eLatDeg = (EditText) v.findViewById(R.id.EditTextLatDeg);
+ eLatMin = (EditText) v.findViewById(R.id.EditTextLatMin);
+ eLatSec = (EditText) v.findViewById(R.id.EditTextLatSec);
+ eLatSub = (EditText) v.findViewById(R.id.EditTextLatSecFrac);
+ tLatSep1 = (TextView) v.findViewById(R.id.LatSeparator1);
+ tLatSep2 = (TextView) v.findViewById(R.id.LatSeparator2);
+ tLatSep3 = (TextView) v.findViewById(R.id.LatSeparator3);
+
+ bLon = (Button) v.findViewById(R.id.ButtonLon);
+ eLon = (EditText) v.findViewById(R.id.longitude);
+ eLonDeg = (EditText) v.findViewById(R.id.EditTextLonDeg);
+ eLonMin = (EditText) v.findViewById(R.id.EditTextLonMin);
+ eLonSec = (EditText) v.findViewById(R.id.EditTextLonSec);
+ eLonSub = (EditText) v.findViewById(R.id.EditTextLonSecFrac);
+ tLonSep1 = (TextView) v.findViewById(R.id.LonSeparator1);
+ tLonSep2 = (TextView) v.findViewById(R.id.LonSeparator2);
+ tLonSep3 = (TextView) v.findViewById(R.id.LonSeparator3);
eLatDeg.addTextChangedListener(new TextChanged(eLatDeg));
eLatMin.addTextChangedListener(new TextChanged(eLatMin));
@@ -118,18 +119,22 @@ public class CoordinatesInputDialog extends NoTitleDialog {
bLat.setOnClickListener(new ButtonClickListener());
bLon.setOnClickListener(new ButtonClickListener());
- final Button buttonCurrent = (Button) findViewById(R.id.current);
+ final Button buttonCurrent = (Button) v.findViewById(R.id.current);
buttonCurrent.setOnClickListener(new CurrentListener());
- final Button buttonCache = (Button) findViewById(R.id.cache);
+ final Button buttonCache = (Button) v.findViewById(R.id.cache);
if (cache != null) {
buttonCache.setOnClickListener(new CacheListener());
} else {
buttonCache.setVisibility(View.GONE);
}
- final Button buttonDone = (Button) findViewById(R.id.done);
+ final Button buttonDone = (Button) v.findViewById(R.id.done);
buttonDone.setOnClickListener(new InputDoneListener());
+
+ return v;
}
+
+
private void updateGUI() {
if (gp == null) {
return;
@@ -140,14 +145,14 @@ public class CoordinatesInputDialog extends NoTitleDialog {
switch (currentFormat) {
case Plain:
- findViewById(R.id.coordTable).setVisibility(View.GONE);
+ getView().findViewById(R.id.coordTable).setVisibility(View.GONE);
eLat.setVisibility(View.VISIBLE);
eLon.setVisibility(View.VISIBLE);
eLat.setText(gp.format(GeopointFormatter.Format.LAT_DECMINUTE));
eLon.setText(gp.format(GeopointFormatter.Format.LON_DECMINUTE));
break;
case Deg: // DDD.DDDDD°
- findViewById(R.id.coordTable).setVisibility(View.VISIBLE);
+ getView().findViewById(R.id.coordTable).setVisibility(View.VISIBLE);
eLat.setVisibility(View.GONE);
eLon.setVisibility(View.GONE);
eLatSec.setVisibility(View.GONE);
@@ -168,7 +173,7 @@ public class CoordinatesInputDialog extends NoTitleDialog {
eLonMin.setText(addZeros(gp.getLonDegFrac(), 5));
break;
case Min: // DDD° MM.MMM
- findViewById(R.id.coordTable).setVisibility(View.VISIBLE);
+ getView().findViewById(R.id.coordTable).setVisibility(View.VISIBLE);
eLat.setVisibility(View.GONE);
eLon.setVisibility(View.GONE);
eLatSec.setVisibility(View.VISIBLE);
@@ -193,7 +198,7 @@ public class CoordinatesInputDialog extends NoTitleDialog {
eLonSec.setText(addZeros(gp.getLonMinFrac(), 3));
break;
case Sec: // DDD° MM SS.SSS
- findViewById(R.id.coordTable).setVisibility(View.VISIBLE);
+ getView().findViewById(R.id.coordTable).setVisibility(View.VISIBLE);
eLat.setVisibility(View.GONE);
eLon.setVisibility(View.GONE);
eLatSec.setVisibility(View.VISIBLE);
@@ -374,7 +379,7 @@ public class CoordinatesInputDialog extends NoTitleDialog {
// Signaled and returned below
}
if (signalError) {
- final AbstractActivity activity = context.get();
+ final AbstractActivity activity = (AbstractActivity) getActivity();
activity.showToast(activity.getResources().getString(R.string.err_parse_lat_lon));
}
return false;
@@ -427,7 +432,7 @@ public class CoordinatesInputDialog extends NoTitleDialog {
@Override
public void onClick(View v) {
if (geo == null || geo.getCoords() == null) {
- final AbstractActivity activity = context.get();
+ final AbstractActivity activity = (AbstractActivity) getActivity();
activity.showToast(activity.getResources().getString(R.string.err_point_unknown_position));
return;
}
@@ -442,7 +447,7 @@ public class CoordinatesInputDialog extends NoTitleDialog {
@Override
public void onClick(View v) {
if (cache == null || cache.getCoords() == null) {
- final AbstractActivity activity = context.get();
+ final AbstractActivity activity = (AbstractActivity) getActivity();
activity.showToast(activity.getResources().getString(R.string.err_location_unknown));
return;
}