OSDN Git Service

Use new keyguard appwidget picker
authorMichael Jurka <mikejurka@google.com>
Wed, 31 Oct 2012 01:30:52 +0000 (18:30 -0700)
committerMichael Jurka <mikejurka@google.com>
Wed, 31 Oct 2012 23:53:04 +0000 (16:53 -0700)
Also, remove ability to filter widgets by feature
in appwidget picker in anticipation of api change

Change-Id: I325de0b98f03d3a250758d504229ea27794b5330

core/java/android/appwidget/AppWidgetManager.java
core/java/com/android/internal/widget/LockPatternUtils.java
core/res/AndroidManifest.xml
core/res/res/values/strings.xml
core/res/res/values/symbols.xml
policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

index 2af65b9..3dd640c 100644 (file)
@@ -80,6 +80,13 @@ public class AppWidgetManager {
     public static final String ACTION_APPWIDGET_PICK = "android.appwidget.action.APPWIDGET_PICK";
 
     /**
+     * Similar to ACTION_APPWIDGET_PICK, but used from keyguard
+     * @hide
+     */
+    public static final String
+            ACTION_KEYGUARD_APPWIDGET_PICK = "android.appwidget.action.KEYGUARD_APPWIDGET_PICK";
+
+    /**
      * Send this from your {@link AppWidgetHost} activity when you want to bind an AppWidget to
      * display and bindAppWidgetIdIfAllowed returns false.
      * <p>
@@ -224,13 +231,6 @@ public class AppWidgetManager {
     public static final String EXTRA_CATEGORY_FILTER = "categoryFilter";
 
     /**
-     * An intent extra to pass to the AppWidget picker which allows the picker to filter
-     * the list based on the {@link AppWidgetProviderInfo#widgetFeatures}.
-     * @hide
-     */
-    public static final String EXTRA_FEATURES_FILTER = "featuresFilter";
-
-    /**
      * An intent extra to pass to the AppWidget picker to specify whether or not to sort
      * the list of caller-specified extra AppWidgets along with the rest of the AppWidgets
      * @hide
index f8c3b4d..3ee3c8c 100644 (file)
@@ -129,6 +129,11 @@ public class LockPatternUtils {
      */
     public static final int ID_DEFAULT_STATUS_WIDGET = -2;
 
+    /**
+     * Intent extra that's used to tag the default widget when using the picker
+     */
+    public static final String EXTRA_DEFAULT_WIDGET = "com.android.settings.DEFAULT_WIDGET";
+
     protected final static String LOCKOUT_PERMANENT_KEY = "lockscreen.lockedoutpermanently";
     protected final static String LOCKOUT_ATTEMPT_DEADLINE = "lockscreen.lockoutattemptdeadline";
     protected final static String PATTERN_EVER_CHOSEN_KEY = "lockscreen.patterneverchosen";
index 92aa06a..a5aa713 100644 (file)
         android:description="@string/permdesc_bindGadget"
         android:protectionLevel="signature|system" />
 
+    <!-- Private permission, to restrict who can bring up a dialog to add a new
+         keyguard widget
+         @hide -->
+    <permission android:name="android.permission.BIND_KEYGUARD_APPWIDGET"
+        android:permissionGroup="android.permission-group.PERSONAL_INFO"
+        android:protectionLevel="signature|system" />
+
     <!-- Internal permission allowing an application to query/set which
          applications can bind AppWidgets.
          @hide -->
index a86405d..8f41a7a 100755 (executable)
     <!-- This can be used in any application wanting to disable the text "Emergency number" -->
     <string name="emergency_call_dialog_number_for_display">Emergency number</string>
 
+    <!-- String to display if the clock status widget is selected (it is the default) [CHAR LIMIT=22] -->
+    <string name="widget_default" msgid="8269383575996003796">Clock</string>
+
+    <!-- Package name for default widget [DO NOT TRANSLATE] -->
+    <string name="widget_default_package_name">com.android.deskclock</string>
+
+    <!-- Class name for default widget [DO NOT TRANSLATE] -->
+    <string name="widget_default_class_name">com.android.deskclock.DeskClock</string>
+
     <!--
        *** touch based lock / unlock ***
                                           --> <skip />
index 5a0088c..5af60c8 100644 (file)
   <java-symbol type="string" name="emailTypeOther" />
   <java-symbol type="string" name="emailTypeWork" />
   <java-symbol type="string" name="emergency_call_dialog_number_for_display" />
+  <java-symbol type="string" name="widget_default" />
+  <java-symbol type="string" name="widget_default_package_name" />
+  <java-symbol type="string" name="widget_default_class_name" />
   <java-symbol type="string" name="emergency_calls_only" />
   <java-symbol type="string" name="enable_accessibility_canceled" />
   <java-symbol type="string" name="eventTypeAnniversary" />
index 96cd7ac..3b2ded2 100644 (file)
@@ -25,19 +25,22 @@ import android.appwidget.AppWidgetHost;
 import android.appwidget.AppWidgetHostView;
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentSender;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
 import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Rect;
+import android.os.Bundle;
 import android.os.Looper;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.provider.Settings;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.util.Slog;
@@ -54,6 +57,7 @@ import com.android.internal.policy.impl.keyguard.KeyguardSecurityModel.SecurityM
 import com.android.internal.widget.LockPatternUtils;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 public class KeyguardHostView extends KeyguardViewBase {
@@ -880,14 +884,22 @@ public class KeyguardHostView extends KeyguardViewBase {
 
                     @Override
                     public void run() {
-                        Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
-                        intent.addFlags(
-                                Intent.FLAG_ACTIVITY_NEW_TASK
-                                | Intent.FLAG_ACTIVITY_SINGLE_TOP
-                                | Intent.FLAG_ACTIVITY_CLEAR_TOP
-                                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
-                        mContext.startActivityAsUser(intent,
-                                new UserHandle(UserHandle.USER_CURRENT));
+                        int defaultIconId = 0;
+                        Resources res = KeyguardHostView.this.getContext().getResources();
+                        ComponentName clock = new ComponentName(
+                                res.getString(R.string.widget_default_package_name),
+                                res.getString(R.string.widget_default_class_name));
+                        try {
+                            ActivityInfo activityInfo =
+                                    mContext.getPackageManager().getActivityInfo(clock, 0);
+                            if (activityInfo != null) {
+                                defaultIconId = activityInfo.icon;
+                            }
+                        } catch (PackageManager.NameNotFoundException e) {
+                            defaultIconId = 0;
+                        }
+                        launchPickActivityIntent(R.string.widget_default, defaultIconId, clock,
+                                LockPatternUtils.EXTRA_DEFAULT_WIDGET);
                     }
                 });
                 mCallback.dismiss(false);
@@ -898,6 +910,58 @@ public class KeyguardHostView extends KeyguardViewBase {
         initializeTransportControl();
     }
 
+    private void launchPickActivityIntent(int defaultLabelId, int defaultIconId,
+            ComponentName defaultComponentName, String defaultTag) {
+        // Create intent to pick widget
+        Intent pickIntent = new Intent(AppWidgetManager.ACTION_KEYGUARD_APPWIDGET_PICK);
+
+        int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+        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);
+
+            // Add an custom entry for the default
+            AppWidgetProviderInfo defaultInfo = new AppWidgetProviderInfo();
+            ArrayList<AppWidgetProviderInfo> extraInfos = new ArrayList<AppWidgetProviderInfo>();
+            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(defaultTag, true);
+            extraExtras.add(b);
+
+            // Launch the widget picker
+            pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_INFO, extraInfos);
+            pickIntent.putExtra(AppWidgetManager.EXTRA_CUSTOM_EXTRAS, extraExtras);
+            pickIntent.putExtra(Intent.EXTRA_INTENT, getBaseIntent());
+            pickIntent.addFlags(
+                    Intent.FLAG_ACTIVITY_NEW_TASK
+                    | Intent.FLAG_ACTIVITY_SINGLE_TOP
+                    | Intent.FLAG_ACTIVITY_CLEAR_TOP
+                    | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
+            mContext.startActivityAsUser(pickIntent,
+                    new UserHandle(UserHandle.USER_CURRENT));
+        } else {
+            Log.e(TAG, "Unable to allocate an AppWidget id in lock screen");
+        }
+    }
+
+    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;
+    }
+
     private void removeTransportFromWidgetPager() {
         int page = getWidgetPosition(R.id.keyguard_transport_control);
         if (page != -1) {