Search in sources :

Example 1 with Alarm

use of org.omnirom.deskclock.provider.Alarm in project android_packages_apps_OmniClock by omnirom.

the class AlarmClockFragment method onTimeSet.

// Callback used by TimePickerDialog
@Override
public void onTimeSet(RadialPickerLayout timePicker, int hourOfDay, int minute, int seconds) {
    if (mCloneAlarm && mSelectedAlarm != null) {
        cloneAlarm(mSelectedAlarm, hourOfDay, minute);
        mSelectedAlarm = null;
    } else {
        if (mSelectedAlarm == null) {
            // If mSelectedAlarm is null then we're creating a new alarm.
            Alarm a = new Alarm();
            a.hour = hourOfDay;
            a.minutes = minute;
            a.enabled = true;
            a.alert = getDefaultAlarmUri();
            a.setRingtoneName(getRingToneTitle(a.alert), BrowseActivity.QUERY_TYPE_ALARM);
            a.deleteAfterUse = false;
            mAddedAlarm = a;
            asyncAddAlarm(a, true);
        } else {
            // only change time but nothing else
            if (mSelectedAlarm.hour != hourOfDay || mSelectedAlarm.minutes != minute) {
                mSelectedAlarm.hour = hourOfDay;
                mSelectedAlarm.minutes = minute;
                asyncUpdateAlarm(mSelectedAlarm, true);
                mSelectedAlarm = null;
            }
        }
    }
}
Also used : Alarm(org.omnirom.deskclock.provider.Alarm)

Example 2 with Alarm

use of org.omnirom.deskclock.provider.Alarm in project android_packages_apps_OmniClock by omnirom.

the class AlarmClockFragment method asyncAddAlarm.

private void asyncAddAlarm(final Alarm alarm, final boolean expand) {
    final Context context = getActivity().getApplicationContext();
    final AsyncTask<Void, Void, AlarmInstance> updateTask = new AsyncTask<Void, Void, AlarmInstance>() {

        @Override
        protected AlarmInstance doInBackground(Void... parameters) {
            if (context != null && alarm != null) {
                ContentResolver cr = context.getContentResolver();
                // Add alarm to db
                Alarm newAlarm = Alarm.addAlarm(cr, alarm);
                mScrollToAlarmId = newAlarm.id;
                if (expand) {
                    mExpandedId = newAlarm.id;
                }
                // Create and add instance to db
                if (newAlarm.enabled) {
                    sDeskClockExtensions.addAlarm(context, newAlarm);
                    return setupAlarmInstance(context, newAlarm);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(AlarmInstance instance) {
            if (instance != null) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                boolean noAlarmSoundHintShown = prefs.getBoolean(PREF_KEY_NO_ALARM_SOUND_HINT_SHOWN, false);
                boolean hintShown = prefs.getBoolean(PREF_KEY_ALARM_HINT_SHOWN, false);
                if (!instance.mRingtone.equals(Alarm.NO_RINGTONE_URI)) {
                    Uri defaultAlarm = Utils.getDefaultAlarmUri(getActivity());
                    if (defaultAlarm == null) {
                        if (!noAlarmSoundHintShown) {
                            // show hint that this alarm has been created with alarm tone choosen
                            AlarmUtils.popNoDefaultAlarmSoundToast(context);
                            prefs.edit().putBoolean(PREF_KEY_NO_ALARM_SOUND_HINT_SHOWN, true).commit();
                            return;
                        }
                    }
                }
                if (!hintShown) {
                    AlarmUtils.popFirstAlarmCreatedToast(context);
                    prefs.edit().putBoolean(PREF_KEY_ALARM_HINT_SHOWN, true).commit();
                } else {
                    AlarmUtils.popAlarmSetToast(context, instance.getAlarmTime().getTimeInMillis());
                }
            }
        }
    };
    updateTask.execute();
}
Also used : Context(android.content.Context) AlarmInstance(org.omnirom.deskclock.provider.AlarmInstance) SharedPreferences(android.content.SharedPreferences) Alarm(org.omnirom.deskclock.provider.Alarm) AsyncTask(android.os.AsyncTask) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver)

Example 3 with Alarm

use of org.omnirom.deskclock.provider.Alarm in project android_packages_apps_OmniClock by omnirom.

the class AlarmClockFragment method showUndoBar.

private void showUndoBar() {
    final Alarm deletedAlarm = mDeletedAlarm;
    mUndoFrame.setVisibility(View.VISIBLE);
    mUndoFrame.setOnTouchListener(this);
    mUndoBar.show(new ActionableToastBar.ActionClickedListener() {

        @Override
        public void onActionClicked() {
            mAddedAlarm = deletedAlarm;
            hideUndoBar(true);
            asyncAddAlarm(deletedAlarm, false);
        }
    }, 0, getResources().getString(R.string.alarm_deleted), false, R.string.alarm_undo, true);
}
Also used : ActionableToastBar(org.omnirom.deskclock.widget.ActionableToastBar) Alarm(org.omnirom.deskclock.provider.Alarm)

Example 4 with Alarm

use of org.omnirom.deskclock.provider.Alarm in project android_packages_apps_OmniClock by omnirom.

the class HandleApiCalls method handleSetAlarm.

/**
 * Processes the SET_ALARM intent
 * @param intent
 */
private void handleSetAlarm(Intent intent) {
    // If not provided or invalid, show UI
    final int hour = intent.getIntExtra(EXTRA_HOUR, -1);
    // If not provided, use zero. If it is provided, make sure it's valid, otherwise, show UI
    final int minutes;
    if (intent.hasExtra(EXTRA_MINUTES)) {
        minutes = intent.getIntExtra(EXTRA_MINUTES, -1);
    } else {
        minutes = 0;
    }
    if (hour < 0 || hour > 23 || minutes < 0 || minutes > 59) {
        // Intent has no time or an invalid time, open the alarm creation UI
        Intent createAlarm = Alarm.createIntent(this, DeskClock.class, Alarm.INVALID_ID);
        createAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        createAlarm.putExtra(AlarmClockFragment.ALARM_CREATE_NEW_INTENT_EXTRA, true);
        createAlarm.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
        startActivity(createAlarm);
        finish();
        LogUtils.i("HandleApiCalls no/invalid time; opening UI");
        return;
    }
    final boolean skipUi = intent.getBooleanExtra(EXTRA_SKIP_UI, false);
    final StringBuilder selection = new StringBuilder();
    final List<String> args = new ArrayList<String>();
    setSelectionFromIntent(intent, hour, minutes, selection, args);
    // Check if the alarm already exists and handle it
    final ContentResolver cr = getContentResolver();
    final List<Alarm> alarms = Alarm.getAlarms(cr, selection.toString(), args.toArray(new String[args.size()]));
    if (!alarms.isEmpty()) {
        Alarm alarm = alarms.get(0);
        alarm.enabled = true;
        Alarm.updateAlarm(cr, alarm);
        // Delete all old instances and create a new one with updated values
        AlarmStateManager.deleteAllInstances(this, alarm.id);
        setupInstance(alarm.createInstanceAfter(Calendar.getInstance()), skipUi);
        LogUtils.i("HandleApiCalls deleted old, created new alarm: %s", alarm);
        finish();
        return;
    }
    // Otherwise insert it and handle it
    final String message = getMessageFromIntent(intent);
    final DaysOfWeek daysOfWeek = getDaysFromIntent(intent);
    final boolean vibrate = intent.getBooleanExtra(EXTRA_VIBRATE, false);
    final String alert = intent.getStringExtra(EXTRA_RINGTONE);
    Alarm alarm = new Alarm(hour, minutes);
    alarm.enabled = true;
    alarm.label = message;
    alarm.daysOfWeek = daysOfWeek;
    alarm.vibrate = vibrate;
    if (alert == null) {
        alarm.alert = Utils.getDefaultAlarmUri(this);
        if (alarm.alert == null) {
            alarm.alert = mAlarms.get(0);
        }
    } else if (VALUE_RINGTONE_SILENT.equals(alert) || alert.isEmpty()) {
        alarm.alert = Alarm.NO_RINGTONE_URI;
    } else {
        alarm.alert = Uri.parse(alert);
    }
    alarm.deleteAfterUse = !daysOfWeek.isRepeating() && skipUi;
    alarm = Alarm.addAlarm(cr, alarm);
    setupInstance(alarm.createInstanceAfter(Calendar.getInstance()), skipUi);
    LogUtils.i("HandleApiCalls set up alarm: %s", alarm);
    finish();
}
Also used : DaysOfWeek(org.omnirom.deskclock.provider.DaysOfWeek) Alarm(org.omnirom.deskclock.provider.Alarm) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ContentResolver(android.content.ContentResolver)

Example 5 with Alarm

use of org.omnirom.deskclock.provider.Alarm in project android_packages_apps_OmniClock by omnirom.

the class AlarmRingtoneDialog method launchBroseActivityWithPerms.

private void launchBroseActivityWithPerms() {
    Alarm testAlarm = new Alarm();
    saveChanges(testAlarm);
    // ignore pre alarm here - activities assume it stored in there
    testAlarm.alert = mRingtone;
    startActivityForResult(Utils.getLocalBrowseIntent(getActivity(), testAlarm), REQUEST_CODE_BROWSE);
}
Also used : Alarm(org.omnirom.deskclock.provider.Alarm)

Aggregations

Alarm (org.omnirom.deskclock.provider.Alarm)11 ContentResolver (android.content.ContentResolver)4 Intent (android.content.Intent)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 TextView (android.widget.TextView)2 Calendar (java.util.Calendar)2 AlarmInstance (org.omnirom.deskclock.provider.AlarmInstance)2 AlertDialog (android.app.AlertDialog)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Button (android.widget.Button)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 SearchView (android.widget.SearchView)1 ArrayList (java.util.ArrayList)1 DaysOfWeek (org.omnirom.deskclock.provider.DaysOfWeek)1 ActionableToastBar (org.omnirom.deskclock.widget.ActionableToastBar)1