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.gatesnfc.existing.DatePicker_Fix.java
@TargetApi(11) @Override//w ww. j a va 2 s . 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()) { /* * Restriction of Date from 1980 Jan 1st to Current Date */ Calendar c = Calendar.getInstance(); picker.getDatePicker().setMaxDate(c.getTimeInMillis()); c.set(Calendar.YEAR, 1980); c.set(Calendar.MONTH, c.getMinimum(Calendar.MONTH)); c.set(Calendar.DATE, c.getMinimum(Calendar.DATE)); c.set(Calendar.HOUR_OF_DAY, c.getMinimum(Calendar.HOUR_OF_DAY)); c.set(Calendar.MINUTE, c.getMinimum(Calendar.MINUTE)); c.set(Calendar.SECOND, c.getMinimum(Calendar.SECOND)); c.set(Calendar.MILLISECOND, c.getMinimum(Calendar.MILLISECOND)); picker.getDatePicker().setMinDate(c.getTimeInMillis()); 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:br.com.heitorcolangelo.mobilereport.DatePickerDialogFragment.java
@TargetApi(11) @Override/* w w w. j a v a 2 s .co 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) { // Quando cancela no retorna nenhuma data. DatePicker dp = picker.getDatePicker(); mListener.onDateSet(dp, 0, 0, 0); } }); } return picker; }
From source file:org.dvbviewer.controller.ui.fragments.DateDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(sDate);/*from w w w . j a v a2 s .c o m*/ switch (type) { case TYPE_DATE: return new DatePickerDialog(sContext, mDateSetListener, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); case TYPE_TIME: return new TimePickerDialog(sContext, mTimeSetListener, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true); default: return null; } }
From source file:com.esh_tech.aviram.barbershop.views.GenerateReportActivity.java
public void handleDates() { dateFormatter = new SimpleDateFormat("dd/MM/yyyy"); fromDate = Calendar.getInstance(); resetTime(fromDate, true);//from w w w .ja v a2s .c o m toDate = Calendar.getInstance(); resetTime(toDate, false); Calendar newCalendar = Calendar.getInstance(); startDateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar newDate = Calendar.getInstance(); newDate.set(year, monthOfYear, dayOfMonth); resetTime(newDate, true); fromDate = newDate; fromDateEdit.setText(dateFormatter.format(fromDate.getTime())); } }, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH)); endDateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar newDate = Calendar.getInstance(); newDate.set(year, monthOfYear, dayOfMonth); resetTime(newDate, false); toDate = newDate; toDateEdit.setText(dateFormatter.format(toDate.getTime())); } }, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH)); fromDateEdit.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { startDateDialog.updateDate(fromDate.getTime().getYear() + 1900, fromDate.getTime().getMonth(), fromDate.getTime().getDate()); startDateDialog.show(); return true; } }); toDateEdit.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { endDateDialog.updateDate(toDate.getTime().getYear() + 1900, toDate.getTime().getMonth(), toDate.getTime().getDate()); endDateDialog.show(); return true; } }); }
From source file:net.evecom.android.log.DailyLogAddActivity.java
/** * /* w ww . j a va 2s . com*/ */ private void listener() { gzsjButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Dialog alertdialog = new AlertDialog.Builder(DailyLogAddActivity.this).setTitle("") .setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Dialog dialog1 = new DatePickerDialog(DailyLogAddActivity.this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { String MonthOfYear = ""; String DayOfMonth = ""; years = year; month = monthOfYear + 1; day = dayOfMonth; if (monthOfYear < 9) { MonthOfYear = "0" + month; } else { MonthOfYear = "" + month; } if (dayOfMonth < 9) { DayOfMonth = "0" + dayOfMonth; } else { DayOfMonth = "" + dayOfMonth; } gzsjButton .setText("" + year + "-" + MonthOfYear + "-" + DayOfMonth); // gzsj= years + "-"+ month + // "-" + day; } }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));// dialog1.show(); } }) // .setNeutralButton("", new // DialogInterface.OnClickListener() { // @Override // public void onClick(DialogInterface dialog,int which) // { // Dialog dialog2 = new TimePickerDialog( // DailyLogAddActivity.this, // new TimePickerDialog.OnTimeSetListener() { // public void onTimeSet(TimePicker view, int hour, int // minute) { // gzsjButton.setText("" + years + "-" // + month // + "-" + day +" " // + hour +":" // + minute+":" // + calendar.get(Calendar.SECOND)); // hours= hour; // minutes = minute; // gzsj= years + "-"+ month + "-" + day // +"+" + hours + "%3A" + minutes + "%3A" + // calendar.get(Calendar.SECOND); // } // }, calendar.get(Calendar.HOUR_OF_DAY), calendar // .get(Calendar.MINUTE), true);// // dialog2.show(); // } // }) .setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { gzsjButton.setText(""); // gzsj = ""; } }).show(); } }); // rzlxButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Dialog schDia = new AlertDialog.Builder(DailyLogAddActivity.this) .setIcon(R.drawable.login_error_icon).setTitle("") .setItems(rzlxs, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { rzlxButton.setText(rzlxs[which]); sourceway = which + 1; } }).setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dia, int which) { dia.dismiss(); } }).create(); schDia.show(); } }); }
From source file:de.egore911.drilog.ShowActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }//w ww .j a v a2 s . co m switch (item.getItemId()) { case R.id.options: Intent intent = new Intent(this, OptionsActivity.class); startActivity(intent); return true; case R.id.refresh: loadData(); return true; case R.id.choose_date: if (mSelectedDate == null) { mSelectedDate = new SimpleDate(); } Dialog dialog = new DatePickerDialog(ShowActivity.this, new DatePickerDialog.OnDateSetListener() { // Workaround for https://code.google.com/p/android/issues/detail?id=34860 boolean executed = false; @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { if (!executed) { mSelectedDate.year = year; mSelectedDate.month = monthOfYear; mSelectedDate.day = dayOfMonth; loadData(); } executed = true; } }, mSelectedDate.year, mSelectedDate.month, mSelectedDate.day) { }; dialog.show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:br.com.anteros.vendas.gui.PedidoCadastroDadosFragment.java
private void selecionarData() { Calendar cal = Calendar.getInstance(); if (edData.getText().length() > 0) cal.setTime(DateUtil.stringToDate(edData.getText().toString(), DateUtil.DATE)); new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { edData.setText(dayOfMonth + "/" + (monthOfYear + 1) + "/" + year); }/*from ww w . j av a2s. c om*/ }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)).show(); }
From source file:com.adithya321.sharesanalysis.fragments.SalesShareFragment.java
@Nullable @Override/*from w w w . j a 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_share_sales, container, false); databaseHandler = new DatabaseHandler(getContext()); salesRecyclerView = (RecyclerView) root.findViewById(R.id.sales_recycler_view); setRecyclerViewAdapter(); FloatingActionButton sellShareFab = (FloatingActionButton) root.findViewById(R.id.sell_share_fab); sellShareFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Sell Share Holdings"); dialog.setContentView(R.layout.dialog_sell_share_holdings); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); 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(); } }); Button sellShareBtn = (Button) dialog.findViewById(R.id.sell_share_btn); sellShareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); purchase.setName(spinner.getSelectedItem().toString()); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.selling_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Selling Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("sell"); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }
From source file:de.langerhans.wallet.ui.ImportKeysQrFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.import_keys_qr_fragment, container); final Intent intent = activity.getIntent(); calendar = Calendar.getInstance(); date = (TextView) view.findViewById(R.id.import_keys_qr_date); final String input = intent.getExtras().getString(ImportKeysQrActivity.INTENT_EXTRA_INPUT); final StringReader sr = new StringReader(input); final BufferedReader keyReader = new BufferedReader(sr); try {//from w ww .jav a 2 s .c o m final List<ECKey> keys = WalletUtils.readKeys(keyReader); String privatekeys = new String(); String addresses = new String(); final String pubkey = new Address(Constants.NETWORK_PARAMETERS, keys.get(0).getPubKeyHash()).toString(); long oldest = calendar.getTimeInMillis() / 1000; for (ECKey key : keys) { privatekeys += key.getPrivateKeyEncoded(Constants.NETWORK_PARAMETERS).toString() + "\n"; addresses += new Address(Constants.NETWORK_PARAMETERS, key.getPubKeyHash()).toString() + "\n"; oldest = Math.min(oldest, key.getCreationTimeSeconds()); } TextView privatekey = (TextView) view.findViewById(R.id.import_keys_qr_privatekey); privatekey.setText(privatekeys); TextView address = (TextView) view.findViewById(R.id.import_keys_qr_address); address.setText(addresses); if (oldest == 0) { // If key creation date is not specified oldest = calendar.getTimeInMillis() / 1000; } updateDate(oldest); date.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { DatePickerDialog datePickerDialog = new DatePickerDialog(activity, dateSetListener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE)); datePickerDialog.show(); } }); importkey = (Button) view.findViewById(R.id.import_keys_qr_importkey); importkey.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { for (ECKey key : keys) { key.setCreationTimeSeconds(calendar.getTimeInMillis() / 1000); } importPrivateKeys(keys); } }); abe = (Button) view.findViewById(R.id.import_keys_qr_abe); abe.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.BLOCKEXPLORER_BASE_URL + "address/" + pubkey))); } }); cancel = (Button) view.findViewById(R.id.import_keys_qr_cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { activity.finish(); } }); } catch (final IOException x) { new AlertDialog.Builder(activity).setInverseBackgroundForced(true) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.import_export_keys_dialog_failure_title) .setMessage(getString(R.string.import_keys_dialog_failure, x.getMessage())) .setNeutralButton(R.string.button_dismiss, null).show(); log.info("problem reading private keys", x); } return view; }
From source file:org.alfresco.mobile.android.application.ui.form.picker.DatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (getArguments() != null) { if (getArguments().containsKey(ARGUMENT_TIME_PICKER)) { showTime = getArguments().getBoolean(ARGUMENT_TIME_PICKER); }//w w w .ja v a 2 s. c o m if (getArguments().containsKey(ARGUMENT_MIN_DATE)) { minDate = getArguments().getLong(ARGUMENT_MIN_DATE); } if (getArguments().containsKey(ARGUMENT_MAX_DATE)) { maxDate = getArguments().getLong(ARGUMENT_MAX_DATE); } if (getArguments().containsKey(ARGUMENT_START_DATE)) { startDate = getArguments().getLong(ARGUMENT_START_DATE); } } // Use the current date as the default date in the picker final Calendar c = Calendar.getInstance(); if (startDate != null) { c.setTime(new Date(startDate)); } int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); picker = new DatePickerDialog(getActivity(), mListener, year, month, day); if (maxDate != null) { picker.getDatePicker().setMaxDate(maxDate); } if (minDate != null) { picker.getDatePicker().setMinDate(minDate); } picker.setButton(DialogInterface.BUTTON_POSITIVE, getActivity().getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { picker.onClick(dialog, which); dismiss(); } }); picker.setButton(DialogInterface.BUTTON_NEUTRAL, getActivity().getString(R.string.clear), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { clearValue = true; onDateSet(picker.getDatePicker(), picker.getDatePicker().getYear(), picker.getDatePicker().getMonth(), picker.getDatePicker().getDayOfMonth()); dismiss(); } }); picker.setButton(DialogInterface.BUTTON_NEGATIVE, getActivity().getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { isCancelled = true; onDateSet(picker.getDatePicker(), picker.getDatePicker().getYear(), picker.getDatePicker().getMonth(), picker.getDatePicker().getDayOfMonth()); dismiss(); } }); return picker; }