Search in sources :

Example 1 with TimerData

use of james.alarmio.data.TimerData 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 TimerData

use of james.alarmio.data.TimerData in project Alarmio by TheAndroidMaster.

the class RestoreOnBootReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Alarmio alarmio = (Alarmio) context.getApplicationContext();
    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    for (AlarmData alarm : alarmio.getAlarms()) {
        if (alarm.isEnabled)
            alarm.set(context, manager);
    }
    for (TimerData timer : alarmio.getTimers()) {
        if (timer.getRemainingMillis() > 0)
            timer.setAlarm(context, manager);
    }
}
Also used : TimerData(james.alarmio.data.TimerData) AlarmManager(android.app.AlarmManager) Alarmio(james.alarmio.Alarmio) AlarmData(james.alarmio.data.AlarmData)

Example 3 with TimerData

use of james.alarmio.data.TimerData in project Alarmio by TheAndroidMaster.

the class TimerReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Alarmio alarmio = (Alarmio) context.getApplicationContext();
    TimerData timer = alarmio.getTimers().get(intent.getIntExtra(EXTRA_TIMER_ID, 0));
    alarmio.removeTimer(timer);
    Intent ringer = new Intent(context, AlarmActivity.class);
    ringer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ringer.putExtra(AlarmActivity.EXTRA_TIMER, timer);
    context.startActivity(ringer);
}
Also used : TimerData(james.alarmio.data.TimerData) Intent(android.content.Intent) Alarmio(james.alarmio.Alarmio)

Example 4 with TimerData

use of james.alarmio.data.TimerData in project Alarmio by TheAndroidMaster.

the class Alarmio method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    /*Crasher crasher = new Crasher(this);
        crasher.setEmail("dev@jfenn.me");
        crasher.setColor(ContextCompat.getColor(this, R.color.colorNightPrimary));*/
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    listeners = new ArrayList<>();
    alarms = new ArrayList<>();
    timers = new ArrayList<>();
    player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector());
    player.addListener(this);
    DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), null);
    mediaSourceFactory = new HlsMediaSource.Factory(dataSourceFactory);
    int alarmLength = PreferenceData.ALARM_LENGTH.getValue(this);
    for (int id = 0; id < alarmLength; id++) {
        alarms.add(new AlarmData(id, this));
    }
    int timerLength = PreferenceData.TIMER_LENGTH.getValue(this);
    for (int id = 0; id < timerLength; id++) {
        TimerData timer = new TimerData(id, this);
        if (timer.isSet())
            timers.add(timer);
    }
    if (timerLength > 0)
        startService(new Intent(this, TimerService.class));
    SleepReminderService.refreshSleepTime(this);
}
Also used : HlsMediaSource(com.google.android.exoplayer2.source.hls.HlsMediaSource) DefaultDataSourceFactory(com.google.android.exoplayer2.upstream.DefaultDataSourceFactory) TimerData(james.alarmio.data.TimerData) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Intent(android.content.Intent) AlarmData(james.alarmio.data.AlarmData)

Example 5 with TimerData

use of james.alarmio.data.TimerData in project Alarmio by TheAndroidMaster.

the class Alarmio method newTimer.

/**
 * Create a new timer, assigning it an unused preference id.
 *
 * @return          The newly instantiated [TimerData](./data/TimerData).
 */
public TimerData newTimer() {
    TimerData timer = new TimerData(timers.size());
    timers.add(timer);
    onTimerCountChanged();
    return timer;
}
Also used : TimerData(james.alarmio.data.TimerData)

Aggregations

TimerData (james.alarmio.data.TimerData)8 Intent (android.content.Intent)3 AlarmData (james.alarmio.data.AlarmData)3 AlarmManager (android.app.AlarmManager)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AnimatedVectorDrawableCompat (androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat)2 Alarmio (james.alarmio.Alarmio)2 SoundData (james.alarmio.data.SoundData)2 SoundChooserListener (james.alarmio.interfaces.SoundChooserListener)2 Animator (android.animation.Animator)1 ArgbEvaluator (android.animation.ArgbEvaluator)1 ValueAnimator (android.animation.ValueAnimator)1 NotificationChannel (android.app.NotificationChannel)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1