AssistContent.java revision 16036f26847f3f1a88a093fb776bf081008ff8d8
1package android.app.assist; 2 3import android.content.ClipData; 4import android.content.Intent; 5import android.net.Uri; 6import android.os.Bundle; 7import android.os.Parcel; 8import android.os.Parcelable; 9 10/** 11 * Holds information about the content an application is viewing, to hand to an 12 * assistant at the user's request. This is filled in by 13 * {@link android.app.Activity#onProvideAssistContent Activity.onProvideAssistContent}. 14 */ 15@Deprecated 16public class AssistContent implements Parcelable { 17 private boolean mIsAppProvidedIntent = false; 18 private Intent mIntent; 19 private String mStructuredData; 20 private ClipData mClipData; 21 private Uri mUri; 22 private final Bundle mExtras; 23 24 public AssistContent() { 25 mExtras = new Bundle(); 26 } 27 28 /** 29 * @hide 30 * Called by {@link android.app.ActivityThread} to set the default Intent based on 31 * {@link android.app.Activity#getIntent Activity.getIntent}. 32 * 33 * <p>Automatically populates {@link #mUri} if that Intent is an {@link Intent#ACTION_VIEW} 34 * of a web (http or https scheme) URI.</p> 35 */ 36 public void setDefaultIntent(Intent intent) { 37 mIntent = intent; 38 setWebUri(null); 39 if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { 40 Uri uri = intent.getData(); 41 if (uri != null) { 42 if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) { 43 setWebUri(uri); 44 } 45 } 46 } 47 } 48 49 /** 50 * Sets the Intent associated with the content, describing the current top-level context of 51 * the activity. If this contains a reference to a piece of data related to the activity, 52 * be sure to set {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} so the accessibility 53 * service can access it. 54 */ 55 public void setIntent(Intent intent) { 56 mIsAppProvidedIntent = true; 57 mIntent = intent; 58 } 59 60 /** 61 * Returns the current {@link #setIntent} if one is set, else the default Intent obtained from 62 * {@link android.app.Activity#getIntent Activity.getIntent}. Can be modified in-place. 63 */ 64 public Intent getIntent() { 65 return mIntent; 66 } 67 68 /** 69 * Returns whether or not the current Intent was explicitly provided in 70 * {@link android.app.Activity#onProvideAssistContent Activity.onProvideAssistContent}. If not, 71 * the Intent was automatically set based on 72 * {@link android.app.Activity#getIntent Activity.getIntent}. 73 */ 74 public boolean isAppProvidedIntent() { 75 return mIsAppProvidedIntent; 76 } 77 78 /** 79 * Optional additional content items that are involved with 80 * the current UI. Access to this content will be granted to the assistant as if you 81 * are sending it through an Intent with {@link Intent#FLAG_GRANT_READ_URI_PERMISSION}. 82 */ 83 public void setClipData(ClipData clip) { 84 mClipData = clip; 85 } 86 87 /** 88 * Return the current {@link #setClipData}, which you can modify in-place. 89 */ 90 public ClipData getClipData() { 91 return mClipData; 92 } 93 94 /** 95 * Sets optional structured data regarding the content being viewed. The provided data 96 * must be a string represented with <a href="http://json-ld.org/">JSON-LD</a> using the 97 * <a href="http://schema.org/">schema.org</a> vocabulary. 98 */ 99 public void setStructuredData(String structuredData) { 100 mStructuredData = structuredData; 101 } 102 103 /** 104 * Returns the current {@link #setStructuredData}. 105 */ 106 public String getStructuredData() { 107 return mStructuredData; 108 } 109 110 /** 111 * Set a web URI associated with the current data being shown to the user. 112 * This URI could be opened in a web browser, or in the app as an 113 * {@link Intent#ACTION_VIEW} Intent, to show the same data that is currently 114 * being displayed by it. The URI here should be something that is transportable 115 * off the device into other environments to acesss the same data as is currently 116 * being shown in the app; if the app does not have such a representation, it should 117 * leave the null and only report the local intent and clip data. 118 */ 119 public void setWebUri(Uri uri) { 120 mUri = uri; 121 } 122 123 /** 124 * Return the content's web URI as per {@link #setWebUri(android.net.Uri)}, or null if 125 * there is none. 126 */ 127 public Uri getWebUri() { 128 return mUri; 129 } 130 131 /** 132 * Return Bundle for extra vendor-specific data that can be modified and examined. 133 */ 134 public Bundle getExtras() { 135 return mExtras; 136 } 137 138 AssistContent(Parcel in) { 139 if (in.readInt() != 0) { 140 mIntent = Intent.CREATOR.createFromParcel(in); 141 } 142 if (in.readInt() != 0) { 143 mClipData = ClipData.CREATOR.createFromParcel(in); 144 } 145 if (in.readInt() != 0) { 146 mUri = Uri.CREATOR.createFromParcel(in); 147 } 148 if (in.readInt() != 0) { 149 mStructuredData = in.readString(); 150 } 151 mIsAppProvidedIntent = in.readInt() == 1; 152 mExtras = in.readBundle(); 153 } 154 155 void writeToParcelInternal(Parcel dest, int flags) { 156 if (mIntent != null) { 157 dest.writeInt(1); 158 mIntent.writeToParcel(dest, flags); 159 } else { 160 dest.writeInt(0); 161 } 162 if (mClipData != null) { 163 dest.writeInt(1); 164 mClipData.writeToParcel(dest, flags); 165 } else { 166 dest.writeInt(0); 167 } 168 if (mUri != null) { 169 dest.writeInt(1); 170 mUri.writeToParcel(dest, flags); 171 } else { 172 dest.writeInt(0); 173 } 174 if (mStructuredData != null) { 175 dest.writeInt(1); 176 dest.writeString(mStructuredData); 177 } else { 178 dest.writeInt(0); 179 } 180 dest.writeInt(mIsAppProvidedIntent ? 1 : 0); 181 dest.writeBundle(mExtras); 182 } 183 184 @Override 185 public int describeContents() { 186 return 0; 187 } 188 189 @Override 190 public void writeToParcel(Parcel dest, int flags) { 191 writeToParcelInternal(dest, flags); 192 } 193 194 public static final Parcelable.Creator<AssistContent> CREATOR 195 = new Parcelable.Creator<AssistContent>() { 196 public AssistContent createFromParcel(Parcel in) { 197 return new AssistContent(in); 198 } 199 200 public AssistContent[] newArray(int size) { 201 return new AssistContent[size]; 202 } 203 }; 204} 205