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

Commit 4e9e6cd1 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Fix IllegalStateException of KeyDetector

A KeyDetector without Keyboard may exist in some rare cases. This
change eliminates throwing IllegalStateException and checks explicitly
against null.

Bug: 6891020
Change-Id: I29ec3e9f10484f30288fac76f0c45b3707bc2259
parent 0ef87868
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -37,8 +37,9 @@ public class KeyDetector {
    }

    public void setKeyboard(Keyboard keyboard, float correctionX, float correctionY) {
        if (keyboard == null)
        if (keyboard == null) {
            throw new NullPointerException();
        }
        mCorrectionX = (int)correctionX;
        mCorrectionY = (int)correctionY;
        mKeyboard = keyboard;
@@ -58,8 +59,6 @@ public class KeyDetector {
    }

    public Keyboard getKeyboard() {
        if (mKeyboard == null)
            throw new IllegalStateException("keyboard isn't set");
        return mKeyboard;
    }

+5 −1
Original line number Diff line number Diff line
@@ -39,7 +39,11 @@ public class MoreKeysDetector extends KeyDetector {

        Key nearestKey = null;
        int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare;
        for (final Key key : getKeyboard().mKeys) {
        final Keyboard keyboard = getKeyboard();
        if (keyboard == null) {
            throw new NullPointerException("Keyboard isn't set");
        }
        for (final Key key : keyboard.mKeys) {
            final int dist = key.squaredDistanceToEdge(touchX, touchY);
            if (dist < nearestDist) {
                nearestKey = key;