1 /* 2 * Copyright (C) 2018 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 package android.service.autofill.augmented; 17 18 import android.annotation.NonNull; 19 import android.annotation.Nullable; 20 import android.annotation.SystemApi; 21 import android.graphics.Rect; 22 import android.service.autofill.augmented.AugmentedAutofillService.AutofillProxy; 23 import android.view.View; 24 25 import java.io.PrintWriter; 26 27 /** 28 * Abstraction of a "Smart Suggestion" component responsible to embed the autofill UI provided by 29 * the augmented autofill service. 30 * 31 * <p>The Smart Suggestion is represented by a {@link Area} object that contains the 32 * dimensions the smart suggestion window, so the service can use it to calculate the size of the 33 * view that will be passed to {@link FillWindow#update(Area, View, long)}. 34 * 35 * @hide 36 */ 37 @SystemApi 38 public abstract class PresentationParams { 39 40 // /** @hide */ PresentationParams()41 PresentationParams() {} 42 43 /** 44 * Gets the area of the suggestion strip for the given {@code metadata} 45 * 46 * @return strip dimensions, or {@code null} if the Smart Suggestion provider does not support 47 * suggestions strip. 48 */ 49 @Nullable getSuggestionArea()50 public Area getSuggestionArea() { 51 return null; 52 } 53 dump(String prefix, PrintWriter pw)54 abstract void dump(String prefix, PrintWriter pw); 55 56 /** 57 * Area associated with a {@link PresentationParams Smart Suggestions} provider. 58 * 59 * @hide 60 */ 61 @SystemApi 62 public abstract static class Area { 63 64 /** @hide */ 65 public final AutofillProxy proxy; 66 67 private final Rect mBounds; 68 Area(@onNull AutofillProxy proxy, @NonNull Rect bounds)69 private Area(@NonNull AutofillProxy proxy, @NonNull Rect bounds) { 70 this.proxy = proxy; 71 mBounds = bounds; 72 } 73 74 /** 75 * Gets the area boundaries. 76 */ 77 @NonNull getBounds()78 public Rect getBounds() { 79 return mBounds; 80 } 81 82 @NonNull 83 @Override toString()84 public String toString() { 85 return mBounds.toString(); 86 } 87 } 88 89 /** 90 * System-provided poup window anchored to a view. 91 * 92 * <p>Used just for debugging purposes. 93 * 94 * @hide 95 */ 96 public static final class SystemPopupPresentationParams extends PresentationParams { 97 private final Area mSuggestionArea; 98 SystemPopupPresentationParams(@onNull AutofillProxy proxy, @NonNull Rect rect)99 public SystemPopupPresentationParams(@NonNull AutofillProxy proxy, @NonNull Rect rect) { 100 mSuggestionArea = new Area(proxy, rect) {}; 101 } 102 103 @Override getSuggestionArea()104 public Area getSuggestionArea() { 105 return mSuggestionArea; 106 } 107 108 @Override dump(@onNull String prefix, @NonNull PrintWriter pw)109 void dump(@NonNull String prefix, @NonNull PrintWriter pw) { 110 pw.print(prefix); pw.print("area: "); pw.println(mSuggestionArea); 111 } 112 } 113 } 114