-
Notifications
You must be signed in to change notification settings - Fork 580
/
MainActivity.java
86 lines (68 loc) · 3.46 KB
/
MainActivity.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
package com.fourmob.datetimepicker.sample;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.Toast;
import com.fourmob.datetimepicker.date.DatePickerDialog;
import com.fourmob.datetimepicker.date.DatePickerDialog.OnDateSetListener;
import com.sleepbot.datetimepicker.time.RadialPickerLayout;
import com.sleepbot.datetimepicker.time.TimePickerDialog;
import java.util.Calendar;
public class MainActivity extends FragmentActivity implements OnDateSetListener, TimePickerDialog.OnTimeSetListener {
public static final String DATEPICKER_TAG = "datepicker";
public static final String TIMEPICKER_TAG = "timepicker";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Calendar calendar = Calendar.getInstance();
final DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), isVibrate());
final TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(this, calendar.get(Calendar.HOUR_OF_DAY) ,calendar.get(Calendar.MINUTE), false, false);
findViewById(R.id.dateButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
datePickerDialog.setVibrate(isVibrate());
datePickerDialog.setYearRange(1985, 2028);
datePickerDialog.setCloseOnSingleTapDay(isCloseOnSingleTapDay());
datePickerDialog.show(getSupportFragmentManager(), DATEPICKER_TAG);
}
});
findViewById(R.id.timeButton).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
timePickerDialog.setVibrate(isVibrate());
timePickerDialog.setCloseOnSingleTapMinute(isCloseOnSingleTapMinute());
timePickerDialog.show(getSupportFragmentManager(), TIMEPICKER_TAG);
}
});
if (savedInstanceState != null) {
DatePickerDialog dpd = (DatePickerDialog) getSupportFragmentManager().findFragmentByTag(DATEPICKER_TAG);
if (dpd != null) {
dpd.setOnDateSetListener(this);
}
TimePickerDialog tpd = (TimePickerDialog) getSupportFragmentManager().findFragmentByTag(TIMEPICKER_TAG);
if (tpd != null) {
tpd.setOnTimeSetListener(this);
}
}
}
private boolean isVibrate() {
return ((CheckBox) findViewById(R.id.checkBoxVibrate)).isChecked();
}
private boolean isCloseOnSingleTapDay() {
return ((CheckBox) findViewById(R.id.checkBoxCloseOnSingleTapDay)).isChecked();
}
private boolean isCloseOnSingleTapMinute() {
return ((CheckBox) findViewById(R.id.checkBoxCloseOnSingleTapMinute)).isChecked();
}
@Override
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
Toast.makeText(MainActivity.this, "new date:" + year + "-" + month + "-" + day, Toast.LENGTH_LONG).show();
}
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
Toast.makeText(MainActivity.this, "new time:" + hourOfDay + "-" + minute, Toast.LENGTH_LONG).show();
}
}