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

Commit 863e9bbe authored by Jonathon Axford's avatar Jonathon Axford Committed by Android (Google) Code Review
Browse files

Merge "Pattern bouncer refactor: motion layout - change constraints on rotate" into main

parents e1d80eff 461f259f
Loading
Loading
Loading
Loading
+109 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 2023, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License")
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<!-- This file is needed when flag lockscreen.enable_landscape is on
     Required for landscape lockscreen on small screens. -->
<com.android.keyguard.KeyguardPatternView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/res-auto"
    android:id="@+id/keyguard_pattern_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal|bottom"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:orientation="vertical">

    <!-- Layout here is visually identical to the previous keyguard_pattern_view.
             I.E., 'constraints here effectively the same as the previous linear layout' -->
    <androidx.constraintlayout.motion.widget.MotionLayout
        android:id="@+id/pattern_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:layoutDirection="ltr"
        android:orientation="vertical"
        android:maxWidth = "@dimen/biometric_auth_pattern_view_max_size"
        androidprv:layoutDescription="@xml/keyguard_pattern_scene">

        <!-- Guideline need to align pattern right of centre,
        when on small screen landscape layout -->
        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/pattern_center_guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            androidprv:layout_constraintGuide_percent="0.5" />

        <LinearLayout
            android:id="@+id/keyguard_bouncer_message_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:layoutDirection="ltr"
            android:orientation="vertical"
            androidprv:layout_constraintTop_toTopOf="parent">

            <include layout="@layout/keyguard_bouncer_message_area" />

            <com.android.systemui.bouncer.ui.BouncerMessageView
                android:id="@+id/bouncer_message_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" />

        </LinearLayout>

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/pattern_top_guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            androidprv:layout_constraintGuide_percent="0" />

        <com.android.internal.widget.LockPatternView
            android:id="@+id/lockPatternView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginBottom="8dp"
            androidprv:layout_constraintVertical_bias="1.0"
            androidprv:layout_constraintDimensionRatio="1.0"
            androidprv:layout_constraintStart_toStartOf="parent"
            androidprv:layout_constraintBottom_toTopOf="@+id/keyguard_selector_fade_container"
            androidprv:layout_constraintEnd_toEndOf="parent"
            androidprv:layout_constraintVertical_chainStyle="packed"
            androidprv:layout_constraintTop_toBottomOf="@id/pattern_top_guideline"/>

        <include
            android:id="@+id/keyguard_selector_fade_container"
            layout="@layout/keyguard_eca"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/keyguard_eca_bottom_margin"
            android:layout_marginTop="@dimen/keyguard_eca_top_margin"
            android:orientation="vertical"
            androidprv:layout_constraintBottom_toBottomOf="parent"
            androidprv:layout_constraintTop_toBottomOf="@+id/lockPatternView" />

    </androidx.constraintlayout.motion.widget.MotionLayout>

</com.android.keyguard.KeyguardPatternView>
 No newline at end of file
+47 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<MotionScene
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto"
    xmlns:androidprv="http://schemas.android.com/apk/res-auto">

    <Transition
        motion:constraintSetStart="@id/single_constraints"
        motion:constraintSetEnd="@+id/split_constraints"
        motion:duration="0"
        motion:autoTransition="none"/>

    <!-- No changes to default layout -->
    <ConstraintSet android:id="@+id/single_constraints"/>

    <ConstraintSet android:id="@+id/split_constraints">

        <Constraint
            android:id="@+id/keyguard_bouncer_message_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            androidprv:layout_constraintEnd_toStartOf="@+id/pattern_center_guideline"
            androidprv:layout_constraintStart_toStartOf="parent"
            androidprv:layout_constraintTop_toTopOf="parent" />
        <Constraint
            android:id="@+id/lockPatternView"
            android:layout_width="0dp"
            android:layout_height="0dp"
            androidprv:layout_constraintDimensionRatio="1.0"
            androidprv:layout_constraintVertical_bias="0.5"
            androidprv:layout_constraintBottom_toBottomOf="parent"
            androidprv:layout_constraintEnd_toEndOf="parent"
            androidprv:layout_constraintStart_toStartOf="@+id/pattern_center_guideline"
            androidprv:layout_constraintTop_toTopOf="parent"
            android:layout_marginBottom="0dp" />
        <Constraint
            android:id="@+id/keyguard_selector_fade_container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            androidprv:layout_constraintBottom_toBottomOf="parent"
            androidprv:layout_constraintEnd_toStartOf="@+id/pattern_center_guideline"
            androidprv:layout_constraintStart_toStartOf="parent"
            android:layout_marginBottom="@dimen/keyguard_eca_bottom_margin"
            android:layout_marginTop="@dimen/keyguard_eca_top_margin" />

    </ConstraintSet>
</MotionScene>
 No newline at end of file
+82 −16
Original line number Diff line number Diff line
@@ -15,9 +15,13 @@
 */
package com.android.keyguard;

import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;

import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_CLOSED;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN;

import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
@@ -29,6 +33,7 @@ import android.view.View;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;

import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;

@@ -75,7 +80,10 @@ public class KeyguardPatternView extends KeyguardInputView

    BouncerKeyguardMessageArea mSecurityMessageDisplay;
    private View mEcaView;
    private ConstraintLayout mContainer;
    @Nullable private MotionLayout mContainerMotionLayout;
    @Nullable private ConstraintLayout mContainerConstraintLayout;
    private boolean mAlreadyUsingSplitBouncer = false;
    private boolean mIsLockScreenLandscapeEnabled = false;
    @DevicePostureInt private int mLastDevicePosture = DEVICE_POSTURE_UNKNOWN;

    public KeyguardPatternView(Context context) {
@@ -98,29 +106,81 @@ public class KeyguardPatternView extends KeyguardInputView
                mContext, android.R.interpolator.fast_out_linear_in));
    }

    /**
     * Use motion layout (new bouncer implementation) if LOCKSCREEN_ENABLE_LANDSCAPE flag is
     * enabled, instead of constraint layout (old bouncer implementation)
     */
    public void setIsLockScreenLandscapeEnabled(boolean isLockScreenLandscapeEnabled) {
        mIsLockScreenLandscapeEnabled = isLockScreenLandscapeEnabled;
        findContainerLayout();
    }

    private void findContainerLayout() {
        if (mIsLockScreenLandscapeEnabled) {
            mContainerMotionLayout = findViewById(R.id.pattern_container);
        } else {
            mContainerConstraintLayout = findViewById(R.id.pattern_container);
        }
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        updateMargins();
    }

    void onDevicePostureChanged(@DevicePostureInt int posture) {
        if (mLastDevicePosture != posture) {
        if (mLastDevicePosture == posture) return;
        mLastDevicePosture = posture;
            updateMargins();

        if (mIsLockScreenLandscapeEnabled) {
            boolean useSplitBouncerAfterFold =
                    mLastDevicePosture == DEVICE_POSTURE_CLOSED
                    && getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE
                    && getResources().getBoolean(R.bool.update_bouncer_constraints);

            if (mAlreadyUsingSplitBouncer != useSplitBouncerAfterFold) {
                updateConstraints(useSplitBouncerAfterFold);
            }
        }

        updateMargins();
    }

    private void updateMargins() {
        // Update the guideline based on the device posture...
        float halfOpenPercentage =
                mContext.getResources().getFloat(R.dimen.half_opened_bouncer_height_ratio);

        if (mIsLockScreenLandscapeEnabled) {
            ConstraintSet cs = mContainerMotionLayout.getConstraintSet(R.id.single_constraints);
            cs.setGuidelinePercent(R.id.pattern_top_guideline,
                    mLastDevicePosture == DEVICE_POSTURE_HALF_OPENED ? halfOpenPercentage : 0.0f);
            cs.applyTo(mContainerMotionLayout);
        } else {
            ConstraintSet cs = new ConstraintSet();
        cs.clone(mContainer);
            cs.clone(mContainerConstraintLayout);
            cs.setGuidelinePercent(R.id.pattern_top_guideline,
                mLastDevicePosture == DEVICE_POSTURE_HALF_OPENED
                ? halfOpenPercentage : 0.0f);
        cs.applyTo(mContainer);
                    mLastDevicePosture == DEVICE_POSTURE_HALF_OPENED ? halfOpenPercentage : 0.0f);
            cs.applyTo(mContainerConstraintLayout);
        }
    }

    /**
     * Updates the keyguard view's constraints (single or split constraints).
     * Split constraints are only used for small landscape screens.
     * Only called when flag LANDSCAPE_ENABLE_LOCKSCREEN is enabled.
     */
    @Override
    protected void updateConstraints(boolean useSplitBouncer) {
        mAlreadyUsingSplitBouncer = useSplitBouncer;
        if (useSplitBouncer) {
            mContainerMotionLayout.jumpToState(R.id.split_constraints);
            mContainerMotionLayout.setMaxWidth(Integer.MAX_VALUE);
        } else {
            mContainerMotionLayout.jumpToState(R.id.single_constraints);
            mContainerMotionLayout.setMaxWidth(getResources()
                    .getDimensionPixelSize(R.dimen.biometric_auth_pattern_view_max_size));
        }
    }

    @Override
@@ -130,7 +190,6 @@ public class KeyguardPatternView extends KeyguardInputView
        mLockPatternView = findViewById(R.id.lockPatternView);

        mEcaView = findViewById(R.id.keyguard_selector_fade_container);
        mContainer = findViewById(R.id.pattern_container);
    }

    @Override
@@ -229,9 +288,16 @@ public class KeyguardPatternView extends KeyguardInputView
    }

    private void enableClipping(boolean enable) {
        if (mContainerConstraintLayout != null) {
            setClipChildren(enable);
        mContainer.setClipToPadding(enable);
        mContainer.setClipChildren(enable);
            mContainerConstraintLayout.setClipToPadding(enable);
            mContainerConstraintLayout.setClipChildren(enable);
        }
        if (mContainerMotionLayout != null) {
            setClipChildren(enable);
            mContainerMotionLayout.setClipToPadding(enable);
            mContainerMotionLayout.setClipChildren(enable);
        }
    }

    @Override
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.keyguard;

import static com.android.internal.util.LatencyTracker.ACTION_CHECK_CREDENTIAL;
import static com.android.internal.util.LatencyTracker.ACTION_CHECK_CREDENTIAL_UNLOCKED;
import static com.android.systemui.flags.Flags.LOCKSCREEN_ENABLE_LANDSCAPE;

import android.content.res.ColorStateList;
import android.os.AsyncTask;
@@ -205,6 +206,8 @@ public class KeyguardPatternViewController
        mLatencyTracker = latencyTracker;
        mFalsingCollector = falsingCollector;
        mEmergencyButtonController = emergencyButtonController;
        view.setIsLockScreenLandscapeEnabled(
                featureFlags.isEnabled(LOCKSCREEN_ENABLE_LANDSCAPE));
        mLockPatternView = mView.findViewById(R.id.lockPatternView);
        mPostureController = postureController;
    }
+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class KeyguardSecurityViewFlipperController
    private int getLayoutIdFor(SecurityMode securityMode) {
        // TODO (b/297863911, b/297864907) - implement motion layout for other bouncers
        switch (securityMode) {
            case Pattern: return R.layout.keyguard_pattern_view;
            case Pattern: return R.layout.keyguard_pattern_motion_layout;
            case PIN: return R.layout.keyguard_pin_motion_layout;
            case Password: return R.layout.keyguard_password_motion_layout;
            case SimPin: return R.layout.keyguard_sim_pin_view;
Loading