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

Commit cdf58ac3 authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Lockscreen next calendar alarm (1/2)" into gingerbread

parents 461efa38 3c19ec41
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2620,6 +2620,12 @@ public final class Settings {
         */
        public static final String LOCKSCREEN_ALWAYS_BATTERY = "lockscreen_always_battery";

        /**
         * Whether to show the next calendar event
         * @hide
         */
        public static final String LOCKSCREEN_CALENDAR_ALARM = "lockscreen_calendar_alarm";

        /**
         * Whether to use lockscreen music controls
         * @hide
+43 −1
Original line number Diff line number Diff line
@@ -19,14 +19,17 @@ package com.android.internal.widget;
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.FileObserver;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.provider.Calendar;
import android.provider.Settings;
import android.security.MessageDigest;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.widget.Button;

@@ -41,6 +44,7 @@ import java.io.RandomAccessFile;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

@@ -96,6 +100,11 @@ public class LockPatternUtils {
    public final static String PASSWORD_TYPE_KEY = "lockscreen.password_type";
    private final static String LOCK_PASSWORD_SALT_KEY = "lockscreen.password_salt";

    /**
     * The time in milliseconds to look ahead for calendar events.
     */
    private final static long LOOK_AHEAD_MILLIS = 86400000; // 24 hours

    private final Context mContext;
    private final ContentResolver mContentResolver;
    private DevicePolicyManager mDevicePolicyManager;
@@ -701,6 +710,39 @@ 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 now = System.currentTimeMillis();
        long lookahead = now + LOOK_AHEAD_MILLIS;
        String nextCalendarAlarm = null;
        Cursor cursor = null;
        try {
            cursor = Calendar.Instances.query(mContentResolver, new String[] {
                    Calendar.EventsColumns.TITLE, Calendar.EventsColumns.DTSTART
            }, now, lookahead, Calendar.EventsColumns.HAS_ALARM + "=1", null);
            if (cursor.moveToFirst()) {
                String title = cursor.getString(0);
                Date start = new Date(cursor.getLong(1));
                StringBuilder sb = new StringBuilder();
                sb.append(DateFormat.format("E", start));
                sb.append(" ");
                sb.append(DateFormat.getTimeFormat(mContext).format(start));
                sb.append(" ");
                sb.append(title);
                nextCalendarAlarm = sb.toString();
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        return nextCalendarAlarm;
    }

    private boolean getBoolean(String secureSettingKey) {
        return 1 ==
                android.provider.Settings.Secure.getInt(mContentResolver, secureSettingKey, 0);
+6 −0
Original line number Diff line number Diff line
@@ -149,6 +149,9 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM
    private boolean mLockAlwaysBattery = (Settings.System.getInt(mContext.getContentResolver(),
            Settings.System.LOCKSCREEN_ALWAYS_BATTERY, 0) == 1);

    private boolean mLockCalendarAlarm = (Settings.System.getInt(mContext.getContentResolver(),
            Settings.System.LOCKSCREEN_CALENDAR_ALARM, 0) == 1);

    private boolean mLockMusicControls = (Settings.System.getInt(mContext.getContentResolver(),
            Settings.System.LOCKSCREEN_MUSIC_CONTROLS, 1) == 1);

@@ -784,6 +787,9 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM

    private void refreshAlarmDisplay() {
        mNextAlarm = mLockPatternUtils.getNextAlarm();
        if (mNextAlarm == null && mLockCalendarAlarm) {
            mNextAlarm = mLockPatternUtils.getNextCalendarAlarm();
        }
        if (mNextAlarm != null) {
            mAlarmIcon = getContext().getResources().getDrawable(R.drawable.ic_lock_idle_alarm);
        }