Search in sources :

Example 1 with SoundChooserListener

use of james.alarmio.interfaces.SoundChooserListener in project Alarmio by TheAndroidMaster.

the class TimerDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog_timer);
    ringtoneImage = findViewById(R.id.ringtoneImage);
    ringtoneText = findViewById(R.id.ringtoneText);
    vibrateImage = findViewById(R.id.vibrateImage);
    time = findViewById(R.id.time);
    backspace = findViewById(R.id.backspace);
    time.setText(getTime());
    backspace.setOnClickListener(this);
    findViewById(R.id.one).setOnClickListener(this);
    findViewById(R.id.two).setOnClickListener(this);
    findViewById(R.id.three).setOnClickListener(this);
    findViewById(R.id.four).setOnClickListener(this);
    findViewById(R.id.five).setOnClickListener(this);
    findViewById(R.id.six).setOnClickListener(this);
    findViewById(R.id.seven).setOnClickListener(this);
    findViewById(R.id.eight).setOnClickListener(this);
    findViewById(R.id.nine).setOnClickListener(this);
    findViewById(R.id.zero).setOnClickListener(this);
    ringtoneImage.setImageResource(ringtone != null ? R.drawable.ic_ringtone : R.drawable.ic_ringtone_disabled);
    ringtoneImage.setAlpha(ringtone != null ? 1f : 0.333f);
    if (ringtone != null)
        ringtoneText.setText(ringtone.getName());
    else
        ringtoneText.setText(R.string.title_sound_none);
    findViewById(R.id.ringtone).setOnClickListener(new View.OnClickListener() {

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

                @Override
                public void onSoundChosen(SoundData sound) {
                    ringtone = sound;
                    ringtoneImage.setImageResource(sound != null ? R.drawable.ic_ringtone : R.drawable.ic_ringtone_disabled);
                    ringtoneImage.setAlpha(sound != null ? 1f : 0.333f);
                    if (sound != null)
                        ringtoneText.setText(sound.getName());
                    else
                        ringtoneText.setText(R.string.title_sound_none);
                }
            });
            dialog.show(manager, "");
        }
    });
    findViewById(R.id.vibrate).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            isVibrate = !isVibrate;
            AnimatedVectorDrawableCompat drawable = AnimatedVectorDrawableCompat.create(v.getContext(), isVibrate ? R.drawable.ic_none_to_vibrate : R.drawable.ic_vibrate_to_none);
            if (drawable != null) {
                vibrateImage.setImageDrawable(drawable);
                drawable.start();
            } else
                vibrateImage.setImageResource(isVibrate ? R.drawable.ic_vibrate : R.drawable.ic_none);
            vibrateImage.animate().alpha(isVibrate ? 1f : 0.333f).start();
            if (isVibrate)
                v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        }
    });
    findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (Integer.parseInt(input) > 0) {
                TimerData timer = alarmio.newTimer();
                timer.setDuration(getMillis(), alarmio);
                timer.setVibrate(view.getContext(), isVibrate);
                timer.setSound(view.getContext(), ringtone);
                timer.set(alarmio, ((AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE)));
                alarmio.onTimerStarted();
                Bundle args = new Bundle();
                args.putParcelable(TimerFragment.EXTRA_TIMER, timer);
                TimerFragment fragment = new TimerFragment();
                fragment.setArguments(args);
                manager.beginTransaction().setCustomAnimations(R.anim.slide_in_up_sheet, R.anim.slide_out_up_sheet, R.anim.slide_in_down_sheet, R.anim.slide_out_down_sheet).replace(R.id.fragment, fragment).addToBackStack(null).commit();
                dismiss();
            }
        }
    });
    findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismiss();
        }
    });
    Aesthetic.Companion.get().textColorPrimary().take(1).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer integer) throws Exception {
            ringtoneImage.setColorFilter(integer);
            vibrateImage.setColorFilter(integer);
            backspace.setColorFilter(integer);
        }
    });
}
Also used : SoundChooserListener(james.alarmio.interfaces.SoundChooserListener) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) TimerData(james.alarmio.data.TimerData) SoundData(james.alarmio.data.SoundData) AnimatedVectorDrawableCompat(androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat) TimerFragment(james.alarmio.fragments.TimerFragment)

Example 2 with SoundChooserListener

use of james.alarmio.interfaces.SoundChooserListener 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.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.nameUnderline.setVisibility(isExpanded ? View.VISIBLE : View.GONE);
        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(alarmio, 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, 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 AestheticTimeSheetPickerDialog(view.getContext(), alarm.time.get(Calendar.HOUR_OF_DAY), alarm.time.get(Calendar.MINUTE)).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                    @Override
                    public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                        AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                        alarm.time.set(Calendar.HOUR_OF_DAY, view.getHourOfDay());
                        alarm.time.set(Calendar.MINUTE, view.getMinute());
                        alarm.setTime(alarmio, alarmManager, alarm.time.getTimeInMillis());
                        alarmHolder.time.setText(FormatUtils.formatShort(alarmio, alarm.time.getTime()));
                    }

                    @Override
                    public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                    }
                }).show();
            }
        });
        alarmHolder.indicators.setVisibility(isExpanded ? View.GONE : View.VISIBLE);
        if (isExpanded) {
            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(alarmio, alarm.days);
                    Transition transition = new AutoTransition();
                    transition.setDuration(150);
                    TransitionManager.beginDelayedTransition(recycler, transition);
                    notifyDataSetChanged();
                }
            });
            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(alarmio, 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.ringtoneImage.setAlpha(alarm.hasSound() ? 1 : 0.333f);
            alarmHolder.ringtoneText.setText(alarm.hasSound() ? alarm.getSound().getName() : alarmio.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(alarmio, sound);
                            notifyItemChanged(position);
                        }
                    });
                    dialog.show(fragmentManager, null);
                }
            });
            AnimatedVectorDrawableCompat vibrateDrawable = AnimatedVectorDrawableCompat.create(alarmio, alarm.isVibrate ? R.drawable.ic_vibrate_to_none : R.drawable.ic_none_to_vibrate);
            alarmHolder.vibrateImage.setImageDrawable(vibrateDrawable);
            alarmHolder.vibrateImage.setAlpha(alarm.isVibrate ? 1 : 0.333f);
            alarmHolder.vibrate.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    AlarmData alarm = getAlarm(alarmHolder.getAdapterPosition());
                    alarm.setVibrate(alarmio, !alarm.isVibrate);
                    AnimatedVectorDrawableCompat vibrateDrawable = AnimatedVectorDrawableCompat.create(alarmio, alarm.isVibrate ? R.drawable.ic_none_to_vibrate : R.drawable.ic_vibrate_to_none);
                    if (vibrateDrawable != null) {
                        alarmHolder.vibrateImage.setImageDrawable(vibrateDrawable);
                        vibrateDrawable.start();
                    } else
                        alarmHolder.vibrateImage.setImageResource(alarm.isVibrate ? R.drawable.ic_vibrate : R.drawable.ic_vibrate_none);
                    alarmHolder.vibrateImage.animate().alpha(alarm.isVibrate ? 1 : 0.333f).setDuration(250).start();
                    if (alarm.isVibrate)
                        view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                }
            });
        } else {
            alarmHolder.repeatIndicator.setAlpha(alarm.isRepeat() ? 1 : 0.333f);
            alarmHolder.soundIndicator.setAlpha(alarm.hasSound() ? 1 : 0.333f);
            alarmHolder.vibrateIndicator.setAlpha(alarm.isVibrate ? 1 : 0.333f);
        }
        alarmHolder.expandImage.animate().rotationX(isExpanded ? 180 : 0).start();
        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(view.getContext()).setContent(alarmio.getString(R.string.msg_delete_confirmation, alarm.getName(alarmio))).setListener(new AlertDialog.Listener() {

                    @Override
                    public void onDismiss(AlertDialog dialog, boolean ok) {
                        if (ok)
                            alarmio.removeAlarm(getAlarm(alarmHolder.getAdapterPosition()));
                    }
                }).show();
            }
        });
        alarmHolder.repeat.setTextColor(textColorPrimary);
        alarmHolder.delete.setTextColor(textColorPrimary);
        alarmHolder.ringtoneImage.setColorFilter(textColorPrimary);
        alarmHolder.vibrateImage.setColorFilter(textColorPrimary);
        alarmHolder.expandImage.setColorFilter(textColorPrimary);
        alarmHolder.repeatIndicator.setColorFilter(textColorPrimary);
        alarmHolder.soundIndicator.setColorFilter(textColorPrimary);
        alarmHolder.vibrateIndicator.setColorFilter(textColorPrimary);
        alarmHolder.nameUnderline.setBackgroundColor(textColorPrimary);
        int visibility = isExpanded ? View.VISIBLE : View.GONE;
        if (visibility != alarmHolder.extra.getVisibility()) {
            alarmHolder.extra.setVisibility(visibility);
            Aesthetic.Companion.get().colorPrimary().take(1).subscribe(new Consumer<Integer>() {

                @Override
                public void accept(Integer integer) throws Exception {
                    ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), isExpanded ? integer : colorForeground, isExpanded ? colorForeground : integer);
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            alarmHolder.itemView.setBackgroundColor((int) animation.getAnimatedValue());
                        }
                    });
                    animator.addListener(new Animator.AnimatorListener() {

                        @Override
                        public void onAnimationStart(Animator animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            alarmHolder.itemView.setBackgroundColor(isExpanded ? colorForeground : Color.TRANSPARENT);
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                        }

                        @Override
                        public void onAnimationRepeat(Animator animation) {
                        }
                    });
                    animator.start();
                }
            });
            ValueAnimator animator = ValueAnimator.ofFloat(isExpanded ? 0 : ConversionUtils.dpToPx(2), isExpanded ? ConversionUtils.dpToPx(2) : 0);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    ViewCompat.setElevation(alarmHolder.itemView, (float) animation.getAnimatedValue());
                }
            });
            animator.start();
        } else {
            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) {
                expandedPosition = isExpanded ? -1 : alarmHolder.getAdapterPosition();
                Transition transition = new AutoTransition();
                transition.setDuration(250);
                TransitionManager.beginDelayedTransition(recycler, transition);
                notifyDataSetChanged();
            }
        });
    }
}
Also used : AlertDialog(james.alarmio.dialogs.AlertDialog) SoundChooserListener(james.alarmio.interfaces.SoundChooserListener) ArgbEvaluator(android.animation.ArgbEvaluator) ValueAnimator(android.animation.ValueAnimator) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SoundData(james.alarmio.data.SoundData) DaySwitch(james.alarmio.views.DaySwitch) AutoTransition(androidx.transition.AutoTransition) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) ImageView(android.widget.ImageView) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) View(android.view.View) ProgressLineView(james.alarmio.views.ProgressLineView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SoundChooserDialog(james.alarmio.dialogs.SoundChooserDialog) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) TimerData(james.alarmio.data.TimerData) PickerDialog(me.jfenn.timedatepickers.dialogs.PickerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) AutoTransition(androidx.transition.AutoTransition) Transition(androidx.transition.Transition) AnimatedVectorDrawableCompat(androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat) CompoundButton(android.widget.CompoundButton) AlarmData(james.alarmio.data.AlarmData) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView)

Example 3 with SoundChooserListener

use of james.alarmio.interfaces.SoundChooserListener in project Alarmio by TheAndroidMaster.

the class RingtonePreferenceData method onClick.

@Override
public void onClick(final ViewHolder holder) {
    SoundChooserDialog dialog = new SoundChooserDialog();
    dialog.setListener(new SoundChooserListener() {

        @Override
        public void onSoundChosen(SoundData sound) {
            preference.setValue(holder.getContext(), sound != null ? sound.toString() : null);
            bindViewHolder(holder);
        }
    });
    dialog.show(holder.getAlarmio().getFragmentManager(), null);
}
Also used : SoundChooserListener(james.alarmio.interfaces.SoundChooserListener) SoundData(james.alarmio.data.SoundData) SoundChooserDialog(james.alarmio.dialogs.SoundChooserDialog)

Aggregations

SoundData (james.alarmio.data.SoundData)3 SoundChooserListener (james.alarmio.interfaces.SoundChooserListener)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AnimatedVectorDrawableCompat (androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat)2 TimerData (james.alarmio.data.TimerData)2 SoundChooserDialog (james.alarmio.dialogs.SoundChooserDialog)2 Animator (android.animation.Animator)1 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 CompoundButton (android.widget.CompoundButton)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AutoTransition (androidx.transition.AutoTransition)1 Transition (androidx.transition.Transition)1 AlarmData (james.alarmio.data.AlarmData)1 AestheticTimeSheetPickerDialog (james.alarmio.dialogs.AestheticTimeSheetPickerDialog)1