summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar/alerts/AlertUtils.java
diff options
context:
space:
mode:
authorIsaac Katzenelson <isaack@android.com>2012-03-01 15:58:30 -0800
committerIsaac Katzenelson <isaack@android.com>2012-03-07 12:05:26 -0800
commit9881907c47b2658fa85954bfb339c4b1eab9fc8e (patch)
tree31c30a6510d27915dc7702a994b10abc2406fa5f /src/com/android/calendar/alerts/AlertUtils.java
parent4526bd2efae219f8470d444e18c7783e90773adf (diff)
downloadandroid_packages_apps_Calendar-9881907c47b2658fa85954bfb339c4b1eab9fc8e.tar.gz
android_packages_apps_Calendar-9881907c47b2658fa85954bfb339c4b1eab9fc8e.tar.bz2
android_packages_apps_Calendar-9881907c47b2658fa85954bfb339c4b1eab9fc8e.zip
Support notification one click to view event and snoozing
Bug: 5934678 Alert - Avoid notification list if there's only one notification. Go straight to event details. Change-Id: I5251888acc417aa4c12f9408c82f24cdf93a6ccf
Diffstat (limited to 'src/com/android/calendar/alerts/AlertUtils.java')
-rw-r--r--src/com/android/calendar/alerts/AlertUtils.java99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/com/android/calendar/alerts/AlertUtils.java b/src/com/android/calendar/alerts/AlertUtils.java
new file mode 100644
index 00000000..9cb6c537
--- /dev/null
+++ b/src/com/android/calendar/alerts/AlertUtils.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2012 The Android Open Source 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.AlarmManager;
+import android.app.PendingIntent;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.provider.CalendarContract;
+import android.provider.CalendarContract.CalendarAlerts;
+
+import com.android.calendar.AllInOneActivity;
+
+public class AlertUtils {
+
+ public static final long SNOOZE_DELAY = 5 * 60 * 1000L;
+
+ // We use one notification id for all events so that we don't clutter
+ // the notification screen. It doesn't matter what the id is, as long
+ // as it is used consistently everywhere.
+ public static final int NOTIFICATION_ID = 0;
+
+ public static final String EVENT_ID_KEY = "eventid";
+ public static final String SHOW_EVENT_KEY = "showevent";
+ public static final String EVENT_START_KEY = "eventstart";
+ public static final String EVENT_END_KEY = "eventend";
+
+ /**
+ * Schedules an alarm intent with the system AlarmManager that will notify
+ * listeners when a reminder should be fired. The provider will keep
+ * scheduled reminders up to date but apps may use this to implement snooze
+ * functionality without modifying the reminders table. Scheduled alarms
+ * will generate an intent using {@link #ACTION_EVENT_REMINDER}.
+ *
+ * @param context A context for referencing system resources
+ * @param manager The AlarmManager to use or null
+ * @param alarmTime The time to fire the intent in UTC millis since epoch
+ */
+ public static void scheduleAlarm(Context context, AlarmManager manager, long alarmTime) {
+
+ // The default snooze delay: 5 minutes
+
+ if (manager == null) {
+ manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ }
+
+ Intent intent = new Intent(CalendarContract.ACTION_EVENT_REMINDER);
+ intent.setData(CalendarAlerts.CONTENT_URI);
+ intent.putExtra(CalendarContract.CalendarAlerts.ALARM_TIME, alarmTime);
+ PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ manager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
+ }
+
+ public static ContentValues makeContentValues(long eventId, long begin, long end,
+ long alarmTime, int minutes) {
+ ContentValues values = new ContentValues();
+ values.put(CalendarAlerts.EVENT_ID, eventId);
+ values.put(CalendarAlerts.BEGIN, begin);
+ values.put(CalendarAlerts.END, end);
+ values.put(CalendarAlerts.ALARM_TIME, alarmTime);
+ long currentTime = System.currentTimeMillis();
+ values.put(CalendarAlerts.CREATION_TIME, currentTime);
+ values.put(CalendarAlerts.RECEIVED_TIME, 0);
+ values.put(CalendarAlerts.NOTIFY_TIME, 0);
+ values.put(CalendarAlerts.STATE, CalendarAlerts.STATE_SCHEDULED);
+ values.put(CalendarAlerts.MINUTES, minutes);
+ return values;
+ }
+
+ public static Intent buildEventViewIntent(Context c, long eventId, long begin, long end){
+ Intent i = new Intent(Intent.ACTION_VIEW);
+ Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
+ i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ builder.appendEncodedPath("events/" + eventId);
+ i.setData(builder.build());
+ i.setClass(c, AllInOneActivity.class);
+ i.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin);
+ i.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);
+ return i;
+ }
+
+}