aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/dialog/DateDialog.java
blob: a9c579ca950a58d348526fca65c79e00b5150159 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cgeo.geocaching.ui.dialog;

import cgeo.geocaching.R;

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.MATCH_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);
            }
        }
    }
}