Merge "Add "results source" parameter to RemoteInput"

This commit is contained in:
Petr Cermak
2018-01-18 17:39:34 +00:00
committed by Android (Google) Code Review
2 changed files with 56 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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;
}