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

Commit dcc1f194 authored by Vishwath Mohan's avatar Vishwath Mohan
Browse files

Add fading to the pattern unlock screen.

This CL sets the user traced pattern on the unlock screen to fade as
it's drawn, reducing the chances of shoulder surfing.

Test: Build, set a pattern, and try.
Change-Id: I2ad37a10782d826d076dcf5142700d8facc2f52e
parent 08455995
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public class LockPatternView extends View {
    private float mInProgressY = -1;

    private long mAnimatingPeriodStart;
    private long[] mLineFadeStart = new long[9];

    private DisplayMode mPatternDisplayMode = DisplayMode.Correct;
    private boolean mInputEnabled = true;
@@ -596,12 +597,14 @@ public class LockPatternView extends View {
    }

    /**
     * Clear the pattern lookup table.
     * Clear the pattern lookup table. Also reset the line fade start times for
     * the next attempt.
     */
    private void clearPatternDrawLookup() {
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                mPatternDrawLookup[i][j] = false;
                mLineFadeStart[i+j] = 0;
            }
        }
    }
@@ -1136,6 +1139,7 @@ public class LockPatternView extends View {
            boolean anyCircles = false;
            float lastX = 0f;
            float lastY = 0f;
            long elapsedRealtime = SystemClock.elapsedRealtime();
           for (int i = 0; i < count; i++) {
                Cell cell = pattern.get(i);

@@ -1147,16 +1151,26 @@ public class LockPatternView extends View {
                }
                anyCircles = true;

                if (mLineFadeStart[i] == 0) {
                  mLineFadeStart[i] = SystemClock.elapsedRealtime();
                }

                float centerX = getCenterXForColumn(cell.column);
                float centerY = getCenterYForRow(cell.row);
                if (i != 0) {
                   // Set this line segment to slowly fade over the next second.
                   int lineFadeVal = (int) Math.min((elapsedRealtime -
                           mLineFadeStart[i])/2f, 255f);

                    CellState state = mCellStates[cell.row][cell.column];
                    currentPath.rewind();
                    currentPath.moveTo(lastX, lastY);
                    if (state.lineEndX != Float.MIN_VALUE && state.lineEndY != Float.MIN_VALUE) {
                        currentPath.lineTo(state.lineEndX, state.lineEndY);
                        mPathPaint.setAlpha((int) 255 - lineFadeVal );
                    } else {
                        currentPath.lineTo(centerX, centerY);
                        mPathPaint.setAlpha((int) 255 - lineFadeVal );
                    }
                    canvas.drawPath(currentPath, mPathPaint);
                }