use of android.widget.DatePicker in project AndFrameWorks by scwang90.
the class AfDialogBuilder method selectDateTime.
/**
* 选择日期时间
* @param title 标题
* @param value 默认时间
* @param listener 监听器
*/
@Override
public Dialog selectDateTime(final CharSequence title, final Date value, final OnDateTimeSetListener listener) {
final Calendar calender = Calendar.getInstance();
calender.setTime(value);
int year = calender.get(Calendar.YEAR);
final int month = calender.get(Calendar.MONTH);
final int day = calender.get(Calendar.DAY_OF_MONTH);
final AlertDialog tDialog = new DatePickerDialog(mContext, new SafeListener((view, year1, month1, day1) -> {
int hour = calender.get(Calendar.HOUR_OF_DAY);
int minute = calender.get(Calendar.MINUTE);
Dialog tDialog1 = new TimePickerDialog(mContext, new SafeListener((OnTimeSetListener) (view1, hour1, minute1) -> listener.onDateTimeSet(year1, month1, day1, hour1, minute1)), hour, minute, true) {
@Override
public void show() {
super.show();
if (listener instanceof OnDateTimeSetVerifyListener) {
getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
try {
TimePicker picker = AfReflecter.getMemberByType(this, TimePicker.class);
if (picker == null) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
} else if (((OnDateTimeSetVerifyListener) listener).onPreTimeSet(picker, picker.getCurrentHour(), picker.getCurrentMinute())) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
}
}
};
;
if (title != null && title.length() > 0) {
tDialog1.setTitle(title);
}
tDialog1.show();
tDialog1.setCancelable(true);
}), year, month, day) {
@Override
public void show() {
super.show();
if (listener instanceof OnDateTimeSetVerifyListener) {
getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
try {
DatePicker picker = AfReflecter.getMemberByType(this, DatePicker.class);
if (picker == null) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
} else if (((OnDateTimeSetVerifyListener) listener).onPreDateSet(picker, picker.getYear(), picker.getMonth(), picker.getDayOfMonth())) {
this.dismiss();
super.onClick(this, BUTTON_POSITIVE);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
});
}
}
};
if (title != null && title.length() > 0) {
tDialog.setTitle(title);
}
tDialog.show();
tDialog.setCancelable(true);
return tDialog;
}
use of android.widget.DatePicker in project android by owncloud.
the class ExpirationDatePickerDialogFragment method onCreateDialog.
/**
* {@inheritDoc}
*
* @return A new dialog to let the user choose an expiration date that will be bound to a share link.
*/
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Chosen date received as an argument must be later than tomorrow ; default to tomorrow in other case
final Calendar chosenDate = Calendar.getInstance();
long tomorrowInMillis = chosenDate.getTimeInMillis() + DateUtils.DAY_IN_MILLIS;
long chosenDateInMillis = getArguments().getLong(ARG_CHOSEN_DATE_IN_MILLIS);
long maxDateInMillis = getArguments().getLong(ARG_MAX_DATE_IN_MILLIS);
if (chosenDateInMillis < tomorrowInMillis) {
chosenDateInMillis = tomorrowInMillis;
}
chosenDate.setTimeInMillis(chosenDateInMillis);
// Create a new instance of DatePickerDialog
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, chosenDate.get(Calendar.YEAR), chosenDate.get(Calendar.MONTH), chosenDate.get(Calendar.DAY_OF_MONTH));
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.share_cancel_public_link_button), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE) {
// Do Stuff
notifyDatePickerListener(null);
}
}
});
// Prevent days in the past may be chosen
DatePicker picker = dialog.getDatePicker();
if (maxDateInMillis >= chosenDateInMillis) {
// the extra second (+1000) is required to prevent a bug of DatePicker that shows
// an extra header with the selected date if maxDateInMillis == chosenDateInMillis
picker.setMaxDate(maxDateInMillis + 1000);
}
picker.setMinDate(tomorrowInMillis - 1000);
// Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
// in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
// shown by default)
picker.setCalendarViewShown(false);
return dialog;
}
use of android.widget.DatePicker in project KJFrameForAndroid by kymjs.
the class ViewInject method getDateDialog.
/**
* 用于创建PopupWindow封装一些公用属性
*/
// private PopupWindow createWindow(View view, int w, int h, int argb) {
// PopupWindow popupView = new PopupWindow(view, w, h);
// popupView.setFocusable(true);
// popupView.setBackgroundDrawable(new ColorDrawable(argb));
// popupView.setOutsideTouchable(true);
// return popupView;
// }
/**
* 返回一个日期对话框
*/
public void getDateDialog(String title, final TextView textView) {
final String[] time = SystemTool.getDataTime("yyyy-MM-dd").split("-");
final int year = StringUtils.toInt(time[0], 0);
final int month = StringUtils.toInt(time[1], 1);
final int day = StringUtils.toInt(time[2], 0);
DatePickerDialog dialog = new DatePickerDialog(textView.getContext(), new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
textView.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
}
}, year, month - 1, day);
dialog.setTitle(title);
dialog.show();
}
use of android.widget.DatePicker in project ride-read-android by Ride-Read.
the class UserInfoActivity method showBirthdayDialog.
private void showBirthdayDialog() {
AlertDialog.Builder dialogBuider = new AlertDialog.Builder(this);
dialogBuider.setTitle(R.string.birthday);
final DatePicker birthPicker = new DatePicker(this);
birthPicker.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
Rect r = new Rect();
birthPicker.getWindowVisibleDisplayFrame(r);
});
int year = 1990;
int month = 1;
int date = 1;
long birthDay = mUserInfo.getBirthday();
if (0 != birthDay) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(birthDay);
year = cal.get(Calendar.YEAR);
month = cal.get(Calendar.MONTH);
date = cal.get(Calendar.DAY_OF_MONTH);
}
ViewGroup tempGroup = ((ViewGroup) (((ViewGroup) birthPicker.getChildAt(0)).getChildAt(0)));
birthPicker.setMaxDate(System.currentTimeMillis());
birthPicker.init(year, month - 1, date, null);
dialogBuider.setView(birthPicker);
dialogBuider.setPositiveButton(R.string.confirm, (arg0, arg1) -> {
mBirthday = String.format("%s-%02d-%02d", birthPicker.getYear(), birthPicker.getMonth() + 1, birthPicker.getDayOfMonth());
mTvBirthday.setText(mBirthday);
});
birthPicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
tempGroup.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
birthPicker.setCalendarViewShown(false);
// birthPicker.setFocusable(false);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(tempGroup.getWindowToken(), 0);
dialogBuider.show();
}
use of android.widget.DatePicker in project Reader by TheKeeperOfPie.
the class FragmentHistory method showDateRangeDialog.
private void showDateRangeDialog() {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date_range, null, false);
final DatePicker datePickerStart = (DatePicker) view.findViewById(R.id.date_picker_start);
final DatePicker datePickerEnd = (DatePicker) view.findViewById(R.id.date_picker_end);
final ViewPager viewPager = (ViewPager) view.findViewById(R.id.view_pager_time);
viewPager.setAdapter(new PagerAdapter() {
@Override
public Object instantiateItem(ViewGroup container, int position) {
switch(position) {
case 0:
return datePickerStart;
case 1:
return datePickerEnd;
}
return super.instantiateItem(container, position);
}
@Override
public CharSequence getPageTitle(int position) {
switch(position) {
case 0:
return viewPager.getContext().getResources().getString(R.string.start);
case 1:
return viewPager.getContext().getResources().getString(R.string.end);
}
return super.getPageTitle(position);
}
@Override
public int getCount() {
return 2;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
});
final TabLayout layoutTab = (TabLayout) view.findViewById(R.id.layout_tab);
layoutTab.setupWithViewPager(viewPager);
final Calendar calendarStart = Calendar.getInstance();
calendarStart.setTimeZone(TimeZone.getTimeZone("UTC"));
datePickerStart.init(calendarStart.get(Calendar.YEAR), calendarStart.get(Calendar.MONTH), calendarStart.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
calendarStart.set(year, monthOfYear, dayOfMonth);
layoutTab.getTabAt(0).setText(DateUtils.formatDateTime(getActivity(), calendarStart.getTimeInMillis(), FORMAT_DATE));
}
});
long timeStart = controllerHistory.getTimeStart();
if (timeStart > 0) {
calendarStart.setTimeInMillis(timeStart);
datePickerStart.updateDate(calendarStart.get(Calendar.YEAR), calendarStart.get(Calendar.MONTH), calendarStart.get(Calendar.DAY_OF_MONTH));
}
final Calendar calendarEnd = Calendar.getInstance();
calendarEnd.setTimeZone(TimeZone.getTimeZone("UTC"));
datePickerEnd.init(calendarEnd.get(Calendar.YEAR), calendarEnd.get(Calendar.MONTH), calendarEnd.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
calendarEnd.set(year, monthOfYear, dayOfMonth);
layoutTab.getTabAt(1).setText(DateUtils.formatDateTime(getActivity(), calendarEnd.getTimeInMillis(), FORMAT_DATE));
}
});
datePickerEnd.setMaxDate(System.currentTimeMillis() + AlarmManager.INTERVAL_DAY);
long timeEnd = controllerHistory.getTimeEnd();
if (timeEnd < Long.MAX_VALUE) {
calendarEnd.setTimeInMillis(timeEnd);
calendarEnd.add(Calendar.DAY_OF_MONTH, -1);
datePickerEnd.updateDate(calendarEnd.get(Calendar.YEAR), calendarEnd.get(Calendar.MONTH), calendarEnd.get(Calendar.DAY_OF_MONTH));
}
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setView(view).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Calendar calendarStart = Calendar.getInstance();
calendarStart.set(datePickerStart.getYear(), datePickerStart.getMonth(), datePickerStart.getDayOfMonth());
calendarStart.setTimeZone(TimeZone.getTimeZone("UTC"));
Calendar calendarEnd = Calendar.getInstance();
calendarEnd.set(datePickerEnd.getYear(), datePickerEnd.getMonth(), datePickerEnd.getDayOfMonth());
calendarEnd.setTimeZone(TimeZone.getTimeZone("UTC"));
calendarEnd.add(Calendar.DAY_OF_MONTH, 1);
controllerHistory.setTimeStart(calendarStart.getTimeInMillis());
controllerHistory.setTimeEnd(calendarEnd.getTimeInMillis());
controllerHistory.reload();
}
}).setNeutralButton(R.string.reset, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
controllerHistory.setTimeStart(0);
controllerHistory.setTimeEnd(Long.MAX_VALUE);
controllerHistory.reload();
}
}).setNegativeButton(R.string.cancel, null).create();
dialog.show();
}
Aggregations