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

Commit 8ec03e81 authored by Shan Huang's avatar Shan Huang
Browse files

Add predictive back animation to Bouncer.

Bug: 238475429
Test: atest KeyguardSecurityContainerControllerTest
Test: atest KeyguardSecurityContainerTest
Test: atest StatusBarKeyguardViewManagerTest
Test: Enable flags and swipe back on Bouncer. Change up security mode and make sure animation looks nice in all modes.

Merged-In: Iaf0c265076bc4a917d9826beee74b9c3a635ef33
Change-Id: Iaf0c265076bc4a917d9826beee74b9c3a635ef33
parent 103ab393
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@ import android.view.View;
import android.view.View.OnKeyListener;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.window.OnBackAnimationCallback;

import androidx.annotation.NonNull;

import com.android.keyguard.KeyguardSecurityContainer.SecurityCallback;
import com.android.keyguard.KeyguardSecurityModel.SecurityMode;
@@ -393,6 +396,14 @@ public class KeyguardHostViewController extends ViewController<KeyguardHostView>
        return false;
    }

    /**
     * @return the {@link OnBackAnimationCallback} to animate this view during a back gesture.
     */
    @NonNull
    public OnBackAnimationCallback getBackCallback() {
        return mKeyguardSecurityContainerController.getBackCallback();
    }

    /**
     * Allows the media keys to work when the keyguard is showing.
     * The media keys should be of no interest to the actual keyguard view(s),
+42 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static androidx.constraintlayout.widget.ConstraintSet.START;
import static androidx.constraintlayout.widget.ConstraintSet.TOP;
import static androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT;

import static com.android.systemui.animation.InterpolatorsAndroidX.DECELERATE_QUINT;
import static com.android.systemui.plugins.FalsingManager.LOW_PENALTY;

import static java.lang.Integer.max;
@@ -73,6 +74,8 @@ import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.window.BackEvent;
import android.window.OnBackAnimationCallback;

import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
@@ -135,7 +138,9 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
    private static final float MIN_DRAG_SIZE = 10;
    // How much to scale the default slop by, to avoid accidental drags.
    private static final float SLOP_SCALE = 4f;

    @VisibleForTesting
    // How much the view scales down to during back gestures.
    static final float MIN_BACK_SCALE = 0.9f;
    @VisibleForTesting
    KeyguardSecurityViewFlipper mSecurityViewFlipper;
    private GlobalSettings mGlobalSettings;
@@ -240,6 +245,33 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
                }
            };

    private final OnBackAnimationCallback mBackCallback = new OnBackAnimationCallback() {
        @Override
        public void onBackCancelled() {
            // TODO(b/259608500): Remove once back API auto animates progress to 0 on cancel.
            resetScale();
        }

        @Override
        public void onBackInvoked() { }

        @Override
        public void onBackProgressed(BackEvent event) {
            float progress = event.getProgress();
            // TODO(b/263819310): Update the interpolator to match spec.
            float scale = MIN_BACK_SCALE
                    +  (1 - MIN_BACK_SCALE) * (1 - DECELERATE_QUINT.getInterpolation(progress));
            setScale(scale);
        }
    };
    /**
     * @return the {@link OnBackAnimationCallback} to animate this view during a back gesture.
     */
    @NonNull
    OnBackAnimationCallback getBackCallback() {
        return mBackCallback;
    }

    // Used to notify the container when something interesting happens.
    public interface SecurityCallback {
        /**
@@ -736,6 +768,15 @@ public class KeyguardSecurityContainer extends ConstraintLayout {
        mViewMode.onDensityOrFontScaleChanged();
    }

    void resetScale() {
        setScale(1);
    }

    private void setScale(float scale) {
        setScaleX(scale);
        setScaleY(scale);
    }

    /**
     * Enscapsulates the differences between bouncer modes for the container.
     */
+13 −0
Original line number Diff line number Diff line
@@ -40,7 +40,9 @@ import android.util.Log;
import android.util.Slog;
import android.view.MotionEvent;
import android.view.View;
import android.window.OnBackAnimationCallback;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.annotations.VisibleForTesting;
@@ -479,6 +481,9 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
    /** Called when the bouncer changes visibility. */
    public void onBouncerVisibilityChanged(@View.Visibility int visibility) {
        setBouncerVisible(visibility == View.VISIBLE);
        if (visibility == View.INVISIBLE) {
            mView.resetScale();
        }
    }

    private void setBouncerVisible(boolean visible) {
@@ -587,6 +592,14 @@ public class KeyguardSecurityContainerController extends ViewController<Keyguard
        return getCurrentSecurityController().needsInput();
    }

    /**
     * @return the {@link OnBackAnimationCallback} to animate this view during a back gesture.
     */
    @NonNull
    OnBackAnimationCallback getBackCallback() {
        return mView.getBackCallback();
    }

    /**
     * Switches to the given security view unless it's already being shown, in which case
     * this is a no-op.
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.keyguard.data

import android.view.KeyEvent
import android.window.OnBackAnimationCallback
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.plugins.ActivityStarter
import java.lang.ref.WeakReference
@@ -51,4 +52,6 @@ interface BouncerViewDelegate {
        cancelAction: Runnable?,
    )
    fun willDismissWithActions(): Boolean
    /** @return the {@link OnBackAnimationCallback} to animate Bouncer during a back gesture. */
    fun getBackCallback(): OnBackAnimationCallback
}
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.keyguard.ui.binder
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import android.window.OnBackAnimationCallback
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.internal.policy.SystemBarUtils
@@ -55,6 +56,10 @@ object KeyguardBouncerViewBinder {
                        mode == KeyguardSecurityModel.SecurityMode.SimPuk
                }

                override fun getBackCallback(): OnBackAnimationCallback {
                    return hostViewController.backCallback
                }

                override fun shouldDismissOnMenuPressed(): Boolean {
                    return hostViewController.shouldEnableMenuKey()
                }
Loading