Merge "Make auth fill UI size sane size" into oc-dev
am: c0851e72a5
Change-Id: Ie7ce1a2a92e2fa3e653df3f95be8ff6a8f4d2a47
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index c421514..cfe25b3 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -63,6 +63,12 @@
<!-- Drawable to be drawn over the view to mark it as autofilled-->
<attr name="autofilledHighlight" format="reference" />
+ <!-- Max width of the autofill data set picker as a fraction of the screen width -->
+ <attr name="autofillDatasetPickerMaxWidth" format="reference" />
+
+ <!-- Max height of the autofill data set picker as a fraction of the screen height -->
+ <attr name="autofillDatasetPickerMaxHeight" format="reference" />
+
<!-- Default disabled alpha for widgets that set enabled/disabled alpha programmatically. -->
<attr name="disabledAlpha" format="float" />
<!-- The alpha applied to the foreground color to create the primary text color. -->
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index ef6c21f..ece0e82 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -536,4 +536,8 @@
<dimen name="item_touch_helper_max_drag_scroll_per_frame">20dp</dimen>
<dimen name="item_touch_helper_swipe_escape_velocity">120dp</dimen>
<dimen name="item_touch_helper_swipe_escape_max_velocity">800dp</dimen>
+
+ <!-- Max width/height of the autofill data set picker as a fraction of the screen width/height -->
+ <dimen name="autofill_dataset_picker_max_size">90%</dimen>
+
</resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 1d2bc19..1966f6a 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -239,7 +239,8 @@
<java-symbol type="attr" name="accessibilityFocusedDrawable"/>
<java-symbol type="attr" name="isLightTheme"/>
<java-symbol type="attr" name="autofilledHighlight"/>
-
+ <java-symbol type="attr" name="autofillDatasetPickerMaxWidth"/>
+ <java-symbol type="attr" name="autofillDatasetPickerMaxHeight"/>
<java-symbol type="bool" name="action_bar_embed_tabs" />
<java-symbol type="bool" name="action_bar_expanded_action_views_exclusive" />
<java-symbol type="bool" name="config_avoidGfxAccel" />
@@ -2906,6 +2907,7 @@
<java-symbol type="string" name="autofill_save_type_email_address" />
<java-symbol type="drawable" name="autofill_dataset_picker_background" />
<java-symbol type="style" name="AutofillDatasetPicker" />
+ <java-symbol type="dimen" name="autofill_dataset_picker_max_size"/>
<!-- Accessibility fingerprint gestures -->
<java-symbol type="string" name="capability_title_canCaptureFingerprintGestures" />
@@ -3007,4 +3009,5 @@
<java-symbol type="array" name="config_allowedGlobalInstantAppSettings" />
<java-symbol type="array" name="config_allowedSystemInstantAppSettings" />
<java-symbol type="array" name="config_allowedSecureInstantAppSettings" />
+
</resources>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index e8fbf34..383ae5d 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -449,6 +449,10 @@
<item name="tooltipFrameBackground">@drawable/tooltip_frame</item>
<item name="tooltipForegroundColor">@color/bright_foreground_light</item>
<item name="tooltipBackgroundColor">@color/tooltip_background_light</item>
+
+ <!-- Autofill: max width/height of the dataset picker as a fraction of screen size -->
+ <item name="autofillDatasetPickerMaxWidth">@dimen/autofill_dataset_picker_max_size</item>
+ <item name="autofillDatasetPickerMaxHeight">@dimen/autofill_dataset_picker_max_size</item>
</style>
<!-- Variant of {@link #Theme} with no title bar -->
diff --git a/services/autofill/java/com/android/server/autofill/ui/FillUi.java b/services/autofill/java/com/android/server/autofill/ui/FillUi.java
index fa95e03..dd297a6 100644
--- a/services/autofill/java/com/android/server/autofill/ui/FillUi.java
+++ b/services/autofill/java/com/android/server/autofill/ui/FillUi.java
@@ -23,10 +23,12 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
+import android.graphics.Point;
import android.graphics.Rect;
import android.service.autofill.Dataset;
import android.service.autofill.FillResponse;
import android.util.Slog;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -52,6 +54,8 @@
private static final int VISIBLE_OPTIONS_MAX_COUNT = 3;
+ private static final TypedValue sTempTypedValue = new TypedValue();
+
interface Callback {
void onResponsePicked(@NonNull FillResponse response);
void onDatasetPicked(@NonNull Dataset dataset);
@@ -63,9 +67,13 @@
void startIntentSender(IntentSender intentSender);
}
+ private final @NonNull Point mTempPoint = new Point();
+
private final @NonNull AutofillWindowPresenter mWindowPresenter =
new AutofillWindowPresenter();
+ private final @NonNull Context mContext;
+
private final @NonNull AnchoredWindow mWindow;
private final @NonNull Callback mCallback;
@@ -84,6 +92,7 @@
FillUi(@NonNull Context context, @NonNull FillResponse response,
@NonNull AutofillId focusedViewId, @NonNull @Nullable String filterText,
@NonNull Callback callback) {
+ mContext = context;
mCallback = callback;
final LayoutInflater inflater = LayoutInflater.from(context);
@@ -115,13 +124,18 @@
mWindow = null;
return;
}
- final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
- final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
- content.measure(widthMeasureSpec, heightMeasureSpec);
+
+ Point maxSize = mTempPoint;
+ resolveMaxWindowSize(context, maxSize);
+ final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(maxSize.x,
+ MeasureSpec.AT_MOST);
+ final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxSize.y,
+ MeasureSpec.AT_MOST);
+
+ decor.measure(widthMeasureSpec, heightMeasureSpec);
decor.setOnClickListener(v -> mCallback.onResponsePicked(response));
- // TODO(b/37567439): temporary limiting maximum height and minimum width
- mContentWidth = Math.max(content.getMeasuredWidth(), 1000);
- mContentHeight = Math.min(content.getMeasuredHeight(), 500);
+ mContentWidth = content.getMeasuredWidth();
+ mContentHeight = content.getMeasuredHeight();
mWindow = new AnchoredWindow(decor);
mCallback.requestShowFillUi(mContentWidth, mContentHeight, mWindowPresenter);
@@ -245,6 +259,9 @@
return changed;
}
+ Point maxSize = mTempPoint;
+ resolveMaxWindowSize(mContext, maxSize);
+
mContentWidth = 0;
mContentHeight = 0;
@@ -254,12 +271,14 @@
for (int i = 0; i < itemCount; i++) {
View view = mAdapter.getItem(i).getView();
view.measure(widthMeasureSpec, heightMeasureSpec);
- final int newContentWidth = Math.max(mContentWidth, view.getMeasuredWidth());
+ final int clampedMeasuredWidth = Math.min(view.getMeasuredWidth(), maxSize.x);
+ final int newContentWidth = Math.max(mContentWidth, clampedMeasuredWidth);
if (newContentWidth != mContentWidth) {
mContentWidth = newContentWidth;
changed = true;
}
- final int newContentHeight = mContentHeight + view.getMeasuredHeight();
+ final int clampedMeasuredHeight = Math.min(view.getMeasuredHeight(), maxSize.y);
+ final int newContentHeight = mContentHeight + clampedMeasuredHeight;
if (newContentHeight != mContentHeight) {
mContentHeight = newContentHeight;
changed = true;
@@ -274,6 +293,17 @@
}
}
+ private static void resolveMaxWindowSize(Context context, Point outPoint) {
+ context.getDisplay().getSize(outPoint);
+ TypedValue typedValue = sTempTypedValue;
+ context.getTheme().resolveAttribute(R.attr.autofillDatasetPickerMaxWidth,
+ typedValue, true);
+ outPoint.x = (int) typedValue.getFraction(outPoint.x, outPoint.x);
+ context.getTheme().resolveAttribute(R.attr.autofillDatasetPickerMaxHeight,
+ typedValue, true);
+ outPoint.y = (int) typedValue.getFraction(outPoint.y, outPoint.y);
+ }
+
private static class ViewItem {
private final String mValue;
private final Dataset mDataset;