diff options
| author | 2018-01-18 17:39:34 +0000 | |
|---|---|---|
| committer | 2018-01-18 17:39:34 +0000 | |
| commit | 4fa2aa03ea0dac86367bec08ed09df0345c4647a (patch) | |
| tree | 7bfc7ed2b7fc95ce88471e998a6e96dad2286b20 | |
| parent | 71ad82d6ed1fd317678bb9d8e26ad8ab139b672a (diff) | |
| parent | 6cb667cb12eb040f0a7f68ee48f2adb39250c1ef (diff) | |
Merge "Add "results source" parameter to RemoteInput"
| -rw-r--r-- | api/current.txt | 4 | ||||
| -rw-r--r-- | core/java/android/app/RemoteInput.java | 52 |
2 files changed, 56 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 1fb64ed179dc..847671ead669 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5859,11 +5859,15 @@ package android.app { method public java.lang.CharSequence getLabel(); method public java.lang.String getResultKey(); method public static android.os.Bundle getResultsFromIntent(android.content.Intent); + method public static int getResultsSource(android.content.Intent); method public boolean isDataOnly(); + method public static void setResultsSource(android.content.Intent, int); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator<android.app.RemoteInput> CREATOR; field public static final java.lang.String EXTRA_RESULTS_DATA = "android.remoteinput.resultsData"; field public static final java.lang.String RESULTS_CLIP_LABEL = "android.remoteinput.results"; + field public static final int SOURCE_CHOICE = 1; // 0x1 + field public static final int SOURCE_FREE_FORM_INPUT = 0; // 0x0 } public static final class RemoteInput.Builder { diff --git a/core/java/android/app/RemoteInput.java b/core/java/android/app/RemoteInput.java index 02a01242c3ba..b7100e6f4d87 100644 --- a/core/java/android/app/RemoteInput.java +++ b/core/java/android/app/RemoteInput.java @@ -24,6 +24,7 @@ import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.util.ArraySet; + import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -73,6 +74,15 @@ public final class RemoteInput implements Parcelable { private static final String EXTRA_DATA_TYPE_RESULTS_DATA = "android.remoteinput.dataTypeResultsData"; + /** Extra added to a clip data intent object identifying the source of the results. */ + private static final String EXTRA_RESULTS_SOURCE = "android.remoteinput.resultsSource"; + + /** The user manually entered the data. */ + public static final int SOURCE_FREE_FORM_INPUT = 0; + + /** The user selected one of the choices from {@link #getChoices}. */ + public static final int SOURCE_CHOICE = 1; + // Flags bitwise-ored to mFlags private static final int FLAG_ALLOW_FREE_FORM_INPUT = 0x1; @@ -416,6 +426,48 @@ public final class RemoteInput implements Parcelable { intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipDataIntent)); } + /** + * Set the source of the RemoteInput results. This method should only be called by remote + * input collection services (e.g. + * {@link android.service.notification.NotificationListenerService}) + * when sending results to a pending intent. + * + * @see #SOURCE_FREE_FORM_INPUT + * @see #SOURCE_CHOICE + * + * @param intent The intent to add remote input source to. The {@link ClipData} + * field of the intent will be modified to contain the source. + * field of the intent will be modified to contain the source. + * @param source The source of the results. + */ + public static void setResultsSource(Intent intent, int source) { + Intent clipDataIntent = getClipDataIntentFromIntent(intent); + if (clipDataIntent == null) { + clipDataIntent = new Intent(); // First time we've added a result. + } + clipDataIntent.putExtra(EXTRA_RESULTS_SOURCE, source); + intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipDataIntent)); + } + + /** + * Get the source of the RemoteInput results. + * + * @see #SOURCE_FREE_FORM_INPUT + * @see #SOURCE_CHOICE + * + * @param intent The intent object that fired in response to an action or content intent + * which also had one or more remote input requested. + * @return The source of the results. If no source was set, {@link #SOURCE_FREE_FORM_INPUT} will + * be returned. + */ + public static int getResultsSource(Intent intent) { + Intent clipDataIntent = getClipDataIntentFromIntent(intent); + if (clipDataIntent == null) { + return SOURCE_FREE_FORM_INPUT; + } + return clipDataIntent.getExtras().getInt(EXTRA_RESULTS_SOURCE, SOURCE_FREE_FORM_INPUT); + } + private static String getExtraResultsKeyForData(String mimeType) { return EXTRA_DATA_TYPE_RESULTS_DATA + mimeType; } |