OSDN Git Service

Apply API feedback for ChooserTarget
authorAdam Powell <adamp@google.com>
Tue, 12 May 2015 21:43:56 +0000 (14:43 -0700)
committerAdam Powell <adamp@google.com>
Tue, 12 May 2015 22:06:24 +0000 (15:06 -0700)
* Add better docs to ChooserTarget
* Change ChooserTarget to use android.graphics.drawable.Icon instead
  of Bitmap
* Preserve EXTRA_REFERRER when starting ChooserTargets

Bug 21045119

Change-Id: If859b86344cebaed3eaae477af132e7d7600aba6

api/current.txt
api/system-current.txt
core/java/android/service/chooser/ChooserTarget.java
core/java/android/service/chooser/ChooserTargetService.java
core/java/com/android/internal/app/ChooserActivity.java

index 0782b39..664ae1b 100644 (file)
@@ -28634,10 +28634,10 @@ package android.service.carrier {
 package android.service.chooser {
 
   public final class ChooserTarget implements android.os.Parcelable {
-    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.app.PendingIntent);
-    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.content.IntentSender);
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.drawable.Icon, float, android.app.PendingIntent);
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.drawable.Icon, float, android.content.IntentSender);
     method public int describeContents();
-    method public android.graphics.Bitmap getIcon();
+    method public android.graphics.drawable.Icon getIcon();
     method public android.content.IntentSender getIntentSender();
     method public float getScore();
     method public java.lang.CharSequence getTitle();
index 9f5dbdd..6a0fb0c 100644 (file)
@@ -30657,10 +30657,10 @@ package android.service.carrier {
 package android.service.chooser {
 
   public final class ChooserTarget implements android.os.Parcelable {
-    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.app.PendingIntent);
-    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.Bitmap, float, android.content.IntentSender);
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.drawable.Icon, float, android.app.PendingIntent);
+    ctor public ChooserTarget(java.lang.CharSequence, android.graphics.drawable.Icon, float, android.content.IntentSender);
     method public int describeContents();
-    method public android.graphics.Bitmap getIcon();
+    method public android.graphics.drawable.Icon getIcon();
     method public android.content.IntentSender getIntentSender();
     method public float getScore();
     method public java.lang.CharSequence getTitle();
index 4c94ee7..50c435a 100644 (file)
@@ -25,6 +25,7 @@ import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.IntentSender;
 import android.graphics.Bitmap;
+import android.graphics.drawable.Icon;
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -34,6 +35,16 @@ import android.util.Log;
 /**
  * A ChooserTarget represents a deep-link into an application as returned by a
  * {@link android.service.chooser.ChooserTargetService}.
+ *
+ * <p>A chooser target represents a specific deep link target into an application exposed
+ * for selection by the user. This might be a frequently emailed contact, a recently active
+ * group messaging conversation, a folder in a cloud storage app, a collection of related
+ * items published on a social media service or any other contextually relevant grouping
+ * of target app + relevant metadata.</p>
+ *
+ * <p>Creators of chooser targets should consult the relevant design guidelines for the type
+ * of target they are presenting. For example, targets involving people should be presented
+ * with a circular icon.</p>
  */
 public final class ChooserTarget implements Parcelable {
     private static final String TAG = "ChooserTarget";
@@ -48,7 +59,7 @@ public final class ChooserTarget implements Parcelable {
      * The icon that will be shown to the user to represent this target.
      * The system may resize this icon as appropriate.
      */
-    private Bitmap mIcon;
+    private Icon mIcon;
 
     /**
      * The IntentSender that will be used to deliver the intent to the target.
@@ -93,7 +104,7 @@ public final class ChooserTarget implements Parcelable {
      * @param score ranking score for this target between 0.0f and 1.0f, inclusive
      * @param pendingIntent PendingIntent to fill in and send if the user chooses this target
      */
-    public ChooserTarget(CharSequence title, Bitmap icon, float score,
+    public ChooserTarget(CharSequence title, Icon icon, float score,
             PendingIntent pendingIntent) {
         this(title, icon, score, pendingIntent.getIntentSender());
     }
@@ -129,7 +140,7 @@ public final class ChooserTarget implements Parcelable {
      * @param score ranking score for this target between 0.0f and 1.0f, inclusive
      * @param intentSender IntentSender to fill in and send if the user chooses this target
      */
-    public ChooserTarget(CharSequence title, Bitmap icon, float score, IntentSender intentSender) {
+    public ChooserTarget(CharSequence title, Icon icon, float score, IntentSender intentSender) {
         mTitle = title;
         mIcon = icon;
         if (score > 1.f || score < 0.f) {
@@ -143,7 +154,7 @@ public final class ChooserTarget implements Parcelable {
     ChooserTarget(Parcel in) {
         mTitle = in.readCharSequence();
         if (in.readInt() != 0) {
-            mIcon = Bitmap.CREATOR.createFromParcel(in);
+            mIcon = Icon.CREATOR.createFromParcel(in);
         } else {
             mIcon = null;
         }
@@ -167,7 +178,7 @@ public final class ChooserTarget implements Parcelable {
      *
      * @return the icon representing this target, intended to be shown to a user
      */
-    public Bitmap getIcon() {
+    public Icon getIcon() {
         return mIcon;
     }
 
index 699bd0a..0d1834a 100644 (file)
@@ -107,7 +107,7 @@ public abstract class ChooserTargetService extends Service {
      * <p>The returned list should be sorted such that the most relevant targets appear first.
      * Any PendingIntents used to construct the resulting ChooserTargets should always be prepared
      * to have the relevant data fields filled in by the sender. See
-     * {@link ChooserTarget#ChooserTarget(CharSequence, android.graphics.Bitmap, float, android.app.PendingIntent) ChooserTarget}.</p>
+     * {@link ChooserTarget#ChooserTarget(CharSequence, android.graphics.drawable.Icon, float, android.app.PendingIntent) ChooserTarget}.</p>
      *
      * <p><em>Important:</em> Calls to this method from other applications will occur on
      * a binder thread, not on your app's main thread. Make sure that access to relevant data
index 83fa967..ea18c12 100644 (file)
@@ -29,8 +29,8 @@ import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
 import android.database.DataSetObserver;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -51,10 +51,8 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
 import android.widget.AbsListView;
 import android.widget.BaseAdapter;
-import android.widget.LinearLayout;
 import android.widget.ListView;
 import com.android.internal.R;
 
@@ -74,6 +72,8 @@ public class ChooserActivity extends ResolverActivity {
     private IntentSender mRefinementIntentSender;
     private RefinementResultReceiver mRefinementResultReceiver;
 
+    private Intent mReferrerFillInIntent;
+
     private ChooserListAdapter mChooserListAdapter;
 
     private final List<ChooserTargetServiceConnection> mServiceConnections = new ArrayList<>();
@@ -81,7 +81,7 @@ public class ChooserActivity extends ResolverActivity {
     private static final int CHOOSER_TARGET_SERVICE_RESULT = 1;
     private static final int CHOOSER_TARGET_SERVICE_WATCHDOG_TIMEOUT = 2;
 
-    private Handler mTargetResultHandler = new Handler() {
+    private final Handler mChooserHandler = new Handler() {
         @Override
         public void handleMessage(Message msg) {
             switch (msg.what) {
@@ -176,6 +176,8 @@ public class ChooserActivity extends ResolverActivity {
             }
         }
 
+        mReferrerFillInIntent = new Intent().putExtra(Intent.EXTRA_REFERRER, getReferrer());
+
         mChosenComponentSender = intent.getParcelableExtra(
                 Intent.EXTRA_CHOSEN_COMPONENT_INTENT_SENDER);
         mRefinementIntentSender = intent.getParcelableExtra(
@@ -346,7 +348,7 @@ public class ChooserActivity extends ResolverActivity {
         if (!mServiceConnections.isEmpty()) {
             if (DEBUG) Log.d(TAG, "queryTargets setting watchdog timer for "
                     + WATCHDOG_TIMEOUT_MILLIS + "ms");
-            mTargetResultHandler.sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_TIMEOUT,
+            mChooserHandler.sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_TIMEOUT,
                     WATCHDOG_TIMEOUT_MILLIS);
         }
     }
@@ -379,7 +381,7 @@ public class ChooserActivity extends ResolverActivity {
             unbindService(conn);
         }
         mServiceConnections.clear();
-        mTargetResultHandler.removeMessages(CHOOSER_TARGET_SERVICE_WATCHDOG_TIMEOUT);
+        mChooserHandler.removeMessages(CHOOSER_TARGET_SERVICE_WATCHDOG_TIMEOUT);
     }
 
     void onRefinementResult(TargetInfo selectedTarget, Intent matchingIntent) {
@@ -435,7 +437,7 @@ public class ChooserActivity extends ResolverActivity {
         private final ResolveInfo mBackupResolveInfo;
         private final ChooserTarget mChooserTarget;
         private Drawable mBadgeIcon = null;
-        private final Drawable mDisplayIcon;
+        private Drawable mDisplayIcon;
         private final Intent mFillInIntent;
         private final int mFillInFlags;
 
@@ -451,7 +453,9 @@ public class ChooserActivity extends ResolverActivity {
                     }
                 }
             }
-            mDisplayIcon = new BitmapDrawable(getResources(), chooserTarget.getIcon());
+            final Icon icon = chooserTarget.getIcon();
+            // TODO do this in the background
+            mDisplayIcon = icon != null ? icon.loadDrawable(ChooserActivity.this) : null;
 
             if (sourceInfo != null) {
                 mBackupResolveInfo = null;
@@ -497,9 +501,12 @@ public class ChooserActivity extends ResolverActivity {
                     ? mSourceInfo.getResolvedIntent() : getTargetIntent();
             if (result == null) {
                 Log.e(TAG, "ChooserTargetInfo#getFillInIntent: no fillIn intent available");
-            } else if (mFillInIntent != null) {
+            } else {
                 result = new Intent(result);
-                result.fillIn(mFillInIntent, mFillInFlags);
+                if (mFillInIntent != null) {
+                    result.fillIn(mFillInIntent, mFillInFlags);
+                }
+                result.fillIn(mReferrerFillInIntent, 0);
             }
             return result;
         }
@@ -867,7 +874,7 @@ public class ChooserActivity extends ResolverActivity {
                 msg.what = CHOOSER_TARGET_SERVICE_RESULT;
                 msg.obj = new ServiceResultInfo(mOriginalTarget, targets,
                         ChooserTargetServiceConnection.this);
-                mTargetResultHandler.sendMessage(msg);
+                mChooserHandler.sendMessage(msg);
             }
         };