List of usage examples for android.widget TimePicker setCurrentHour
@Deprecated public void setCurrentHour(@NonNull Integer currentHour)
From source file:Main.java
public static void initTimePicker(TimePicker timePicker, long date) { timePicker.setCurrentMinute(getMinute(date)); timePicker.setCurrentHour(getHourOfDay(date)); }
From source file:some.fragments.TimePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { currentTime = (String) getArguments().getSerializable(EXTRA_CURRENT_TIME); Integer hour = Integer.parseInt(currentTime.split(":")[0]); Integer minute = Integer.parseInt(currentTime.split(":")[1]); View calendarView = getActivity().getLayoutInflater().inflate(R.layout.dialog_time, null); TimePicker timePicker = (TimePicker) calendarView.findViewById(R.id.dialog_time_timePicker); timePicker.setCurrentHour(hour); timePicker.setCurrentMinute(minute); timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { String newTime = hourOfDay + ":" + minute; getArguments().putSerializable(EXTRA_CURRENT_TIME, newTime); currentTime = newTime;/*from w w w .j a v a 2 s . c o m*/ Log.i(TAG, "Nueva hora: " + newTime); } }); return new AlertDialog.Builder(getActivity()).setView(calendarView).setTitle(R.string.time_picker_title) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.i(TAG, "Enviando resultado de Time"); sendResult(Activity.RESULT_OK); } }).create(); }
From source file:com.villetainio.travelcardreminder.fragments.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) { final View view = inflater.inflate(R.layout.settings_fragment, container, false); // Enable notifications is true by default CheckBox enableNotificationsView = (CheckBox) view.findViewById(R.id.enable_notifications); boolean enableNotifications = cardStorage.getBoolean(getString(R.string.settings_enable_notifications), true);//w ww .j a v a 2 s. co m enableNotificationsView.setChecked(enableNotifications); // Day to start notifications is 3 days before by default. int days = cardStorage.getInt(getString(R.string.settings_days), 3); // Maximum days to start notifications days left for the period // or 30 days if there isn't a valid period on the card. TravelCardReminder app = (TravelCardReminder) getActivity().getApplication(); int daysLeft = app.calculateStatus(); NumberPicker numberPicker = (NumberPicker) view.findViewById(R.id.days_pick); numberPicker.setMinValue(0); if (daysLeft > 0) { numberPicker.setMaxValue(app.calculateStatus()); } else { numberPicker.setMaxValue(30); } numberPicker.setValue(days); // Time to start notifications is 12.00 by default. int hours = cardStorage.getInt(getString(R.string.settings_hours), 12); int minutes = cardStorage.getInt(getString(R.string.settings_minutes), 0); TimePicker timePicker = (TimePicker) view.findViewById(R.id.time_pick); timePicker.setCurrentHour(hours); timePicker.setCurrentMinute(minutes); // Save settings. Button saveButton = (Button) view.findViewById(R.id.save_button); saveButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { saveValues(view); Toast.makeText(getActivity().getApplicationContext(), R.string.success_message_save_settings, Toast.LENGTH_LONG).show(); } }); return view; }
From source file:org.ounl.lifelonglearninghub.learntracker.gis.ou.swipe.DayFragment.java
public void inflateLayout(int iPos) { String sIdSubject = Session.getSingleInstance().getDatabaseHandler().getSubjects().get(iPos).getsId(); // String sIdSubject = Session.getSingleInstance().getActivity(iPos).getId_subject(); long lDuration = Session.getSingleInstance().getDatabaseHandler().getAccumulatedTime(sIdSubject); // List of activities to inflate history List<ActividadDb> lADb = Session.getSingleInstance().getDatabaseHandler().getActivities(sIdSubject); // Duration/*w w w .ja va 2s.c o m*/ DateUtils du = new DateUtils(); TextView t = (TextView) rootView.findViewById(R.id.tvDuration); t.setText(du.duration(lDuration)); // Time picker TimePicker timePicker = (TimePicker) rootView.findViewById(R.id.tpTask); timePicker.setIs24HourView(true); timePicker.setCurrentHour(0); timePicker.setCurrentMinute(45); // Button image view ImageView iv = (ImageView) rootView.findViewById(R.id.ivActionActivity); int currentStatus = Session.getSingleInstance().getActivity(iPos).getStatus(); if (currentStatus == ActivitySession.STATUS_STOPPED) { Drawable d = getResources().getDrawable(R.drawable.play); iv.setImageDrawable(d); } else { Drawable d = getResources().getDrawable(R.drawable.stop); iv.setImageDrawable(d); } // History if (lADb.size() != 0) { LinearLayout llHistory = (LinearLayout) rootView.findViewById(R.id.llHistory); TextView tvHeader = (TextView) llHistory.findViewById(R.id.tvHeaderHisory); tvHeader.setVisibility(View.VISIBLE); for (int i = 0; i < lADb.size(); i++) { ActividadDb adb = lADb.get(i); LinearLayout llCheckItemWrapper = (LinearLayout) mInflater.inflate(R.layout.check_item, null); // Passing order as param so it can be removed llCheckItemWrapper.setTag(i); LinearLayout liContent = (LinearLayout) llCheckItemWrapper.getChildAt(0); TextView tvTimeStamp = (TextView) liContent.findViewById(R.id.textViewTimeStamp); tvTimeStamp.setText(Constants.TIME_FORMAT.format(adb.getlDateCheckIn())); // Passing checkin time in mills as tag tvTimeStamp.setTag(Long.valueOf(adb.getlDateCheckIn())); TextView tvDurRecord = (TextView) liContent.findViewById(R.id.textViewDuration); tvDurRecord.setText(" [" + du.duration(adb.getlDateCheckIn(), adb.getlDateCheckOut()) + "]"); // Passing subject id as parameter tvDurRecord.setTag(adb.getsIdSubject()); llHistory.addView(mInflater.inflate(R.layout.tag_divider, llHistory, false), 1); llHistory.addView(llCheckItemWrapper, 2); } } }
From source file:de.androvdr.activities.ChannelsActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_WHATS_ON: final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.extendedchannels_whats_on); dialog.setTitle(R.string.channels_whats_on); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); final DatePicker dp = (DatePicker) dialog.findViewById(R.id.channels_datePicker); final TimePicker tp = (TimePicker) dialog.findViewById(R.id.channels_timePicker); tp.setIs24HourView(DateFormat.is24HourFormat(getApplicationContext())); if (sp.contains("whats_on_hour")) { tp.setCurrentHour(sp.getInt("whats_on_hour", 0)); tp.setCurrentMinute(sp.getInt("whats_on_minute", 0)); }//ww w . ja v a2 s.com Button button = (Button) dialog.findViewById(R.id.channels_cancel); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); button = (Button) dialog.findViewById(R.id.channels_search); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Editor editor = sp.edit(); editor.putInt("whats_on_hour", tp.getCurrentHour()); editor.putInt("whats_on_minute", tp.getCurrentMinute()); editor.commit(); SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy hh:mm"); try { long time = df.parse(dp.getDayOfMonth() + "." + (dp.getMonth() + 1) + "." + dp.getYear() + " " + tp.getCurrentHour() + ":" + tp.getCurrentMinute()).getTime() / 1000; getController().whatsOn(time); } catch (ParseException e) { logger.error("Couldn't get date from pickers", e); } dialog.dismiss(); } }); return dialog; default: return super.onCreateDialog(id); } }
From source file:de.escoand.readdaily.ReminderDialogFragment.java
@Override public Dialog onCreateDialog(final Bundle savedInstanceState) { TimePicker v = new TimePicker(getContext()); settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); hour = settings.getInt(SETTINGS_HOUR, 9); minute = settings.getInt(SETTINGS_MINUTE, 0); v.setIs24HourView(true);/*from w w w .ja v a 2s .co m*/ v.setOnTimeChangedListener(this); v.setCurrentHour(hour); v.setCurrentMinute(minute); return new AlertDialog.Builder(getContext()).setView(v).setPositiveButton(R.string.button_ok, this) .setNegativeButton(R.string.button_cancel, this).create(); }
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: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 w w. j a v a 2 s . co m*/ 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:net.reichholf.dreamdroid.activities.TimerEditActivity.java
/** * Set the the values of the date and the time picker of the DateTimePicker * dialog/*from w w w.ja v a 2 s .c om*/ * * @param dialog * The Dialog containing the date and the time picker * @param cal * The calendar-object to set date and time from */ private void setDateAndTimePicker(final Dialog dialog, Calendar cal) { DatePicker dp = (DatePicker) dialog.findViewById(R.id.DatePicker); TimePicker tp = (TimePicker) dialog.findViewById(R.id.TimePicker); dp.updateDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); tp.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY)); tp.setCurrentMinute(cal.get(Calendar.MINUTE)); }
From source file:com.roque.rueda.cashflows.fragments.AddMovementFragment.java
/** * Create a date time dialog to allow the user choose the date for the movement. * *//* w w w . j a v a2 s. co m*/ private void createDateTimeDialog() { // Add a listener to display a dialog when the user taps on this view. mDateText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Set the current date if it's one the saved instance object. final Calendar c = Calendar.getInstance(); c.setTimeInMillis(mCurrentDate); // Dialog settings. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK); LayoutInflater layoutInflater = getActivity().getLayoutInflater(); builder.setTitle(R.string.time_date_dialog_title); // Custom view used to display date picker and time picker. View dateTimeLayout = layoutInflater.inflate(R.layout.date_time_layout, null); // Text used to display the selected date. final TextView selectedDate = (TextView) dateTimeLayout.findViewById(R.id.selected_date); final Date selectedDateByUser = new Date(getInputDate()); selectedDate.setText(StringFormatter.formatDate(selectedDateByUser)); final DatePicker datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.date_picker); final TimePicker timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.time_picker); Calendar calendar = Calendar.getInstance(); calendar.setTime(selectedDateByUser); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); int hourOfTheDay = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); timePicker.setCurrentHour(hourOfTheDay); timePicker.setCurrentMinute(minute); // Initialize the date picker, also add a listener to // update the label when user change the values. datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, monthOfYear); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour()); calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute()); calendar.set(Calendar.SECOND, 0); Date modifyDate = calendar.getTime(); // Update the text view. selectedDate.setText(StringFormatter.formatDate(modifyDate)); } }); // Listener used to update the values when time is selected. timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, datePicker.getYear()); calendar.set(Calendar.MONTH, datePicker.getMonth()); calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth()); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); Date modifyDate = calendar.getTime(); // Update the text view. selectedDate.setText(StringFormatter.formatDate(modifyDate)); } }); // Set the view to the dialog. builder.setView(dateTimeLayout); // Accept button behaviour. builder.setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Calendar dialogDate = Calendar.getInstance(); dialogDate.set(Calendar.YEAR, datePicker.getYear()); dialogDate.set(Calendar.MONTH, datePicker.getMonth()); dialogDate.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth()); dialogDate.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour()); dialogDate.set(Calendar.MINUTE, timePicker.getCurrentMinute()); dialogDate.set(Calendar.SECOND, 0); setCurrentDateText(dialogDate.getTime()); dialog.dismiss(); } }); // Cancel button behaviour. builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // Create and display the dialog. Dialog dateDialog = builder.create(); dateDialog.show(); } }); }