Loading core/java/android/provider/Settings.java +36 −0 Original line number Diff line number Diff line Loading @@ -2448,6 +2448,42 @@ public final class Settings { */ public static final String WEATHER_INVERT_LOWHIGH = "weather_invert_lowhigh"; /** * Whether to show the next calendar event * @hide */ public static final String LOCKSCREEN_CALENDAR = "lockscreen_calendar"; /** * Whether to show the next calendar event's location * @hide */ public static final String LOCKSCREEN_CALENDAR_SHOW_LOCATION = "lockscreen_calendar_show_location"; /** * Whether to show the next calendar event's description * @hide */ public static final String LOCKSCREEN_CALENDAR_SHOW_DESCRIPTION = "lockscreen_calendar_show_description"; /** * Which calendars to look for events * @hide */ public static final String LOCKSCREEN_CALENDARS = "lockscreen_calendars"; /** * How far in the future to look for events * @hide */ public static final String LOCKSCREEN_CALENDAR_LOOKAHEAD = "lockscreen_calendar_lookahead"; /** * Whether to find only events with reminders * @hide */ public static final String LOCKSCREEN_CALENDAR_REMINDERS_ONLY = "lockscreen_calendar_reminders_only"; /** * Settings to backup. This is here so that it's in the same place as the settings * keys and easy to update. Loading core/java/com/android/internal/widget/LockPatternUtils.java +169 −0 Original line number Diff line number Diff line /* * Copyright (C) 2007 The Android Open Source Project * Copyright (C) 2012 The CyanogenMod Project (Calendar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -25,16 +26,21 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.os.FileObserver; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.storage.IMountService; import android.provider.CalendarContract; import android.provider.Settings; import android.security.KeyStore; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.format.DateFormat; import android.text.format.Time; import android.util.Log; import android.view.View; import android.widget.Button; Loading @@ -46,8 +52,11 @@ import java.io.RandomAccessFile; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.concurrent.atomic.AtomicBoolean; /** Loading Loading @@ -991,6 +1000,166 @@ public class LockPatternUtils { return nextAlarm; } /** * @return A formatted string of the next calendar event with a reminder * (for showing on the lock screen), or null if there is no next event * within a certain look-ahead time. */ public String[] getNextCalendarAlarm(long lookahead, String[] calendars, boolean remindersOnly) { long now = System.currentTimeMillis(); long later = now + lookahead; StringBuilder where = new StringBuilder(); if (remindersOnly) { where.append(CalendarContract.Events.HAS_ALARM + "=1"); } if (calendars != null && calendars.length > 0) { if (remindersOnly) { where.append(" AND "); } where.append(CalendarContract.Events.CALENDAR_ID + " in ("); for (int i = 0; i < calendars.length; i++) { where.append(calendars[i]); if (i != calendars.length - 1) { where.append(","); } } where.append(") "); } // Projection array String[] projection = new String[] { CalendarContract.Events.TITLE, CalendarContract.Instances.BEGIN, CalendarContract.Events.DESCRIPTION, CalendarContract.Events.EVENT_LOCATION, CalendarContract.Events.ALL_DAY }; // The indices for the projection array int TITLE_INDEX = 0; int BEGIN_TIME_INDEX = 1; int DESCRIPTION_INDEX = 2; int LOCATION_INDEX = 3; int ALL_DAY_INDEX = 4; Uri uri = Uri.withAppendedPath(CalendarContract.Instances.CONTENT_URI, String.format("%d/%d", now, later)); String[] nextCalendarAlarm = new String[2]; Cursor cursor = null; try { cursor = mContentResolver.query(uri, projection, where.toString(), null, "begin ASC"); if (cursor != null && cursor.moveToFirst()) { String title = cursor.getString(TITLE_INDEX); long begin = cursor.getLong(BEGIN_TIME_INDEX); String description = cursor.getString(DESCRIPTION_INDEX); String location = cursor.getString(LOCATION_INDEX); boolean allDay = cursor.getInt(ALL_DAY_INDEX) != 0; // Check the next event in the case of all day event. As UTC is used for all day // events, the next event may be the one that actually starts sooner if (allDay && !cursor.isLast()) { cursor.moveToNext(); long nextBegin = cursor.getLong(BEGIN_TIME_INDEX); if (nextBegin < begin + TimeZone.getDefault().getOffset(begin)) { title = cursor.getString(TITLE_INDEX); begin = nextBegin; description = cursor.getString(DESCRIPTION_INDEX); location = cursor.getString(LOCATION_INDEX); allDay = cursor.getInt(ALL_DAY_INDEX) != 0; } } // Set the event title as the first array item nextCalendarAlarm[0] = title.toString(); // Start building the event details string // Starting with the date Date start = new Date(begin); StringBuilder sb = new StringBuilder(); if (allDay) { SimpleDateFormat sdf = new SimpleDateFormat( mContext.getString(R.string.abbrev_wday_month_day_no_year)); // Calendar stores all-day events in UTC -- setting the time zone ensures // the correct date is shown. sdf.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC)); sb.append(sdf.format(start)); } else { sb.append(DateFormat.format("E", start)); sb.append(" "); sb.append(DateFormat.getTimeFormat(mContext).format(start)); } // Add the event location if it should be shown int showLocation = Settings.System.getInt(mContext.getContentResolver(), Settings.System.LOCKSCREEN_CALENDAR_SHOW_LOCATION, 0); if (showLocation != 0 && !TextUtils.isEmpty(location)) { switch(showLocation) { case 1: // Show first line int end = location.indexOf('\n'); if(end == -1) { sb.append(": " + location); } else { sb.append(": " + location.substring(0, end)); } break; case 2: // Show all sb.append(": " + location); break; } } // Add the event description if it should be shown int showDescription = Settings.System.getInt(mContext.getContentResolver(), Settings.System.LOCKSCREEN_CALENDAR_SHOW_DESCRIPTION, 0); if (showDescription != 0 && !TextUtils.isEmpty(description)) { // Show the appropriate separator if (showLocation == 0) { sb.append(": "); } else { sb.append(" - "); } switch(showDescription) { case 1: // Show first line int end = description.indexOf('\n'); if(end == -1) { sb.append(description); } else { sb.append(description.substring(0, end)); } break; case 2: // Show all sb.append(description); break; } } // Set the time, location and description as the second array item nextCalendarAlarm[1] = sb.toString(); } } catch (Exception e) { // Do nothing } finally { if (cursor != null) { cursor.close(); } } return nextCalendarAlarm; } private boolean getBoolean(String secureSettingKey, boolean defaultValue) { return 1 == android.provider.Settings.Secure.getInt(mContentResolver, secureSettingKey, Loading core/res/res/drawable-hdpi/ic_lock_idle_calendar.png 0 → 100644 +709 B Loading image diff... core/res/res/drawable-mdpi/ic_lock_idle_calendar.png 0 → 100644 +583 B Loading image diff... core/res/res/drawable-xhdpi/ic_lock_idle_calendar.png 0 → 100644 +823 B Loading image diff... Loading
core/java/android/provider/Settings.java +36 −0 Original line number Diff line number Diff line Loading @@ -2448,6 +2448,42 @@ public final class Settings { */ public static final String WEATHER_INVERT_LOWHIGH = "weather_invert_lowhigh"; /** * Whether to show the next calendar event * @hide */ public static final String LOCKSCREEN_CALENDAR = "lockscreen_calendar"; /** * Whether to show the next calendar event's location * @hide */ public static final String LOCKSCREEN_CALENDAR_SHOW_LOCATION = "lockscreen_calendar_show_location"; /** * Whether to show the next calendar event's description * @hide */ public static final String LOCKSCREEN_CALENDAR_SHOW_DESCRIPTION = "lockscreen_calendar_show_description"; /** * Which calendars to look for events * @hide */ public static final String LOCKSCREEN_CALENDARS = "lockscreen_calendars"; /** * How far in the future to look for events * @hide */ public static final String LOCKSCREEN_CALENDAR_LOOKAHEAD = "lockscreen_calendar_lookahead"; /** * Whether to find only events with reminders * @hide */ public static final String LOCKSCREEN_CALENDAR_REMINDERS_ONLY = "lockscreen_calendar_reminders_only"; /** * Settings to backup. This is here so that it's in the same place as the settings * keys and easy to update. Loading
core/java/com/android/internal/widget/LockPatternUtils.java +169 −0 Original line number Diff line number Diff line /* * Copyright (C) 2007 The Android Open Source Project * Copyright (C) 2012 The CyanogenMod Project (Calendar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading @@ -25,16 +26,21 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.database.Cursor; import android.net.Uri; import android.os.FileObserver; import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.storage.IMountService; import android.provider.CalendarContract; import android.provider.Settings; import android.security.KeyStore; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.format.DateFormat; import android.text.format.Time; import android.util.Log; import android.view.View; import android.widget.Button; Loading @@ -46,8 +52,11 @@ import java.io.RandomAccessFile; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.TimeZone; import java.util.concurrent.atomic.AtomicBoolean; /** Loading Loading @@ -991,6 +1000,166 @@ public class LockPatternUtils { return nextAlarm; } /** * @return A formatted string of the next calendar event with a reminder * (for showing on the lock screen), or null if there is no next event * within a certain look-ahead time. */ public String[] getNextCalendarAlarm(long lookahead, String[] calendars, boolean remindersOnly) { long now = System.currentTimeMillis(); long later = now + lookahead; StringBuilder where = new StringBuilder(); if (remindersOnly) { where.append(CalendarContract.Events.HAS_ALARM + "=1"); } if (calendars != null && calendars.length > 0) { if (remindersOnly) { where.append(" AND "); } where.append(CalendarContract.Events.CALENDAR_ID + " in ("); for (int i = 0; i < calendars.length; i++) { where.append(calendars[i]); if (i != calendars.length - 1) { where.append(","); } } where.append(") "); } // Projection array String[] projection = new String[] { CalendarContract.Events.TITLE, CalendarContract.Instances.BEGIN, CalendarContract.Events.DESCRIPTION, CalendarContract.Events.EVENT_LOCATION, CalendarContract.Events.ALL_DAY }; // The indices for the projection array int TITLE_INDEX = 0; int BEGIN_TIME_INDEX = 1; int DESCRIPTION_INDEX = 2; int LOCATION_INDEX = 3; int ALL_DAY_INDEX = 4; Uri uri = Uri.withAppendedPath(CalendarContract.Instances.CONTENT_URI, String.format("%d/%d", now, later)); String[] nextCalendarAlarm = new String[2]; Cursor cursor = null; try { cursor = mContentResolver.query(uri, projection, where.toString(), null, "begin ASC"); if (cursor != null && cursor.moveToFirst()) { String title = cursor.getString(TITLE_INDEX); long begin = cursor.getLong(BEGIN_TIME_INDEX); String description = cursor.getString(DESCRIPTION_INDEX); String location = cursor.getString(LOCATION_INDEX); boolean allDay = cursor.getInt(ALL_DAY_INDEX) != 0; // Check the next event in the case of all day event. As UTC is used for all day // events, the next event may be the one that actually starts sooner if (allDay && !cursor.isLast()) { cursor.moveToNext(); long nextBegin = cursor.getLong(BEGIN_TIME_INDEX); if (nextBegin < begin + TimeZone.getDefault().getOffset(begin)) { title = cursor.getString(TITLE_INDEX); begin = nextBegin; description = cursor.getString(DESCRIPTION_INDEX); location = cursor.getString(LOCATION_INDEX); allDay = cursor.getInt(ALL_DAY_INDEX) != 0; } } // Set the event title as the first array item nextCalendarAlarm[0] = title.toString(); // Start building the event details string // Starting with the date Date start = new Date(begin); StringBuilder sb = new StringBuilder(); if (allDay) { SimpleDateFormat sdf = new SimpleDateFormat( mContext.getString(R.string.abbrev_wday_month_day_no_year)); // Calendar stores all-day events in UTC -- setting the time zone ensures // the correct date is shown. sdf.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC)); sb.append(sdf.format(start)); } else { sb.append(DateFormat.format("E", start)); sb.append(" "); sb.append(DateFormat.getTimeFormat(mContext).format(start)); } // Add the event location if it should be shown int showLocation = Settings.System.getInt(mContext.getContentResolver(), Settings.System.LOCKSCREEN_CALENDAR_SHOW_LOCATION, 0); if (showLocation != 0 && !TextUtils.isEmpty(location)) { switch(showLocation) { case 1: // Show first line int end = location.indexOf('\n'); if(end == -1) { sb.append(": " + location); } else { sb.append(": " + location.substring(0, end)); } break; case 2: // Show all sb.append(": " + location); break; } } // Add the event description if it should be shown int showDescription = Settings.System.getInt(mContext.getContentResolver(), Settings.System.LOCKSCREEN_CALENDAR_SHOW_DESCRIPTION, 0); if (showDescription != 0 && !TextUtils.isEmpty(description)) { // Show the appropriate separator if (showLocation == 0) { sb.append(": "); } else { sb.append(" - "); } switch(showDescription) { case 1: // Show first line int end = description.indexOf('\n'); if(end == -1) { sb.append(description); } else { sb.append(description.substring(0, end)); } break; case 2: // Show all sb.append(description); break; } } // Set the time, location and description as the second array item nextCalendarAlarm[1] = sb.toString(); } } catch (Exception e) { // Do nothing } finally { if (cursor != null) { cursor.close(); } } return nextCalendarAlarm; } private boolean getBoolean(String secureSettingKey, boolean defaultValue) { return 1 == android.provider.Settings.Secure.getInt(mContentResolver, secureSettingKey, Loading