-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ShadowDatePickerDialog.java
106 lines (90 loc) · 3.51 KB
/
ShadowDatePickerDialog.java
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
package org.robolectric.shadows;
import static android.os.Build.VERSION_CODES.KITKAT;
import static android.os.Build.VERSION_CODES.KITKAT_WATCH;
import static android.os.Build.VERSION_CODES.M;
import static android.os.Build.VERSION_CODES.N;
import static org.robolectric.shadow.api.Shadow.invokeConstructor;
import static org.robolectric.util.ReflectionHelpers.ClassParameter;
import static org.robolectric.util.reflector.Reflector.reflector;
import android.annotation.TargetApi;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Context;
import androidx.annotation.RequiresApi;
import java.util.Calendar;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.util.reflector.Accessor;
import org.robolectric.util.reflector.ForType;
@Implements(DatePickerDialog.class)
public class ShadowDatePickerDialog extends ShadowAlertDialog {
@RealObject protected DatePickerDialog realDatePickerDialog;
private Calendar calendar;
@Implementation(maxSdk = M)
protected void __constructor__(
Context context,
int theme,
DatePickerDialog.OnDateSetListener callBack,
int year,
int monthOfYear,
int dayOfMonth) {
invokeConstructor(DatePickerDialog.class, realDatePickerDialog,
ClassParameter.from(Context.class, context),
ClassParameter.from(int.class, theme),
ClassParameter.from(DatePickerDialog.OnDateSetListener.class, callBack),
ClassParameter.from(int.class, year),
ClassParameter.from(int.class, monthOfYear),
ClassParameter.from(int.class, dayOfMonth));
}
@Implementation(minSdk = N)
protected void __constructor__(
Context context,
int theme,
DatePickerDialog.OnDateSetListener callBack,
Calendar calendar,
int year,
int monthOfYear,
int dayOfMonth) {
this.calendar = calendar;
invokeConstructor(DatePickerDialog.class, realDatePickerDialog,
ClassParameter.from(Context.class, context),
ClassParameter.from(int.class, theme),
ClassParameter.from(DatePickerDialog.OnDateSetListener.class, callBack),
ClassParameter.from(Calendar.class, calendar),
ClassParameter.from(int.class, year),
ClassParameter.from(int.class, monthOfYear),
ClassParameter.from(int.class, dayOfMonth));
}
public Calendar getCalendar() {
return calendar;
}
public int getYear() {
return realDatePickerDialog.getDatePicker().getYear();
}
public int getMonthOfYear() {
return realDatePickerDialog.getDatePicker().getMonth();
}
public int getDayOfMonth() {
return realDatePickerDialog.getDatePicker().getDayOfMonth();
}
public DatePickerDialog.OnDateSetListener getOnDateSetListenerCallback() {
if (RuntimeEnvironment.getApiLevel() <= KITKAT) {
return reflector(DatePickerDialogReflector.class, realDatePickerDialog).getCallback();
} else {
return reflector(DatePickerDialogReflector.class, realDatePickerDialog).getDateSetListener();
}
}
@ForType(DatePickerDialog.class)
interface DatePickerDialogReflector {
/** For sdk version at least {@link KITKAT_WATCH} */
@RequiresApi(KITKAT_WATCH)
@Accessor("mDateSetListener")
OnDateSetListener getDateSetListener();
/** For sdk version is equals to {@link KITKAT} */
@TargetApi(KITKAT)
@Accessor("mCallBack")
OnDateSetListener getCallback();
}
}