diff options
| author | 2022-05-17 00:55:55 +0000 | |
|---|---|---|
| committer | 2022-05-17 00:55:55 +0000 | |
| commit | a5f8f650ce774476e15ff91f1bbfe749bc7e2c1e (patch) | |
| tree | 3bad626ad7f93207b4138d9970056bcc6a52b1da | |
| parent | b15f154c2b037f11beebabd3fd8ab10661e8a748 (diff) | |
| parent | 9476fc299ae9c191e9a7dfa05d34ac5f9c5e7cfa (diff) | |
Merge "Add config for save dialog height percent" into tm-dev
| -rw-r--r-- | services/autofill/java/com/android/server/autofill/ui/CustomScrollView.java | 72 |
1 files changed, 63 insertions, 9 deletions
diff --git a/services/autofill/java/com/android/server/autofill/ui/CustomScrollView.java b/services/autofill/java/com/android/server/autofill/ui/CustomScrollView.java index 14bd7d78f3bf..9e8b2228195e 100644 --- a/services/autofill/java/com/android/server/autofill/ui/CustomScrollView.java +++ b/services/autofill/java/com/android/server/autofill/ui/CustomScrollView.java @@ -18,7 +18,9 @@ package com.android.server.autofill.ui; import static com.android.server.autofill.Helper.sDebug; import android.content.Context; +import android.content.res.Configuration; import android.graphics.Point; +import android.provider.DeviceConfig; import android.util.AttributeSet; import android.util.Slog; import android.util.TypedValue; @@ -34,24 +36,59 @@ public class CustomScrollView extends ScrollView { private static final String TAG = "CustomScrollView"; + /** + * Sets the max percent of screen that the autofill save dialog can take up in height + * when the device is in portrait orientation. + * + * @hide + */ + public static final String DEVICE_CONFIG_SAVE_DIALOG_PORTRAIT_BODY_HEIGHT_MAX_PERCENT = + "autofill_save_dialog_portrait_body_height_max_percent"; + + /** + * Sets the max percent of screen that the autofill save dialog can take up in height + * when the device is in landscape orientation. + * + * @hide + */ + public static final String DEVICE_CONFIG_SAVE_DIALOG_LANDSCAPE_BODY_HEIGHT_MAX_PERCENT = + "autofill_save_dialog_landscape_body_height_max_percent"; + private int mWidth = -1; private int mHeight = -1; + private int mMaxPortraitBodyHeightPercent = 20; + private int mMaxLandscapeBodyHeightPercent = 20; public CustomScrollView(Context context) { super(context); + setMaxBodyHeightPercent(); } public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); + setMaxBodyHeightPercent(); } public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + setMaxBodyHeightPercent(); } public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); + setMaxBodyHeightPercent(); + } + + private void setMaxBodyHeightPercent() { + mMaxPortraitBodyHeightPercent = DeviceConfig.getInt( + DeviceConfig.NAMESPACE_AUTOFILL, + DEVICE_CONFIG_SAVE_DIALOG_PORTRAIT_BODY_HEIGHT_MAX_PERCENT, + mMaxPortraitBodyHeightPercent); + mMaxLandscapeBodyHeightPercent = DeviceConfig.getInt( + DeviceConfig.NAMESPACE_AUTOFILL, + DEVICE_CONFIG_SAVE_DIALOG_LANDSCAPE_BODY_HEIGHT_MAX_PERCENT, + mMaxLandscapeBodyHeightPercent); } @Override @@ -72,20 +109,37 @@ public class CustomScrollView extends ScrollView { private void calculateDimensions() { if (mHeight != -1) return; - final TypedValue typedValue = new TypedValue(); final Point point = new Point(); final Context context = getContext(); context.getDisplayNoVerify().getSize(point); - context.getTheme().resolveAttribute(R.attr.autofillSaveCustomSubtitleMaxHeight, - typedValue, true); - final View child = getChildAt(0); - final int childHeight = child.getMeasuredHeight(); - final int maxHeight = (int) typedValue.getFraction(point.y, point.y); - mHeight = Math.min(childHeight, maxHeight); + final View content = getChildAt(0); + final int contentHeight = content.getMeasuredHeight(); + int displayHeight = point.y; + + int configBasedMaxHeight = (getResources().getConfiguration().orientation + == Configuration.ORIENTATION_LANDSCAPE) + ? (int) (mMaxLandscapeBodyHeightPercent * displayHeight / 100) + : (int) (mMaxPortraitBodyHeightPercent * displayHeight / 100); + mHeight = configBasedMaxHeight > 0 + ? Math.min(contentHeight, configBasedMaxHeight) + : Math.min(contentHeight, getAttrBasedMaxHeight(context, displayHeight)); + if (sDebug) { - Slog.d(TAG, "calculateDimensions(): maxHeight=" + maxHeight - + ", childHeight=" + childHeight + ", w=" + mWidth + ", h=" + mHeight); + Slog.d(TAG, "calculateDimensions():" + + " mMaxPortraitBodyHeightPercent=" + mMaxPortraitBodyHeightPercent + + ", mMaxLandscapeBodyHeightPercent=" + mMaxLandscapeBodyHeightPercent + + ", configBasedMaxHeight=" + configBasedMaxHeight + + ", attrBasedMaxHeight=" + getAttrBasedMaxHeight(context, displayHeight) + + ", contentHeight=" + contentHeight + + ", w=" + mWidth + ", h=" + mHeight); } } + + private int getAttrBasedMaxHeight(Context context, int displayHeight) { + final TypedValue maxHeightAttrTypedValue = new TypedValue(); + context.getTheme().resolveAttribute(R.attr.autofillSaveCustomSubtitleMaxHeight, + maxHeightAttrTypedValue, true); + return (int) maxHeightAttrTypedValue.getFraction(displayHeight, displayHeight); + } } |