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

Commit 7d758001 authored by Adam Powell's avatar Adam Powell
Browse files

Bringing new Chooser UI closer to spec

Separate the chooser targets into rows by type. Remove some API that
was redundant with LabeledIntent, simplifying ChooserTarget.

Change-Id: I90de471825f05d85e6ffbe72a32fb597be824a30
parent 1c861591
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -8294,7 +8294,6 @@ package android.content {
    field public static final java.lang.String EXTRA_CHANGED_PACKAGE_LIST = "android.intent.extra.changed_package_list";
    field public static final java.lang.String EXTRA_CHANGED_UID_LIST = "android.intent.extra.changed_uid_list";
    field public static final java.lang.String EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER = "android.intent.extra.CHOOSER_REFINEMENT_INTENT_SENDER";
    field public static final java.lang.String EXTRA_CHOOSER_TARGETS = "android.intent.extra.CHOOSER_TARGETS";
    field public static final java.lang.String EXTRA_CHOSEN_COMPONENT = "android.intent.extra.CHOSEN_COMPONENT";
    field public static final java.lang.String EXTRA_CHOSEN_COMPONENT_INTENT_SENDER = "android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER";
    field public static final java.lang.String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
@@ -28730,10 +28729,8 @@ 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.Bitmap, float, android.content.Intent);
    method public int describeContents();
    method public android.graphics.Bitmap getIcon();
    method public android.content.Intent getIntent();
    method public android.content.IntentSender getIntentSender();
    method public float getScore();
    method public java.lang.CharSequence getTitle();
+0 −3
Original line number Diff line number Diff line
@@ -8520,7 +8520,6 @@ package android.content {
    field public static final java.lang.String EXTRA_CHANGED_PACKAGE_LIST = "android.intent.extra.changed_package_list";
    field public static final java.lang.String EXTRA_CHANGED_UID_LIST = "android.intent.extra.changed_uid_list";
    field public static final java.lang.String EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER = "android.intent.extra.CHOOSER_REFINEMENT_INTENT_SENDER";
    field public static final java.lang.String EXTRA_CHOOSER_TARGETS = "android.intent.extra.CHOOSER_TARGETS";
    field public static final java.lang.String EXTRA_CHOSEN_COMPONENT = "android.intent.extra.CHOSEN_COMPONENT";
    field public static final java.lang.String EXTRA_CHOSEN_COMPONENT_INTENT_SENDER = "android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER";
    field public static final java.lang.String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
@@ -30744,10 +30743,8 @@ 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.Bitmap, float, android.content.Intent);
    method public int describeContents();
    method public android.graphics.Bitmap getIcon();
    method public android.content.Intent getIntent();
    method public android.content.IntentSender getIntentSender();
    method public float getScore();
    method public java.lang.CharSequence getTitle();
+0 −8
Original line number Diff line number Diff line
@@ -3364,14 +3364,6 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";

    /**
     * A Parcelable[] of {@link android.service.chooser.ChooserTarget ChooserTarget} objects
     * as set with {@link #putExtra(String, Parcelable[])} representing additional app-specific
     * targets to place at the front of the list of choices. Shown to the user with
     * {@link #ACTION_CHOOSER}.
     */
    public static final String EXTRA_CHOOSER_TARGETS = "android.intent.extra.CHOOSER_TARGETS";

    /**
     * A Bundle forming a mapping of potential target package names to different extras Bundles
     * to add to the default intent extras in {@link #EXTRA_INTENT} when used with
+2 −147
Original line number Diff line number Diff line
@@ -57,12 +57,6 @@ public final class ChooserTarget implements Parcelable {
     */
    private IntentSender mIntentSender;

    /**
     * A raw intent provided in lieu of an IntentSender. Will be filled in and sent
     * by {@link #sendIntent(Context, Intent)}.
     */
    private Intent mIntent;

    /**
     * The score given to this item. It can be normalized.
     */
@@ -146,43 +140,6 @@ 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;
        if (score > 1.f || score < 0.f) {
            throw new IllegalArgumentException("Score " + score + " out of range; "
                    + "must be between 0.0f and 1.0f");
        }
        mScore = score;
        mIntent = intent;
    }

    ChooserTarget(Parcel in) {
        mTitle = in.readCharSequence();
        if (in.readInt() != 0) {
@@ -192,9 +149,6 @@ public final class ChooserTarget implements Parcelable {
        }
        mScore = in.readFloat();
        mIntentSender = IntentSender.readIntentSenderOrNullFromParcel(in);
        if (in.readInt() != 0) {
            mIntent = Intent.CREATOR.createFromParcel(in);
        }
    }

    /**
@@ -240,18 +194,6 @@ public final class ChooserTarget implements Parcelable {
        return mIntentSender;
    }

    /**
     * Returns the Intent supplied by the ChooserTarget's creator.
     * This may be null if the creator specified an IntentSender or PendingIntent instead.
     *
     * <p>To fill in and send the intent, see {@link #sendIntent(Context, Intent)}.</p>
     *
     * @return the Intent supplied by the ChooserTarget's creator
     */
    public Intent getIntent() {
        return mIntent;
    }

    /**
     * Fill in the IntentSender supplied by the ChooserTarget's creator and send it.
     *
@@ -272,91 +214,8 @@ public final class ChooserTarget implements Parcelable {
                Log.e(TAG, "sendIntent " + this + " failed", e);
                return false;
            }
        } else if (mIntent != null) {
            try {
                final Intent toSend = new Intent(mIntent);
                toSend.fillIn(fillInIntent, 0);
                context.startActivity(toSend);
                return true;
            } catch (Exception e) {
                Log.e(TAG, "sendIntent " + this + " failed", e);
                return false;
            }
        } else {
            Log.e(TAG, "sendIntent " + this + " failed - no IntentSender or Intent to send");
            return false;
        }
    }

    /**
     * Same as {@link #sendIntent(Context, Intent)}, but offers a userId field to use
     * for launching the {@link #getIntent() intent} using
     * {@link Activity#startActivityAsCaller(Intent, Bundle, int)} if the
     * {@link #getIntentSender() IntentSender} is not present. If the IntentSender is present,
     * it will be invoked as usual with its own calling identity.
     *
     * @hide internal use only.
     */
    public boolean sendIntentAsCaller(Activity context, Intent fillInIntent, int userId) {
        if (fillInIntent != null) {
            fillInIntent.migrateExtraStreamToClipData();
            fillInIntent.prepareToLeaveProcess();
        }
        if (mIntentSender != null) {
            try {
                mIntentSender.sendIntent(context, 0, fillInIntent, null, null);
                return true;
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "sendIntent " + this + " failed", e);
                return false;
            }
        } else if (mIntent != null) {
            try {
                final Intent toSend = new Intent(mIntent);
                toSend.fillIn(fillInIntent, 0);
                context.startActivityAsCaller(toSend, null, userId);
                return true;
            } catch (Exception e) {
                Log.e(TAG, "sendIntent " + this + " failed", e);
                return false;
            }
        } else {
            Log.e(TAG, "sendIntent " + this + " failed - no IntentSender or Intent to send");
            return false;
        }
    }

    /**
     * The UserHandle is only used if we're launching a raw intent. The IntentSender will be
     * launched with its associated identity.
     *
     * @hide Internal use only
     */
    public boolean sendIntentAsUser(Activity context, Intent fillInIntent, UserHandle user) {
        if (fillInIntent != null) {
            fillInIntent.migrateExtraStreamToClipData();
            fillInIntent.prepareToLeaveProcess();
        }
        if (mIntentSender != null) {
            try {
                mIntentSender.sendIntent(context, 0, fillInIntent, null, null);
                return true;
            } catch (IntentSender.SendIntentException e) {
                Log.e(TAG, "sendIntent " + this + " failed", e);
                return false;
            }
        } else if (mIntent != null) {
            try {
                final Intent toSend = new Intent(mIntent);
                toSend.fillIn(fillInIntent, 0);
                context.startActivityAsUser(toSend, user);
                return true;
            } catch (Exception e) {
                Log.e(TAG, "sendIntent " + this + " failed", e);
                return false;
            }
        } else {
            Log.e(TAG, "sendIntent " + this + " failed - no IntentSender or Intent to send");
            Log.e(TAG, "sendIntent " + this + " failed - no IntentSender to send");
            return false;
        }
    }
@@ -364,7 +223,7 @@ public final class ChooserTarget implements Parcelable {
    @Override
    public String toString() {
        return "ChooserTarget{"
                + (mIntentSender != null ? mIntentSender.getCreatorPackage() : mIntent)
                + (mIntentSender != null ? mIntentSender.getCreatorPackage() : null)
                + ", "
                + "'" + mTitle
                + "', " + mScore + "}";
@@ -386,10 +245,6 @@ 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
+256 −42

File changed.

Preview size limit exceeded, changes collapsed.

Loading