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);
}
});
}
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);
}
}
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);
}
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);
}
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;
}
Aggregations