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

Commit ff5f25dd authored by Martin Olsson's avatar Martin Olsson Committed by Lingxue Luo
Browse files

DO NOT MERGE Screen lock: Fade out recorded pattern smoothly

After setting up a new lock pattern it fades
out smoothly instead of toggling visibility

Bug: 253102373
Test: Manually set up new pattern
Settings -> Security -> Screen lock -> Pattern

Change-Id: I2d9ca503c2cea57036424d5b700314efbe3497ab
parent 00558ac5
Loading
Loading
Loading
Loading
+64 −2
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class LockPatternView extends View {
    private static final int DOT_ACTIVATION_DURATION_MILLIS = 50;
    private static final int DOT_RADIUS_INCREASE_DURATION_MILLIS = 96;
    private static final int DOT_RADIUS_DECREASE_DURATION_MILLIS = 192;
    private static final int ALPHA_MAX_VALUE = 255;
    private static final float MIN_DOT_HIT_FACTOR = 0.2f;
    private final CellState[][] mCellStates;

@@ -92,6 +93,8 @@ public class LockPatternView extends View {
    private final int mPathWidth;
    private final int mLineFadeOutAnimationDurationMs;
    private final int mLineFadeOutAnimationDelayMs;
    private final int mFadePatternAnimationDurationMs;
    private final int mFadePatternAnimationDelayMs;

    private boolean mDrawingProfilingStarted = false;

@@ -148,6 +151,10 @@ public class LockPatternView extends View {
    private boolean mPatternInProgress = false;
    private boolean mFadePattern = true;

    private boolean mFadeClear = false;
    private int mFadeAnimationAlpha = ALPHA_MAX_VALUE;
    private final Path mPatternPath = new Path();

    @UnsupportedAppUsage
    private float mSquareWidth;
    @UnsupportedAppUsage
@@ -169,6 +176,7 @@ public class LockPatternView extends View {

    private final Interpolator mFastOutSlowInInterpolator;
    private final Interpolator mLinearOutSlowInInterpolator;
    private final Interpolator mStandardAccelerateInterpolator;
    private final PatternExploreByTouchHelper mExploreByTouchHelper;

    private Drawable mSelectedDrawable;
@@ -356,6 +364,11 @@ public class LockPatternView extends View {
        mLineFadeOutAnimationDelayMs =
            getResources().getInteger(R.integer.lock_pattern_line_fade_out_delay);

        mFadePatternAnimationDurationMs =
                getResources().getInteger(R.integer.lock_pattern_fade_pattern_duration);
        mFadePatternAnimationDelayMs =
                getResources().getInteger(R.integer.lock_pattern_fade_pattern_delay);

        mDotSize = getResources().getDimensionPixelSize(R.dimen.lock_pattern_dot_size);
        mDotSizeActivated = getResources().getDimensionPixelSize(
                R.dimen.lock_pattern_dot_size_activated);
@@ -386,6 +399,8 @@ public class LockPatternView extends View {
                AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_slow_in);
        mLinearOutSlowInInterpolator =
                AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in);
        mStandardAccelerateInterpolator =
                AnimationUtils.loadInterpolator(context, android.R.interpolator.fast_out_linear_in);
        mExploreByTouchHelper = new PatternExploreByTouchHelper(this);
        setAccessibilityDelegate(mExploreByTouchHelper);

@@ -626,6 +641,15 @@ public class LockPatternView extends View {
        resetPattern();
    }

    /**
     * Clear the pattern by fading it out.
     */
    @UnsupportedAppUsage
    public void fadeClearPattern() {
        mFadeClear = true;
        startFadePatternAnimation();
    }

    @Override
    protected boolean dispatchHoverEvent(MotionEvent event) {
        // Dispatch to onHoverEvent first so mPatternInProgress is up to date when the
@@ -643,6 +667,7 @@ public class LockPatternView extends View {
            resetLastActivatedCellProgress();
        }
        mPattern.clear();
        mPatternPath.reset();
        clearPatternDrawLookup();
        mPatternDisplayMode = DisplayMode.Correct;
        invalidate();
@@ -815,6 +840,33 @@ public class LockPatternView extends View {
        notifyCellAdded();
    }

    private void startFadePatternAnimation() {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(createFadePatternAnimation());
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mFadeAnimationAlpha = ALPHA_MAX_VALUE;
                mFadeClear = false;
                resetPattern();
            }
        });
        animatorSet.start();

    }

    private Animator createFadePatternAnimation() {
        ValueAnimator valueAnimator = ValueAnimator.ofInt(ALPHA_MAX_VALUE, 0);
        valueAnimator.addUpdateListener(animation -> {
            mFadeAnimationAlpha = (int) animation.getAnimatedValue();
            invalidate();
        });
        valueAnimator.setInterpolator(mStandardAccelerateInterpolator);
        valueAnimator.setStartDelay(mFadePatternAnimationDelayMs);
        valueAnimator.setDuration(mFadePatternAnimationDurationMs);
        return valueAnimator;
    }

    private void startCellActivatedAnimation(Cell cell) {
        startCellActivationAnimation(cell, CELL_ACTIVATE);
    }
@@ -1247,7 +1299,7 @@ public class LockPatternView extends View {
        // draw the path of the pattern (unless we are in stealth mode)
        final boolean drawPath = !mInStealthMode;

        if (drawPath) {
        if (drawPath && !mFadeClear) {
            mPathPaint.setColor(getCurrentColor(true /* partOfPattern */));

            boolean anyCircles = false;
@@ -1285,6 +1337,11 @@ public class LockPatternView extends View {
                    }
                    drawLineSegment(canvas, /* startX = */ lastX, /* startY = */ lastY, endX, endY,
                            mLineFadeStart[i], elapsedRealtime);

                    Path tempPath = new Path();
                    tempPath.moveTo(lastX, lastY);
                    tempPath.lineTo(centerX, centerY);
                    mPatternPath.addPath(tempPath);
                }
                lastX = centerX;
                lastY = centerY;
@@ -1303,6 +1360,11 @@ public class LockPatternView extends View {
            }
        }

        if (mFadeClear) {
            mPathPaint.setAlpha(mFadeAnimationAlpha);
            canvas.drawPath(mPatternPath, mPathPaint);
        }

        // draw the circles
        for (int i = 0; i < 3; i++) {
            float centerY = getCenterYForRow(i);
+3 −0
Original line number Diff line number Diff line
@@ -685,6 +685,9 @@
    <!-- Parameters applied to line disappearing animation in LockPatternView in milliseconds. -->
    <integer name="lock_pattern_line_fade_out_duration">500</integer>
    <integer name="lock_pattern_line_fade_out_delay">150</integer>
    <!-- Parameters applied to fade pattern animation in LockPatternView in milliseconds. -->
    <integer name="lock_pattern_fade_pattern_duration">200</integer>
    <integer name="lock_pattern_fade_pattern_delay">2300</integer>

    <dimen name="text_handle_min_size">40dp</dimen>

+2 −0
Original line number Diff line number Diff line
@@ -1283,6 +1283,8 @@
  <java-symbol type="dimen" name="lock_pattern_fade_away_gradient_width" />
  <java-symbol type="integer" name="lock_pattern_line_fade_out_duration" />
  <java-symbol type="integer" name="lock_pattern_line_fade_out_delay" />
  <java-symbol type="integer" name="lock_pattern_fade_pattern_delay" />
  <java-symbol type="integer" name="lock_pattern_fade_pattern_duration" />
  <java-symbol type="drawable" name="clock_dial" />
  <java-symbol type="drawable" name="clock_hand_hour" />
  <java-symbol type="drawable" name="clock_hand_minute" />