Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1cc32aa authored by pragma78's avatar pragma78 Committed by Steve Kondik
Browse files

(1/2) Lockscreen calendar now supports all-day events, event description and...

(1/2) Lockscreen calendar now supports all-day events, event description and location, new calendar icon

* Lockscreen calendar now displays all-day events in correct timezone.
* All-day events display as localized "Thu Jul 4" instead of "Thu 5:00 PM" (date instead of time).
* Added event location and event description on newlines underneath title, if either are set.
  (Can toggle display by: Don't show; Show first line; Show all)
* Use calendar icon instead of alarm icon for calendar, and alarm icon for regular alarms.
* Adjusted lockscreen layout so widgets fit better:
  moved "now playing" to directly above music controls in portrait mode
  moved music controls to bottom left corner in landscape mode
  moved album art and "now playing" to right of music controls in landscape mode
  "now playing" text appears over tabs/rotary/rings widgets instead of behind
  album art resized smaller in landscape mode
* Music "Now playing" widget now appears correctly in landscape and portrait modes

Change-Id: I9f1c500fe5a2a5e84cedcee822b827a09e063f1c
parent d92ed76b
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -2656,6 +2656,18 @@ public final class Settings {
         */
        public static final String LOCKSCREEN_CALENDAR_ALARM = "lockscreen_calendar_alarm";

        /**
         * 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
+76 −8
Original line number Diff line number Diff line
@@ -44,10 +44,12 @@ import java.io.IOException;
import java.io.RandomAccessFile;
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.concurrent.atomic.AtomicBoolean;
import java.util.TimeZone;

/**
 * Utilities for the lock patten and its settings.
@@ -736,18 +738,84 @@ public class LockPatternUtils {
        String nextCalendarAlarm = null;
        Cursor cursor = null;
        try {
            cursor = Calendar.Instances.query(mContentResolver, new String[] {
                    Calendar.EventsColumns.TITLE, Calendar.EventsColumns.DTSTART
            }, now, later, where.toString(), null);
            cursor = Calendar.Instances.query(mContentResolver,
                    new String[] {
                        Calendar.EventsColumns.TITLE,
                        Calendar.EventsColumns.DTSTART,
                        Calendar.EventsColumns.DESCRIPTION,
                        Calendar.EventsColumns.EVENT_LOCATION,
                        Calendar.EventsColumns.ALL_DAY,
                    },
                    now,
                    later,
                    where.toString(),
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                String  title       = cursor.getString(0);
                Date    start       = new Date(cursor.getLong(1));
                String  description = cursor.getString(2);
                String  location    = cursor.getString(3);
                boolean allDay      = cursor.getInt(4) != 0;

                StringBuilder sb = new StringBuilder();

                if (allDay == true) {
                    SimpleDateFormat sdf = new SimpleDateFormat(mContext.getString(R.string.abbrev_wday_month_day_no_year));
                    // Calendar stores all-day events in UTC -- setting the timezone ensures
                    // the correct date is shown.
                    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
                    sb.append(sdf.format(start));
                } else {
                    sb.append(DateFormat.format("E", start));
                    sb.append(" ");
                    sb.append(DateFormat.getTimeFormat(mContext).format(start));
                }

                sb.append(" ");
                sb.append(title);

                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("\n" + location);
                            } else {
                                sb.append("\n" + location.substring(0, end));
                            }
                            break;
                        case 2:
                            // Show all
                            sb.append("\n" + location);
                            break;
                    }
                }

                int showDescription = Settings.System.getInt(mContext.getContentResolver(),
                            Settings.System.LOCKSCREEN_CALENDAR_SHOW_DESCRIPTION, 0);

                if (showDescription != 0 && !TextUtils.isEmpty(description)) {
                    switch(showDescription) {
                        case 1:
                            // Show first line
                            int end = description.indexOf('\n');
                            if(end == -1) {
                                sb.append("\n" + description);
                            } else {
                                sb.append("\n" + description.substring(0, end));
                            }
                            break;
                        case 2:
                            // Show all
                            sb.append("\n" + description);
                            break;
                    }
                }

                nextCalendarAlarm = sb.toString();
            }
        } finally {
+1.69 KiB
Loading image diff...
+1.27 KiB
Loading image diff...
+3.49 KiB
Loading image diff...
Loading