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

Commit 4ef27c03 authored by Jean Chalard's avatar Jean Chalard
Browse files

[ML13] Fix the locale passing in ProximityInfo

The locale is used to determine additional proximity characters. This
is dependent on the dictionary language, but was passed as a function
of the layout, which is wrong and would have given bad suggestions in
multi-lingual mode.

Ideally, additional proximity characters should be inserted in the
dictionary header, but for now it's a rather simple change to get
it from the dictionary's locale instead of the proximity info locale.

Also, that allows us to remove completely the locale parameter from
proximity info, which is a much needed change.

This change has zero effect on unit tests and on regression tests.

Bug: 11230254
Change-Id: If95157155db7dccd1f00b8ba55ccb3600283f9e4
parent fb051c39
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -108,10 +108,9 @@ public class Keyboard {
        mAltCodeKeysWhileTyping = Collections.unmodifiableList(params.mAltCodeKeysWhileTyping);
        mIconsSet = params.mIconsSet;

        mProximityInfo = new ProximityInfo(params.mId.mLocale.toString(),
                params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
                mMostCommonKeyWidth, mMostCommonKeyHeight, mSortedKeys,
                params.mTouchPositionCorrection);
        mProximityInfo = new ProximityInfo(params.GRID_WIDTH, params.GRID_HEIGHT,
                mOccupiedWidth, mOccupiedHeight, mMostCommonKeyWidth, mMostCommonKeyHeight,
                mSortedKeys, params.mTouchPositionCorrection);
        mProximityCharsCorrectionEnabled = params.mProximityCharsCorrectionEnabled;
    }

+10 −18
Original line number Diff line number Diff line
@@ -52,18 +52,11 @@ public class ProximityInfo {
    private final int mMostCommonKeyHeight;
    private final List<Key> mSortedKeys;
    private final List<Key>[] mGridNeighbors;
    private final String mLocaleStr;

    @SuppressWarnings("unchecked")
    ProximityInfo(final String localeStr, final int gridWidth, final int gridHeight,
            final int minWidth, final int height, final int mostCommonKeyWidth,
            final int mostCommonKeyHeight, final List<Key> sortedKeys,
    ProximityInfo(final int gridWidth, final int gridHeight, final int minWidth, final int height,
            final int mostCommonKeyWidth, final int mostCommonKeyHeight, final List<Key> sortedKeys,
            final TouchPositionCorrection touchPositionCorrection) {
        if (TextUtils.isEmpty(localeStr)) {
            mLocaleStr = "";
        } else {
            mLocaleStr = localeStr;
        }
        mGridWidth = gridWidth;
        mGridHeight = gridHeight;
        mGridSize = mGridWidth * mGridHeight;
@@ -89,11 +82,10 @@ public class ProximityInfo {
    }

    // TODO: Stop passing proximityCharsArray
    private static native long setProximityInfoNative(String locale,
            int displayWidth, int displayHeight, int gridWidth, int gridHeight,
            int mostCommonKeyWidth, int mostCommonKeyHeight, int[] proximityCharsArray,
            int keyCount, int[] keyXCoordinates, int[] keyYCoordinates, int[] keyWidths,
            int[] keyHeights, int[] keyCharCodes, float[] sweetSpotCenterXs,
    private static native long setProximityInfoNative(int displayWidth, int displayHeight,
            int gridWidth, int gridHeight, int mostCommonKeyWidth, int mostCommonKeyHeight,
            int[] proximityCharsArray, int keyCount, int[] keyXCoordinates, int[] keyYCoordinates,
            int[] keyWidths, int[] keyHeights, int[] keyCharCodes, float[] sweetSpotCenterXs,
            float[] sweetSpotCenterYs, float[] sweetSpotRadii);

    private static native void releaseProximityInfoNative(long nativeProximityInfo);
@@ -221,10 +213,10 @@ public class ProximityInfo {
        }

        // TODO: Stop passing proximityCharsArray
        return setProximityInfoNative(mLocaleStr, mKeyboardMinWidth, mKeyboardHeight,
                mGridWidth, mGridHeight, mMostCommonKeyWidth, mMostCommonKeyHeight,
                proximityCharsArray, keyCount, keyXCoordinates, keyYCoordinates, keyWidths,
                keyHeights, keyCharCodes, sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
        return setProximityInfoNative(mKeyboardMinWidth, mKeyboardHeight, mGridWidth, mGridHeight,
                mMostCommonKeyWidth, mMostCommonKeyHeight, proximityCharsArray, keyCount,
                keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
                sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
    }

    public long getNativeProximityInfo() {
+3 −3
Original line number Diff line number Diff line
@@ -25,13 +25,13 @@

namespace latinime {

static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jclass clazz, jstring localeJStr,
static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jclass clazz,
        jint displayWidth, jint displayHeight, jint gridWidth, jint gridHeight,
        jint mostCommonkeyWidth, jint mostCommonkeyHeight, jintArray proximityChars, jint keyCount,
        jintArray keyXCoordinates, jintArray keyYCoordinates, jintArray keyWidths,
        jintArray keyHeights, jintArray keyCharCodes, jfloatArray sweetSpotCenterXs,
        jfloatArray sweetSpotCenterYs, jfloatArray sweetSpotRadii) {
    ProximityInfo *proximityInfo = new ProximityInfo(env, localeJStr, displayWidth, displayHeight,
    ProximityInfo *proximityInfo = new ProximityInfo(env, displayWidth, displayHeight,
            gridWidth, gridHeight, mostCommonkeyWidth, mostCommonkeyHeight, proximityChars,
            keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
            sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
@@ -46,7 +46,7 @@ static void latinime_Keyboard_release(JNIEnv *env, jclass clazz, jlong proximity
static const JNINativeMethod sMethods[] = {
    {
        const_cast<char *>("setProximityInfoNative"),
        const_cast<char *>("(Ljava/lang/String;IIIIII[II[I[I[I[I[I[F[F[F)J"),
        const_cast<char *>("(IIIIII[II[I[I[I[I[I[F[F[F)J"),
        reinterpret_cast<void *>(latinime_Keyboard_setProximityInfo)
    },
    {
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
namespace latinime {
// TODO: Stop using hardcoded additional proximity characters.
// TODO: Have proximity character informations in each language's binary dictionary.
const char *AdditionalProximityChars::LOCALE_EN_US = "en";
const int AdditionalProximityChars::LOCALE_EN_US[LOCALE_EN_US_SIZE] = { 'e', 'n' };

const int AdditionalProximityChars::EN_US_ADDITIONAL_A[EN_US_ADDITIONAL_A_SIZE] = {
    'e', 'i', 'o', 'u'
+18 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define LATINIME_ADDITIONAL_PROXIMITY_CHARS_H

#include <cstring>
#include <vector>

#include "defines.h"

@@ -26,7 +27,8 @@ namespace latinime {
class AdditionalProximityChars {
 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(AdditionalProximityChars);
    static const char *LOCALE_EN_US;
    static const int LOCALE_EN_US_SIZE = 2;
    static const int LOCALE_EN_US[LOCALE_EN_US_SIZE];
    static const int EN_US_ADDITIONAL_A_SIZE = 4;
    static const int EN_US_ADDITIONAL_A[];
    static const int EN_US_ADDITIONAL_E_SIZE = 4;
@@ -38,15 +40,22 @@ class AdditionalProximityChars {
    static const int EN_US_ADDITIONAL_U_SIZE = 4;
    static const int EN_US_ADDITIONAL_U[];

    AK_FORCE_INLINE static bool isEnLocale(const char *localeStr) {
        const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US);
        return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE
                && strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0;
    AK_FORCE_INLINE static bool isEnLocale(const std::vector<int> *locale) {
        const int NCHARS = NELEMS(LOCALE_EN_US);
        if (locale->size() < NCHARS) {
            return false;
        }
        for (int i = 0; i < NCHARS; ++i) {
            if ((*locale)[i] != LOCALE_EN_US[i]) {
                return false;
            }
        }
        return true;
    }

 public:
    static int getAdditionalCharsSize(const char *const localeStr, const int c) {
        if (!isEnLocale(localeStr)) {
    static int getAdditionalCharsSize(const std::vector<int> *locale, const int c) {
        if (!isEnLocale(locale)) {
            return 0;
        }
        switch (c) {
@@ -65,8 +74,8 @@ class AdditionalProximityChars {
        }
    }

    static const int *getAdditionalChars(const char *const localeStr, const int c) {
        if (!isEnLocale(localeStr)) {
    static const int *getAdditionalChars(const std::vector<int> *locale, const int c) {
        if (!isEnLocale(locale)) {
            return 0;
        }
        switch (c) {
Loading