Search in sources :

Example 31 with TimePickerDialog

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);
}
Also used : Context(android.content.Context) LocalTime(java.time.LocalTime) TimePickerDialog(android.app.TimePickerDialog)

Example 32 with TimePickerDialog

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();
    });
}
Also used : DeleteEvent(de.tum.in.tumcampusapp.component.tumui.calendar.model.DeleteEvent) TimePickerDialog(android.app.TimePickerDialog) R(de.tum.in.tumcampusapp.R) Bundle(android.os.Bundle) DateUtils(de.tum.in.tumcampusapp.utils.DateUtils) TUMOnlineRequest(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequest) SimpleDateFormat(java.text.SimpleDateFormat) Const(de.tum.in.tumcampusapp.utils.Const) TUMOnlineConst(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineConst) CreateEvent(de.tum.in.tumcampusapp.component.tumui.calendar.model.CreateEvent) TUMOnlineRequestFetchListener(de.tum.in.tumcampusapp.api.tumonline.TUMOnlineRequestFetchListener) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Calendar(java.util.Calendar) DatePickerDialog(android.app.DatePickerDialog) CalendarItem(de.tum.in.tumcampusapp.component.tumui.calendar.model.CalendarItem) Locale(java.util.Locale) ActivityForAccessingTumOnline(de.tum.in.tumcampusapp.component.other.generic.activity.ActivityForAccessingTumOnline) Utils(de.tum.in.tumcampusapp.utils.Utils) Button(android.widget.Button) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) DatePickerDialog(android.app.DatePickerDialog) TimePickerDialog(android.app.TimePickerDialog)

Example 33 with TimePickerDialog

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;
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) DatePickerDialog(android.app.DatePickerDialog) Intent(android.content.Intent) TimePickerDialog(android.app.TimePickerDialog) DatePickerDialog(android.app.DatePickerDialog) AlertDialog(android.app.AlertDialog) TimePickerDialog(android.app.TimePickerDialog) Dialog(android.app.Dialog) OnClickListener(android.view.View.OnClickListener)

Example 34 with TimePickerDialog

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;
    }
}
Also used : AlertDialog(android.app.AlertDialog) ListView(android.widget.ListView) DatePickerDialog(android.app.DatePickerDialog) TimePickerDialog(android.app.TimePickerDialog)

Example 35 with TimePickerDialog

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;
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) MainActivity(kogvet.eye.MainActivity) View(android.view.View) LocalDate(org.threeten.bp.LocalDate) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat) Nullable(android.support.annotation.Nullable)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)64 TimePicker (android.widget.TimePicker)27 Calendar (java.util.Calendar)25 View (android.view.View)20 DatePickerDialog (android.app.DatePickerDialog)15 TextView (android.widget.TextView)14 Context (android.content.Context)11 DialogInterface (android.content.DialogInterface)11 AlertDialog (android.app.AlertDialog)9 Button (android.widget.Button)8 CompoundButton (android.widget.CompoundButton)7 Bundle (android.os.Bundle)6 DatePicker (android.widget.DatePicker)6 LocalTime (java.time.LocalTime)6 FrameLayout (android.widget.FrameLayout)5 SuppressLint (android.annotation.SuppressLint)4 Intent (android.content.Intent)4 LinearLayout (android.widget.LinearLayout)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4