List of usage examples for android.widget DatePicker init
public void init(int year, int monthOfYear, int dayOfMonth, OnDateChangedListener onDateChangedListener)
From source file:Main.java
public static void initDatePicker(DatePicker datePicker, long date) { datePicker.init(getYear(date), getMonthOfYear(date), getDayOfMonth(date), null); }
From source file:some.fragments.DatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mDate = (Date) getArguments().getSerializable(EXTRA_DATE); // Create a Calendar to get the year, month, and day Calendar calendar = Calendar.getInstance(); calendar.setTime(mDate);/*w w w. j a v a2 s . c om*/ int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); View calendarView = getActivity().getLayoutInflater().inflate(R.layout.dialog_date, null); DatePicker datePicker = (DatePicker) calendarView.findViewById(R.id.dialog_date_datePicker); datePicker.init(year, month, day, new OnDateChangedListener() { public void onDateChanged(DatePicker view, int year, int month, int day) { // Translate year, month, day into a Date object using a calendar mDate = new GregorianCalendar(year, month, day).getTime(); // Update argument to preserve selected value on rotation getArguments().putSerializable(EXTRA_DATE, mDate); Log.i(TAG, "Seteando nueva fecha: " + mDate); } }); return new AlertDialog.Builder(getActivity()).setView(calendarView).setTitle(R.string.date_picker_title) // .setPositiveButton(android.R.string.ok, null) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { sendResult(Activity.RESULT_OK); } }).create(); }
From source file:com.simplaapliko.wakeup.sample.ui.DialogDateTime.java
private void initUiWidgets(View rootView) { Log.d(TAG, "initUiWidgets()"); // set up tabhost TabHost tabHost = (TabHost) rootView.findViewById(R.id.tabhost); tabHost.setup();//from w ww . java2s . c om TabHost.TabSpec tabSpec; // adding tabs tabSpec = tabHost.newTabSpec("date"); tabSpec.setIndicator("Date"); tabSpec.setContent(R.id.date); tabHost.addTab(tabSpec); tabSpec = tabHost.newTabSpec("time"); tabSpec.setIndicator("Time"); tabSpec.setContent(R.id.time); tabHost.addTab(tabSpec); TimePicker timePicker = (TimePicker) rootView.findViewById(R.id.time); timePicker.setIs24HourView(true); //set to true, because it is more compact timePicker.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); // init time picker before OnTimeChangedListener() is set // otherwise minutes will be set to current time, once setCurrentHour() is called timePicker.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY)); timePicker.setCurrentMinute(mCalendar.get(Calendar.MINUTE)); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { mCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay); mCalendar.set(Calendar.MINUTE, minute); mCalendar.set(Calendar.SECOND, 0); } }); DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.date); datePicker.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); datePicker.init(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mCalendar.set(Calendar.YEAR, year); mCalendar.set(Calendar.MONTH, monthOfYear); mCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); } }); }
From source file:com.flowzr.activity.DateFilterActivity.java
private void prepareDialog(Dialog dialog, Calendar c) { DatePicker dp = (DatePicker) dialog.findViewById(R.id.date); dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), null); TimePicker tp = (TimePicker) dialog.findViewById(R.id.time); tp.setIs24HourView(is24HourFormat(this)); tp.setCurrentHour(c.get(Calendar.HOUR_OF_DAY)); tp.setCurrentMinute(c.get(Calendar.MINUTE)); }
From source file:edu.rit.csh.androidwebnews.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DatePicker startDate; setContentView(R.layout.activity_search); dialog = new InvalidApiKeyDialog(this); hc = new HttpsConnector(this); hc.getNewsGroups(); // used for list of newsgroups to look through sf = (SearchFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment); startDate = (DatePicker) findViewById(R.id.search_datePicker1); startDate.init(startDate.getYear() - 1, startDate.getMonth(), startDate.getDayOfMonth(), null); setTitle("Search"); }
From source file:com.kunze.androidlocaltodo.TaskActivityFragment.java
private void InitializeView(final View rootView) { final View activityView = rootView; TextWatcher textWatcher = new TextWatcher() { @Override/*from w ww . j a v a2s . c o m*/ public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { TaskChanged(activityView); } }; final EditText nameEdit = (EditText) rootView.findViewById(R.id.task_name_edit); final TextView nameStatic = (TextView) rootView.findViewById(R.id.task_name_static); nameStatic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { nameEdit.setVisibility(View.VISIBLE); nameStatic.setVisibility(View.INVISIBLE); } }); nameEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { nameEdit.setVisibility(View.INVISIBLE); nameStatic.setVisibility(View.VISIBLE); } } }); nameEdit.addTextChangedListener(textWatcher); final TextView descriptionEdit = (TextView) rootView.findViewById(R.id.task_description_edit); descriptionEdit.addTextChangedListener(textWatcher); final TextView dueDateView = (TextView) rootView.findViewById(R.id.due_date_text); final DatePicker datePicker = (DatePicker) rootView.findViewById(R.id.due_date_calendar); datePicker.init(0, 0, 0, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0); SetFriendlyDueDateText(dueDateView, calendar); TaskChanged(activityView); } }); Button todayButton = (Button) rootView.findViewById(R.id.today_button); todayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); datePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, now); } }); Button plusDayButton = (Button) rootView.findViewById(R.id.plus_day_button); plusDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 1); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, calendar); } }); Button thisWeekendButton = (Button) rootView.findViewById(R.id.this_weekend_button); thisWeekendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar weekend = Calendar.getInstance(); while (weekend.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { weekend.add(Calendar.DATE, 1); } datePicker.updateDate(weekend.get(Calendar.YEAR), weekend.get(Calendar.MONTH), weekend.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, weekend); } }); Button plusWeekButton = (Button) rootView.findViewById(R.id.plus_week_button); plusWeekButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 7); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dueDateView, calendar); } }); final CheckBox repeatCheck = (CheckBox) rootView.findViewById(R.id.repeat); repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { View dialog = (View) buttonView.getParent(); SetRepeatVisibility(dialog, isChecked); TaskChanged(activityView); } }); final EditText repeatTimeEdit = (EditText) rootView.findViewById(R.id.repeat_time); repeatTimeEdit.addTextChangedListener(textWatcher); final Spinner repeatUnitSpinner = (Spinner) rootView.findViewById(R.id.repeat_unit); String[] repeatUnits = { "Days", "Weeks", "Months", "Years" }; repeatUnitSpinner.setAdapter( new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, repeatUnits)); repeatUnitSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mRow != -1 && mRow != id) { TaskChanged(activityView); } mRow = id; } @Override public void onNothingSelected(AdapterView<?> arg0) { TaskChanged(activityView); } private long mRow = -1; }); final RadioButton repeatFromComplete = (RadioButton) rootView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) rootView.findViewById(R.id.repeat_from_due); Button revertButton = (Button) rootView.findViewById(R.id.revert_button); Button acceptButton = (Button) rootView.findViewById(R.id.accept_button); final Button doneButton = (Button) rootView.findViewById(R.id.done_button); Button deleteButton = (Button) rootView.findViewById(R.id.delete_button); revertButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mNewTask = new Task(mOriginalTask); mProgrammaticChange = true; InitializeViewFields(activityView, mOriginalTask); mProgrammaticChange = false; TaskReverted(activityView); } }); doneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(doneButton.getContext()); builder.setTitle("Done?"); builder.setMessage("Mark task \"" + mNewTask.mName + "\" as done?"); builder.setNegativeButton("No", null); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNewTask.Done(); TaskDatabase db = new TaskDatabase(getActivity()); db.SaveTask(mNewTask); InitializeViewFields(rootView, mNewTask); } }); builder.show(); } }); }
From source file:com.cmput301w17t07.moody.EditMoodActivity.java
/** * set up the datetimePicker <br>/* w ww. j a v a2 s. co m*/ * link: http://blog.csdn.net/hzflogo/article/details/62423240 <br> * author: hzflogo 2017-03-16 14:58 <br> * taken by Xin Huang 2017-03-29 21:42 <br> */ private void innit() { final View dateView = View.inflate(getApplicationContext(), R.layout.datepicker, null); final View timeView = View.inflate(getApplicationContext(), R.layout.timepicker, null); TimePicker timePicker = (TimePicker) timeView.findViewById(R.id.time); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { currentHour = hourOfDay; currentMinte = minute; } }); DatePicker datePicker = (DatePicker) dateView.findViewById(R.id.pick); datePicker.setDrawingCacheBackgroundColor(getResources().getColor(R.color.colorAccent)); datePicker.init(currentYear, currentMonth, currentDay, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { currentYear = year; currentMonth = monthOfYear + 1; currentDay = dayOfMonth; } }); DateDialog = new AlertDialog.Builder(EditMoodActivity.this).setView(dateView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dateString = currentYear + "-" + currentMonth + "-" + currentDay + " " + currentHour + ":" + currentMinte; try { java.text.SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); date = formatter.parse(dateString); } catch (Exception e) { e.printStackTrace(); } Toast.makeText(EditMoodActivity.this, "" + date, Toast.LENGTH_LONG).show(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DateDialog.dismiss(); } }).create(); TimeDialog = new AlertDialog.Builder(EditMoodActivity.this).setView(timeView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DateDialog.show(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { TimeDialog.dismiss(); } }).create(); }
From source file:at.wada811.dayscounter.view.activity.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // catch UncaughtException Thread.setDefaultUncaughtExceptionHandler(new CrashExceptionHandler(getApplicationContext())); super.onCreate(savedInstanceState); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); setContentView(R.layout.activity_settings); ButterKnife.inject(this); // Window size dialog WindowManager.LayoutParams params = getWindow().getAttributes(); params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.MATCH_PARENT; getWindow().setAttributes(params);//w w w . j a va2s . co m LogUtils.d(); // check Crash report File file = ResourceUtils.getFile(this, CrashExceptionHandler.FILE_NAME); if (file.exists()) { startActivity(new Intent(this, CrashReportActivity.class)); finish(); return; } // AppWidgetId Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } LogUtils.d("appWidgetId: " + appWidgetId); WidgetModel model = new WidgetModel(this, appWidgetId); viewModel = new Widget1x1ViewModel(this, model); // Title new EditTextBinding(titleEditText).bind(new Func<EditText, String>() { @Override public String apply(EditText editText) { return editText.getText().toString(); } }, viewModel.getTitle(), new EditTextTextChanged() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { titleTextView.setText(viewModel.getTitle().getValue()); } }); titleEditText.setText(viewModel.getTitle().getValue()); // Date String date = viewModel.getDate().getValue(); LogUtils.d("date: " + date); LocalDateTime dateTime = date != null ? new LocalDateTime(date) : LocalDateTime.now(); DatePickerBinding datePickerBinding = new DatePickerBinding(datePicker); datePickerBinding.bind(new Func<DatePicker, String>() { @Override public String apply(DatePicker datePicker) { return DatePickerUtils.format(datePicker); } }, viewModel.getDate(), new OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { diffTextView.setText(viewModel.getDiff().getValue()); diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewModel.getDiffTextSize().getValue()); daysTextView.setText(viewModel.getComparison().getValue()); } }); datePicker.init(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth(), datePickerBinding.getOnDateChangedListener()); diffTextView.setText(viewModel.getDiff().getValue()); diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewModel.getDiffTextSize().getValue()); daysTextView.setText(viewModel.getComparison().getValue()); // Button submitButton.setOnClickListener(this); }
From source file:com.cmput301w17t07.moody.CreateMoodActivity.java
private void innit() { final View dateView = View.inflate(getApplicationContext(), R.layout.datepicker, null); final View timeView = View.inflate(getApplicationContext(), R.layout.timepicker, null); TimePicker timePicker = (TimePicker) timeView.findViewById(R.id.time); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override/*from w ww. ja va2 s .c o m*/ public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { currentHour = hourOfDay; currentMinute = minute; } }); DatePicker datePicker = (DatePicker) dateView.findViewById(R.id.pick); datePicker.setDrawingCacheBackgroundColor(getResources().getColor(R.color.colorAccent)); datePicker.init(currentYear, currentMonth, currentDay, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { currentYear = year; currentMonth = monthOfYear + 1; currentDay = dayOfMonth; } }); DateDialog = new AlertDialog.Builder(CreateMoodActivity.this).setView(dateView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dateString = currentYear + "-" + currentMonth + "-" + currentDay + " " + currentHour + ":" + currentMinute; try { java.text.SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); date = formatter.parse(dateString); } catch (Exception e) { e.printStackTrace(); } Toast.makeText(CreateMoodActivity.this, "" + date, Toast.LENGTH_LONG).show(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DateDialog.dismiss(); } }).create(); TimeDialog = new AlertDialog.Builder(CreateMoodActivity.this).setView(timeView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DateDialog.show(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { TimeDialog.dismiss(); } }).create(); }
From source file:com.kunze.androidlocaltodo.TaskListActivity.java
private void ShowDueDateDialog(Calendar dueDate, OnClickListener okListener) { LayoutInflater inflater = this.getLayoutInflater(); View dlgView = inflater.inflate(R.layout.dialog_due_date, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(dlgView);//from w w w .jav a 2s. com builder.setTitle("Due Date"); builder.setNegativeButton("Cancel", null); builder.setPositiveButton("OK", okListener); final TextView dateText = (TextView) dlgView.findViewById(R.id.due_date_text); SetFriendlyDueDateText(dateText, dueDate); final DatePicker datePicker = (DatePicker) dlgView.findViewById(R.id.due_date_calendar); //datePicker.setMinDate(Math.min(now.getTimeInMillis(), dueDate.getTimeInMillis())); datePicker.init(dueDate.get(Calendar.YEAR), dueDate.get(Calendar.MONTH), dueDate.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(year, monthOfYear, dayOfMonth, 0, 0, 0); SetFriendlyDueDateText(dateText, calendar); } }); datePicker.setCalendarViewShown(false); Button todayButton = (Button) dlgView.findViewById(R.id.today_button); todayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); datePicker.updateDate(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dateText, now); } }); Button plusDayButton = (Button) dlgView.findViewById(R.id.plus_day_button); plusDayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 1); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dateText, calendar); } }); Button thisWeekendButton = (Button) dlgView.findViewById(R.id.this_weekend_button); thisWeekendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar weekend = Calendar.getInstance(); while (weekend.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY) { weekend.add(Calendar.DATE, 1); } datePicker.updateDate(weekend.get(Calendar.YEAR), weekend.get(Calendar.MONTH), weekend.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dateText, weekend); } }); Button plusWeekButton = (Button) dlgView.findViewById(R.id.plus_week_button); plusWeekButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); calendar.add(Calendar.DATE, 7); datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); SetFriendlyDueDateText(dateText, calendar); } }); builder.show(); }