aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/dialog
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui/dialog')
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java157
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/DateDialog.java42
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/Dialogs.java14
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/NoTitleDialog.java32
4 files changed, 132 insertions, 113 deletions
diff --git a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
index 67b8923..00b5abe 100644
--- a/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/CoordinatesInputDialog.java
@@ -3,7 +3,6 @@ package cgeo.geocaching.ui.dialog;
import cgeo.geocaching.Geocache;
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;
@@ -12,12 +11,14 @@ 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.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;
@@ -26,14 +27,11 @@ import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
-import java.lang.ref.WeakReference;
+public class CoordinatesInputDialog extends DialogFragment {
-public class CoordinatesInputDialog extends NoTitleDialog {
-
- final private WeakReference<AbstractActivity> context;
- 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;
@@ -42,34 +40,64 @@ public class CoordinatesInputDialog extends NoTitleDialog {
private TextView tLatSep1, tLatSep2, tLatSep3;
private TextView tLonSep1, tLonSep2, tLonSep3;
- private CoordinateUpdate cuListener;
-
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);
- 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);
+
+ }
- setContentView(R.layout.coordinatesinput_dialog);
+ @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
+ 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 +105,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 +146,24 @@ 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);
- if (cache != null) {
+ final Button buttonCache = (Button) v.findViewById(R.id.cache);
+
+ if (cacheCoords != 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 +174,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 +202,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 +227,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 +408,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;
@@ -403,8 +437,8 @@ public class CoordinatesInputDialog extends NoTitleDialog {
// 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 NoTitleDialog {
@Override
public void onClick(View v) {
- if (geo == null || geo.getCoords() == null) {
- final AbstractActivity activity = context.get();
+ 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 NoTitleDialog {
@Override
public void onClick(View v) {
- if (cache == null || cache.getCoords() == null) {
- final AbstractActivity activity = context.get();
+ 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 NoTitleDialog {
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);
}
}
diff --git a/main/src/cgeo/geocaching/ui/dialog/DateDialog.java b/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
index 18f8e2e..fc69f44 100644
--- a/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
+++ b/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
@@ -2,48 +2,56 @@ package cgeo.geocaching.ui.dialog;
import cgeo.geocaching.R;
-import android.app.Activity;
import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
import android.widget.DatePicker;
import java.util.Calendar;
-public class DateDialog extends NoTitleDialog {
+public class DateDialog extends DialogFragment {
public interface DateDialogParent {
abstract public void setDate(final Calendar date);
}
- private final DateDialogParent parent;
- private final Calendar date;
+ private Calendar date;
- public DateDialog(Activity contextIn, DateDialogParent parentIn, Calendar dateIn) {
- super(contextIn);
-
- // init
- this.date = dateIn;
- this.parent = parentIn;
+ public static DateDialog getInstance(Calendar date) {
+ DateDialog dd = new DateDialog();
+ Bundle args = new Bundle();
+ args.putSerializable("date", date);
+ dd.setArguments(args);
+ return dd;
}
@Override
- public void onCreate(Bundle savedInstanceState) {
+ public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setStyle(DialogFragment.STYLE_NO_TITLE, 0);
+ Bundle args = getArguments();
+ date = (Calendar) args.getSerializable("date");
+ }
- setContentView(R.layout.date);
+ @Override
+ public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
+ View v = inflater.inflate(R.layout.date, container, false);
- final DatePicker picker = (DatePicker) findViewById(R.id.picker);
+ final DatePicker picker = (DatePicker) v.findViewById(R.id.picker);
picker.init(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), new DatePickerListener());
+ return v;
}
private class DatePickerListener implements DatePicker.OnDateChangedListener {
@Override
public void onDateChanged(DatePicker picker, int year, int month, int day) {
- if (parent != null) {
- date.set(year, month, day);
+ date.set(year, month, day);
+
+ ((DateDialogParent) getActivity()).setDate(date);
- parent.setDate(date);
- }
}
}
} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
index cb8926a..6a2f9a5 100644
--- a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
+++ b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
@@ -218,7 +218,19 @@ public final class Dialogs {
/**
* Show a message dialog with a single "OK" button.
- *
+ *
+ * @param context
+ * activity owning the dialog
+ * @param message
+ * message dialog content
+ */
+ public static void message(final Activity context, final int message) {
+ message(context, null, getString(message));
+ }
+
+ /**
+ * Show a message dialog with a single "OK" button.
+ *
* @param context
* activity owning the dialog
* @param title
diff --git a/main/src/cgeo/geocaching/ui/dialog/NoTitleDialog.java b/main/src/cgeo/geocaching/ui/dialog/NoTitleDialog.java
deleted file mode 100644
index 8660a7b..0000000
--- a/main/src/cgeo/geocaching/ui/dialog/NoTitleDialog.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package cgeo.geocaching.ui.dialog;
-
-import cgeo.geocaching.utils.Log;
-
-import android.app.Dialog;
-import android.content.Context;
-import android.os.Bundle;
-import android.view.ViewGroup.LayoutParams;
-import android.view.Window;
-
-public abstract class NoTitleDialog extends Dialog {
-
- public NoTitleDialog(Context context) {
- super(context);
- }
-
- public NoTitleDialog(Context context, int theme) {
- super(context, theme);
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- try {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
- } catch (final Exception e) {
- Log.e("NoTitleDialog.onCreate", e);
- }
- }
-}