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

Commit 152944f4 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add InputConnection#insertContent().

Providing an official protocol for IMEs to insert an image to the
application is something that has been requested from many IME
developers to Android OS.  With this CL, IMEs are able to ask
applications to insert a content including image files as follows.

 1. An application that opts in to this protocol specifies a list of
    supported content MIME types in EditorInfo#contentMimeTypes.
 2. When an IME is actively interacting with such an application, the
    IME can call InputConnection#insertContent() with a InputContentInfo
    that contains content URI, metadata (ClipDescription), and an
    optional link URI.
 3. The application can read the stream data from the given content URI
    to insert the content into somewhere in the application.

Detailed design background can be found in the JavaDoc of
InputConnection#insertContent().

Bug: 22830793
Change-Id: Iaadf934a997ffcd6000a516cc3c1873db56e60ad
parent 779adf88
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -44715,6 +44715,7 @@ package android.view.inputmethod {
    method public java.lang.CharSequence getSelectedText(int);
    method public java.lang.CharSequence getTextAfterCursor(int, int);
    method public java.lang.CharSequence getTextBeforeCursor(int, int);
    method public boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public boolean performContextMenuAction(int);
    method public boolean performEditorAction(int);
    method public boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -44809,6 +44810,7 @@ package android.view.inputmethod {
    field public static final int IME_NULL = 0; // 0x0
    field public int actionId;
    field public java.lang.CharSequence actionLabel;
    field public java.lang.String[] contentMimeTypes;
    field public android.os.Bundle extras;
    field public int fieldId;
    field public java.lang.String fieldName;
@@ -44880,6 +44882,7 @@ package android.view.inputmethod {
    method public abstract java.lang.CharSequence getSelectedText(int);
    method public abstract java.lang.CharSequence getTextAfterCursor(int, int);
    method public abstract java.lang.CharSequence getTextBeforeCursor(int, int);
    method public abstract boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public abstract boolean performContextMenuAction(int);
    method public abstract boolean performEditorAction(int);
    method public abstract boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -44913,6 +44916,7 @@ package android.view.inputmethod {
    method public java.lang.CharSequence getSelectedText(int);
    method public java.lang.CharSequence getTextAfterCursor(int, int);
    method public java.lang.CharSequence getTextBeforeCursor(int, int);
    method public boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public boolean performContextMenuAction(int);
    method public boolean performEditorAction(int);
    method public boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -44925,6 +44929,17 @@ package android.view.inputmethod {
    method public void setTarget(android.view.inputmethod.InputConnection);
  }
  public class InputContentInfo implements android.os.Parcelable {
    ctor public InputContentInfo(android.net.Uri, android.content.ClipDescription);
    ctor public InputContentInfo(android.net.Uri, android.content.ClipDescription, android.net.Uri);
    method public int describeContents();
    method public android.net.Uri getContentUri();
    method public android.content.ClipDescription getDescription();
    method public android.net.Uri getLinkUri();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.view.inputmethod.InputContentInfo> CREATOR;
  }
  public abstract interface InputMethod {
    method public abstract void attachToken(android.os.IBinder);
    method public abstract void bindInput(android.view.inputmethod.InputBinding);
+15 −0
Original line number Diff line number Diff line
@@ -47716,6 +47716,7 @@ package android.view.inputmethod {
    method public java.lang.CharSequence getSelectedText(int);
    method public java.lang.CharSequence getTextAfterCursor(int, int);
    method public java.lang.CharSequence getTextBeforeCursor(int, int);
    method public boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public boolean performContextMenuAction(int);
    method public boolean performEditorAction(int);
    method public boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -47810,6 +47811,7 @@ package android.view.inputmethod {
    field public static final int IME_NULL = 0; // 0x0
    field public int actionId;
    field public java.lang.CharSequence actionLabel;
    field public java.lang.String[] contentMimeTypes;
    field public android.os.Bundle extras;
    field public int fieldId;
    field public java.lang.String fieldName;
@@ -47881,6 +47883,7 @@ package android.view.inputmethod {
    method public abstract java.lang.CharSequence getSelectedText(int);
    method public abstract java.lang.CharSequence getTextAfterCursor(int, int);
    method public abstract java.lang.CharSequence getTextBeforeCursor(int, int);
    method public abstract boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public abstract boolean performContextMenuAction(int);
    method public abstract boolean performEditorAction(int);
    method public abstract boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -47914,6 +47917,7 @@ package android.view.inputmethod {
    method public java.lang.CharSequence getSelectedText(int);
    method public java.lang.CharSequence getTextAfterCursor(int, int);
    method public java.lang.CharSequence getTextBeforeCursor(int, int);
    method public boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public boolean performContextMenuAction(int);
    method public boolean performEditorAction(int);
    method public boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -47926,6 +47930,17 @@ package android.view.inputmethod {
    method public void setTarget(android.view.inputmethod.InputConnection);
  }
  public class InputContentInfo implements android.os.Parcelable {
    ctor public InputContentInfo(android.net.Uri, android.content.ClipDescription);
    ctor public InputContentInfo(android.net.Uri, android.content.ClipDescription, android.net.Uri);
    method public int describeContents();
    method public android.net.Uri getContentUri();
    method public android.content.ClipDescription getDescription();
    method public android.net.Uri getLinkUri();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.view.inputmethod.InputContentInfo> CREATOR;
  }
  public abstract interface InputMethod {
    method public abstract void attachToken(android.os.IBinder);
    method public abstract void bindInput(android.view.inputmethod.InputBinding);
+15 −0
Original line number Diff line number Diff line
@@ -44795,6 +44795,7 @@ package android.view.inputmethod {
    method public java.lang.CharSequence getSelectedText(int);
    method public java.lang.CharSequence getTextAfterCursor(int, int);
    method public java.lang.CharSequence getTextBeforeCursor(int, int);
    method public boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public boolean performContextMenuAction(int);
    method public boolean performEditorAction(int);
    method public boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -44889,6 +44890,7 @@ package android.view.inputmethod {
    field public static final int IME_NULL = 0; // 0x0
    field public int actionId;
    field public java.lang.CharSequence actionLabel;
    field public java.lang.String[] contentMimeTypes;
    field public android.os.Bundle extras;
    field public int fieldId;
    field public java.lang.String fieldName;
@@ -44960,6 +44962,7 @@ package android.view.inputmethod {
    method public abstract java.lang.CharSequence getSelectedText(int);
    method public abstract java.lang.CharSequence getTextAfterCursor(int, int);
    method public abstract java.lang.CharSequence getTextBeforeCursor(int, int);
    method public abstract boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public abstract boolean performContextMenuAction(int);
    method public abstract boolean performEditorAction(int);
    method public abstract boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -44993,6 +44996,7 @@ package android.view.inputmethod {
    method public java.lang.CharSequence getSelectedText(int);
    method public java.lang.CharSequence getTextAfterCursor(int, int);
    method public java.lang.CharSequence getTextBeforeCursor(int, int);
    method public boolean insertContent(android.view.inputmethod.InputContentInfo, android.os.Bundle);
    method public boolean performContextMenuAction(int);
    method public boolean performEditorAction(int);
    method public boolean performPrivateCommand(java.lang.String, android.os.Bundle);
@@ -45005,6 +45009,17 @@ package android.view.inputmethod {
    method public void setTarget(android.view.inputmethod.InputConnection);
  }
  public class InputContentInfo implements android.os.Parcelable {
    ctor public InputContentInfo(android.net.Uri, android.content.ClipDescription);
    ctor public InputContentInfo(android.net.Uri, android.content.ClipDescription, android.net.Uri);
    method public int describeContents();
    method public android.net.Uri getContentUri();
    method public android.content.ClipDescription getDescription();
    method public android.net.Uri getLinkUri();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.view.inputmethod.InputContentInfo> CREATOR;
  }
  public abstract interface InputMethod {
    method public abstract void attachToken(android.os.IBinder);
    method public abstract void bindInput(android.view.inputmethod.InputBinding);
+5 −0
Original line number Diff line number Diff line
@@ -851,4 +851,9 @@ public class BaseInputConnection implements InputConnection {
        
        endBatchEdit();
    }

    /**
     * The default implementation does nothing.
     */
    public boolean insertContent(InputContentInfo inputContentInfo, Bundle opts) { return false; }
}
+17 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.text.InputType;
import android.text.TextUtils;
import android.util.Printer;

import java.util.Arrays;

/**
 * An EditorInfo describes several attributes of a text editing object
 * that an input method is communicating with (typically an EditText), most
@@ -363,6 +365,18 @@ public class EditorInfo implements InputType, Parcelable {
    @Nullable
    public LocaleList hintLocales = null;


    /**
     * List of acceptable MIME types for
     * {@link InputConnection#insertContent(InputContentInfo, Bundle)}.
     *
     * <p>{@code null} or an empty array means that
     * {@link InputConnection#insertContent(InputContentInfo, Bundle)} is not supported in this
     * editor.</p>
     */
    @Nullable
    public String[] contentMimeTypes = null;

    /**
     * Ensure that the data in this EditorInfo is compatible with an application
     * that was developed against the given target API version.  This can
@@ -418,6 +432,7 @@ public class EditorInfo implements InputType, Parcelable {
                + " fieldName=" + fieldName);
        pw.println(prefix + "extras=" + extras);
        pw.println(prefix + "hintLocales=" + hintLocales);
        pw.println(prefix + "contentMimeTypes=" + Arrays.toString(contentMimeTypes));
    }

    /**
@@ -446,6 +461,7 @@ public class EditorInfo implements InputType, Parcelable {
        } else {
            LocaleList.getEmptyLocaleList().writeToParcel(dest, flags);
        }
        dest.writeStringArray(contentMimeTypes);
    }

    /**
@@ -471,6 +487,7 @@ public class EditorInfo implements InputType, Parcelable {
                    res.extras = source.readBundle();
                    LocaleList hintLocales = LocaleList.CREATOR.createFromParcel(source);
                    res.hintLocales = hintLocales.isEmpty() ? null : hintLocales;
                    res.contentMimeTypes = source.readStringArray();
                    return res;
                }

Loading