@Override public void onClick(View v) { int id = v.getId(); Log.v(TAG, "Clicked " + id); if (id == R.id.findBusId) { if (this.fromLocationId == 0) { Toast.makeText(v.getContext(), "Please choose a starting point", Toast.LENGTH_SHORT).show(); } else if (this.toLocationId == 0) { Toast.makeText(v.getContext(), "Please choose your final stop", Toast.LENGTH_SHORT).show(); } else if (travelDate == null) { Toast.makeText(v.getContext(), "When do you want to travel ?", Toast.LENGTH_SHORT).show(); } else { if (this.mHomeListener != null) { Log.v(TAG, "Data being passed is " + this.fromLocationId + " and " + this.toLocationId); this.mHomeListener.displayBuses( String.valueOf(this.fromLocationId), String.valueOf(this.toLocationId), travelDate.getText().toString()); } } } else if (id == R.id.travelDateId) { Log.v(TAG, "In Date Picker"); DatePickerFragment dialogFragment = new DatePickerFragment(); dialogFragment.setTravelDateIdText(travelDate); dialogFragment.show(getFragmentManager(), "datePicker"); } }
static DialogFragment newInstance(long dateInMillis) { DatePickerFragment f = new DatePickerFragment(); Bundle b = new Bundle(); b.putLong(KEY_EDIT_DATE, dateInMillis); f.setArguments(b); return f; }
@Override protected Fragment createFragment() { Date date = (Date) getIntent().getSerializableExtra(TodoFragment.EXTRA_DATE); return DatePickerFragment.newInstance(date); }
public void onEndDateClick(View v) { Calendar d = Calendar.getInstance(); d.setTime(mEndDate); /* DatePickerDialog datePicker = new DatePickerDialog(getApplicationContext(), new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar c = Calendar.getInstance(); c.set(year,monthOfYear, dayOfMonth); ((TextView) findViewById(R.id.endDate)).setText(new SimpleDateFormat("yyyy-MM-dd").format(c.getTime())); } }, d.get(Calendar.YEAR), d.get(Calendar.MONTH), d.get(Calendar.DAY_OF_MONTH)); datePicker.show(); */ DatePickerFragment newFragment = new DatePickerFragment(); newFragment.setCalendar(d); newFragment.setDateTextView((TextView) findViewById(R.id.endDate)); newFragment.show(getSupportFragmentManager(), "datePicker"); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.edit_event_startDate: datePicker = 0; sd.show(getActivity().getSupportFragmentManager(), "start date picker"); break; case R.id.edit_event_startTime: timePicker = 0; st.show(getActivity().getSupportFragmentManager(), "start time picker"); break; case R.id.edit_event_endDate: datePicker = 1; ed.show(getActivity().getSupportFragmentManager(), "end date picker"); break; case R.id.edit_event_endTime: timePicker = 1; et.show(getActivity().getSupportFragmentManager(), "end time picker"); break; } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_edit_event, container, false); // Set title if (((MainActivity) getActivity()).getSupportActionBar() != null) { if (newEvent) ((MainActivity) getActivity()).getSupportActionBar().setTitle("New event"); else ((MainActivity) getActivity()).getSupportActionBar().setTitle("Edit event"); } // Views editName = (EditText) view.findViewById(R.id.edit_event_name); editInfo = (EditText) view.findViewById(R.id.edit_event_info); editStartDate = (Button) view.findViewById(R.id.edit_event_startDate); editStartTime = (Button) view.findViewById(R.id.edit_event_startTime); editEndDate = (Button) view.findViewById(R.id.edit_event_endDate); editEndTime = (Button) view.findViewById(R.id.edit_event_endTime); // Locations spinner editLocation = (Spinner) view.findViewById(R.id.edit_event_location); ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, locationNamesList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); editLocation.setAdapter(adapter); editLocation.setOnItemSelectedListener(this); // Date/time buttons Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); if (!newEvent) { start.setTime(startTime); end.setTime(endTime); } // Button text String startDateText = start.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US) + " " + start.get(Calendar.DATE) + ", " + start.get(Calendar.YEAR); String startTimeMinutes = (start.get(Calendar.MINUTE) == 0) ? "00" : Integer.toString(start.get(Calendar.MINUTE)); String startTimeText = start.get(Calendar.HOUR) + ":" + startTimeMinutes; String endDateText = end.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US) + " " + end.get(Calendar.DATE) + ", " + end.get(Calendar.YEAR); String endTimeMinutes = (end.get(Calendar.MINUTE) == 0) ? "00" : Integer.toString(end.get(Calendar.MINUTE)); String endTimeText = end.get(Calendar.HOUR) + ":" + endTimeMinutes; editStartDate.setText(startDateText); editEndDate.setText(endDateText); editStartTime.setText(startTimeText); editEndTime.setText(endTimeText); // Button on click listener editStartDate.setOnClickListener(this); editStartTime.setOnClickListener(this); editEndDate.setOnClickListener(this); editEndTime.setOnClickListener(this); // Edit texts if (!newEvent) { editName.setText(this.name); editInfo.setText(this.info); } // Pickers sd = new DatePickerFragment(); sd.setListener(this); sd.setData(newEvent, this.startTime); st = new TimePickerFragment(); st.setListener(this); st.setData(newEvent, startTime); ed = new DatePickerFragment(); ed.setListener(this); ed.setData(newEvent, endTime); et = new TimePickerFragment(); et.setListener(this); et.setData(newEvent, endTime); return view; }
@Nullable @OnClick(R.id.expirationDate) public void onClick() { DatePickerFragment datePickerFragment = new DatePickerFragment(this); datePickerFragment.show(getFragmentManager(), "datePicker"); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mPickDate = (Button) findViewById(R.id.pickDate); mPickTime = (Button) findViewById(R.id.pickTime); phoneNumber = (EditText) findViewById(R.id.phoneNumber); smsBody = (EditText) findViewById(R.id.smsBody); smsManagerBtn = (Button) findViewById(R.id.smsManager); dateTextView = (TextView) findViewById(R.id.date_text); timeTextView = (TextView) findViewById(R.id.time_text); // Przygotowanie obiektu MessageModel do pracy smsModel = new MessageModel(0, "", "", 0, 0, 0, 0, 0, 0); smsManagerBtn.setOnClickListener( new OnClickListener() { public void onClick(View view) { sendSmsByManager(); } }); mPickDate.setOnClickListener( new OnClickListener() { public void onClick(View v) { // showDialog(DATE_DIALOG_ID); DialogFragment newFragment = new DatePickerFragment(); ((DatePickerFragment) newFragment).setM(smsModel); ((DatePickerFragment) newFragment).setTextView(dateTextView); ((DatePickerFragment) newFragment).setContext(MainActivity.this); newFragment.show(getFragmentManager(), "datePicker"); } }); mPickTime.setOnClickListener( new OnClickListener() { public void onClick(View v) { // showDialog(TIME_DIALOG_ID); DialogFragment newFragment = new TimePickerFragment(); ((TimePickerFragment) newFragment).setM(smsModel); ((TimePickerFragment) newFragment).setTextView(timeTextView); ((TimePickerFragment) newFragment).setContext(MainActivity.this); newFragment.show(getFragmentManager(), "timePicker"); } }); if (savedInstanceState != null) { DatePickerFragment dpf = (DatePickerFragment) getFragmentManager().findFragmentByTag("datePicker"); if (dpf != null) { dpf.setContext(MainActivity.this); dpf.setM(smsModel); dpf.setTextView(dateTextView); } TimePickerFragment tpf = (TimePickerFragment) getFragmentManager().findFragmentByTag("timePicker"); if (tpf != null) { tpf.setContext(MainActivity.this); tpf.setM(smsModel); tpf.setTextView(timeTextView); } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: // Starting a new Intent Intent nextScreen = new Intent(getApplicationContext(), PreferencesActivity.class); startActivity(nextScreen); return true; case R.id.action_logs: // Starting a new Intent nextScreen = new Intent(getApplicationContext(), LogActivity.class); startActivity(nextScreen); return true; case R.id.action_select_pupil: AlertDialog alertDialog; LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.pupil_dialog, null); ArrayList<String> names = mGshisLoader.getPupilNames(); ArrayAdapter<String> adp = new ArrayAdapter<String>( GradesActivity.this, android.R.layout.simple_spinner_item, names); mPupilSpinner = (Spinner) layout.findViewById(R.id.pupilSpinner); mPupilSpinner.setAdapter(adp); AlertDialog.Builder builder = new AlertDialog.Builder(GradesActivity.this); builder.setView(layout); alertDialog = builder.create(); alertDialog.setTitle(getString(R.string.action_select_pupil)); alertDialog.setButton( DialogInterface.BUTTON_POSITIVE, getString(R.string.label_submit), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { if (mPupilSpinner != null && mPupilSpinner.getSelectedItem() != null) mPupilName = mPupilSpinner.getSelectedItem().toString(); } }); alertDialog.setButton( DialogInterface.BUTTON_NEGATIVE, getString(R.string.label_cancel), new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) {} }); alertDialog.show(); return true; case R.id.action_select_date: mDateSetFragment = new DatePickerFragment(); mDateSetFragment.show(getSupportFragmentManager(), "dateDialog"); return true; case R.id.action_reload: setRecurringAlarm(this, true); return true; case R.id.action_diary: // TODO: put pupil name in the intent Intent i = new Intent(GradesActivity.this, DiaryActivity.class); startActivity(i); // close this activity finish(); return true; } return true; }
public void showDatePickerDialogForToDate(View v) { toDateTextView = (TextView) v; DatePickerFragment newFragment = new DatePickerFragment(); newFragment.isFromDate = false; newFragment.show(getFragmentManager(), "toDatePicker"); }
private void showDatePickerDialog(View v) { dateTimeFragment.show(this.getSupportFragmentManager(), "datePicker"); }
private void showDialog() { DatePickerFragment picker = new DatePickerFragment(); picker.show(getActivity().getSupportFragmentManager(), "datePicker"); picker.setCallBackListener(onDate); }
private void showDateDialog() { FragmentManager fm = getFragmentManager(); DatePickerFragment newFragment = new DatePickerFragment(); newFragment.show(fm, "date_picker"); }