Search in sources :

Example 1 with Alarmio

use of james.alarmio.Alarmio 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 2 with Alarmio

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

the class AlarmReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Alarmio alarmio = (Alarmio) context.getApplicationContext();
    AlarmData alarm = alarmio.getAlarms().get(intent.getIntExtra(EXTRA_ALARM_ID, 0));
    if (alarm.isRepeat())
        alarm.set(context, manager);
    else
        alarm.setEnabled(alarmio, manager, false);
    alarmio.onAlarmsChanged();
    Intent ringer = new Intent(context, AlarmActivity.class);
    ringer.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ringer.putExtra(AlarmActivity.EXTRA_ALARM, alarm);
    context.startActivity(ringer);
}
Also used : AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) Alarmio(james.alarmio.Alarmio) AlarmData(james.alarmio.data.AlarmData)

Example 3 with Alarmio

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

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

the class ThemePreferenceData method bindViewHolder.

@Override
public void bindViewHolder(final ViewHolder holder) {
    holder.themeSpinner.setAdapter(ArrayAdapter.createFromResource(holder.itemView.getContext(), R.array.array_themes, R.layout.support_simple_spinner_dropdown_item));
    int theme = ((Alarmio) holder.itemView.getContext().getApplicationContext()).getActivityTheme();
    holder.themeSpinner.setOnItemSelectedListener(null);
    holder.themeSpinner.setSelection(theme);
    holder.sunriseAutoSwitch.setVisibility(theme == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
    holder.sunriseLayout.setVisibility(theme == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
    holder.themeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        Integer selection = null;

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (selection != null) {
                PreferenceData.THEME.setValue(adapterView.getContext(), i);
                holder.sunriseAutoSwitch.setVisibility(i == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
                holder.sunriseLayout.setVisibility(i == Alarmio.THEME_DAY_NIGHT ? View.VISIBLE : View.GONE);
                ((Alarmio) holder.itemView.getContext().getApplicationContext()).updateTheme();
            } else
                selection = i;
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    final SunriseView.SunriseListener listener = new SunriseView.SunriseListener() {

        @Override
        public void onSunriseChanged(int sunrise, int sunset) {
            Calendar sunriseCalendar = Calendar.getInstance();
            sunriseCalendar.set(Calendar.HOUR_OF_DAY, sunrise);
            sunriseCalendar.set(Calendar.MINUTE, 0);
            holder.sunriseTextView.setText(FormatUtils.formatShort(holder.getContext(), new Date(sunriseCalendar.getTimeInMillis())));
            Calendar sunsetCalendar = Calendar.getInstance();
            sunsetCalendar.set(Calendar.HOUR_OF_DAY, sunset);
            sunsetCalendar.set(Calendar.MINUTE, 0);
            holder.sunsetTextView.setText(FormatUtils.formatShort(holder.getContext(), new Date(sunsetCalendar.getTimeInMillis())));
        }
    };
    holder.sunriseAutoSwitch.setOnCheckedChangeListener(null);
    holder.sunriseAutoSwitch.setChecked(holder.getAlarmio().isDayAuto());
    holder.sunriseAutoSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            PreferenceData.DAY_AUTO.setValue(holder.getContext(), b);
            if (b && ContextCompat.checkSelfPermission(holder.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                holder.getAlarmio().requestPermissions(Manifest.permission.ACCESS_COARSE_LOCATION);
                holder.sunriseAutoSwitch.setChecked(false);
            } else {
                holder.sunriseView.invalidate();
                listener.onSunriseChanged(holder.getAlarmio().getDayStart(), holder.getAlarmio().getDayEnd());
            }
            holder.getAlarmio().updateTheme();
        }
    });
    holder.sunriseView.setListener(listener);
    listener.onSunriseChanged(holder.getAlarmio().getDayStart(), holder.getAlarmio().getDayEnd());
    holder.sunriseTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!holder.getAlarmio().isDayAuto()) {
                new AestheticTimeSheetPickerDialog(view.getContext(), holder.getAlarmio().getDayStart(), 0).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                    @Override
                    public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                        int dayEnd = holder.getAlarmio().getDayEnd();
                        if (view.getHourOfDay() < dayEnd) {
                            PreferenceData.DAY_START.setValue(holder.getContext(), view.getHourOfDay());
                            holder.sunriseView.invalidate();
                            listener.onSunriseChanged(view.getHourOfDay(), dayEnd);
                            holder.getAlarmio().updateTheme();
                        }
                    }

                    @Override
                    public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                    }
                }).show();
            }
        }
    });
    holder.sunsetTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!holder.getAlarmio().isDayAuto()) {
                new AestheticTimeSheetPickerDialog(view.getContext(), holder.getAlarmio().getDayEnd(), 0).setListener(new PickerDialog.OnSelectedListener<LinearTimePickerView>() {

                    @Override
                    public void onSelect(PickerDialog<LinearTimePickerView> dialog, LinearTimePickerView view) {
                        int dayStart = holder.getAlarmio().getDayStart();
                        if (view.getHourOfDay() > dayStart) {
                            PreferenceData.DAY_END.setValue(holder.getContext(), view.getHourOfDay());
                            holder.sunriseView.invalidate();
                            listener.onSunriseChanged(dayStart, view.getHourOfDay());
                            holder.getAlarmio().updateTheme();
                        }
                    }

                    @Override
                    public void onCancel(PickerDialog<LinearTimePickerView> dialog) {
                    }
                }).show();
            }
        }
    });
    Aesthetic.Companion.get().textColorSecondary().take(1).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer textColorSecondary) throws Exception {
            holder.themeSpinner.setSupportBackgroundTintList(ColorStateList.valueOf(textColorSecondary));
        }
    });
    Aesthetic.Companion.get().colorCardViewBackground().take(1).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(Integer colorForeground) throws Exception {
            holder.themeSpinner.setPopupBackgroundDrawable(new ColorDrawable(colorForeground));
        }
    });
}
Also used : Alarmio(james.alarmio.Alarmio) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) Calendar(java.util.Calendar) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView) View(android.view.View) SunriseView(james.alarmio.views.SunriseView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Date(java.util.Date) ColorDrawable(android.graphics.drawable.ColorDrawable) PickerDialog(me.jfenn.timedatepickers.dialogs.PickerDialog) AestheticTimeSheetPickerDialog(james.alarmio.dialogs.AestheticTimeSheetPickerDialog) AdapterView(android.widget.AdapterView) SunriseView(james.alarmio.views.SunriseView) CompoundButton(android.widget.CompoundButton) LinearTimePickerView(me.jfenn.timedatepickers.views.LinearTimePickerView)

Aggregations

Alarmio (james.alarmio.Alarmio)4 AlarmManager (android.app.AlarmManager)2 Intent (android.content.Intent)2 AlarmData (james.alarmio.data.AlarmData)2 TimerData (james.alarmio.data.TimerData)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 TextView (android.widget.TextView)1 AestheticTimeSheetPickerDialog (james.alarmio.dialogs.AestheticTimeSheetPickerDialog)1 SunriseView (james.alarmio.views.SunriseView)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 PickerDialog (me.jfenn.timedatepickers.dialogs.PickerDialog)1 LinearTimePickerView (me.jfenn.timedatepickers.views.LinearTimePickerView)1