List of usage examples for android.app DatePickerDialog DatePickerDialog
public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month, int dayOfMonth)
From source file:com.flowzr.activity.RecurActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Setup ActionBar getSupportActionBar().setDisplayHomeAsUpEnabled(true); //@see: http://stackoverflow.com/questions/16539251/get-rid-of-blue-line, //only way found to remove on various devices 2.3x, 3.0, ... getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#000000"))); setContentView(R.layout.recur);/*from w w w .j av a 2 s. c o m*/ df = DateUtils.getLongDateFormat(this); stopsOnDate.add(Calendar.YEAR, 1); sInterval = (Spinner) findViewById(R.id.intervalSpinner); sPeriod = (Spinner) findViewById(R.id.recurSpinner); layoutInterval = (LinearLayout) findViewById(R.id.layoutInterval); layoutRecur = (LinearLayout) findViewById(R.id.recurInterval); bStartDate = (Button) findViewById(R.id.bStartDate); bStartDate.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { final Calendar c = startDate; DatePickerDialog d = new DatePickerDialog(RecurActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, monthOfYear); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); DateUtils.startOfDay(c); editStartDate(c.getTimeInMillis()); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); d.show(); } }); addSpinnerItems(sInterval, new RecurInterval[] { RecurInterval.NO_RECUR, RecurInterval.WEEKLY, RecurInterval.MONTHLY }); addSpinnerItems(sPeriod, periods); LayoutInflater inflater = getLayoutInflater(); //addLayouts(inflater, layoutInterval, intervals); addLayouts(inflater, layoutRecur, periods); Recur recur = RecurUtils.createDefaultRecur(); Intent intent = getIntent(); if (intent != null) { String extra = intent.getStringExtra(EXTRA_RECUR); if (extra != null) { recur = RecurUtils.createFromExtraString(extra); } } editRecur(recur); sInterval.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { RecurInterval interval = getRecurInterval(sInterval.getSelectedItem()); selectInterval(interval); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); sPeriod.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { RecurPeriod period = periods[position]; selectPeriod(period); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); }
From source file:net.grappendorf.doitlater.TaskEditorActivity.java
public void onDueDatePopup(@SuppressWarnings("unused") View source) { final Calendar cal = Calendar.getInstance(); if (task.getDue() != null) { cal.setTimeInMillis(task.getDue().getValue()); }//from w ww . j a v a 2s . c o m new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); dueDate.setText(DoItLaterApplication.formatDate(cal.getTime())); } }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)).show(); }
From source file:com.polyvi.xface.extension.XCalendarExt.java
/** * ??/* w w w. ja v a2 s. c om*/ * * @param year * ? * @param month * ? * @param day * ? * */ private void getDate(final int year, final int month, final int day, final XCallbackContext callbackCtx) { mExtensionContext.getSystemContext().runOnUiThread(new Runnable() { @Override public void run() { new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { setDate(year, monthOfYear, dayOfMonth, callbackCtx); } }, year, (month - 1), day).show();// 0 // ?1?? // js??1 } }); }
From source file:com.cavega.DatePickerDialogSample.DatePickerDialogFragment.java
@TargetApi(11) @Override// w ww. j ava 2s.c o m public Dialog onCreateDialog(Bundle savedInstanceState) { // Jelly Bean introduced a bug in DatePickerDialog (and possibly // TimePickerDialog as well), and one of the possible solutions is // to postpone the creation of both the listener and the BUTTON_* . // // Passing a null here won't harm because DatePickerDialog checks for a null // whenever it reads the listener that was passed here. >>> This seems to be // true down to 1.5 / API 3, up to 4.1.1 / API 16. <<< No worries. For now. // // See my own question and answer, and details I included for the issue: // // http://stackoverflow.com/a/11493752/489607 // http://code.google.com/p/android/issues/detail?id=34833 // // Of course, suggestions welcome. final DatePickerDialog picker = new DatePickerDialog(getActivity(), getConstructorListener(), year, month, day); if (hasJellyBeanAndAbove()) { picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, dp.getYear(), dp.getMonth(), dp.getDayOfMonth()); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); } return picker; }
From source file:com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment.java
/** * {@inheritDoc}/* w ww . j a v a2s.c o m*/ * * @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; }
From source file:com.kubotaku.android.code4kyoto5374.fragments.DateTimePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (type == TYPE_PICKER_DATE) { // Create a new instance of DatePickerDialog and return it return new DatePickerDialog(getActivity(), this, year, month, day); } else {//from w w w.j av a2 s . c o m // Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), this, hour, minute, DateFormat.is24HourFormat(getActivity())); } }
From source file:com.flowzr.activity.DateFilterActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.date_filter); df = DateUtils.getShortDateFormat(this); Intent intent = getIntent();//w w w . j a va 2 s . c om setCorrectPeriods(intent); createPeriodsSpinner(); Button bNoFilter = (Button) findViewById(R.id.bNoFilter); bNoFilter.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setResult(RESULT_FIRST_USER); finish(); } }); if (intent == null) { reset(); } else { WhereFilter filter = WhereFilter.fromIntent(intent); DateTimeCriteria c = (DateTimeCriteria) filter.get(BlotterFilter.DATETIME); if (c != null) { if (c.getPeriod() == null || c.getPeriod().type == PeriodType.CUSTOM) { selectPeriod(c.getLongValue1(), c.getLongValue2()); } else { selectPeriod(c.getPeriod()); } } if (intent.getBooleanExtra(EXTRA_FILTER_DONT_SHOW_NO_FILTER, false)) { bNoFilter.setVisibility(View.GONE); } } buttonPeriodFrom = (Button) findViewById(R.id.bPeriodFrom); buttonPeriodFrom.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Calendar c = cFrom; DatePickerDialog d = new DatePickerDialog(DateFilterActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, monthOfYear); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); DateUtils.startOfDay(c); cFrom.setTimeInMillis(c.getTimeInMillis()); updateDate(); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); d.show(); } }); buttonPeriodTo = (Button) findViewById(R.id.bPeriodTo); buttonPeriodTo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Calendar c = cTo; DatePickerDialog d = new DatePickerDialog(DateFilterActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { c.set(Calendar.YEAR, year); c.set(Calendar.MONTH, monthOfYear); c.set(Calendar.DAY_OF_MONTH, dayOfMonth); DateUtils.startOfDay(c); cTo.setTimeInMillis(c.getTimeInMillis()); updateDate(); } }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)); d.show(); } }); }
From source file:com.polyvi.xface.extension.calendar.XCalendarExt.java
/** * ??//from w w w.j a va 2s . com * * @param year * ? * @param month * ? * @param day * ? */ private void getDate(final int year, final int month, final int day) { ((Activity) cordova.getActivity()).runOnUiThread(new Runnable() { @Override public void run() { new DatePickerDialog(cordova.getActivity(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { setDate(year, monthOfYear, dayOfMonth); } }, year, (month - 1), day).show();// 0 // ?1?? // js??1 } }); }
From source file:net.evecom.androidecssp.activity.taskresponse.TaskAddActivity.java
/** * /*from w w w . ja va 2 s . c o m*/ * * * @author Mars zhang * @created 2015-11-25 2:06:15 */ private void init() { tasknameeditText = (EditText) findViewById(R.id.taskadd_taskname_et); contenteditText = (EditText) findViewById(R.id.taskadd_taskcontern_et); remarkeditText = (EditText) findViewById(R.id.taskadd_remark_et); keywordeditText = (EditText) findViewById(R.id.taskadd_keyword_et); taskeffiView = (TextView) findViewById(R.id.taskadd_taskeffi_tv); taskpersonView = (EditText) findViewById(R.id.taskadd_taskpersonid_ed); taskdeptView = (EditText) findViewById(R.id.taskadd_taskdept_et); taskeffilinearLayout = (RelativeLayout) findViewById(R.id.taskadd_taskeffi_ll); calendar = Calendar.getInstance(); taskeffiView.setText(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-" + calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.HOUR_OF_DAY) + ":" + calendar.get(Calendar.MINUTE)); taskeffilinearLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { new DatePickerDialog(instance, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker arg0, int year, int monthOfYear, int dayOfMonth) { taskeffiView.setText("" + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 00:00"); if (!istimePicked) { istimePicked = true; new TimePickerDialog(instance, new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { String tasteffivalue = taskeffiView.getText().toString(); String[] strs = tasteffivalue.split(" "); taskeffiView.setText(""); taskeffiView.setText(strs[0] + " " + hourOfDay + ":" + minute); istimePicked = false; } }, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show(); } } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)) .show(); } }); }
From source file:com.adithya321.sharesanalysis.fragments.FundFlowFragment.java
@Nullable @Override//from w ww .ja v a 2 s.c om public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_fund_flow, container, false); Window window = getActivity().getWindow(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) window.setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark)); ((AppCompatActivity) getActivity()).getSupportActionBar() .setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); databaseHandler = new DatabaseHandler(getContext()); fundIn = (TextView) root.findViewById(R.id.fund_in); fundOut = (TextView) root.findViewById(R.id.fund_out); fundsListView = (ListView) root.findViewById(R.id.funds_list_view); setViews(); FloatingActionButton addFundFab = (FloatingActionButton) root.findViewById(R.id.add_fund_fab); addFundFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Add Fund Flow"); dialog.setContentView(R.layout.dialog_add_fund); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start, month_start - 1, day_start); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { selectDate.setText(new StringBuilder().append(day_start).append("/") .append(month_start).append("/").append(year_start)); } }); dialog.show(); } }); final EditText amount = (EditText) dialog.findViewById(R.id.amount); Button addFundBtn = (Button) dialog.findViewById(R.id.add_fund_btn); addFundBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fund fund = new Fund(); fund.setId(databaseHandler.getNextKey("fund")); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); fund.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } try { fund.setAmount(Double.parseDouble(amount.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Amount", Toast.LENGTH_SHORT).show(); return; } if (((RadioButton) dialog.findViewById(R.id.radioBtn_fund_in)).isChecked()) fund.setType("in"); else if (((RadioButton) dialog.findViewById(R.id.radioBtn_fund_out)).isChecked()) fund.setType("out"); else { Toast.makeText(getActivity(), "Invalid Fund Type", Toast.LENGTH_SHORT).show(); return; } databaseHandler.addFund(fund); setViews(); dialog.dismiss(); } }); } }); return root; }