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

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

Merge "Lockscreen calendar improvements (1/2)" into gingerbread

parents cdf58ac3 0a041697
Loading
Loading
Loading
Loading
+106 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The CyanogenMod 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 android.preference;

import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.AttributeSet;

public class MultiSelectListPreference extends ListPreference {

    private static final String SEPARATOR = "OV=I=XseparatorX=I=VO";

    private boolean[] mClickedDialogEntryIndices;

    public MultiSelectListPreference(Context context) {
        super(context);
    }

    public MultiSelectListPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onPrepareDialogBuilder(Builder builder) {
        CharSequence[] entries = getEntries();
        CharSequence[] entryValues = getEntryValues();

        if (entries == null || entryValues == null || entries.length != entryValues.length) {
            throw new IllegalStateException(
                    this.getClass().getSimpleName()
                            + " requires an entries array and an entryValues array which are both the same length");
        }

        mClickedDialogEntryIndices = new boolean[entryValues.length];
        restoreCheckedEntries();
        builder.setMultiChoiceItems(entries, mClickedDialogEntryIndices, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                mClickedDialogEntryIndices[which] = isChecked;
            }
        });
    }

    public static String[] parseStoredValue(CharSequence val) {
        if (TextUtils.isEmpty(val)) {
            return null;
        } else {
            return val.toString().split(SEPARATOR);
        }
    }

    private void restoreCheckedEntries() {
        CharSequence[] entryValues = getEntryValues();

        String[] vals = parseStoredValue(getValue());
        if (vals != null) {
            for (String val : vals) {
                for (int i = 0; i < entryValues.length; i++) {
                    CharSequence entry = entryValues[i];
                    if (entry.equals(val)) {
                        mClickedDialogEntryIndices[i] = true;
                        break;
                    }
                }
            }
        }
    }

    @Override
    protected void onDialogClosed(boolean positiveResult) {
        CharSequence[] entryValues = getEntryValues();

        if (positiveResult && entryValues != null) {
            StringBuilder value = new StringBuilder();
            for (int i = 0; i < entryValues.length; i++) {
                if (mClickedDialogEntryIndices[i]) {
                    if (value.length() > 0) {
                        value.append(SEPARATOR);
                    }
                    value.append(entryValues[i]);
                }
            }

            String val = value.toString();
            if (callChangeListener(val)) {
                setValue(val);
            }
        }
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -2626,6 +2626,24 @@ public final class Settings {
         */
        public static final String LOCKSCREEN_CALENDAR_ALARM = "lockscreen_calendar_alarm";

        /**
         * 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";

        /**
         * Whether to use lockscreen music controls
         * @hide
+23 −8
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.widget.Button;

import com.android.internal.R;
import com.android.internal.telephony.ITelephony;

import com.google.android.collect.Lists;

import java.io.File;
@@ -100,11 +101,6 @@ 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;
@@ -715,15 +711,34 @@ public class LockPatternUtils {
     * (for showing on the lock screen), or null if there is no next event
     * within a certain look-ahead time.
     */
    public String getNextCalendarAlarm() {
    public String getNextCalendarAlarm(long lookahead, String[] calendars,
            boolean remindersOnly) {
        long now = System.currentTimeMillis();
        long lookahead = now + LOOK_AHEAD_MILLIS;
        long later = now + lookahead;

        StringBuilder where = new StringBuilder();
        if (remindersOnly) {
            where.append(Calendar.EventsColumns.HAS_ALARM + "=1");
        }
        if (calendars != null && calendars.length > 0) {
            if (remindersOnly) {
                where.append(" AND ");
            }
            where.append(Calendar.EventsColumns.CALENDAR_ID + " in (");
            for (int i = 0; i < calendars.length; i++) {
                where.append(calendars[i]);
                if (i != calendars.length - 1) {
                    where.append(",");
                }
            }
            where.append(") ");
        }
        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);
            }, now, later, where.toString(), null);
            if (cursor.moveToFirst()) {
                String title = cursor.getString(0);
                Date start = new Date(cursor.getLong(1));
+12 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.os.ParcelFileDescriptor;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Vibrator;
import android.preference.MultiSelectListPreference;
import android.provider.Settings;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
@@ -152,6 +153,15 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM
    private boolean mLockCalendarAlarm = (Settings.System.getInt(mContext.getContentResolver(),
            Settings.System.LOCKSCREEN_CALENDAR_ALARM, 0) == 1);

    private String[] mCalendars = MultiSelectListPreference.parseStoredValue(Settings.System.getString(
            mContext.getContentResolver(), Settings.System.LOCKSCREEN_CALENDARS));

    private boolean mLockCalendarRemindersOnly = (Settings.System.getInt(mContext.getContentResolver(),
            Settings.System.LOCKSCREEN_CALENDAR_REMINDERS_ONLY, 0) == 1);

    private long mLockCalendarLookahead = Settings.System.getLong(mContext.getContentResolver(),
            Settings.System.LOCKSCREEN_CALENDAR_LOOKAHEAD, 10800000);

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

@@ -788,7 +798,8 @@ class LockScreen extends LinearLayout implements KeyguardScreen, KeyguardUpdateM
    private void refreshAlarmDisplay() {
        mNextAlarm = mLockPatternUtils.getNextAlarm();
        if (mNextAlarm == null && mLockCalendarAlarm) {
            mNextAlarm = mLockPatternUtils.getNextCalendarAlarm();
            mNextAlarm = mLockPatternUtils.getNextCalendarAlarm(mLockCalendarLookahead,
                    mCalendars, mLockCalendarRemindersOnly);
        }
        if (mNextAlarm != null) {
            mAlarmIcon = getContext().getResources().getDrawable(R.drawable.ic_lock_idle_alarm);