use of android.app.TimePickerDialog in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class NightDisplaySettings method onCreateDialog.
@Override
public Dialog onCreateDialog(final int dialogId) {
if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) {
final LocalTime initialTime;
if (dialogId == DIALOG_START_TIME) {
initialTime = mColorDisplayManager.getNightDisplayCustomStartTime();
} else {
initialTime = mColorDisplayManager.getNightDisplayCustomEndTime();
}
final Context context = getContext();
final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);
return new TimePickerDialog(context, (view, hourOfDay, minute) -> {
final LocalTime time = LocalTime.of(hourOfDay, minute);
if (dialogId == DIALOG_START_TIME) {
mColorDisplayManager.setNightDisplayCustomStartTime(time);
} else {
mColorDisplayManager.setNightDisplayCustomEndTime(time);
}
}, initialTime.getHour(), initialTime.getMinute(), use24HourFormat);
}
return super.onCreateDialog(dialogId);
}
use of android.app.TimePickerDialog in project TumCampusApp by TCA-Team.
the class CreateEventActivity method setDateAndTimeListeners.
private void setDateAndTimeListeners() {
// DATE
startDateView.setOnClickListener(view -> {
new DatePickerDialog(this, (datePicker, year, month, dayOfMonth) -> {
start.set(year, month, dayOfMonth);
if (end.before(start)) {
end.set(year, month, dayOfMonth);
}
updateDateViews();
}, start.get(Calendar.YEAR), start.get(Calendar.MONTH), start.get(Calendar.DAY_OF_MONTH)).show();
});
endDateView.setOnClickListener(view -> {
new DatePickerDialog(this, (datePicker, year, month, dayOfMonth) -> {
end.set(year, month, dayOfMonth);
updateDateViews();
}, start.get(Calendar.YEAR), start.get(Calendar.MONTH), start.get(Calendar.DAY_OF_MONTH)).show();
});
// TIME
startTimeView.setOnClickListener(view -> {
new TimePickerDialog(this, (timePicker, hour, minute) -> {
long eventLength = end.getTimeInMillis() - start.getTimeInMillis();
start.set(Calendar.HOUR_OF_DAY, hour);
start.set(Calendar.MINUTE, minute);
end.setTimeInMillis(start.getTimeInMillis() + eventLength);
updateTimeViews();
}, start.get(Calendar.HOUR_OF_DAY), start.get(Calendar.MINUTE), true).show();
});
endTimeView.setOnClickListener(view -> {
new TimePickerDialog(this, (timePicker, hour, minute) -> {
end.set(Calendar.HOUR_OF_DAY, hour);
end.set(Calendar.MINUTE, minute);
updateTimeViews();
}, end.get(Calendar.HOUR_OF_DAY), end.get(Calendar.MINUTE), true).show();
});
}
use of android.app.TimePickerDialog in project Ushahidi_Android by ushahidi.
the class AddReportActivity method createDialog.
/**
* Create various dialog
*/
private void createDialog(int id) {
switch(id) {
case DIALOG_ERROR_NETWORK:
{
Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.network_error).setMessage(R.string.network_error_msg).setPositiveButton(getString(R.string.ok), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setCancelable(false).create();
dialog.show();
break;
}
case DIALOG_ERROR_SAVING:
{
Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.network_error).setMessage(R.string.file_system_error_msg).setPositiveButton(getString(R.string.ok), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setCancelable(false).create();
dialog.show();
break;
}
case DIALOG_CHOOSE_IMAGE_METHOD:
{
Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.choose_method).setMessage(R.string.how_to_select_pic).setPositiveButton(getString(R.string.gallery_option), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, REQUEST_CODE_IMAGE);
dialog.dismiss();
}
}).setNegativeButton(getString(R.string.cancel), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNeutralButton(R.string.camera_option, new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, PhotoUtils.getPhotoUri(photoName, AddReportActivity.this));
startActivityForResult(intent, REQUEST_CODE_CAMERA);
dialog.dismiss();
}
}).setCancelable(false).create();
dialog.show();
break;
}
case DIALOG_MULTIPLE_CATEGORY:
{
if (showCategories() != null) {
new AlertDialog.Builder(this).setTitle(R.string.choose_categories).setMultiChoiceItems(showCategories(), setCheckedCategories(), new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
if (isChecked) {
mVectorCategories.add(mCategoriesId.get(whichButton));
mError = false;
} else {
mVectorCategories.remove(mCategoriesId.get(whichButton));
}
setSelectedCategories(mVectorCategories);
}
}).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Yes so do some stuff */
}
}).create().show();
}
break;
}
case TIME_DIALOG_ID:
new TimePickerDialog(this, mTimeSetListener, mCalendar.get(Calendar.HOUR), mCalendar.get(Calendar.MINUTE), false).show();
break;
case DATE_DIALOG_ID:
new DatePickerDialog(this, mDateSetListener, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)).show();
break;
case DIALOG_SHOW_MESSAGE:
AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this);
messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog showDialog = messageBuilder.create();
showDialog.show();
break;
case DIALOG_SHOW_REQUIRED:
AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this);
requiredBuilder.setTitle(R.string.required_fields);
requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog showRequiredDialog = requiredBuilder.create();
showRequiredDialog.show();
break;
// prompt for unsaved changes
case DIALOG_SHOW_PROMPT:
{
Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.unsaved_changes).setMessage(R.string.want_to_cancel).setNegativeButton(getString(R.string.no), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setPositiveButton(getString(R.string.yes), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
new DiscardTask(AddReportActivity.this).execute((String) null);
finish();
dialog.dismiss();
}
}).setCancelable(false).create();
dialog.show();
break;
}
// prompt for report deletion
case DIALOG_SHOW_DELETE_PROMPT:
{
Dialog dialog = new AlertDialog.Builder(this).setTitle(R.string.delete_report).setMessage(R.string.want_to_delete).setNegativeButton(getString(R.string.no), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setPositiveButton(getString(R.string.yes), new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// delete report
deleteReport();
dialog.dismiss();
}
}).setCancelable(false).create();
dialog.show();
}
break;
}
}
use of android.app.TimePickerDialog in project Ushahidi_Android by ushahidi.
the class AddReportActivity method onPrepareDialog.
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch(id) {
case TIME_DIALOG_ID:
((TimePickerDialog) dialog).updateTime(mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE));
break;
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
break;
case DIALOG_MULTIPLE_CATEGORY:
final AlertDialog alert = (AlertDialog) dialog;
final ListView list = alert.getListView();
// selected categories
if (mVectorCategories.size() > 0) {
for (Integer s : mVectorCategories) {
try {
// @inoran fix
if (list != null) {
list.setItemChecked(mCategoryLength - s, true);
}
} catch (NumberFormatException e) {
log("NumberFormatException", e);
}
}
} else {
if (list != null) {
list.clearChoices();
}
}
break;
}
}
use of android.app.TimePickerDialog in project Eye by tommyolsson.
the class FragmentCreateEvent method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View inf = inflater.inflate(R.layout.fragment_create_event, container, false);
// Changes title to the subject name
((MainActivity) getActivity()).setActionBarTitle(getResources().getString(R.string.newActivity));
((MainActivity) getActivity()).showBackButton();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
subjectEditText = (EditText) inf.findViewById(R.id.subjectEditText);
locationEditText = (EditText) inf.findViewById(R.id.locationEditText);
dateEditText = (EditText) inf.findViewById(R.id.dateEditText);
startEditText = (EditText) inf.findViewById(R.id.startEditText);
endEditText = (EditText) inf.findViewById(R.id.endEditText);
dateEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// To show current date in the datepicker
final Calendar mCalendar = Calendar.getInstance();
int mYear = mCalendar.get(Calendar.YEAR);
int mMonth = mCalendar.get(Calendar.MONTH);
int mDay = mCalendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
/* Set picked date in textedit */
String myFormat = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.getDefault());
mCalendar.set(Calendar.YEAR, selectedyear);
mCalendar.set(Calendar.MONTH, selectedmonth);
mCalendar.set(Calendar.DAY_OF_MONTH, selectedday);
dateEditText.setText(sdf.format(mCalendar.getTime()));
}
}, mYear, mMonth, mDay);
mDatePicker.getDatePicker().setCalendarViewShown(false);
mDatePicker.setTitle("Select date");
mDatePicker.show();
}
});
startEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
startEditText.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
}
}, hour, minute, // Yes 24 hour time
true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
endEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
endEditText.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
}
}, hour, minute, // Yes 24 hour time
true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
checkBox = inf.findViewById(R.id.checkBox);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
// Disables editText for time if event is all day
startEditText.setEnabled(false);
endEditText.setEnabled(false);
isAllDay = true;
} else {
startEditText.setEnabled(true);
endEditText.setEnabled(true);
isAllDay = false;
}
}
});
createButton = inf.findViewById(R.id.createButton);
createButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String subject = subjectEditText.getText().toString();
String location = locationEditText.getText().toString();
String date = dateEditText.getText().toString();
String start = startEditText.getText().toString();
String end = endEditText.getText().toString();
Log.i("Ämne", subject);
Log.i("Plats", location);
Log.i("Datum", date);
Log.i("Start", start);
Log.i("Slut", end);
Log.i("Heldag", Boolean.toString(isAllDay));
if (subject.matches("")) {
Toast.makeText(getContext(), "Namn på aktivitet saknas", Toast.LENGTH_SHORT).show();
} else {
if (isAllDay) {
LocalDate ld = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String endDate = ld.plusDays(1).toString();
((MainActivity) getActivity()).createEventGraphAPI(subject, location, date, endDate, "00", "00", isAllDay);
} else {
((MainActivity) getActivity()).createEventGraphAPI(subject, location, date, date, start, end, isAllDay);
}
Toast.makeText(getContext(), "Aktivitet skapad", Toast.LENGTH_SHORT).show();
getActivity().onBackPressed();
}
}
});
return inf;
}
Aggregations