Search in sources :

Example 16 with TimePickerDialog

use of android.app.TimePickerDialog in project android-app-common-tasks by multidots.

the class Common method showTimePickerDialog.

/**
     * show timepicker
     *
     * @param mContext
     * @param mTextView formar of the time
     * @return show timepicker
     */
public static void showTimePickerDialog(final Context mContext, final TextView mTextView) {
    new TimePickerDialog(mContext, new OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            SimpleDateFormat timeFormatter = new SimpleDateFormat("hh:mm a");
            dateTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
            dateTime.set(Calendar.MINUTE, minute);
            mTextView.setText(timeFormatter.format(dateTime.getTime()));
        }
    }, dateTime.get(Calendar.HOUR_OF_DAY), dateTime.get(Calendar.MINUTE), false).show();
}
Also used : TimePicker(android.widget.TimePicker) OnTimeSetListener(android.app.TimePickerDialog.OnTimeSetListener) TimePickerDialog(android.app.TimePickerDialog) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with TimePickerDialog

use of android.app.TimePickerDialog in project AntennaPod by AntennaPod.

the class PreferenceController method showUpdateIntervalTimePreferencesDialog.

// UPDATE TIME/INTERVAL DIALOG
private void showUpdateIntervalTimePreferencesDialog() {
    final Context context = ui.getActivity();
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context);
    builder.title(R.string.pref_autoUpdateIntervallOrTime_title);
    builder.content(R.string.pref_autoUpdateIntervallOrTime_message);
    builder.positiveText(R.string.pref_autoUpdateIntervallOrTime_Interval);
    builder.negativeText(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay);
    builder.neutralText(R.string.pref_autoUpdateIntervallOrTime_Disable);
    builder.onPositive((dialog, which) -> {
        AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
        builder1.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_Interval));
        final String[] values = context.getResources().getStringArray(R.array.update_intervall_values);
        final String[] entries = getUpdateIntervalEntries(values);
        long currInterval = UserPreferences.getUpdateInterval();
        int checkedItem = -1;
        if (currInterval > 0) {
            String currIntervalStr = String.valueOf(TimeUnit.MILLISECONDS.toHours(currInterval));
            checkedItem = ArrayUtils.indexOf(values, currIntervalStr);
        }
        builder1.setSingleChoiceItems(entries, checkedItem, (dialog1, which1) -> {
            int hours = Integer.parseInt(values[which1]);
            UserPreferences.setUpdateInterval(hours);
            dialog1.dismiss();
            setUpdateIntervalText();
        });
        builder1.setNegativeButton(context.getString(R.string.cancel_label), null);
        builder1.show();
    });
    builder.onNegative((dialog, which) -> {
        int hourOfDay = 7, minute = 0;
        int[] updateTime = UserPreferences.getUpdateTimeOfDay();
        if (updateTime.length == 2) {
            hourOfDay = updateTime[0];
            minute = updateTime[1];
        }
        TimePickerDialog timePickerDialog = new TimePickerDialog(context, (view, selectedHourOfDay, selectedMinute) -> {
            if (view.getTag() == null) {
                // onTimeSet() may get called twice!
                view.setTag("TAGGED");
                UserPreferences.setUpdateTimeOfDay(selectedHourOfDay, selectedMinute);
                setUpdateIntervalText();
            }
        }, hourOfDay, minute, DateFormat.is24HourFormat(context));
        timePickerDialog.setTitle(context.getString(R.string.pref_autoUpdateIntervallOrTime_TimeOfDay));
        timePickerDialog.show();
    });
    builder.onNeutral((dialog, which) -> {
        UserPreferences.setUpdateInterval(0);
        setUpdateIntervalText();
    });
    builder.show();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TimePickerDialog(android.app.TimePickerDialog) SuppressLint(android.annotation.SuppressLint)

Example 18 with TimePickerDialog

use of android.app.TimePickerDialog in project android_frameworks_base by ResurrectionRemix.

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);
}
Also used : Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) TimePickerDialog(android.app.TimePickerDialog) View(android.view.View)

Example 19 with TimePickerDialog

use of android.app.TimePickerDialog in project android_frameworks_base by crdroidandroid.

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);
}
Also used : Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) TimePickerDialog(android.app.TimePickerDialog) View(android.view.View)

Example 20 with TimePickerDialog

use of android.app.TimePickerDialog in project IITB-App by wncc.

the class AddEventFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    container.removeAllViews();
    view = inflater.inflate(R.layout.fragment_add_event, container, false);
    ButterKnife.bind(this, view);
    eventPictureImageView = view.findViewById(R.id.ib_eventImage);
    progressDialog = new ProgressDialog(getContext());
    cb_permission.setVisibility(View.GONE);
    cb_public.setVisibility(View.GONE);
    et_mapLocation.setVisibility(View.GONE);
    close.setVisibility(View.GONE);
    open.setVisibility(View.VISIBLE);
    start.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            int mYear = calendar.get(Calendar.YEAR);
            int mMonth = calendar.get(Calendar.MONTH);
            int mDay = calendar.get(Calendar.DAY_OF_MONTH);
            final int mHour = calendar.get(Calendar.HOUR_OF_DAY);
            final int mMin = calendar.get(Calendar.MINUTE);
            long millis = calendar.getTimeInMillis();
            DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, final int year, final int month, final int dayOfMonth) {
                    TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {

                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                            start.setText(dayOfMonth + "/" + month + "/" + year + " " + hourOfDay + ":" + minute);
                        }
                    }, mHour, mMin, true);
                    timePickerDialog.show();
                }
            }, mYear, mMonth, mDay);
            datePickerDialog.show();
            timestamp_start = new Timestamp(millis);
        }
    });
    end.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            int mYear = calendar.get(Calendar.YEAR);
            int mMonth = calendar.get(Calendar.MONTH);
            int mDay = calendar.get(Calendar.DAY_OF_MONTH);
            final int mHour = calendar.get(Calendar.HOUR_OF_DAY);
            final int mMin = calendar.get(Calendar.MINUTE);
            long millis = calendar.getTimeInMillis();
            DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, final int year, final int month, final int dayOfMonth) {
                    TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {

                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                            end.setText(dayOfMonth + "/" + month + "/" + year + " " + hourOfDay + ":" + minute);
                        }
                    }, mHour, mMin, true);
                    timePickerDialog.show();
                }
            }, mYear, mMonth, mDay);
            datePickerDialog.show();
            timestamp_end = new Timestamp(millis);
        }
    });
    if (cb_permission.isChecked()) {
        publicStatus = 1;
    } else
        publicStatus = 0;
    advancedMenu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (cb_public.getVisibility() == View.VISIBLE) {
                open.setVisibility(View.VISIBLE);
                close.setVisibility(View.GONE);
                cb_permission.setVisibility(View.GONE);
                cb_public.setVisibility(View.GONE);
                et_mapLocation.setVisibility(View.GONE);
            } else {
                close.setVisibility(View.VISIBLE);
                open.setVisibility(View.GONE);
                cb_permission.setVisibility(View.VISIBLE);
                cb_public.setVisibility(View.VISIBLE);
                et_mapLocation.setVisibility(View.VISIBLE);
            }
        }
    });
    imageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                // Permission is not granted
                ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
                return;
            }
            Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });
    createEvent.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            progressDialog.setIndeterminate(true);
            progressDialog.setCancelable(false);
            progressDialog.show();
            sendImage();
        }
    });
    return view;
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Timestamp(java.sql.Timestamp) DatePicker(android.widget.DatePicker)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)20 View (android.view.View)6 DatePickerDialog (android.app.DatePickerDialog)5 Button (android.widget.Button)5 FrameLayout (android.widget.FrameLayout)5 Calendar (java.util.Calendar)5 TimePicker (android.widget.TimePicker)4 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 Intent (android.content.Intent)2 SimpleDateFormat (java.text.SimpleDateFormat)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 ProgressDialog (android.app.ProgressDialog)1 OnTimeSetListener (android.app.TimePickerDialog.OnTimeSetListener)1 SharedPreferences (android.content.SharedPreferences)1 PreferenceManager (android.preference.PreferenceManager)1 AlertDialog (android.support.v7.app.AlertDialog)1