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

Commit 147dfc86 authored by Michael Jurka's avatar Michael Jurka Committed by Android (Google) Code Review
Browse files

Merge "Adding ability to add multiple widgets to keyguard" into jb-mr1-lockscreen-dev

parents db3efba6 aa2859ae
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -3221,19 +3221,12 @@ public final class Settings {
         */
        public static final String LOCK_SCREEN_OWNER_INFO = "lock_screen_owner_info";

        /**
         * Id of the time appwidget on the lockscreen, or -1 if none
         * @hide
         */
        public static final String LOCK_SCREEN_STATUS_APPWIDGET_ID =
            "lock_screen_status_appwidget_id";

        /**
         * Id of the user-selected appwidget on the lockscreen, or -1 if none
         * @hide
         */
        public static final String LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID =
            "lock_screen_user_selected_appwidget_id";
        public static final String LOCK_SCREEN_APPWIDGET_IDS =
            "lock_screen_appwidget_ids";

        /**
         * This preference enables showing the owner info on LockScren.
+91 −14
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -43,9 +42,12 @@ import android.util.Log;
import android.view.View;
import android.widget.Button;

import org.apache.harmony.kernel.vm.StringUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;

/**
@@ -1045,28 +1047,103 @@ public class LockPatternUtils {
        }
    }

    public int[] getUserDefinedWidgets() {
        int appWidgetId = -1;
    public int[] getAppWidgets() {
        String appWidgetIdString = Settings.Secure.getStringForUser(
                mContentResolver, Settings.Secure.LOCK_SCREEN_USER_SELECTED_APPWIDGET_ID,
                mContentResolver, Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS,
                UserHandle.USER_CURRENT);
        String delims = ",";
        if (appWidgetIdString != null) {
            appWidgetId = (int) Integer.decode(appWidgetIdString);
            String[] appWidgetStringIds = appWidgetIdString.split(delims);
            int[] appWidgetIds = new int[appWidgetStringIds.length];
            for (int i = 0; i < appWidgetStringIds.length; i++) {
                String appWidget = appWidgetStringIds[i];
                try {
                    appWidgetIds[i] = Integer.decode(appWidget);
                } catch (NumberFormatException e) {
                    return null;
                }
            }
            return appWidgetIds;
        }
        return new int[0];
    }

    private static String combineStrings(int[] list, String separator) {
        int listLength = list.length;

        return new int[] { appWidgetId };
        switch (listLength) {
            case 0: {
                return "";
            }
            case 1: {
                return Integer.toString(list[0]);
            }
        }

    public int getStatusWidget() {
        int appWidgetId = -1;
        String appWidgetIdString = Settings.Secure.getStringForUser(
                mContentResolver, Settings.Secure.LOCK_SCREEN_STATUS_APPWIDGET_ID,
        int strLength = 0;
        int separatorLength = separator.length();

        String[] stringList = new String[list.length];
        for (int i = 0; i < listLength; i++) {
            stringList[i] = Integer.toString(list[i]);
            strLength += stringList[i].length();
            if (i < listLength - 1) {
                strLength += separatorLength;
            }
        }

        StringBuilder sb = new StringBuilder(strLength);

        for (int i = 0; i < listLength; i++) {
            sb.append(list[i]);
            if (i < listLength - 1) {
                sb.append(separator);
            }
        }

        return sb.toString();
    }

    private void writeAppWidgets(int[] appWidgetIds) {
        Settings.Secure.putString(mContentResolver,
        Settings.Secure.putStringForUser(mContentResolver,
                        Settings.Secure.LOCK_SCREEN_APPWIDGET_IDS,
                        combineStrings(appWidgetIds, ","),
                        UserHandle.USER_CURRENT);
        if (appWidgetIdString != null) {
            appWidgetId = (int) Integer.decode(appWidgetIdString);
    }

        return appWidgetId;
    public void addAppWidget(int widgetId, int index) {
        int[] widgets = getAppWidgets();
        int[] newWidgets = new int[widgets.length + 1];
        for (int i = 0, j = 0; i < newWidgets.length; i++) {
            if (index == i) {
                newWidgets[i] = widgetId;
                i++;
            }
            if (i < newWidgets.length) {
                newWidgets[i] = widgets[j];
                j++;
            }
        }
        writeAppWidgets(newWidgets);
    }

    public boolean removeAppWidget(int widgetId, int index) {
        int[] widgets = getAppWidgets();
        int[] newWidgets = new int[widgets.length - 1];
        for (int i = 0, j = 0; i < widgets.length; i++) {
            if (index == i) {
                if (widgets[i] != widgetId) {
                    return false;
                }
                // continue...
            } else {
                newWidgets[j] = widgets[i];
                j++;
            }
        }
        writeAppWidgets(newWidgets);
        return true;
    }

    private long getLong(String secureSettingKey, long defaultValue) {
+11 −7
Original line number Diff line number Diff line
@@ -955,7 +955,10 @@ public class KeyguardHostView extends KeyguardViewBase {
        }

        // Add user-selected widget
        final int[] widgets = mLockPatternUtils.getUserDefinedWidgets();
        final int[] widgets = mLockPatternUtils.getAppWidgets();
        if (widgets == null) {
            Log.d(TAG, "Problem reading widgets");
        } else {
            for (int i = widgets.length -1; i >= 0; i--) {
                if (widgets[i] != -1) {
                    // We add the widgets from left to right, starting after the first page after
@@ -965,6 +968,7 @@ public class KeyguardHostView extends KeyguardViewBase {
                }
            }
        }
    }

    Runnable mSwitchPageRunnable = new Runnable() {
        @Override