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

Commit 16398c9c authored by Michael Jurka's avatar Michael Jurka
Browse files

UI refinements to security screen widgets interface

Bug #7158868

Change-Id: Ia5be3986323119ea78b9e486b4d2e6e81bf145e7
parent 8bea3c3f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -17,9 +17,9 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:gravity="center_vertical"
    android:drawablePadding="14dip"
    android:paddingStart="15dip"
    android:paddingEnd="15dip" />
    android:drawablePadding="8dip"
    android:paddingStart="11dip"
    android:paddingEnd="11dip" />
+2 −2
Original line number Diff line number Diff line
@@ -807,8 +807,8 @@
    <!--  String to display if there is no user-selected widget on lock screen [CHAR LIMIT=22] -->
    <string name="widget_none">None</string>

    <!--  String to display if the default status widget is selected [CHAR LIMIT=22] -->
    <string name="widget_default">Default</string>
    <!--  String to display if the clock status widget is selected (it is the default) [CHAR LIMIT=22] -->
    <string name="widget_default">Clock</string>

    <!--  Title for PreferenceScreen to change security method: None/Pattern/PIN/Password [CHAR LIMIT=22] -->
    <string name="unlock_set_unlock_launch_picker_change_title">Change lock screen</string>
+46 −16
Original line number Diff line number Diff line
@@ -21,17 +21,20 @@ import android.appwidget.AppWidgetProviderInfo;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.os.SystemProperties;
import android.util.DisplayMetrics;
import android.util.Log;

import java.text.Collator;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Displays a list of {@link AppWidgetProviderInfo} widgets, along with any
@@ -49,6 +52,7 @@ public class AppWidgetPickActivity extends ActivityPicker {

    private PackageManager mPackageManager;
    private AppWidgetManager mAppWidgetManager;
    List<PickAdapter.Item> mItems;
    
    /**
     * The allocated {@link AppWidgetManager#EXTRA_APPWIDGET_ID} that this
@@ -143,11 +147,10 @@ public class AppWidgetPickActivity extends ActivityPicker {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        Intent intent = getIntentForPosition(which);
        PickAdapter.Item item = (PickAdapter.Item) mItems.get(which);

        int result;
        if (intent.getExtras() != null && 
                (intent.getExtras().containsKey(AppWidgetManager.EXTRA_CUSTOM_INFO) ||
                 intent.getExtras().containsKey(AppWidgetManager.EXTRA_CUSTOM_EXTRAS))) {
        if (item.extras != null) {
            // If these extras are present it's because this entry is custom.
            // Don't try to bind it, just pass it back to the app.
            setResultData(RESULT_OK, intent);
@@ -185,11 +188,47 @@ public class AppWidgetPickActivity extends ActivityPicker {
        for (int i = 0; i < size; i++) {
            AppWidgetProviderInfo info = appWidgets.get(i);

            // We remove any widgets whose category isn't included in the filter
            if (!ignoreFilters && (info.widgetCategory & categoryFilter) == 0) {
                continue;
            }

            // We remove any widgets who don't have all the features in the features filter
            if (!ignoreFilters && (info.widgetFeatures & featuresFilter) != featuresFilter) {
                continue;
            }

            CharSequence label = info.label;
            Drawable icon = null;

            if (info.icon != 0) {
                icon = mPackageManager.getDrawable(info.provider.getPackageName(), info.icon, null);
                try {
                    final Resources res = getResources();
                    final int density = res.getDisplayMetrics().densityDpi;
                    int iconDensity;
                    switch (density) {
                        case DisplayMetrics.DENSITY_MEDIUM:
                            iconDensity = DisplayMetrics.DENSITY_LOW;
                        case DisplayMetrics.DENSITY_TV:
                            iconDensity = DisplayMetrics.DENSITY_MEDIUM;
                        case DisplayMetrics.DENSITY_HIGH:
                            iconDensity = DisplayMetrics.DENSITY_MEDIUM;
                        case DisplayMetrics.DENSITY_XHIGH:
                            iconDensity = DisplayMetrics.DENSITY_HIGH;
                        case DisplayMetrics.DENSITY_XXHIGH:
                            iconDensity = DisplayMetrics.DENSITY_XHIGH;
                        default:
                            // The density is some abnormal value.  Return some other
                            // abnormal value that is a reasonable scaling of it.
                            iconDensity = (int)((density*0.75f)+.5f);
                    }
                    Resources packageResources = mPackageManager.
                            getResourcesForApplication(info.provider.getPackageName());
                    icon = packageResources.getDrawableForDensity(info.icon, iconDensity);
                } catch (NameNotFoundException e) {
                    Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
                            + " for provider: " + info.provider);
                }
                if (icon == null) {
                    Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
                            + " for provider: " + info.provider);
@@ -205,16 +244,6 @@ public class AppWidgetPickActivity extends ActivityPicker {
                item.extras = customExtras.get(i);
            }

            // We remove any widgets whose category isn't included in the filter
            if (!ignoreFilters && (info.widgetCategory & categoryFilter) == 0) {
                continue;
            }

            // We remove any widgets who don't have all the features in the features filter
            if (!ignoreFilters && (info.widgetFeatures & featuresFilter) != featuresFilter) {
                continue;
            }

            items.add(item);
        }
    }
@@ -259,8 +288,9 @@ public class AppWidgetPickActivity extends ActivityPicker {
        if (!sortCustomAppWidgets) {
            List<PickAdapter.Item> customItems = new ArrayList<PickAdapter.Item>();
            putCustomAppWidgets(customItems);
            items.addAll(0, customItems);
            items.addAll(customItems);
        }
        mItems = items;
        return items;
    }

+51 −65
Original line number Diff line number Diff line
@@ -475,26 +475,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
        }
    }

    private Intent getBaseIntent() {
        Intent baseIntent = new Intent(Intent.ACTION_MAIN, null);
        baseIntent.addCategory(Intent.CATEGORY_DEFAULT);

        Bundle options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
        baseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
        return baseIntent;
    }

    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        final String key = preference.getKey();

        final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
        if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
            startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
                    SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
        } else if (KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET.equals(key)) {
    private void launchPickActivityIntent(int featuresFilter, int defaultLabelId, int defaultIconId,
            ComponentName defaultComponentName, String defaultTag) {
        // Create intent to pick widget
        Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);

@@ -506,17 +488,21 @@ public class SecuritySettings extends SettingsPreferenceFragment
            pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, false);
            pickIntent.putExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER,
                    AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
            if (featuresFilter != AppWidgetProviderInfo.WIDGET_FEATURES_NONE) {
                pickIntent.putExtra(AppWidgetManager.EXTRA_FEATURES_FILTER, featuresFilter);
            }

            // Add an entry for "none" to let someone select no widget
                AppWidgetProviderInfo noneInfo = new AppWidgetProviderInfo();
            AppWidgetProviderInfo defaultInfo = new AppWidgetProviderInfo();
            ArrayList<AppWidgetProviderInfo> extraInfos = new ArrayList<AppWidgetProviderInfo>();
                noneInfo.label = getResources().getString(R.string.widget_none);
                noneInfo.provider = new ComponentName("", "");
                extraInfos.add(noneInfo);
            defaultInfo.label = getResources().getString(defaultLabelId);
            defaultInfo.icon = defaultIconId;
            defaultInfo.provider = defaultComponentName;
            extraInfos.add(defaultInfo);

            ArrayList<Bundle> extraExtras = new ArrayList<Bundle>();
            Bundle b = new Bundle();
                b.putBoolean(EXTRA_NO_WIDGET, true);
            b.putBoolean(defaultTag, true);
            extraExtras.add(b);

            // Launch the widget picker
@@ -527,41 +513,41 @@ public class SecuritySettings extends SettingsPreferenceFragment
        } else {
            Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");
        }
        } else if (KEY_CHOOSE_LOCKSCREEN_STATUS_WIDGET.equals(key)) {
            // Create intent to pick widget
            Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
    }

            // Found in KeyguardHostView.java
            final int KEYGUARD_HOST_ID = 0x4B455947;
            int appWidgetId = AppWidgetHost.allocateAppWidgetIdForSystem(KEYGUARD_HOST_ID);
            if (appWidgetId != -1) {
                pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_SORT, false);
                pickIntent.putExtra(AppWidgetManager.EXTRA_CATEGORY_FILTER,
                        AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
                pickIntent.putExtra(AppWidgetManager.EXTRA_FEATURES_FILTER,
                        AppWidgetProviderInfo.WIDGET_FEATURES_STATUS);
    private Intent getBaseIntent() {
        Intent baseIntent = new Intent(Intent.ACTION_MAIN, null);
        baseIntent.addCategory(Intent.CATEGORY_DEFAULT);

                // Add an entry for "none" to let someone select no widget
                AppWidgetProviderInfo noneInfo = new AppWidgetProviderInfo();
                ArrayList<AppWidgetProviderInfo> extraInfos = new ArrayList<AppWidgetProviderInfo>();
                noneInfo.label = getResources().getString(R.string.widget_default);
                noneInfo.provider = new ComponentName("", "");
                extraInfos.add(noneInfo);
        Bundle options = new Bundle();
        options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
                AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD);
        baseIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
        return baseIntent;
    }

                ArrayList<Bundle> extraExtras = new ArrayList<Bundle>();
                Bundle b = new Bundle();
                b.putBoolean(EXTRA_DEFAULT_WIDGET, true);
                extraExtras.add(b);
    @Override
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
        final String key = preference.getKey();

                // Launch the widget picker
                pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos);
                pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras);
                pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent());
                startActivityForResult(pickIntent, REQUEST_PICK_STATUS_APPWIDGET);
            } else {
                Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");
        final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
        if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
            startFragment(this, "com.android.settings.ChooseLockGeneric$ChooseLockGenericFragment",
                    SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
        } else if (KEY_CHOOSE_USER_SELECTED_LOCKSCREEN_WIDGET.equals(key)) {
            launchPickActivityIntent(AppWidgetProviderInfo.WIDGET_FEATURES_NONE,
                    R.string.widget_none, 0, new ComponentName("", ""), EXTRA_NO_WIDGET);
        } else if (KEY_CHOOSE_LOCKSCREEN_STATUS_WIDGET.equals(key)) {
            int defaultIconId;
            ComponentName clock = new ComponentName(
                    "com.google.android.deskclock", "com.android.deskclock.DeskClock");
            try {
                defaultIconId = getActivity().getPackageManager().getActivityInfo(clock, 0).icon;
            } catch (PackageManager.NameNotFoundException e) {
                defaultIconId = 0;
            }
            launchPickActivityIntent(AppWidgetProviderInfo.WIDGET_FEATURES_STATUS,
                    R.string.widget_default, defaultIconId, clock, EXTRA_DEFAULT_WIDGET);
        } else if (KEY_BIOMETRIC_WEAK_IMPROVE_MATCHING.equals(key)) {
            ChooseLockSettingsHelper helper =
                    new ChooseLockSettingsHelper(this.getActivity(), this);