Search in sources :

Example 46 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)

Example 47 with TimePickerDialog

use of android.app.TimePickerDialog in project AndFrameWorks by scwang90.

the class AfDialogBuilder method selectTime.

/**
 * 选择时间
 * @param title 标题
 * @param value 默认时间
 * @param listener 监听器
 */
@Override
public Dialog selectTime(CharSequence title, Date value, final OnTimeSetListener listener) {
    Calendar calender = Calendar.getInstance();
    calender.setTime(value);
    int hour = calender.get(Calendar.HOUR_OF_DAY);
    int minute = calender.get(Calendar.MINUTE);
    AlertDialog tDialog = new TimePickerDialog(mContext, new SafeListener(listener), hour, minute, true) {

        @Override
        public void show() {
            super.show();
            if (listener instanceof OnTimeSetVerifyListener) {
                getButton(BUTTON_POSITIVE).setOnClickListener(v -> {
                    try {
                        TimePicker picker = AfReflecter.getMemberByType(this, TimePicker.class);
                        if (picker == null) {
                            this.dismiss();
                            super.onClick(this, BUTTON_POSITIVE);
                        } else if (((OnTimeSetVerifyListener) listener).onPreTimeSet(this, picker, picker.getCurrentHour(), picker.getCurrentMinute())) {
                            this.dismiss();
                            super.onClick(this, BUTTON_POSITIVE);
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                });
            }
        }
    };
    if (title != null && title.length() > 0) {
        tDialog.setTitle(title);
    }
    tDialog.show();
    tDialog.setCancelable(true);
    return tDialog;
}
Also used : AlertDialog(android.app.AlertDialog) TimePicker(android.widget.TimePicker) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) SafeListener(com.andframe.listener.SafeListener) SuppressLint(android.annotation.SuppressLint)

Example 48 with TimePickerDialog

use of android.app.TimePickerDialog in project Alarmio by TheAndroidMaster.

the class AlarmsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (getItemViewType(position) == 0) {
        final TimerViewHolder timerHolder = (TimerViewHolder) holder;
        if (timerHolder.runnable != null)
            timerHolder.handler.removeCallbacks(timerHolder.runnable);
        timerHolder.runnable = new Runnable() {

            @Override
            public void run() {
                try {
                    TimerData timer = getTimer(timerHolder.getAdapterPosition());
                    String text = FormatUtils.formatMillis(timer.getRemainingMillis());
                    timerHolder.time.setText(text.substring(0, text.length() - 3));
                    timerHolder.progress.update(1 - ((float) timer.getRemainingMillis() / timer.getDuration()));
                    timerHolder.handler.postDelayed(this, 1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        timerHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, MainActivity.class);
                intent.putExtra(TimerReceiver.EXTRA_TIMER_ID, timerHolder.getAdapterPosition());
                context.startActivity(intent);
            }
        });
        timerHolder.stop.setColorFilter(textColorPrimary);
        timerHolder.stop.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                TimerData timer = getTimer(timerHolder.getAdapterPosition());
                alarmio.removeTimer(timer);
            }
        });
        timerHolder.handler.post(timerHolder.runnable);
    } else {
        final AlarmViewHolder alarmHolder = (AlarmViewHolder) holder;
        final boolean isExpanded = position == expandedPosition;
        AlarmData alarm = getAlarm(position);
        alarmHolder.name.setFocusable(isExpanded);
        alarmHolder.name.setEnabled(isExpanded);
        alarmHolder.name.clearFocus();
        alarmHolder.name.setText(alarm.getName(alarmio));
        alarmHolder.name.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                getAlarm(alarmHolder.getAdapterPosition()).setName(prefs, alarmHolder.name.getText().toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        alarmHolder.enable.setOnCheckedChangeListener(null);
        alarmHolder.enable.setChecked(alarm.isEnabled);
        alarmHolder.enable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                getAlarm(alarmHolder.getAdapterPosition()).setEnabled(alarmio, prefs, alarmManager, b);
            }
        });
        alarmHolder.time.setText(FormatUtils.formatShort(alarmio, alarm.time.getTime()));
        alarmHolder.time.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

                    @Override
                    public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                        AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                        alarm.time.set(Calendar.HOUR_OF_DAY, hourOfDay);
                        alarm.time.set(Calendar.MINUTE, minute);
                        alarm.setTime(alarmio, prefs, alarmManager, alarm.time.getTimeInMillis());
                        alarmHolder.time.setText(FormatUtils.formatShort(alarmio, alarm.time.getTime()));
                    }
                }, alarm.time.get(Calendar.HOUR_OF_DAY), alarm.time.get(Calendar.MINUTE), DateFormat.is24HourFormat(alarmio)).show();
            }
        });
        alarmHolder.repeat.setOnCheckedChangeListener(null);
        alarmHolder.repeat.setChecked(alarm.isRepeat());
        alarmHolder.repeat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                for (int i = 0; i < 7; i++) {
                    alarm.days[i] = b;
                }
                alarm.setDays(prefs, alarm.days);
                notifyItemChanged(alarmHolder.getAdapterPosition());
            }
        });
        alarmHolder.days.setVisibility(alarm.isRepeat() ? View.VISIBLE : View.GONE);
        DaySwitch.OnCheckedChangeListener listener = new DaySwitch.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(DaySwitch daySwitch, boolean b) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                alarm.days[alarmHolder.days.indexOfChild(daySwitch)] = b;
                alarm.setDays(prefs, alarm.days);
                if (!alarm.isRepeat())
                    notifyItemChanged(alarmHolder.getAdapterPosition());
            }
        };
        for (int i = 0; i < 7; i++) {
            DaySwitch daySwitch = (DaySwitch) alarmHolder.days.getChildAt(i);
            daySwitch.setChecked(alarm.days[i]);
            daySwitch.setOnCheckedChangeListener(listener);
            switch(i) {
                case 0:
                case 6:
                    daySwitch.setText("S");
                    break;
                case 1:
                    daySwitch.setText("M");
                    break;
                case 2:
                case 4:
                    daySwitch.setText("T");
                    break;
                case 3:
                    daySwitch.setText("W");
                    break;
                case 5:
                    daySwitch.setText("F");
            }
        }
        alarmHolder.ringtoneImage.setImageResource(alarm.hasSound() ? R.drawable.ic_ringtone : R.drawable.ic_ringtone_disabled);
        alarmHolder.ringtoneText.setText(alarm.hasSound() ? alarm.getSound().getName() : context.getString(R.string.title_sound_none));
        alarmHolder.ringtone.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                SoundChooserDialog dialog = new SoundChooserDialog();
                dialog.setListener(new SoundChooserListener() {

                    @Override
                    public void onSoundChosen(SoundData sound) {
                        int position = alarmHolder.getAdapterPosition();
                        AlarmData alarm = getAlarm(position);
                        alarm.setSound(prefs, sound);
                        notifyItemChanged(position);
                    }
                });
                dialog.show(fragmentManager, null);
            }
        });
        alarmHolder.vibrateImage.setImageResource(alarm.isVibrate ? R.drawable.ic_vibrate : R.drawable.ic_none);
        alarmHolder.vibrate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                alarm.setVibrate(prefs, !alarm.isVibrate);
                alarmHolder.vibrateImage.setImageResource(alarm.isVibrate ? R.drawable.ic_vibrate : R.drawable.ic_none);
                if (alarm.isVibrate)
                    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        });
        alarmHolder.delete.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
        alarmHolder.delete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                new AlertDialog.Builder(context).setMessage(alarmio.getString(R.string.msg_delete_confirmation, alarm.getName(alarmio))).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        alarmio.removeAlarm(getAlarm(alarmHolder.getAdapterPosition()));
                        dialog.dismiss();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int i) {
                        dialog.dismiss();
                    }
                }).show();
            }
        });
        int[][] states = new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } };
        ColorStateList colorStateList = new ColorStateList(states, new int[] { Color.argb(100, 128, 128, 128), colorAccent });
        ColorStateList thumbStateList = new ColorStateList(states, new int[] { Color.argb(255, 128, 128, 128), colorAccent });
        ColorStateList trackStateList = new ColorStateList(states, new int[] { Color.argb(100, 128, 128, 128), Color.argb(100, Color.red(colorAccent), Color.green(colorAccent), Color.blue(colorAccent)) });
        CompoundButtonCompat.setButtonTintList(alarmHolder.enable, colorStateList);
        CompoundButtonCompat.setButtonTintList(alarmHolder.repeat, colorStateList);
        DrawableCompat.setTintList(DrawableCompat.wrap(alarmHolder.enable.getThumbDrawable()), thumbStateList);
        DrawableCompat.setTintList(DrawableCompat.wrap(alarmHolder.enable.getTrackDrawable()), trackStateList);
        alarmHolder.repeat.setTextColor(textColorPrimary);
        alarmHolder.delete.setTextColor(textColorPrimary);
        alarmHolder.ringtoneImage.setColorFilter(textColorPrimary);
        alarmHolder.vibrateImage.setColorFilter(textColorPrimary);
        alarmHolder.expandImage.setColorFilter(textColorPrimary);
        alarmHolder.extra.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
        alarmHolder.expandImage.animate().rotation(isExpanded ? 180 : 0);
        alarmHolder.itemView.setBackgroundColor(isExpanded ? colorForeground : Color.TRANSPARENT);
        ViewCompat.setElevation(alarmHolder.itemView, isExpanded ? ConversionUtils.dpToPx(2) : 0);
        alarmHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int previousPosition = expandedPosition;
                expandedPosition = isExpanded ? -1 : alarmHolder.getAdapterPosition();
                if (previousPosition != expandedPosition && previousPosition != -1)
                    notifyItemChanged(previousPosition);
                notifyItemChanged(alarmHolder.getAdapterPosition());
            }
        });
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) TimePicker(android.widget.TimePicker) SoundChooserListener(james.alarmio.interfaces.SoundChooserListener) DialogInterface(android.content.DialogInterface) ColorStateList(android.content.res.ColorStateList) MainActivity(james.alarmio.activities.MainActivity) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SoundData(james.alarmio.data.SoundData) DaySwitch(james.alarmio.views.DaySwitch) Intent(android.content.Intent) TimePickerDialog(android.app.TimePickerDialog) ImageView(android.widget.ImageView) View(android.view.View) ProgressLineView(james.alarmio.views.ProgressLineView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SoundChooserDialog(james.alarmio.dialogs.SoundChooserDialog) TimerData(james.alarmio.data.TimerData) CompoundButton(android.widget.CompoundButton) AlarmData(james.alarmio.data.AlarmData)

Example 49 with TimePickerDialog

use of android.app.TimePickerDialog in project xDrip by NightscoutFoundation.

the class MissedReadingActivity method addListenerOnButtons.

public void addListenerOnButtons() {
    checkboxAllDay.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllControls();
        }
    });
    checkboxEnableAlert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllControls();
        }
    });
    checkboxEnableReraise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        // @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            enableAllControls();
        }
    });
    View.OnClickListener startTimeListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerDialog mTimePicker = new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    startHour = selectedHour;
                    startMinute = selectedMinute;
                    setTimeRanges();
                }
            }, startHour, startMinute, DateFormat.is24HourFormat(mContext));
            mTimePicker.setTitle("Select start time");
            mTimePicker.show();
        }
    };
    View.OnClickListener endTimeListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            TimePickerDialog mTimePicker = new TimePickerDialog(mContext, AlertDialog.THEME_HOLO_DARK, new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                    endHour = selectedHour;
                    endMinute = selectedMinute;
                    setTimeRanges();
                }
            }, endHour, endMinute, DateFormat.is24HourFormat(mContext));
            mTimePicker.setTitle("Select end time");
            mTimePicker.show();
        }
    };
    viewTimeStart.setOnClickListener(startTimeListener);
    timeInstructionsStart.setOnClickListener(startTimeListener);
    viewTimeEnd.setOnClickListener(endTimeListener);
    timeInstructionsEnd.setOnClickListener(endTimeListener);
}
Also used : TimePicker(android.widget.TimePicker) TimePickerDialog(android.app.TimePickerDialog) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Example 50 with TimePickerDialog

use of android.app.TimePickerDialog in project android_packages_apps_Settings by omnirom.

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 = mController.getCustomStartTime();
        } else {
            initialTime = mController.getCustomEndTime();
        }
        final Context context = getContext();
        final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);
        return new TimePickerDialog(context, new TimePickerDialog.OnTimeSetListener() {

            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                final LocalTime time = LocalTime.of(hourOfDay, minute);
                if (dialogId == DIALOG_START_TIME) {
                    mController.setCustomStartTime(time);
                } else {
                    mController.setCustomEndTime(time);
                }
            }
        }, initialTime.getHour(), initialTime.getMinute(), use24HourFormat);
    }
    return super.onCreateDialog(dialogId);
}
Also used : Context(android.content.Context) TimePicker(android.widget.TimePicker) LocalTime(java.time.LocalTime) TimePickerDialog(android.app.TimePickerDialog)

Aggregations

TimePickerDialog (android.app.TimePickerDialog)66 TimePicker (android.widget.TimePicker)30 Calendar (java.util.Calendar)26 View (android.view.View)23 TextView (android.widget.TextView)16 DatePickerDialog (android.app.DatePickerDialog)15 DialogInterface (android.content.DialogInterface)12 Context (android.content.Context)11 AlertDialog (android.app.AlertDialog)9 Button (android.widget.Button)8 CompoundButton (android.widget.CompoundButton)8 Bundle (android.os.Bundle)7 DatePicker (android.widget.DatePicker)6 LocalTime (java.time.LocalTime)6 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)5 Date (java.util.Date)5 SuppressLint (android.annotation.SuppressLint)4 Nullable (android.support.annotation.Nullable)4 LinearLayout (android.widget.LinearLayout)4