List of usage examples for android.widget DatePicker init
public void init(int year, int monthOfYear, int dayOfMonth, OnDateChangedListener onDateChangedListener)
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. * *///from ww w .jav a 2s.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(); } }); }
From source file:org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment.java
/** * Creates dialog/* w w w. jav a 2 s .c o m*/ */ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); long creation = getArguments().getLong(ARG_CREATION); long expiry = getArguments().getLong(ARG_EXPIRY); final Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationCal.setTimeInMillis(creation * 1000); Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiryCal.setTimeInMillis(expiry * 1000); // date picker works with default time zone, we need to convert from UTC to default timezone creationCal.setTimeZone(TimeZone.getDefault()); expiryCal.setTimeZone(TimeZone.getDefault()); // Explicitly not using DatePickerDialog here! // DatePickerDialog is difficult to customize and has many problems (see old git versions) CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.expiry_date_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.edit_subkey_expiry_dialog, null); alert.setView(view); final CheckBox noExpiry = (CheckBox) view.findViewById(R.id.edit_subkey_expiry_no_expiry); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.edit_subkey_expiry_date_picker); final TextView currentExpiry = (TextView) view.findViewById(R.id.edit_subkey_expiry_current_expiry); final LinearLayout expiryLayout = (LinearLayout) view.findViewById(R.id.edit_subkey_expiry_layout); noExpiry.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { expiryLayout.setVisibility(View.GONE); } else { expiryLayout.setVisibility(View.VISIBLE); } } }); if (expiry == 0L) { noExpiry.setChecked(true); expiryLayout.setVisibility(View.GONE); currentExpiry.setText(R.string.btn_no_date); } else { noExpiry.setChecked(false); expiryLayout.setVisibility(View.VISIBLE); currentExpiry.setText(DateFormat.getDateFormat(getActivity()).format(expiryCal.getTime())); } // date picker works based on default time zone Calendar todayCal = Calendar.getInstance(TimeZone.getDefault()); if (creationCal.after(todayCal)) { // NOTE: This is just for the rare cases where creation is _after_ today // Min Date: Creation date + 1 day Calendar creationCalPlusOne = (Calendar) creationCal.clone(); creationCalPlusOne.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(creationCalPlusOne.getTime().getTime()); datePicker.init(creationCalPlusOne.get(Calendar.YEAR), creationCalPlusOne.get(Calendar.MONTH), creationCalPlusOne.get(Calendar.DAY_OF_MONTH), null); } else { // Min Date: today + 1 day // at least one day after creation (today) todayCal.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(todayCal.getTime().getTime()); datePicker.init(todayCal.get(Calendar.YEAR), todayCal.get(Calendar.MONTH), todayCal.get(Calendar.DAY_OF_MONTH), null); } alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); long expiry; if (noExpiry.isChecked()) { expiry = 0L; } else { Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault()); //noinspection ResourceType selectedCal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); // date picker uses default time zone, we need to convert to UTC selectedCal.setTimeZone(TimeZone.getTimeZone("UTC")); long numDays = (selectedCal.getTimeInMillis() / 86400000) - (creationCal.getTimeInMillis() / 86400000); if (numDays <= 0) { Activity activity = getActivity(); if (activity != null) { Notify.create(activity, R.string.error_expiry_past, Style.ERROR).show(); } return; } expiry = selectedCal.getTime().getTime() / 1000; } Bundle data = new Bundle(); data.putSerializable(MESSAGE_DATA_EXPIRY, expiry); sendMessageToHandler(MESSAGE_NEW_EXPIRY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.show(); }
From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java
/** * Handles showing the Calendar pop up, fetching the selected date, calling to fetch * submissions again/*from w ww . j a v a2 s . co m*/ */ private void showCalendarPicker() { // Inflate the popup_layout.xml ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root); LayoutInflater layoutInflater = (LayoutInflater) getMainActivity() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup); // Some offset to align the popup a bit to the right, and a bit down, relative to button's position. //or if popup is on edge display it to the left of the circle Display display = getMainActivity().getWindowManager().getDefaultDisplay(); Point size = new Point(0, 0); display.getSize(size); int OFFSET_X = 25; int OFFSET_Y = 25; final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker); // Creating the PopupWindow final PopupWindow popup = new PopupWindow(getMainActivity()); popup.setAnimationStyle(android.R.style.Animation_Dialog); popup.setContentView(layout); popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); popup.setFocusable(true); //gets rid of default background popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null)); //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu)); // Displaying the popup at the specified location, + offsets. popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y); Calendar minDate; minDate = Calendar.getInstance(); this.tempY = minDate.get(Calendar.YEAR); this.tempM = minDate.get(Calendar.MONTH); this.tempD = minDate.get(Calendar.DAY_OF_MONTH); dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() { @Override // Months start from 0, so January is month 0 public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { tempY = year; tempM = monthOfYear; tempD = dayOfMonth; Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY); } }); ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept); ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar calendar = Calendar.getInstance(); calendar.set(tempY, tempM, tempD, 1, 0); Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis()); // clear items from clustermanager and submissionMarkerList, as all new submissions // need to be fetched based on the selected date clusterManager.clearItems(); submissionMarkerIdList.clear(); addAdminMarkersToMap(); setMinDateInMs(calendar.getTimeInMillis()); popup.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { setMinDateInMs(0); popup.dismiss(); } }); }
From source file:fr.cobaltians.cobalt.fragments.CobaltDatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();// ww w .j a v a2s . com if (args != null) { int year = args.getInt(ARG_YEAR); int month = args.getInt(ARG_MONTH); int day = args.getInt(ARG_DAY); mCallbackId = args.getString(ARG_CALLBACK_ID); mTitle = args.getString(ARG_TITLE); mDelete = args.getString(ARG_DELETE); mCancel = args.getString(ARG_CANCEL); mValidate = args.getString(ARG_VALIDATE); if (year != 0 && month >= 0 && day != 0) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } } if (mDelete == null && mCancel == null && mValidate == null && mTitle == null) { return new DatePickerDialog(mContext, this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); } else { LayoutInflater inflater = (LayoutInflater) ((Activity) mContext).getLayoutInflater(); final DatePicker datePicker = (DatePicker) inflater.inflate(R.layout.date_picker_cobalt, null); AlertDialog.Builder datePickerBuilder = new AlertDialog.Builder(mContext); datePickerBuilder.setView(datePicker); /* // Init the datePicker with mindate under 1900 //TODO test for under HoneyComb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy", Locale.FRANCE); Calendar minDate = Calendar.getInstance(); try { minDate.setTime(formatter.parse("01.01.1800")); } catch (ParseException e) { e.printStackTrace(); } datePicker.setMinDate(minDate.getTimeInMillis()); } else { datePicker.init(1800, 01, 01, new OnDateChangedListener() { @Override public void onDateChanged(DatePicker datePicker, int year, int month, int day) { Calendar newDate = Calendar.getInstance(); newDate.set(year, month, day); } }); }*/ // View settings int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (mTitle != null) { datePickerBuilder.setTitle(mTitle); } // Buttons datePickerBuilder.setNegativeButton(mDelete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.clear(); if (mListener != null) { mListener.sendDate(-1, -1, -1, mCallbackId); } } }); datePickerBuilder.setNeutralButton(mCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); datePickerBuilder.setPositiveButton(mValidate, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); if (mListener != null) { mListener.sendDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), mCallbackId); } dialog.dismiss(); } }); final AlertDialog dialog = datePickerBuilder.create(); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } }); return dialog; } }
From source file:org.cobaltians.cobalt.fragments.CobaltDatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();/*from www. j a v a2 s . c om*/ if (args != null) { int year = args.getInt(ARG_YEAR); int month = args.getInt(ARG_MONTH); int day = args.getInt(ARG_DAY); mCallbackId = args.getString(ARG_CALLBACK_ID); mTitle = args.getString(ARG_TITLE); mDelete = args.getString(ARG_DELETE); mCancel = args.getString(ARG_CANCEL); mValidate = args.getString(ARG_VALIDATE); if (year != 0 && month >= 0 && day != 0) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } } if (mDelete == null && mCancel == null && mValidate == null && mTitle == null) { return new DatePickerDialog(mContext, this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); } else { LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); final DatePicker datePicker = (DatePicker) inflater.inflate(R.layout.date_picker_cobalt, null); AlertDialog.Builder datePickerBuilder = new AlertDialog.Builder(mContext); datePickerBuilder.setView(datePicker); /* // Init the datePicker with mindate under 1900 //TODO test for under HoneyComb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy", Locale.FRANCE); Calendar minDate = Calendar.getInstance(); try { minDate.setTime(formatter.parse("01.01.1800")); } catch (ParseException e) { e.printStackTrace(); } datePicker.setMinDate(minDate.getTimeInMillis()); } else { datePicker.init(1800, 01, 01, new OnDateChangedListener() { @Override public void onDateChanged(DatePicker datePicker, int year, int month, int day) { Calendar newDate = Calendar.getInstance(); newDate.set(year, month, day); } }); }*/ // View settings int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (mTitle != null) { datePickerBuilder.setTitle(mTitle); } // Buttons datePickerBuilder.setNegativeButton(mDelete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.clear(); if (mListener != null) { mListener.sendDate(-1, -1, -1, mCallbackId); } } }); datePickerBuilder.setNeutralButton(mCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); datePickerBuilder.setPositiveButton(mValidate, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); if (mListener != null) { mListener.sendDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), mCallbackId); } dialog.dismiss(); } }); final AlertDialog dialog = datePickerBuilder.create(); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } }); return dialog; } }
From source file:com.bt.heliniumstudentapp.ScheduleFragment.java
@SuppressWarnings("ConstantConditions") @Override//from w ww .j a va 2 s . c om public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) { mainContext = (AppCompatActivity) getActivity(); scheduleLayout = inflater.inflate(R.layout.fragment_schedule, viewGroup, false); MainActivity.setToolbarTitle(mainContext, getResources().getString(R.string.schedule), null); weekDaysLV = (ListView) scheduleLayout.findViewById(R.id.lv_weekDays_fs); final boolean restart = PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("forced_restart", false); if (restart) PreferenceManager.getDefaultSharedPreferences(mainContext).edit().putBoolean("forced_restart", false) .apply(); if (restart) { //TODO Database check? MainActivity.setStatusBar(mainContext); scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null); if (MainActivity.isOnline()) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } else if (scheduleJson == null) { final boolean online = MainActivity.isOnline(); scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); if (online && PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_updates_auto_update", true)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) new UpdateClass(mainContext, false).execute(); else new UpdateClass(mainContext, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } if (online && (PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_schedule_init", true) || PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null) == null)) { getSchedule(HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { MainActivity.setStatusBar(mainContext); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_0", null); if (online) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } } ((SwipeRefreshLayout) scheduleLayout).setColorSchemeResources(MainActivity.accentSecondaryColor, MainActivity.accentPrimaryColor, MainActivity.primaryColor); ((SwipeRefreshLayout) scheduleLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); MainActivity.prevIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { scheduleFocus--; getSchedule(HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN); } else { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (scheduleFocus > currentWeek + 1) { scheduleFocus = currentWeek + 1; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.historyIV.setOnClickListener(new OnClickListener() { //FIXME Huge mess private int year; private int monthOfYear; private int dayOfMonth; @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { MainActivity.setUI(HeliniumStudentApp.VIEW_SCHEDULE, HeliniumStudentApp.ACTION_ONLINE); final AlertDialog.Builder weekpickerDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); final View view = View.inflate(mainContext, R.layout.dialog_schedule, null); weekpickerDialogBuilder.setView(view); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.np_weekpicker_dw); year = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.YEAR); monthOfYear = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.MONTH); dayOfMonth = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.DAY_OF_MONTH); weekpickerDialogBuilder.setTitle(getString(R.string.go_to)); weekpickerDialogBuilder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final GregorianCalendar date = new GregorianCalendar( HeliniumStudentApp.LOCALE); final GregorianCalendar today = new GregorianCalendar( HeliniumStudentApp.LOCALE); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, monthOfYear); date.set(Calendar.DAY_OF_MONTH, dayOfMonth); date.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); today.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); scheduleFocus = (today.get(Calendar.WEEK_OF_YEAR)) - ((int) ((today.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7)) - (date.getTimeInMillis() / (1000 * 60 * 60 * 24 * 7)))); getSchedule(HeliniumStudentApp.DIREC_OTHER, HeliniumStudentApp.ACTION_REFRESH_IN); } }); weekpickerDialogBuilder.setNegativeButton(getString(android.R.string.cancel), null); final AlertDialog weekPickerDialog = weekpickerDialogBuilder.create(); final GregorianCalendar minDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); minDate.set(Calendar.YEAR, 2000); minDate.set(Calendar.WEEK_OF_YEAR, 1); final GregorianCalendar maxDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); maxDate.set(Calendar.YEAR, 2038); maxDate.set(Calendar.WEEK_OF_YEAR, 1); datePicker.init(year, monthOfYear, dayOfMonth, new DatePicker.OnDateChangedListener() { final GregorianCalendar newDate = new GregorianCalendar(HeliniumStudentApp.LOCALE); @Override public void onDateChanged(DatePicker view, int dialogYear, int dialogMonthOfYear, int dialogDayOfMonth) { newDate.set(year, monthOfYear, dayOfMonth); year = dialogYear; monthOfYear = dialogMonthOfYear; dayOfMonth = dialogDayOfMonth; if (minDate != null && minDate.after(newDate)) view.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH), this); else if (maxDate != null && maxDate.before(newDate)) view.init(maxDate.get(Calendar.YEAR), maxDate.get(Calendar.MONTH), maxDate.get(Calendar.DAY_OF_MONTH), this); else view.init(year, monthOfYear, dayOfMonth, this); } }); weekPickerDialog.setCanceledOnTouchOutside(true); weekPickerDialog.show(); weekPickerDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor)); weekPickerDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(getColor(mainContext, MainActivity.accentSecondaryColor)); } else { scheduleFocus = new GregorianCalendar(HeliniumStudentApp.LOCALE).get(Calendar.WEEK_OF_YEAR); scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.nextIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (checkDatabase() != HeliniumStudentApp.DB_REFRESHING) { if (MainActivity.isOnline()) { scheduleFocus++; getSchedule(HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN); } else { final int currentWeek = new GregorianCalendar(HeliniumStudentApp.LOCALE) .get(Calendar.WEEK_OF_YEAR); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("schedule_1", null) != null && scheduleFocus >= currentWeek) { scheduleFocus = currentWeek + 1; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_1", null); } else { scheduleFocus = currentWeek; scheduleJson = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("schedule_0", null); } parseData(HeliniumStudentApp.ACTION_OFFLINE); } } } }); return scheduleLayout; }