Merge "Add config for save dialog height percent" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a5f8f650ce
@@ -18,7 +18,9 @@ package com.android.server.autofill.ui;
|
|||||||
import static com.android.server.autofill.Helper.sDebug;
|
import static com.android.server.autofill.Helper.sDebug;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
|
import android.provider.DeviceConfig;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@@ -34,24 +36,59 @@ public class CustomScrollView extends ScrollView {
|
|||||||
|
|
||||||
private static final String TAG = "CustomScrollView";
|
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 mWidth = -1;
|
||||||
private int mHeight = -1;
|
private int mHeight = -1;
|
||||||
|
private int mMaxPortraitBodyHeightPercent = 20;
|
||||||
|
private int mMaxLandscapeBodyHeightPercent = 20;
|
||||||
|
|
||||||
public CustomScrollView(Context context) {
|
public CustomScrollView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
setMaxBodyHeightPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomScrollView(Context context, AttributeSet attrs) {
|
public CustomScrollView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
setMaxBodyHeightPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
|
setMaxBodyHeightPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr,
|
public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, 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
|
@Override
|
||||||
@@ -72,20 +109,37 @@ public class CustomScrollView extends ScrollView {
|
|||||||
private void calculateDimensions() {
|
private void calculateDimensions() {
|
||||||
if (mHeight != -1) return;
|
if (mHeight != -1) return;
|
||||||
|
|
||||||
final TypedValue typedValue = new TypedValue();
|
|
||||||
final Point point = new Point();
|
final Point point = new Point();
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
context.getDisplayNoVerify().getSize(point);
|
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) {
|
if (sDebug) {
|
||||||
Slog.d(TAG, "calculateDimensions(): maxHeight=" + maxHeight
|
Slog.d(TAG, "calculateDimensions():"
|
||||||
+ ", childHeight=" + childHeight + ", w=" + mWidth + ", h=" + mHeight);
|
+ " 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user