1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view.inputmethod; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SuppressLint; 22 import android.annotation.TestApi; 23 import android.os.Parcelable; 24 import android.widget.inline.InlinePresentationSpec; 25 26 import com.android.internal.util.DataClass; 27 28 /** 29 * This class represents the description of an inline suggestion. It contains information to help 30 * the IME to decide where and when to show the suggestions. See {@link InlineSuggestion} for more 31 * information. 32 */ 33 @DataClass( 34 genEqualsHashCode = true, 35 genToString = true, 36 genHiddenConstDefs = true, 37 genHiddenConstructor = true) 38 public final class InlineSuggestionInfo implements Parcelable { 39 40 /** 41 * Suggestion source: the suggestion is made by the user selected autofill service. 42 */ 43 public static final @Source String SOURCE_AUTOFILL = "android:autofill"; 44 /** 45 * Suggestion source: the suggestion is made by the platform. 46 */ 47 public static final @Source String SOURCE_PLATFORM = "android:platform"; 48 49 /** 50 * UI type: the UI contains an Autofill suggestion that will autofill the fields when tapped. 51 */ 52 public static final @Type String TYPE_SUGGESTION = "android:autofill:suggestion"; 53 54 /** 55 * UI type: the UI contains an widget that will launch an intent when tapped. 56 */ 57 @SuppressLint({"IntentName"}) 58 public static final @Type String TYPE_ACTION = "android:autofill:action"; 59 60 /** The presentation spec to which the inflated suggestion view abides. */ 61 private final @NonNull InlinePresentationSpec mInlinePresentationSpec; 62 63 /** The source from which the suggestion is provided. */ 64 private final @NonNull @Source String mSource; 65 66 /** Hints for the type of data being suggested. */ 67 private final @Nullable String[] mAutofillHints; 68 69 /** The type of the UI. */ 70 private final @NonNull @Type String mType; 71 72 /** Whether the suggestion should be pinned or not. */ 73 private final boolean mPinned; 74 75 /** 76 * @hide 77 */ 78 private final @Nullable InlineSuggestion mTooltip; 79 80 /** 81 * Creates a new {@link InlineSuggestionInfo}, for testing purpose. 82 * 83 * @hide 84 */ 85 @TestApi 86 @NonNull newInlineSuggestionInfo( @onNull InlinePresentationSpec presentationSpec, @NonNull @Source String source, @SuppressLint(R) @Nullable String[] autofillHints, @NonNull @Type String type, boolean isPinned)87 public static InlineSuggestionInfo newInlineSuggestionInfo( 88 @NonNull InlinePresentationSpec presentationSpec, 89 @NonNull @Source String source, 90 @SuppressLint("NullableCollection") 91 @Nullable String[] autofillHints, @NonNull @Type String type, boolean isPinned) { 92 return new InlineSuggestionInfo(presentationSpec, source, autofillHints, type, isPinned, 93 null); 94 } 95 96 /** 97 * Creates a new {@link InlineSuggestionInfo}, for testing purpose. 98 * 99 * @hide 100 */ 101 @NonNull newInlineSuggestionInfo( @onNull InlinePresentationSpec presentationSpec, @NonNull @Source String source, @Nullable String[] autofillHints, @NonNull @Type String type, boolean isPinned, @Nullable InlineSuggestion tooltip)102 public static InlineSuggestionInfo newInlineSuggestionInfo( 103 @NonNull InlinePresentationSpec presentationSpec, 104 @NonNull @Source String source, 105 @Nullable String[] autofillHints, @NonNull @Type String type, boolean isPinned, 106 @Nullable InlineSuggestion tooltip) { 107 return new InlineSuggestionInfo(presentationSpec, source, autofillHints, type, isPinned, 108 tooltip); 109 } 110 111 112 113 114 115 // Code below generated by codegen v1.0.22. 116 // 117 // DO NOT MODIFY! 118 // CHECKSTYLE:OFF Generated code 119 // 120 // To regenerate run: 121 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/inputmethod/InlineSuggestionInfo.java 122 // 123 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 124 // Settings > Editor > Code Style > Formatter Control 125 //@formatter:off 126 127 128 /** @hide */ 129 @android.annotation.StringDef(prefix = "SOURCE_", value = { 130 SOURCE_AUTOFILL, 131 SOURCE_PLATFORM 132 }) 133 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) 134 @DataClass.Generated.Member 135 public @interface Source {} 136 137 /** @hide */ 138 @android.annotation.StringDef(prefix = "TYPE_", value = { 139 TYPE_SUGGESTION, 140 TYPE_ACTION 141 }) 142 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) 143 @DataClass.Generated.Member 144 public @interface Type {} 145 146 /** 147 * Creates a new InlineSuggestionInfo. 148 * 149 * @param inlinePresentationSpec 150 * The presentation spec to which the inflated suggestion view abides. 151 * @param source 152 * The source from which the suggestion is provided. 153 * @param autofillHints 154 * Hints for the type of data being suggested. 155 * @param type 156 * The type of the UI. 157 * @param pinned 158 * Whether the suggestion should be pinned or not. 159 * @hide 160 */ 161 @DataClass.Generated.Member InlineSuggestionInfo( @onNull InlinePresentationSpec inlinePresentationSpec, @NonNull @Source String source, @Nullable String[] autofillHints, @NonNull @Type String type, boolean pinned, @Nullable InlineSuggestion tooltip)162 public InlineSuggestionInfo( 163 @NonNull InlinePresentationSpec inlinePresentationSpec, 164 @NonNull @Source String source, 165 @Nullable String[] autofillHints, 166 @NonNull @Type String type, 167 boolean pinned, 168 @Nullable InlineSuggestion tooltip) { 169 this.mInlinePresentationSpec = inlinePresentationSpec; 170 com.android.internal.util.AnnotationValidations.validate( 171 NonNull.class, null, mInlinePresentationSpec); 172 this.mSource = source; 173 174 if (!(java.util.Objects.equals(mSource, SOURCE_AUTOFILL)) 175 && !(java.util.Objects.equals(mSource, SOURCE_PLATFORM))) { 176 throw new java.lang.IllegalArgumentException( 177 "source was " + mSource + " but must be one of: " 178 + "SOURCE_AUTOFILL(" + SOURCE_AUTOFILL + "), " 179 + "SOURCE_PLATFORM(" + SOURCE_PLATFORM + ")"); 180 } 181 182 com.android.internal.util.AnnotationValidations.validate( 183 NonNull.class, null, mSource); 184 this.mAutofillHints = autofillHints; 185 this.mType = type; 186 187 if (!(java.util.Objects.equals(mType, TYPE_SUGGESTION)) 188 && !(java.util.Objects.equals(mType, TYPE_ACTION))) { 189 throw new java.lang.IllegalArgumentException( 190 "type was " + mType + " but must be one of: " 191 + "TYPE_SUGGESTION(" + TYPE_SUGGESTION + "), " 192 + "TYPE_ACTION(" + TYPE_ACTION + ")"); 193 } 194 195 com.android.internal.util.AnnotationValidations.validate( 196 NonNull.class, null, mType); 197 this.mPinned = pinned; 198 this.mTooltip = tooltip; 199 200 // onConstructed(); // You can define this method to get a callback 201 } 202 203 /** 204 * The presentation spec to which the inflated suggestion view abides. 205 */ 206 @DataClass.Generated.Member getInlinePresentationSpec()207 public @NonNull InlinePresentationSpec getInlinePresentationSpec() { 208 return mInlinePresentationSpec; 209 } 210 211 /** 212 * The source from which the suggestion is provided. 213 */ 214 @DataClass.Generated.Member getSource()215 public @NonNull @Source String getSource() { 216 return mSource; 217 } 218 219 /** 220 * Hints for the type of data being suggested. 221 */ 222 @DataClass.Generated.Member getAutofillHints()223 public @Nullable String[] getAutofillHints() { 224 return mAutofillHints; 225 } 226 227 /** 228 * The type of the UI. 229 */ 230 @DataClass.Generated.Member getType()231 public @NonNull @Type String getType() { 232 return mType; 233 } 234 235 /** 236 * Whether the suggestion should be pinned or not. 237 */ 238 @DataClass.Generated.Member isPinned()239 public boolean isPinned() { 240 return mPinned; 241 } 242 243 /** 244 * @hide 245 */ 246 @DataClass.Generated.Member getTooltip()247 public @Nullable InlineSuggestion getTooltip() { 248 return mTooltip; 249 } 250 251 @Override 252 @DataClass.Generated.Member toString()253 public String toString() { 254 // You can override field toString logic by defining methods like: 255 // String fieldNameToString() { ... } 256 257 return "InlineSuggestionInfo { " + 258 "inlinePresentationSpec = " + mInlinePresentationSpec + ", " + 259 "source = " + mSource + ", " + 260 "autofillHints = " + java.util.Arrays.toString(mAutofillHints) + ", " + 261 "type = " + mType + ", " + 262 "pinned = " + mPinned + ", " + 263 "tooltip = " + mTooltip + 264 " }"; 265 } 266 267 @Override 268 @DataClass.Generated.Member equals(@ullable Object o)269 public boolean equals(@Nullable Object o) { 270 // You can override field equality logic by defining either of the methods like: 271 // boolean fieldNameEquals(InlineSuggestionInfo other) { ... } 272 // boolean fieldNameEquals(FieldType otherValue) { ... } 273 274 if (this == o) return true; 275 if (o == null || getClass() != o.getClass()) return false; 276 @SuppressWarnings("unchecked") 277 InlineSuggestionInfo that = (InlineSuggestionInfo) o; 278 //noinspection PointlessBooleanExpression 279 return true 280 && java.util.Objects.equals(mInlinePresentationSpec, that.mInlinePresentationSpec) 281 && java.util.Objects.equals(mSource, that.mSource) 282 && java.util.Arrays.equals(mAutofillHints, that.mAutofillHints) 283 && java.util.Objects.equals(mType, that.mType) 284 && mPinned == that.mPinned 285 && java.util.Objects.equals(mTooltip, that.mTooltip); 286 } 287 288 @Override 289 @DataClass.Generated.Member hashCode()290 public int hashCode() { 291 // You can override field hashCode logic by defining methods like: 292 // int fieldNameHashCode() { ... } 293 294 int _hash = 1; 295 _hash = 31 * _hash + java.util.Objects.hashCode(mInlinePresentationSpec); 296 _hash = 31 * _hash + java.util.Objects.hashCode(mSource); 297 _hash = 31 * _hash + java.util.Arrays.hashCode(mAutofillHints); 298 _hash = 31 * _hash + java.util.Objects.hashCode(mType); 299 _hash = 31 * _hash + Boolean.hashCode(mPinned); 300 _hash = 31 * _hash + java.util.Objects.hashCode(mTooltip); 301 return _hash; 302 } 303 304 @Override 305 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)306 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 307 // You can override field parcelling by defining methods like: 308 // void parcelFieldName(Parcel dest, int flags) { ... } 309 310 byte flg = 0; 311 if (mPinned) flg |= 0x10; 312 if (mAutofillHints != null) flg |= 0x4; 313 if (mTooltip != null) flg |= 0x20; 314 dest.writeByte(flg); 315 dest.writeTypedObject(mInlinePresentationSpec, flags); 316 dest.writeString(mSource); 317 if (mAutofillHints != null) dest.writeStringArray(mAutofillHints); 318 dest.writeString(mType); 319 if (mTooltip != null) dest.writeTypedObject(mTooltip, flags); 320 } 321 322 @Override 323 @DataClass.Generated.Member describeContents()324 public int describeContents() { return 0; } 325 326 /** @hide */ 327 @SuppressWarnings({"unchecked", "RedundantCast"}) 328 @DataClass.Generated.Member InlineSuggestionInfo(@onNull android.os.Parcel in)329 /* package-private */ InlineSuggestionInfo(@NonNull android.os.Parcel in) { 330 // You can override field unparcelling by defining methods like: 331 // static FieldType unparcelFieldName(Parcel in) { ... } 332 333 byte flg = in.readByte(); 334 boolean pinned = (flg & 0x10) != 0; 335 InlinePresentationSpec inlinePresentationSpec = (InlinePresentationSpec) in.readTypedObject(InlinePresentationSpec.CREATOR); 336 String source = in.readString(); 337 String[] autofillHints = (flg & 0x4) == 0 ? null : in.createStringArray(); 338 String type = in.readString(); 339 InlineSuggestion tooltip = (flg & 0x20) == 0 ? null : (InlineSuggestion) in.readTypedObject(InlineSuggestion.CREATOR); 340 341 this.mInlinePresentationSpec = inlinePresentationSpec; 342 com.android.internal.util.AnnotationValidations.validate( 343 NonNull.class, null, mInlinePresentationSpec); 344 this.mSource = source; 345 346 if (!(java.util.Objects.equals(mSource, SOURCE_AUTOFILL)) 347 && !(java.util.Objects.equals(mSource, SOURCE_PLATFORM))) { 348 throw new java.lang.IllegalArgumentException( 349 "source was " + mSource + " but must be one of: " 350 + "SOURCE_AUTOFILL(" + SOURCE_AUTOFILL + "), " 351 + "SOURCE_PLATFORM(" + SOURCE_PLATFORM + ")"); 352 } 353 354 com.android.internal.util.AnnotationValidations.validate( 355 NonNull.class, null, mSource); 356 this.mAutofillHints = autofillHints; 357 this.mType = type; 358 359 if (!(java.util.Objects.equals(mType, TYPE_SUGGESTION)) 360 && !(java.util.Objects.equals(mType, TYPE_ACTION))) { 361 throw new java.lang.IllegalArgumentException( 362 "type was " + mType + " but must be one of: " 363 + "TYPE_SUGGESTION(" + TYPE_SUGGESTION + "), " 364 + "TYPE_ACTION(" + TYPE_ACTION + ")"); 365 } 366 367 com.android.internal.util.AnnotationValidations.validate( 368 NonNull.class, null, mType); 369 this.mPinned = pinned; 370 this.mTooltip = tooltip; 371 372 // onConstructed(); // You can define this method to get a callback 373 } 374 375 @DataClass.Generated.Member 376 public static final @NonNull Parcelable.Creator<InlineSuggestionInfo> CREATOR 377 = new Parcelable.Creator<InlineSuggestionInfo>() { 378 @Override 379 public InlineSuggestionInfo[] newArray(int size) { 380 return new InlineSuggestionInfo[size]; 381 } 382 383 @Override 384 public InlineSuggestionInfo createFromParcel(@NonNull android.os.Parcel in) { 385 return new InlineSuggestionInfo(in); 386 } 387 }; 388 389 @DataClass.Generated( 390 time = 1614287616672L, 391 codegenVersion = "1.0.22", 392 sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestionInfo.java", 393 inputSignatures = "public static final @android.view.inputmethod.InlineSuggestionInfo.Source java.lang.String SOURCE_AUTOFILL\npublic static final @android.view.inputmethod.InlineSuggestionInfo.Source java.lang.String SOURCE_PLATFORM\npublic static final @android.view.inputmethod.InlineSuggestionInfo.Type java.lang.String TYPE_SUGGESTION\npublic static final @android.annotation.SuppressLint @android.view.inputmethod.InlineSuggestionInfo.Type java.lang.String TYPE_ACTION\nprivate final @android.annotation.NonNull android.widget.inline.InlinePresentationSpec mInlinePresentationSpec\nprivate final @android.annotation.NonNull @android.view.inputmethod.InlineSuggestionInfo.Source java.lang.String mSource\nprivate final @android.annotation.Nullable java.lang.String[] mAutofillHints\nprivate final @android.annotation.NonNull @android.view.inputmethod.InlineSuggestionInfo.Type java.lang.String mType\nprivate final boolean mPinned\nprivate final @android.annotation.Nullable android.view.inputmethod.InlineSuggestion mTooltip\npublic static @android.annotation.TestApi @android.annotation.NonNull android.view.inputmethod.InlineSuggestionInfo newInlineSuggestionInfo(android.widget.inline.InlinePresentationSpec,java.lang.String,java.lang.String[],java.lang.String,boolean)\npublic static @android.annotation.NonNull android.view.inputmethod.InlineSuggestionInfo newInlineSuggestionInfo(android.widget.inline.InlinePresentationSpec,java.lang.String,java.lang.String[],java.lang.String,boolean,android.view.inputmethod.InlineSuggestion)\nclass InlineSuggestionInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstDefs=true, genHiddenConstructor=true)") 394 @Deprecated __metadata()395 private void __metadata() {} 396 397 398 //@formatter:on 399 // End of generated code 400 401 } 402