Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 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 | */ |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame^] | 16 | package android.service.autofill.augmented; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 17 | |
| 18 | import android.annotation.IntDef; |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.annotation.SystemApi; |
| 22 | import android.graphics.Rect; |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame^] | 23 | import android.service.autofill.augmented.AugmentedAutofillService.AutofillProxy; |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 24 | import android.util.DebugUtils; |
| 25 | import android.view.View; |
| 26 | |
| 27 | import java.io.PrintWriter; |
| 28 | import java.lang.annotation.Retention; |
| 29 | import java.lang.annotation.RetentionPolicy; |
| 30 | |
| 31 | /** |
| 32 | * Abstraction of a "Smart Suggestion" component responsible to embed the autofill UI provided by |
| 33 | * the intelligence service. |
| 34 | * |
| 35 | * <p>The Smart Suggestion can embed the autofill UI in 3 distinct places: |
| 36 | * |
| 37 | * <ul> |
| 38 | * <li>A small area associated with suggestions (like a small strip in the top of the IME), |
| 39 | * returned by {@link #getSuggestionArea()} |
| 40 | * <li>The full area (like the full IME window), returned by {@link #getFullArea()} |
| 41 | * <li>A subset of the aforementioned areas, returned by {@link Area#getSubArea(Rect)} |
| 42 | * </ul> |
| 43 | * |
| 44 | * <p>The Smart Suggestion is represented by a {@link Area} object that contains the |
| 45 | * dimensions the smart suggestion window, so the service can use it to calculate the size of the |
| 46 | * view that will be passed to {@link FillWindow#update(Area, View, long)}. |
| 47 | * |
| 48 | * @hide |
| 49 | */ |
| 50 | @SystemApi |
| 51 | public abstract class PresentationParams { |
| 52 | |
| 53 | /** |
| 54 | * Flag indicating the Smart Suggestion is hosted in the top of its container. |
| 55 | */ |
| 56 | public static final int FLAG_HINT_GRAVITY_TOP = 0x1; |
| 57 | |
| 58 | /** |
| 59 | * Flag indicating the Smart Suggestion is hosted in the bottom of its container. |
| 60 | */ |
| 61 | public static final int FLAG_HINT_GRAVITY_BOTTOM = 0x2; |
| 62 | |
| 63 | /** |
| 64 | * Flag indicating the Smart Suggestion is hosted in the left of its container. |
| 65 | */ |
| 66 | public static final int FLAG_HINT_GRAVITY_LEFT = 0x4; |
| 67 | |
| 68 | /** |
| 69 | * Flag indicating the Smart Suggestion is hosted in the right of its container. |
| 70 | */ |
| 71 | public static final int FLAG_HINT_GRAVITY_RIGHT = 0x8; |
| 72 | |
| 73 | /** |
| 74 | * Flag indicating the Smart Suggestion is hosted by the IME. |
| 75 | */ |
| 76 | public static final int FLAG_HOST_IME = 0x10; |
| 77 | |
| 78 | /** |
| 79 | * Flag indicating the Smart Suggestion is hosted by the Android System as a floating popup |
| 80 | * window. |
| 81 | */ |
| 82 | public static final int FLAG_HOST_SYSTEM = 0x20; |
| 83 | |
| 84 | /** @hide */ |
| 85 | @IntDef(flag = true, prefix = { "FLAG_" }, value = { |
| 86 | FLAG_HINT_GRAVITY_TOP, |
| 87 | FLAG_HINT_GRAVITY_BOTTOM, |
| 88 | FLAG_HINT_GRAVITY_LEFT, |
| 89 | FLAG_HINT_GRAVITY_RIGHT, |
| 90 | FLAG_HOST_IME, |
| 91 | FLAG_HOST_SYSTEM |
| 92 | }) |
| 93 | @Retention(RetentionPolicy.SOURCE) |
| 94 | @interface Flags {} |
| 95 | |
| 96 | |
| 97 | // /** @hide */ |
| 98 | PresentationParams() {} |
| 99 | |
| 100 | /** |
| 101 | * Gets the area of the suggestion strip for the given {@code metadata} |
| 102 | * |
| 103 | * @return strip dimensions, or {@code null} if the Smart Suggestion provider does not support |
| 104 | * suggestions strip. |
| 105 | */ |
| 106 | @Nullable |
| 107 | public Area getSuggestionArea() { |
| 108 | return null; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Gets the full area for the of the Smart Suggestion provider. |
| 113 | * |
| 114 | * @return full dimensions, or {@code null} if the Smart Suggestion provider does not support |
| 115 | * embeding the UI on its full area. |
| 116 | */ |
| 117 | @Nullable |
| 118 | public Area getFullArea() { |
| 119 | return null; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Gets flags associated with the Smart Suggestion. |
| 124 | * |
| 125 | * @return any combination of {@link #FLAG_HINT_GRAVITY_TOP}, |
| 126 | * {@link #FLAG_HINT_GRAVITY_BOTTOM}, {@link #FLAG_HINT_GRAVITY_LEFT}, |
| 127 | * {@link #FLAG_HINT_GRAVITY_RIGHT}, {@link #FLAG_HOST_IME}, or |
| 128 | * {@link #FLAG_HOST_SYSTEM}, |
| 129 | */ |
| 130 | public @Flags int getFlags() { |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | /** @hide */ |
| 135 | void dump(@NonNull String prefix, @NonNull PrintWriter pw) { |
| 136 | final int flags = getFlags(); |
| 137 | if (flags > 0) { |
| 138 | pw.print(prefix); pw.print("flags: "); pw.println(flagsToString(flags)); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | private static String flagsToString(int flags) { |
| 143 | return DebugUtils.flagsToString(PresentationParams.class, "FLAG_", flags); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Area associated with a {@link PresentationParams Smart Suggestions} provider. |
| 148 | * |
| 149 | * @hide |
| 150 | * */ |
| 151 | @SystemApi |
| 152 | public abstract static class Area { |
| 153 | |
| 154 | /** @hide */ |
| 155 | public final AutofillProxy proxy; |
| 156 | |
| 157 | private final Rect mBounds; |
| 158 | |
| 159 | private Area(@NonNull AutofillProxy proxy, @NonNull Rect bounds) { |
| 160 | this.proxy = proxy; |
| 161 | mBounds = bounds; |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Gets the area boundaries. |
| 166 | */ |
| 167 | @NonNull |
| 168 | public Rect getBounds() { |
| 169 | return mBounds; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Gets a subarea limited by given boundaries. |
| 174 | * |
| 175 | * @param bounds boundaries relative to this Area. |
| 176 | * |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 177 | * @return new subarea, or {@code null} if the Smart Suggestion host does not support such |
| 178 | * subaarea. |
Felipe Leme | 749b889 | 2018-12-03 16:30:30 -0800 | [diff] [blame^] | 179 | * |
| 180 | * @throws IllegalArgumentException if the {@code bounds} is not fully-contained inside this |
| 181 | * full Area. |
| 182 | * |
Felipe Leme | 284ad1c | 2018-11-15 18:16:12 -0800 | [diff] [blame] | 183 | */ |
| 184 | @Nullable |
| 185 | public Area getSubArea(@NonNull Rect bounds) { |
| 186 | // TODO(b/111330312): implement / check boundaries / throw IAE / add unit test |
| 187 | return null; |
| 188 | } |
| 189 | |
| 190 | @Override |
| 191 | public String toString() { |
| 192 | return mBounds.toString(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * System-provided poup window anchored to a view. |
| 198 | * |
| 199 | * <p>Used just for debugging purposes. |
| 200 | * |
| 201 | * @hide |
| 202 | */ |
| 203 | public static final class SystemPopupPresentationParams extends PresentationParams { |
| 204 | private final Area mSuggestionArea; |
| 205 | |
| 206 | public SystemPopupPresentationParams(@NonNull AutofillProxy proxy, @NonNull Rect rect) { |
| 207 | mSuggestionArea = new Area(proxy, rect) {}; |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public Area getSuggestionArea() { |
| 212 | return mSuggestionArea; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public int getFlags() { |
| 217 | return FLAG_HOST_SYSTEM | FLAG_HINT_GRAVITY_BOTTOM; |
| 218 | } |
| 219 | |
| 220 | @Override |
| 221 | void dump(@NonNull String prefix, @NonNull PrintWriter pw) { |
| 222 | super.dump(prefix, pw); |
| 223 | pw.print(prefix); pw.print("area: "); pw.println(mSuggestionArea); |
| 224 | } |
| 225 | } |
| 226 | } |