Files
calendar-lite/android/org/gingercal/Reminders.java
T
XoséandClaude Opus 5.5 748f6add54 Calendar Lite 1.5: GingerCal is now Calendar Lite, new icon and reminder icon
Renames the app (label, texts, User-Agent, PRODID, APK) and uses the new launcher icon pack
(ldpi to xhdpi, master in art/) instead of drawing one at build time. Reminders show a white
calendar glyph in the status bar (stat_notify, 18-48 px) instead of the system's colour
alarm clock, which didn't fit the Gingerbread bar. The package name, database and signing key
stay, so it installs over GingerCal and keeps its data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:57:48 +02:00

65 lines
2.8 KiB
Java

package org.gingercal;
import java.util.List;
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import org.gingercal.Model.Ev;
/** Local notifications before timed events, driven from the cached agenda. */
public final class Reminders {
private Reminders() {}
static PendingIntent alarmIntent(Context c) {
Intent i = new Intent(c, AlarmReceiver.class);
i.setAction(AlarmReceiver.REMIND);
return PendingIntent.getBroadcast(c, 2, i, 0x08000000 /* FLAG_UPDATE_CURRENT */);
}
public static void schedule(Context c) {
AlarmManager am = (AlarmManager) c.getSystemService("alarm");
PendingIntent pi = alarmIntent(c);
am.cancel(pi);
int m = App.remind(c);
if (m < 0) return;
long now = System.currentTimeMillis();
long notified = App.prefs(c).getLong("notified", 0);
long next = Db.get(c).nextStartAfter(Math.max(notified, now - 60000L));
if (next < 0) return;
am.set(0 /* RTC_WAKEUP */, Math.max(now + 1000, next - m * ICal.MIN), pi);
}
public static void fire(Context c) {
int m = App.remind(c);
if (m < 0) return;
long now = System.currentTimeMillis();
long notified = App.prefs(c).getLong("notified", 0);
// never nag about things that started more than 30 minutes ago
List<Ev> due = Db.get(c).startingBetween(Math.max(notified, now - 30 * ICal.MIN), now + m * ICal.MIN + 30000L);
NotificationManager nm = (NotificationManager) c.getSystemService("notification");
long newest = notified;
// our own white status-bar glyph: the system's colour alarm-clock icon looks out of place up there
int icon = c.getResources().getIdentifier("stat_notify", "drawable", c.getPackageName());
if (icon == 0) icon = App.sysDrawable(c, "ic_popup_reminder");
for (Ev e : due) {
Intent open = new Intent(c, MainActivity.class);
open.setFlags(0x10000000 /* FLAG_ACTIVITY_NEW_TASK */);
PendingIntent pi = PendingIntent.getActivity(c, 0, open, 0);
Notification n = new Notification(icon, e.title, e.start);
String body = App.when(c, e) + (e.location.length() > 0 ? " · " + e.location : "");
n.setLatestEventInfo(c, e.title.length() > 0 ? e.title : L.t("(no title)"), body, pi);
n.flags |= 16; // FLAG_AUTO_CANCEL
n.defaults = -1; // DEFAULT_ALL: sound, vibrate, lights
nm.notify((e.href + e.start).hashCode(), n);
if (e.start > newest) newest = e.start;
}
if (newest != notified) App.prefs(c).edit().putLong("notified", newest).commit();
schedule(c);
}
}