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

Commit de565f3b authored by Adam Powell's avatar Adam Powell Committed by Android Git Automerger
Browse files

am 7136544c: Merge "Keyguard - MultiPaneChallengeLayout measurement/layout...

am 7136544c: Merge "Keyguard - MultiPaneChallengeLayout measurement/layout changes" into jb-mr1-lockscreen-dev

* commit '7136544c':
  Keyguard - MultiPaneChallengeLayout measurement/layout changes
parents b000c362 7136544c
Loading
Loading
Loading
Loading
+60 −42
Original line number Original line Diff line number Diff line
@@ -16,21 +16,22 @@


package com.android.internal.policy.impl.keyguard;
package com.android.internal.policy.impl.keyguard;


import com.android.internal.R;

import android.animation.Animator;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.Gravity;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout;


import com.android.internal.R;

public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayout {
public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayout {
    private static final String TAG = "MultiPaneChallengeLayout";
    private static final String TAG = "MultiPaneChallengeLayout";


@@ -47,7 +48,8 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
    private OnBouncerStateChangedListener mBouncerListener;
    private OnBouncerStateChangedListener mBouncerListener;


    private final Rect mTempRect = new Rect();
    private final Rect mTempRect = new Rect();
    private final Context mContext;

    private final DisplayMetrics mDisplayMetrics;


    private final OnClickListener mScrimClickListener = new OnClickListener() {
    private final OnClickListener mScrimClickListener = new OnClickListener() {
        @Override
        @Override
@@ -67,13 +69,14 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
    public MultiPaneChallengeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    public MultiPaneChallengeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        super(context, attrs, defStyleAttr);


        mContext = context;

        final TypedArray a = context.obtainStyledAttributes(attrs,
        final TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.MultiPaneChallengeLayout, defStyleAttr, 0);
                R.styleable.MultiPaneChallengeLayout, defStyleAttr, 0);
        mOrientation = a.getInt(R.styleable.MultiPaneChallengeLayout_orientation,
        mOrientation = a.getInt(R.styleable.MultiPaneChallengeLayout_orientation,
                HORIZONTAL);
                HORIZONTAL);
        a.recycle();
        a.recycle();

        final Resources res = getResources();
        mDisplayMetrics = res.getDisplayMetrics();
    }
    }


    @Override
    @Override
@@ -169,15 +172,32 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
        mScrimView.setOnClickListener(mScrimClickListener);
        mScrimView.setOnClickListener(mScrimClickListener);
    }
    }


    private int getVirtualHeight(LayoutParams lp, int height, int heightUsed) {
        int virtualHeight = height;
        final View root = getRootView();
        if (root != null) {
            // This calculation is super dodgy and relies on several assumptions.
            // Specifically that the root of the window will be padded in for insets
            // and that the window is LAYOUT_IN_SCREEN.
            virtualHeight = mDisplayMetrics.heightPixels - root.getPaddingTop();
        }
        if (lp.childType == LayoutParams.CHILD_TYPE_WIDGET ||
                lp.childType == LayoutParams.CHILD_TYPE_USER_SWITCHER) {
            // Always measure the widget pager/user switcher as if there were no IME insets
            // on the window. We want to avoid resizing widgets when possible as it can
            // be ugly/expensive. This lets us simply clip them instead.
            return virtualHeight - heightUsed;
        }
        return Math.min(virtualHeight - heightUsed, height);
    }

    @Override
    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {
    protected void onMeasure(final int widthSpec, final int heightSpec) {
        if (MeasureSpec.getMode(widthSpec) != MeasureSpec.EXACTLY ||
        if (MeasureSpec.getMode(widthSpec) != MeasureSpec.EXACTLY ||
                MeasureSpec.getMode(heightSpec) != MeasureSpec.EXACTLY) {
                MeasureSpec.getMode(heightSpec) != MeasureSpec.EXACTLY) {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
                    "MultiPaneChallengeLayout must be measured with an exact size");
                    "MultiPaneChallengeLayout must be measured with an exact size");
        }
        }
        float squashedLayoutThreshold =
                mContext.getResources().getDimension(R.dimen.kg_squashed_layout_threshold);


        final int width = MeasureSpec.getSize(widthSpec);
        final int width = MeasureSpec.getSize(widthSpec);
        final int height = MeasureSpec.getSize(heightSpec);
        final int height = MeasureSpec.getSize(heightSpec);
@@ -213,21 +233,16 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
                mUserSwitcherView = child;
                mUserSwitcherView = child;


                if (child.getVisibility() == GONE) continue;
                if (child.getVisibility() == GONE) continue;
                if (height < squashedLayoutThreshold) {

                    int zero = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);
                    measureChild(child, zero, zero);
                } else {
                int adjustedWidthSpec = widthSpec;
                int adjustedWidthSpec = widthSpec;
                int adjustedHeightSpec = heightSpec;
                int adjustedHeightSpec = heightSpec;
                if (lp.maxWidth >= 0) {
                if (lp.maxWidth >= 0) {
                    adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                    adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                                Math.min(lp.maxWidth, MeasureSpec.getSize(widthSpec)),
                            Math.min(lp.maxWidth, width), MeasureSpec.EXACTLY);
                                MeasureSpec.EXACTLY);
                }
                }
                if (lp.maxHeight >= 0) {
                if (lp.maxHeight >= 0) {
                    adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                    adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                                Math.min(lp.maxHeight, MeasureSpec.getSize(heightSpec)),
                            Math.min(lp.maxHeight, height), MeasureSpec.EXACTLY);
                                MeasureSpec.EXACTLY);
                }
                }
                // measureChildWithMargins will resolve layout direction for the LayoutParams
                // measureChildWithMargins will resolve layout direction for the LayoutParams
                measureChildWithMargins(child, adjustedWidthSpec, 0, adjustedHeightSpec, 0);
                measureChildWithMargins(child, adjustedWidthSpec, 0, adjustedHeightSpec, 0);
@@ -239,7 +254,6 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
                } else if (Gravity.isHorizontal(lp.gravity)) {
                } else if (Gravity.isHorizontal(lp.gravity)) {
                    widthUsed += child.getMeasuredWidth() * 1.5f;
                    widthUsed += child.getMeasuredWidth() * 1.5f;
                }
                }
                }
            } else if (lp.childType == LayoutParams.CHILD_TYPE_SCRIM) {
            } else if (lp.childType == LayoutParams.CHILD_TYPE_SCRIM) {
                setScrimView(child);
                setScrimView(child);
                child.measure(widthSpec, heightSpec);
                child.measure(widthSpec, heightSpec);
@@ -258,6 +272,8 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
                continue;
                continue;
            }
            }


            final int virtualHeight = getVirtualHeight(lp, height, heightUsed);

            int adjustedWidthSpec;
            int adjustedWidthSpec;
            int adjustedHeightSpec;
            int adjustedHeightSpec;
            if (lp.centerWithinArea > 0) {
            if (lp.centerWithinArea > 0) {
@@ -266,19 +282,19 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
                            (int) ((width - widthUsed) * lp.centerWithinArea + 0.5f),
                            (int) ((width - widthUsed) * lp.centerWithinArea + 0.5f),
                            MeasureSpec.EXACTLY);
                            MeasureSpec.EXACTLY);
                    adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                    adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                            MeasureSpec.getSize(heightSpec) - heightUsed, MeasureSpec.EXACTLY);
                            virtualHeight, MeasureSpec.EXACTLY);
                } else {
                } else {
                    adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                    adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                            MeasureSpec.getSize(widthSpec) - widthUsed, MeasureSpec.EXACTLY);
                            width - widthUsed, MeasureSpec.EXACTLY);
                    adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                    adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                            (int) ((height - heightUsed) * lp.centerWithinArea + 0.5f),
                            (int) (virtualHeight * lp.centerWithinArea + 0.5f),
                            MeasureSpec.EXACTLY);
                            MeasureSpec.EXACTLY);
                }
                }
            } else {
            } else {
                adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                        MeasureSpec.getSize(widthSpec) - widthUsed, MeasureSpec.EXACTLY);
                        width - widthUsed, MeasureSpec.EXACTLY);
                adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                adjustedHeightSpec = MeasureSpec.makeMeasureSpec(
                        MeasureSpec.getSize(heightSpec) - heightUsed, MeasureSpec.EXACTLY);
                        virtualHeight, MeasureSpec.EXACTLY);
            }
            }
            if (lp.maxWidth >= 0) {
            if (lp.maxWidth >= 0) {
                adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
                adjustedWidthSpec = MeasureSpec.makeMeasureSpec(
@@ -331,6 +347,9 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
            boolean adjustPadding) {
            boolean adjustPadding) {
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();


        final int heightUsed = padding.top + padding.bottom - getPaddingTop() - getPaddingBottom();
        height = getVirtualHeight(lp, height, heightUsed);

        final int gravity = Gravity.getAbsoluteGravity(lp.gravity, getLayoutDirection());
        final int gravity = Gravity.getAbsoluteGravity(lp.gravity, getLayoutDirection());


        final boolean fixedLayoutSize = lp.centerWithinArea > 0;
        final boolean fixedLayoutSize = lp.centerWithinArea > 0;
@@ -382,8 +401,7 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
                }
                }
                break;
                break;
            case Gravity.CENTER_VERTICAL:
            case Gravity.CENTER_VERTICAL:
                final int paddedHeight = height - padding.top - padding.bottom;
                top = padding.top + (height - childHeight) / 2;
                top = padding.top + (paddedHeight - childHeight) / 2;
                bottom = top + childHeight;
                bottom = top + childHeight;
                break;
                break;
        }
        }