    public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
        final List<Key> keys = getKeys();
        final int touchX = getTouchX(x);
        final int touchY = getTouchY(y);
        initializeNearbyKeys();
        int primaryIndex = NOT_A_KEY;
        for (final int index : mKeyboard.getNearestKeys(touchX, touchY)) {
            final Key key = keys.get(index);
            final boolean isInside = mKeyboard.isInside(key, touchX, touchY);
            final int distance = key.squaredDistanceToEdge(touchX, touchY);
            if (isInside || (mProximityCorrectOn && distance < mProximityThresholdSquare)) {
                final int insertedPosition = sortNearbyKeys(index, distance);
                if (insertedPosition == 0 && isInside)
                    primaryIndex = index;
            }
        }
        if (allCodes != null && allCodes.length > 0) {
            getNearbyKeyCodes(allCodes);
            if (DEBUG) {
                Log.d(TAG, "x=" + x + " y=" + y
                        + " primary="
                        + (primaryIndex == NOT_A_KEY ? "none" : keys.get(primaryIndex).mCode)
                        + " codes=" + Arrays.toString(allCodes));
            }
        }
        return primaryIndex;
    }

    public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) {
        final List<Key> keys = getKeys();
        final int touchX = getTouchX(x);
        final int touchY = getTouchY(y);
        initializeNearbyKeys();
        int primaryIndex = NOT_A_KEY;
        for (final int index : mKeyboard.getNearestKeys(touchX, touchY)) {
            final Key key = keys.get(index);
            final boolean isInside = mKeyboard.isInside(key, touchX, touchY);
            final int distance = key.squaredDistanceToEdge(touchX, touchY);
            if (isInside || (mProximityCorrectOn && distance < mProximityThresholdSquare)) {
                final int insertedPosition = sortNearbyKeys(index, distance);
                if (insertedPosition == 0)
                    primaryIndex = index;
            }
        }
        if (allCodes != null && allCodes.length > 0) {
            getNearbyKeyCodes(allCodes);
            if (DEBUG) {
                Log.d(TAG, "x=" + x + " y=" + y
                        + " primary="
                        + (primaryIndex == NOT_A_KEY ? "none" : keys.get(primaryIndex).mCode)
                        + " codes=" + Arrays.toString(allCodes));
            }
        }
        return primaryIndex;
    }
