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

Commit aced12fd authored by Jim Miller's avatar Jim Miller
Browse files

Handle dropped motion events in Pattern Unlock due to high system activity

This enables the pattern unlock screen to look at historical motion
events to make unlocking easier during high system load.

Change-Id: I74a9c2d0833e8bb6745b89e8d397116baebb24a1
parent 576715c7
Loading
Loading
Loading
Loading
+169 −152
Original line number Diff line number Diff line
@@ -603,51 +603,26 @@ public class LockPatternView extends View {
    }

    @Override
    public boolean onTouchEvent(MotionEvent motionEvent) {
    public boolean onTouchEvent(MotionEvent event) {
        if (!mInputEnabled || !isEnabled()) {
            return false;
        }

        final float x = motionEvent.getX();
        final float y = motionEvent.getY();
        Cell hitCell;
        switch(motionEvent.getAction()) {
        switch(event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                resetPattern();
                hitCell = detectAndAddHit(x, y);
                if (hitCell != null && mOnPatternListener != null) {
                    mPatternInProgress = true;
                    mPatternDisplayMode = DisplayMode.Correct;
                    mOnPatternListener.onPatternStart();
                } else if (mOnPatternListener != null) {
                    mPatternInProgress = false;
                    mOnPatternListener.onPatternCleared();
                }
                if (hitCell != null) {
                    final float startX = getCenterXForColumn(hitCell.column);
                    final float startY = getCenterYForRow(hitCell.row);

                    final float widthOffset = mSquareWidth / 2f;
                    final float heightOffset = mSquareHeight / 2f;

                    invalidate((int) (startX - widthOffset), (int) (startY - heightOffset),
                            (int) (startX + widthOffset), (int) (startY + heightOffset));
                }
                mInProgressX = x;
                mInProgressY = y;
                if (PROFILE_DRAWING) {
                    if (!mDrawingProfilingStarted) {
                        Debug.startMethodTracing("LockPatternDrawing");
                        mDrawingProfilingStarted = true;
                    }
                }
                handleActionDown(event);
                return true;
            case MotionEvent.ACTION_UP:
                // report pattern detected
                if (!mPattern.isEmpty() && mOnPatternListener != null) {
                handleActionUp(event);
                return true;
            case MotionEvent.ACTION_MOVE:
                handleActionMove(event);
                return true;
            case MotionEvent.ACTION_CANCEL:
                resetPattern();
                if (mOnPatternListener != null) {
                    mPatternInProgress = false;
                    mOnPatternListener.onPatternDetected(mPattern);
                    invalidate();
                    mOnPatternListener.onPatternCleared();
                }
                if (PROFILE_DRAWING) {
                    if (mDrawingProfilingStarted) {
@@ -656,16 +631,25 @@ public class LockPatternView extends View {
                    }
                }
                return true;
            case MotionEvent.ACTION_MOVE:
        }
        return false;
    }

    private void handleActionMove(MotionEvent event) {
        // Handle all recent motion events so we don't skip any cells even when the device
        // is busy...
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize + 1; i++) {
            final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
            final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
            final int patternSizePreHitDetect = mPattern.size();
                hitCell = detectAndAddHit(x, y);
            Cell hitCell = detectAndAddHit(x, y);
            final int patternSize = mPattern.size();
            if (hitCell != null && (mOnPatternListener != null) && (patternSize == 1)) {
                mPatternInProgress = true;
                mOnPatternListener.onPatternStart();
            }
                // note current x and y for rubber banding of in progress
                // patterns
            // note current x and y for rubber banding of in progress patterns
            final float dx = Math.abs(x - mInProgressX);
            final float dy = Math.abs(y - mInProgressY);
            if (dx + dy > mSquareWidth * 0.01f) {
@@ -775,12 +759,15 @@ public class LockPatternView extends View {
                    invalidate();
                }
            }
                return true;
            case MotionEvent.ACTION_CANCEL:
                resetPattern();
                if (mOnPatternListener != null) {
        }
    }

    private void handleActionUp(MotionEvent event) {
        // report pattern detected
        if (!mPattern.isEmpty() && mOnPatternListener != null) {
            mPatternInProgress = false;
                    mOnPatternListener.onPatternCleared();
            mOnPatternListener.onPatternDetected(mPattern);
            invalidate();
        }
        if (PROFILE_DRAWING) {
            if (mDrawingProfilingStarted) {
@@ -788,9 +775,39 @@ public class LockPatternView extends View {
                mDrawingProfilingStarted = false;
            }
        }
                return true;
    }
        return false;

    private void handleActionDown(MotionEvent event) {
        resetPattern();
        final float x = event.getX();
        final float y = event.getY();
        final Cell hitCell = detectAndAddHit(x, y);
        if (hitCell != null && mOnPatternListener != null) {
            mPatternInProgress = true;
            mPatternDisplayMode = DisplayMode.Correct;
            mOnPatternListener.onPatternStart();
        } else if (mOnPatternListener != null) {
            mPatternInProgress = false;
            mOnPatternListener.onPatternCleared();
        }
        if (hitCell != null) {
            final float startX = getCenterXForColumn(hitCell.column);
            final float startY = getCenterYForRow(hitCell.row);

            final float widthOffset = mSquareWidth / 2f;
            final float heightOffset = mSquareHeight / 2f;

            invalidate((int) (startX - widthOffset), (int) (startY - heightOffset),
                    (int) (startX + widthOffset), (int) (startY + heightOffset));
        }
        mInProgressX = x;
        mInProgressY = y;
        if (PROFILE_DRAWING) {
            if (!mDrawingProfilingStarted) {
                Debug.startMethodTracing("LockPatternDrawing");
                mDrawingProfilingStarted = true;
            }
        }
    }

    private float getCenterXForColumn(int column) {