diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r-- | main/src/cgeo/geocaching/ui/DateDialog.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/ui/DateDialog.java b/main/src/cgeo/geocaching/ui/DateDialog.java new file mode 100644 index 0000000..f8996ce --- /dev/null +++ b/main/src/cgeo/geocaching/ui/DateDialog.java @@ -0,0 +1,61 @@ +package cgeo.geocaching.ui; + +import cgeo.geocaching.R; +import cgeo.geocaching.R.id; +import cgeo.geocaching.R.layout; + +import android.app.Activity; +import android.app.Dialog; +import android.os.Bundle; +import android.view.ViewGroup.LayoutParams; +import android.view.Window; +import android.widget.DatePicker; + +import java.util.Calendar; + +public class DateDialog extends Dialog { + + public interface DateDialogParent { + abstract public void setDate(final Calendar date); + } + + private final DateDialogParent parent; + private final Calendar date; + + public DateDialog(Activity contextIn, DateDialogParent parentIn, Calendar dateIn) { + super(contextIn); + + // init + this.date = dateIn; + this.parent = parentIn; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + try { + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); + } catch (Exception e) { + // nothing + } + + setContentView(R.layout.date); + + final DatePicker picker = (DatePicker) findViewById(R.id.picker); + picker.init(date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DATE), new DatePickerListener()); + } + + 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); + + parent.setDate(date); + } + } + } +}
\ No newline at end of file |