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 butterknife.ButterKnife;
import cgeo.geocaching.R;
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 DialogFragment {
public interface DateDialogParent {
abstract public void setDate(final Calendar date);
}
private Calendar date;
public static DateDialog getInstance(final Calendar date) {
final DateDialog dateDialog = new DateDialog();
final Bundle args = new Bundle();
args.putSerializable("date", date);
dateDialog.setArguments(args);
return dateDialog;
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, 0);
final Bundle args = getArguments();
date = (Calendar) args.getSerializable("date");
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.date, container, false);
final DatePicker picker = ButterKnife.findById(v, 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(final DatePicker picker, final int year, final int month, final int day) {
date.set(year, month, day);
((DateDialogParent) getActivity()).setDate(date);
}
}
}
|