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 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 weex-example by KalicyZhou.
the class DatePickerImpl method pickTime.
public static void pickTime(@NonNull Context context, String value, @NonNull final OnPickListener listener) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(parseTime(value));
TimePickerDialog dialog = new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String h = hourOfDay < 10 ? "0" + hourOfDay : String.valueOf(hourOfDay);
String m = minute < 10 ? "0" + minute : String.valueOf(minute);
String result = h + ":" + m;
listener.onPick(true, result);
}
}, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), false);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
listener.onPick(false, null);
}
});
dialog.show();
}
use of android.app.TimePickerDialog in project android_frameworks_base by DirtyUnicorns.
the class TimeDialogActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout layout = new FrameLayout(this);
Button b = new Button(this);
b.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
b.setText("Show dialog");
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new TimePickerDialog(TimeDialogActivity.this, null, 12, 12, true).show();
}
});
layout.addView(b);
setContentView(layout);
}
use of android.app.TimePickerDialog in project Etar-Calendar by Etar-Group.
the class SnoozeDelayActivity method onPrepareDialog.
@Override
protected void onPrepareDialog(int id, Dialog d) {
if (id == DIALOG_DELAY) {
TimePickerDialog tpd = (TimePickerDialog) d;
int delayMinutes = (int) (Utils.getDefaultSnoozeDelayMs(this) / (60L * 1000L));
int hours = delayMinutes / 60;
int minutes = delayMinutes % 60;
tpd.updateTime(hours, minutes);
}
super.onPrepareDialog(id, d);
}
Aggregations