diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-01-02 19:03:39 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-01-02 19:03:39 +0100 |
commit | 0e29296fcf6585a5aa654537f88f07166bc2a8fb (patch) | |
tree | 6806d72ca2fb8944e55337d00a4f04dc9f567e8d /main/src/cgeo/geocaching/ui | |
parent | cb69be1b19bd9c52ef9062c3e272d98952fed2f2 (diff) | |
download | cgeo-0e29296fcf6585a5aa654537f88f07166bc2a8fb.zip cgeo-0e29296fcf6585a5aa654537f88f07166bc2a8fb.tar.gz cgeo-0e29296fcf6585a5aa654537f88f07166bc2a8fb.tar.bz2 |
refactoring: replace useless super class by nested interface
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 |