OSDN Git Service

Fixes for ChooserTargetActivity
authorAdam Powell <adamp@google.com>
Thu, 23 Apr 2015 19:22:20 +0000 (12:22 -0700)
committerAdam Powell <adamp@google.com>
Thu, 23 Apr 2015 21:29:30 +0000 (14:29 -0700)
* Always ensure intent filter is supplied to a ChooserTargetService.
* Add and clarify docs for ChooserTarget constructors.
* Fix a bug where ChooserTargets were being parceled incorrectly.

Change-Id: I32b70c424b0e6bb317e2eeb810566a30c21b9d53

core/java/android/service/chooser/ChooserTarget.java
core/java/com/android/internal/app/ChooserActivity.java
core/java/com/android/internal/app/ResolverActivity.java

index d21cc3c..f0ca276 100644 (file)
@@ -78,7 +78,8 @@ public final class ChooserTarget implements Parcelable {
      * <p>The creator of a target may supply a ranking score. This score is assumed to be relative
      * to the other targets supplied by the same
      * {@link ChooserTargetService#onGetChooserTargets(ComponentName, IntentFilter) query}.
-     * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).</p>
+     * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).
+     * Scores for a set of targets do not need to sum to 1.</p>
      *
      * <p>Before being sent, the PendingIntent supplied will be
      * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied
@@ -113,7 +114,8 @@ public final class ChooserTarget implements Parcelable {
      * <p>The creator of a target may supply a ranking score. This score is assumed to be relative
      * to the other targets supplied by the same
      * {@link ChooserTargetService#onGetChooserTargets(ComponentName, IntentFilter) query}.
-     * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).</p>
+     * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).
+     * Scores for a set of targets do not need to sum to 1.</p>
      *
      * <p>Before being sent, the IntentSender supplied will be
      * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied
@@ -144,6 +146,32 @@ public final class ChooserTarget implements Parcelable {
         mIntentSender = intentSender;
     }
 
+    /**
+     * Construct a deep link target for presentation by a chooser UI.
+     *
+     * <p>A target is composed of a title and an icon for presentation to the user.
+     * The UI presenting this target may truncate the title if it is too long to be presented
+     * in the available space, as well as crop, resize or overlay the supplied icon.</p>
+     *
+     * <p>The creator of a target may supply a ranking score. This score is assumed to be relative
+     * to the other targets supplied by the same
+     * {@link ChooserTargetService#onGetChooserTargets(ComponentName, IntentFilter) query}.
+     * Scores should be in the range from 0.0f (unlikely match) to 1.0f (very relevant match).
+     * Scores for a set of targets do not need to sum to 1.</p>
+     *
+     * <p>Before being sent, the Intent supplied will be
+     * {@link Intent#fillIn(Intent, int) filled in} by the Intent originally supplied
+     * to the chooser.</p>
+     *
+     * <p>Take care not to place custom {@link android.os.Parcelable} types into
+     * the Intent as extras, as the system will not be able to unparcel it to merge
+     * additional extras.</p>
+     *
+     * @param title title of this target that will be shown to a user
+     * @param icon icon to represent this target
+     * @param score ranking score for this target between 0.0f and 1.0f, inclusive
+     * @param intent Intent to fill in and send if the user chooses this target
+     */
     public ChooserTarget(CharSequence title, Bitmap icon, float score, Intent intent) {
         mTitle = title;
         mIcon = icon;
@@ -358,6 +386,10 @@ public final class ChooserTarget implements Parcelable {
         }
         dest.writeFloat(mScore);
         IntentSender.writeIntentSenderOrNullToParcel(mIntentSender, dest);
+        dest.writeInt(mIntent != null ? 1 : 0);
+        if (mIntent != null) {
+            mIntent.writeToParcel(dest, 0);
+        }
     }
 
     public static final Creator<ChooserTarget> CREATOR
index 8403e77..a6c39e6 100644 (file)
@@ -401,6 +401,11 @@ public class ChooserActivity extends ResolverActivity {
         }
 
         @Override
+        public boolean shouldGetResolvedFilter() {
+            return true;
+        }
+
+        @Override
         public int getCount() {
             int count = super.getCount();
             if (mServiceTargets != null) {
index 3cd69a1..7f51d92 100644 (file)
@@ -1062,7 +1062,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
             } else {
                 currentResolveList = mOrigResolveList = mPm.queryIntentActivities(mIntent,
                         PackageManager.MATCH_DEFAULT_ONLY
-                        | (mFilterLastUsed ? PackageManager.GET_RESOLVED_FILTER : 0)
+                        | (shouldGetResolvedFilter() ? PackageManager.GET_RESOLVED_FILTER : 0)
                         | (shouldGetActivityMetadata() ? PackageManager.GET_META_DATA : 0)
                 );
                 // Filter out any activities that the launched uid does not
@@ -1188,6 +1188,10 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
             // This space for rent
         }
 
+        public boolean shouldGetResolvedFilter() {
+            return mFilterLastUsed;
+        }
+
         private void processGroup(List<ResolveInfo> rList, int start, int end, ResolveInfo ro,
                 CharSequence roLabel) {
             // Process labels from start to i