Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82f60fe7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add config for save dialog height percent" into tm-dev am: a5f8f650...

Merge "Add config for save dialog height percent" into tm-dev am: a5f8f650 am: b04c2c12 am: 616b5db3 am: 3d9619dd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18260673



Change-Id: If1402940bdb4bf2e357946394d765d7530d06190
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 24afc17f 3d9619dd
Loading
Loading
Loading
Loading
+63 −9
Original line number Diff line number Diff line
@@ -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);
    }
}