Search in sources :

Example 1 with TimerFragment

use of james.alarmio.fragments.TimerFragment 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 TimerFragment

use of james.alarmio.fragments.TimerFragment in project Alarmio by TheAndroidMaster.

the class MainActivity method onNewIntent.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent.hasExtra(EXTRA_FRAGMENT)) {
        boolean shouldBackStack = fragment instanceof HomeFragment;
        int fragmentId = intent.getIntExtra(EXTRA_FRAGMENT, -1);
        if (fragmentId == FRAGMENT_TIMER && intent.hasExtra(TimerReceiver.EXTRA_TIMER_ID)) {
            int id = intent.getIntExtra(TimerReceiver.EXTRA_TIMER_ID, 0);
            if (alarmio.getTimers().size() <= id || id < 0)
                return;
            Bundle args = new Bundle();
            args.putParcelable(TimerFragment.EXTRA_TIMER, alarmio.getTimers().get(id));
            fragment = new TimerFragment();
            fragment.setArguments(args);
        } else if (fragmentId == FRAGMENT_STOPWATCH) {
            if (fragment instanceof StopwatchFragment)
                return;
            fragment = new StopwatchFragment();
        } else
            return;
        FragmentTransaction transaction = getSupportFragmentManager().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);
        if (shouldBackStack)
            transaction.addToBackStack(null);
        transaction.commit();
    }
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) Bundle(android.os.Bundle) HomeFragment(james.alarmio.fragments.HomeFragment) StopwatchFragment(james.alarmio.fragments.StopwatchFragment) TimerFragment(james.alarmio.fragments.TimerFragment)

Aggregations

Bundle (android.os.Bundle)2 TimerFragment (james.alarmio.fragments.TimerFragment)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 AnimatedVectorDrawableCompat (androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat)1 SoundData (james.alarmio.data.SoundData)1 TimerData (james.alarmio.data.TimerData)1 HomeFragment (james.alarmio.fragments.HomeFragment)1 StopwatchFragment (james.alarmio.fragments.StopwatchFragment)1 SoundChooserListener (james.alarmio.interfaces.SoundChooserListener)1