summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2013-01-21 15:28:44 +0100
committerSteve Kondik <steve@cyngn.com>2015-10-18 13:52:38 -0700
commit0e9cabffc2a262ad2432f28d94d8dae672af87fb (patch)
tree3d79108c6140b8bc47eb7479c3555e9cc2edc8e7 /src
parent916259681ce2216d95c05a5064ed71d0b0d7f422 (diff)
downloadandroid_packages_apps_Calendar-0e9cabffc2a262ad2432f28d94d8dae672af87fb.tar.gz
android_packages_apps_Calendar-0e9cabffc2a262ad2432f28d94d8dae672af87fb.tar.bz2
android_packages_apps_Calendar-0e9cabffc2a262ad2432f28d94d8dae672af87fb.zip
Allow configuring the delay for snoozing calendar reminders.
This allows both configuring the default snooze delay as well as ask for the delay whenever snoozing a reminder. Change-Id: Ib875c231535ff4f53dc7c97dd15a6a4b29f48fba
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calendar/GeneralPreferences.java28
-rw-r--r--src/com/android/calendar/Utils.java15
-rw-r--r--src/com/android/calendar/alerts/AlertReceiver.java14
-rw-r--r--src/com/android/calendar/alerts/AlertUtils.java3
-rw-r--r--src/com/android/calendar/alerts/SnoozeAlarmsService.java6
-rw-r--r--src/com/android/calendar/alerts/SnoozeDelayActivity.java79
6 files changed, 140 insertions, 5 deletions
diff --git a/src/com/android/calendar/GeneralPreferences.java b/src/com/android/calendar/GeneralPreferences.java
index 54fc0e78..15a6213d 100644
--- a/src/com/android/calendar/GeneralPreferences.java
+++ b/src/com/android/calendar/GeneralPreferences.java
@@ -47,6 +47,7 @@ import android.text.format.Time;
import android.widget.Toast;
import com.android.calendar.alerts.AlertReceiver;
+import com.android.calendar.event.EventViewUtils;
import com.android.timezonepicker.TimeZoneInfo;
import com.android.timezonepicker.TimeZonePickerDialog;
import com.android.timezonepicker.TimeZonePickerDialog.OnTimeZoneSetListener;
@@ -83,6 +84,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";
@@ -182,6 +187,13 @@ public class GeneralPreferences extends PreferenceFragment implements
mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
+
+ mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
+ mDefaultStart.setOnPreferenceChangeListener(this);
+
+ mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
+ buildSnoozeDelayEntries();
+
mWeekStart.setSummary(mWeekStart.getEntry());
mDefaultReminder.setSummary(mDefaultReminder.getEntry());
@@ -263,6 +275,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);
@@ -324,6 +337,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) {
Utils.setRingTonePreference(activity, (String) newValue);
@@ -400,6 +416,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 41961852..837141a1 100644
--- a/src/com/android/calendar/Utils.java
+++ b/src/com/android/calendar/Utils.java
@@ -700,6 +700,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 83dcc9fc..8c2d4a78 100644
--- a/src/com/android/calendar/alerts/AlertReceiver.java
+++ b/src/com/android/calendar/alerts/AlertReceiver.java
@@ -235,7 +235,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);
@@ -245,7 +244,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) {
@@ -305,6 +311,10 @@ public class AlertReceiver extends BroadcastReceiver {
mapIntent = createMapBroadcastIntent(context, urlSpans, eventId);
callIntent = createCallBroadcastIntent(context, urlSpans, eventId);
+ // Create snooze intent.
+ snoozeIntent = createSnoozeIntent(context, eventId, startMillis, endMillis,
+ notificationId);
+
// Create email intent for emailing attendees.
emailIntent = createBroadcastMailIntent(context, eventId, title);
diff --git a/src/com/android/calendar/alerts/AlertUtils.java b/src/com/android/calendar/alerts/AlertUtils.java
index fec7b111..8d7de12e 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 NOTIFICATION_ID_KEY = "notificationid";
public static final String EVENT_IDS_KEY = "eventids";
public static final String EVENT_STARTS_KEY = "starts";
+ 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();
+ }
+}