-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDatePickerProxy.java
More file actions
183 lines (156 loc) · 4.67 KB
/
Copy pathDatePickerProxy.java
File metadata and controls
183 lines (156 loc) · 4.67 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package yy.tidialogs;
import java.util.Calendar;
import java.util.Date;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;
import android.R;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.DialogInterface;
import android.os.Build;
import android.widget.DatePicker;
import ti.modules.titanium.ui.widget.picker.TiDatePickerDialog;
@Kroll.proxy(creatableInModule = TidialogsModule.class)
public class DatePickerProxy extends BaseDialogProxy
{
private class BasicDatePicker extends BaseUIDialog
{
private int year;
private int month;
private int day;
private Date maxDate;
private Date minDate;
private String okButtonTitle;
private String cancelButtonTitle;
public BasicDatePicker(TiViewProxy proxy)
{
super(proxy);
}
protected DatePickerDialog getDialog()
{
if (dialog != null) {
return (DatePickerDialog) dialog;
}
OnDateSetListener dateSetListener = new OnDateSetListener() {
// when dialog box is closed, below method will be
// called.
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay)
{
year = selectedYear;
month = selectedMonth;
day = selectedDay;
KrollDict data = new KrollDict();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
Date value = calendar.getTime();
data.put("value", value);
data.put("year", year);
data.put("month", month);
data.put("day", day);
fireEvent("click", data);
}
};
DatePickerDialog picker;
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
&& (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)) {
picker =
new TiDatePickerDialog(TiApplication.getAppCurrentActivity(), dateSetListener, year, month, day);
} else {
picker = new DatePickerDialog(TiApplication.getAppCurrentActivity(), dateSetListener, year, month, day);
}
if (minDate != null) {
picker.getDatePicker().setMinDate(trimDate(minDate).getTime());
}
if (maxDate != null) {
picker.getDatePicker().setMaxDate(trimDate(maxDate).getTime());
}
picker.setOnDismissListener(dismissListener);
picker.setCanceledOnTouchOutside(false);
picker.setButton(DialogInterface.BUTTON_POSITIVE, okButtonTitle, picker);
dialog = picker;
return picker;
}
@Override
public void processProperties(KrollDict d)
{
super.processProperties(d);
Calendar c = Calendar.getInstance();
if (d.containsKey("value")) {
c.setTime((Date) d.get("value"));
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
} else {
if (d.containsKey("year")) {
year = d.getInt("year");
} else {
year = c.get(Calendar.YEAR);
}
if (d.containsKey("month")) {
month = d.getInt("month");
} else {
month = c.get(Calendar.MONTH);
}
if (d.containsKey("day")) {
day = d.getInt("day");
} else {
day = c.get(Calendar.DAY_OF_MONTH);
}
}
if (d.containsKey(TiC.PROPERTY_MIN_DATE)) {
minDate = (Date) d.get(TiC.PROPERTY_MIN_DATE);
}
if (d.containsKey(TiC.PROPERTY_MAX_DATE)) {
maxDate = (Date) d.get(TiC.PROPERTY_MAX_DATE);
}
if (d.containsKey("okButtonTitle")) {
okButtonTitle = d.getString("okButtonTitle");
} else {
okButtonTitle =
TiApplication.getAppCurrentActivity().getApplication().getResources().getString(R.string.ok);
}
if (d.containsKey("cancelButtonTitle")) {
cancelButtonTitle = d.getString("cancelButtonTitle");
} else {
cancelButtonTitle =
TiApplication.getAppCurrentActivity().getApplication().getResources().getString(R.string.cancel);
}
}
}
public DatePickerProxy()
{
super();
}
@Override
public TiUIView createView(Activity activity)
{
return new BasicDatePicker(this);
}
@Override
public void handleCreationDict(KrollDict options)
{
super.handleCreationDict(options);
}
/**
* Trim hour, minute, second and millisecond from the date
* @param inDate input date
* @return return the trimmed date
*/
public static Date trimDate(Date inDate)
{
Calendar cal = Calendar.getInstance();
cal.setTime(inDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
}