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

Commit d8b6ec5f authored by Nikita Dubrovsky's avatar Nikita Dubrovsky Committed by Android (Google) Code Review
Browse files

Merge "Add View.performReceiveContent in addition to View.onReceiveContent"

parents 0db230cf 53bf38e9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52924,6 +52924,7 @@ package android.view {
    method public boolean performHapticFeedback(int, int);
    method public boolean performLongClick();
    method public boolean performLongClick(float, float);
    method @Nullable public android.view.OnReceiveContentListener.Payload performReceiveContent(@NonNull android.view.OnReceiveContentListener.Payload);
    method public void playSoundEffect(int);
    method public boolean post(Runnable);
    method public boolean postDelayed(Runnable, long);
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ import java.util.function.Predicate;
 *     public static final String[] MIME_TYPES = new String[] {"image/*", "video/*"};
 *
 *     @Override
 *     public Payload onReceiveContent(TextView view, Payload payload) {
 *     public Payload onReceiveContent(View view, Payload payload) {
 *         Map<Boolean, Payload> split = payload.partition(item -> item.getUri() != null);
 *         if (split.get(true) != null) {
 *             ClipData clip = payload.getClip();
+28 −10
Original line number Diff line number Diff line
@@ -9008,7 +9008,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    }
    /**
     * Sets the listener to be {@link #onReceiveContent used} to handle insertion of
     * Sets the listener to be {@link #performReceiveContent used} to handle insertion of
     * content into this view.
     *
     * <p>Depending on the type of view, this listener may be invoked for different scenarios. For
@@ -9039,7 +9039,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     *                  not be null or empty if a non-null listener is passed in.
     * @param listener The listener to use. This can be null to reset to the default behavior.
     */
    @SuppressWarnings("rawtypes")
    public void setOnReceiveContentListener(@Nullable String[] mimeTypes,
            @Nullable OnReceiveContentListener listener) {
        if (listener != null) {
@@ -9055,27 +9054,46 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
    }
    /**
     * Receives the given content. Invokes the listener configured via
     * {@link #setOnReceiveContentListener}; if no listener is set, the default implementation is a
     * no-op (returns the passed-in content without acting on it).
     * Receives the given content. If no listener is set, invokes {@link #onReceiveContent}. If a
     * listener is {@link #setOnReceiveContentListener set}, invokes the listener instead; if the
     * listener returns a non-null result, invokes {@link #onReceiveContent} to handle it.
     *
     * @param payload The content to insert and related metadata.
     *
     * @return The portion of the passed-in content that was not accepted (may be all, some, or none
     * of the passed-in content).
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    public @Nullable Payload onReceiveContent(@NonNull Payload payload) {
    public @Nullable Payload performReceiveContent(@NonNull Payload payload) {
        final OnReceiveContentListener listener = (mListenerInfo == null) ? null
                : getListenerInfo().mOnReceiveContentListener;
        if (listener != null) {
            return listener.onReceiveContent(this, payload);
            final Payload remaining = listener.onReceiveContent(this, payload);
            return (remaining == null) ? null : onReceiveContent(remaining);
        }
        return onReceiveContent(payload);
    }
    /**
     * Implements the default behavior for receiving content for this type of view. The default
     * view implementation is a no-op (returns the passed-in content without acting on it).
     *
     * <p>Widgets should override this method to define their default behavior for receiving
     * content. Apps should {@link #setOnReceiveContentListener set a listener} to provide
     * app-specific handling for receiving content.
     *
     * <p>See {@link #setOnReceiveContentListener} and {@link #performReceiveContent} for more info.
     *
     * @param payload The content to insert and related metadata.
     *
     * @return The portion of the passed-in content that was not handled (may be all, some, or none
     * of the passed-in content).
     */
    public @Nullable Payload onReceiveContent(@NonNull Payload payload) {
        return payload;
    }
    /**
     * Returns the MIME types accepted by {@link #onReceiveContent} for this view, as
     * Returns the MIME types accepted by {@link #performReceiveContent} for this view, as
     * configured via {@link #setOnReceiveContentListener}. By default returns null.
     *
     * <p>Different features (e.g. pasting from the clipboard, inserting stickers from the soft
@@ -9092,7 +9110,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * {@link android.content.Intent#normalizeMimeType} to ensure that it is converted to
     * lowercase.
     *
     * @return The MIME types accepted by {@link #onReceiveContent} for this view (may
     * @return The MIME types accepted by {@link #performReceiveContent} for this view (may
     * include patterns such as "image/*").
     */
    public @Nullable String[] getOnReceiveContentMimeTypes() {
+1 −1
Original line number Diff line number Diff line
@@ -2372,7 +2372,7 @@ public final class AutofillManager {
                return;
            }
            Payload payload = new Payload.Builder(clip, SOURCE_AUTOFILL).build();
            Payload result = view.onReceiveContent(payload);
            Payload result = view.performReceiveContent(payload);
            if (result != null) {
                Log.w(TAG, "autofillContent(): receiver could not insert content: id=" + id
                        + ", view=" + view + ", clip=" + clip);
+4 −4
Original line number Diff line number Diff line
@@ -927,9 +927,9 @@ public class BaseInputConnection implements InputConnection {
    }

    /**
     * Default implementation which invokes {@link View#onReceiveContent} on the target view if the
     * view {@link View#getOnReceiveContentMimeTypes allows} content insertion; otherwise returns
     * false without any side effects.
     * Default implementation which invokes {@link View#performReceiveContent} on the target
     * view if the view {@link View#getOnReceiveContentMimeTypes allows} content insertion;
     * otherwise returns false without any side effects.
     */
    public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
        ClipDescription description = inputContentInfo.getDescription();
@@ -954,6 +954,6 @@ public class BaseInputConnection implements InputConnection {
                .setLinkUri(inputContentInfo.getLinkUri())
                .setExtras(opts)
                .build();
        return mTargetView.onReceiveContent(payload) == null;
        return mTargetView.performReceiveContent(payload) == null;
    }
}
Loading