diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/calendar/GeneralPreferences.java | 26 | ||||
-rw-r--r-- | src/com/android/calendar/Utils.java | 15 | ||||
-rw-r--r-- | src/com/android/calendar/alerts/AlertReceiver.java | 12 | ||||
-rw-r--r-- | src/com/android/calendar/alerts/AlertUtils.java | 3 | ||||
-rw-r--r-- | src/com/android/calendar/alerts/SnoozeAlarmsService.java | 6 | ||||
-rw-r--r-- | src/com/android/calendar/alerts/SnoozeDelayActivity.java | 79 |
6 files changed, 135 insertions, 6 deletions
diff --git a/src/com/android/calendar/GeneralPreferences.java b/src/com/android/calendar/GeneralPreferences.java index d98d3e65..ffaa0ffd 100644 --- a/src/com/android/calendar/GeneralPreferences.java +++ b/src/com/android/calendar/GeneralPreferences.java @@ -43,6 +43,7 @@ import android.text.TextUtils; import android.widget.Toast; import com.android.calendar.alerts.AlertReceiver; +import com.android.calendar.event.EventViewUtils; public class GeneralPreferences extends PreferenceFragment implements OnSharedPreferenceChangeListener, OnPreferenceChangeListener { @@ -72,6 +73,10 @@ public class GeneralPreferences extends PreferenceFragment implements public static final String NO_REMINDER_STRING = "-1"; public static final int REMINDER_DEFAULT_TIME = 10; // in minutes + public static final String KEY_USE_CUSTOM_SNOOZE_DELAY = "preferences_custom_snooze_delay"; + public static final String KEY_DEFAULT_SNOOZE_DELAY = "preferences_default_snooze_delay"; + public static final int SNOOZE_DELAY_DEFAULT_TIME = 5; // in minutes + public static final String KEY_DEFAULT_CELL_HEIGHT = "preferences_default_cell_height"; public static final String KEY_VERSION = "preferences_version"; @@ -112,6 +117,7 @@ public class GeneralPreferences extends PreferenceFragment implements ListPreference mHomeTZ; ListPreference mWeekStart; ListPreference mDefaultReminder; + ListPreference mSnoozeDelay; private static CharSequence[][] mTimezones; @@ -166,8 +172,12 @@ public class GeneralPreferences extends PreferenceFragment implements mHomeTZ = (ListPreference) preferenceScreen.findPreference(KEY_HOME_TZ); String tz = mHomeTZ.getValue(); + mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY); + buildSnoozeDelayEntries(); + mWeekStart.setSummary(mWeekStart.getEntry()); mDefaultReminder.setSummary(mDefaultReminder.getEntry()); + mSnoozeDelay.setSummary(mSnoozeDelay.getEntry()); if (mTimezones == null) { mTimezones = (new TimezoneAdapter(activity, tz, System.currentTimeMillis())) @@ -203,6 +213,7 @@ public class GeneralPreferences extends PreferenceFragment implements mHomeTZ.setOnPreferenceChangeListener(listener); mWeekStart.setOnPreferenceChangeListener(listener); mDefaultReminder.setOnPreferenceChangeListener(listener); + mSnoozeDelay.setOnPreferenceChangeListener(listener); mRingtone.setOnPreferenceChangeListener(listener); mHideDeclined.setOnPreferenceChangeListener(listener); mVibrate.setOnPreferenceChangeListener(listener); @@ -270,6 +281,9 @@ public class GeneralPreferences extends PreferenceFragment implements } else if (preference == mDefaultReminder) { mDefaultReminder.setValue((String) newValue); mDefaultReminder.setSummary(mDefaultReminder.getEntry()); + } else if (preference == mSnoozeDelay) { + mSnoozeDelay.setValue((String) newValue); + mSnoozeDelay.setSummary(mSnoozeDelay.getEntry()); } else if (preference == mRingtone) { if (newValue instanceof String) { String ringtone = getRingtoneTitleFromUri(getActivity(), (String) newValue); @@ -345,6 +359,18 @@ public class GeneralPreferences extends PreferenceFragment implements } } + private void buildSnoozeDelayEntries() { + final CharSequence[] values = mSnoozeDelay.getEntryValues(); + final int count = values.length; + final CharSequence[] entries = new CharSequence[count]; + + for (int i = 0; i < count; i++) { + int value = Integer.parseInt(values[i].toString()); + entries[i] = EventViewUtils.constructReminderLabel(getActivity(), value, false); + } + + mSnoozeDelay.setEntries(entries); + } @Override public boolean onPreferenceTreeClick( diff --git a/src/com/android/calendar/Utils.java b/src/com/android/calendar/Utils.java index e21a8f32..d0be6867 100644 --- a/src/com/android/calendar/Utils.java +++ b/src/com/android/calendar/Utils.java @@ -544,6 +544,21 @@ public class Utils { return prefs.getInt(GeneralPreferences.KEY_DAYS_PER_WEEK, 7); } + public static boolean useCustomSnoozeDelay(Context context) { + final SharedPreferences prefs = GeneralPreferences.getSharedPreferences(context); + return prefs.getBoolean(GeneralPreferences.KEY_USE_CUSTOM_SNOOZE_DELAY, false); + } + + public static long getDefaultSnoozeDelayMs(Context context) { + final SharedPreferences prefs = GeneralPreferences.getSharedPreferences(context); + final String value = prefs.getString(GeneralPreferences.KEY_DEFAULT_SNOOZE_DELAY, null); + final long intValue = value != null + ? Long.valueOf(value) + : GeneralPreferences.SNOOZE_DELAY_DEFAULT_TIME; + + return intValue * 60L * 1000L; // min -> ms + } + /** * Determine whether the column position is Saturday or not. * diff --git a/src/com/android/calendar/alerts/AlertReceiver.java b/src/com/android/calendar/alerts/AlertReceiver.java index a0a82d54..a95235df 100644 --- a/src/com/android/calendar/alerts/AlertReceiver.java +++ b/src/com/android/calendar/alerts/AlertReceiver.java @@ -196,7 +196,6 @@ public class AlertReceiver extends BroadcastReceiver { private static PendingIntent createSnoozeIntent(Context context, long eventId, long startMillis, long endMillis, int notificationId) { Intent intent = new Intent(); - intent.setClass(context, SnoozeAlarmsService.class); intent.putExtra(AlertUtils.EVENT_ID_KEY, eventId); intent.putExtra(AlertUtils.EVENT_START_KEY, startMillis); intent.putExtra(AlertUtils.EVENT_END_KEY, endMillis); @@ -206,7 +205,14 @@ public class AlertReceiver extends BroadcastReceiver { ContentUris.appendId(builder, eventId); ContentUris.appendId(builder, startMillis); intent.setData(builder.build()); - return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + + if (Utils.useCustomSnoozeDelay(context)) { + intent.setClass(context, SnoozeDelayActivity.class); + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } else { + intent.setClass(context, SnoozeAlarmsService.class); + return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } } private static PendingIntent createAlertActivityIntent(Context context) { @@ -257,7 +263,7 @@ public class AlertReceiver extends BroadcastReceiver { PendingIntent snoozeIntent = null; PendingIntent emailIntent = null; if (addActionButtons) { - // Create snooze intent. TODO: change snooze to 10 minutes. + // Create snooze intent. snoozeIntent = createSnoozeIntent(context, eventId, startMillis, endMillis, notificationId); diff --git a/src/com/android/calendar/alerts/AlertUtils.java b/src/com/android/calendar/alerts/AlertUtils.java index f68f5224..ae96b9ed 100644 --- a/src/com/android/calendar/alerts/AlertUtils.java +++ b/src/com/android/calendar/alerts/AlertUtils.java @@ -44,8 +44,6 @@ public class AlertUtils { private static final String TAG = "AlertUtils"; static final boolean DEBUG = true; - public static final long SNOOZE_DELAY = 5 * 60 * 1000L; - // We use one notification id for the expired events notification. All // other notifications (the 'active' future/concurrent ones) use a unique ID. public static final int EXPIRED_GROUP_NOTIFICATION_ID = 0; @@ -56,6 +54,7 @@ public class AlertUtils { public static final String EVENT_END_KEY = "eventend"; public static final String NOTIFICATION_ID_KEY = "notificationid"; public static final String EVENT_IDS_KEY = "eventids"; + public static final String SNOOZE_DELAY_KEY = "snoozedelay"; // A flag for using local storage to save alert state instead of the alerts DB table. // This allows the unbundled app to run alongside other calendar apps without eating diff --git a/src/com/android/calendar/alerts/SnoozeAlarmsService.java b/src/com/android/calendar/alerts/SnoozeAlarmsService.java index 6ef983d5..9490c719 100644 --- a/src/com/android/calendar/alerts/SnoozeAlarmsService.java +++ b/src/com/android/calendar/alerts/SnoozeAlarmsService.java @@ -26,6 +26,8 @@ import android.net.Uri; import android.os.IBinder; import android.provider.CalendarContract.CalendarAlerts; +import com.android.calendar.Utils; + /** * Service for asynchronously marking a fired alarm as dismissed and scheduling * a new alarm in the future. @@ -51,6 +53,8 @@ public class SnoozeAlarmsService extends IntentService { long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1); long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1); long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1); + long snoozeDelay = intent.getLongExtra(AlertUtils.SNOOZE_DELAY_KEY, + Utils.getDefaultSnoozeDelayMs(this)); // The ID reserved for the expired notification digest should never be passed in // here, so use that as a default. @@ -76,7 +80,7 @@ public class SnoozeAlarmsService extends IntentService { resolver.update(uri, dismissValues, selection, null); // Add a new alarm - long alarmTime = System.currentTimeMillis() + AlertUtils.SNOOZE_DELAY; + long alarmTime = System.currentTimeMillis() + snoozeDelay; ContentValues values = AlertUtils.makeContentValues(eventId, eventStart, eventEnd, alarmTime, 0); resolver.insert(uri, values); diff --git a/src/com/android/calendar/alerts/SnoozeDelayActivity.java b/src/com/android/calendar/alerts/SnoozeDelayActivity.java new file mode 100644 index 00000000..4f00df70 --- /dev/null +++ b/src/com/android/calendar/alerts/SnoozeDelayActivity.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2013 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.calendar.alerts; + +import android.app.Activity; +import android.app.Dialog; +import android.app.TimePickerDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.widget.TimePicker; + +import com.android.calendar.R; +import com.android.calendar.Utils; + +public class SnoozeDelayActivity extends Activity implements + TimePickerDialog.OnTimeSetListener, DialogInterface.OnCancelListener { + private static final int DIALOG_DELAY = 1; + + @Override + protected void onResume() { + super.onResume(); + showDialog(DIALOG_DELAY); + } + + @Override + protected Dialog onCreateDialog(int id) { + if (id == DIALOG_DELAY) { + TimePickerDialog d = new TimePickerDialog(this, this, 0, 0, true); + d.setTitle(R.string.snooze_delay_dialog_title); + d.setCancelable(true); + d.setOnCancelListener(this); + return d; + } + + return super.onCreateDialog(id); + } + + @Override + protected void onPrepareDialog(int id, Dialog d) { + if (id == DIALOG_DELAY) { + TimePickerDialog tpd = (TimePickerDialog) d; + int delayMinutes = (int) (Utils.getDefaultSnoozeDelayMs(this) / (60L * 1000L)); + int hours = delayMinutes / 60; + int minutes = delayMinutes % 60; + + tpd.updateTime(hours, minutes); + } + super.onPrepareDialog(id, d); + } + + @Override + public void onCancel(DialogInterface d) { + finish(); + } + + @Override + public void onTimeSet(TimePicker view, int hour, int minute) { + long delay = (hour * 60 + minute) * 60L * 1000L; + Intent intent = getIntent(); + intent.setClass(this, SnoozeAlarmsService.class); + intent.putExtra(AlertUtils.SNOOZE_DELAY_KEY, delay); + startService(intent); + finish(); + } +} |