Search in sources :

Example 1 with InputPointers

use of com.android.inputmethod.latin.common.InputPointers in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class InputTestsBase method gesture.

protected void gesture(final String stringToGesture) {
    if (StringUtils.codePointCount(stringToGesture) < 2) {
        throw new RuntimeException("Can't gesture strings less than 2 chars long");
    }
    mLatinIME.onStartBatchInput();
    final int startCodePoint = stringToGesture.codePointAt(0);
    Point oldPoint = getXY(startCodePoint);
    // In milliseconds since the start of the gesture
    int timestamp = 0;
    final InputPointers pointers = new InputPointers(Constants.DEFAULT_GESTURE_POINTS_CAPACITY);
    pointers.addPointer(oldPoint.x, oldPoint.y, 0, /* pointerId */
    timestamp);
    for (int i = Character.charCount(startCodePoint); i < stringToGesture.length(); i = stringToGesture.offsetByCodePoints(i, 1)) {
        final Point newPoint = getXY(stringToGesture.codePointAt(i));
        // Arbitrarily 0.5s between letters and 0.1 between events. Refine this later if needed.
        final int STEPS = 5;
        for (int j = 0; j < STEPS; ++j) {
            timestamp += 100;
            pointers.addPointer(oldPoint.x + ((newPoint.x - oldPoint.x) * j) / STEPS, oldPoint.y + ((newPoint.y - oldPoint.y) * j) / STEPS, 0, /* pointerId */
            timestamp);
        }
        oldPoint.x = newPoint.x;
        oldPoint.y = newPoint.y;
        mLatinIME.onUpdateBatchInput(pointers);
    }
    mLatinIME.onEndBatchInput(pointers);
    sleep(DELAY_TO_WAIT_FOR_GESTURE_MILLIS);
    runMessages();
}
Also used : InputPointers(com.android.inputmethod.latin.common.InputPointers) Point(android.graphics.Point) Point(android.graphics.Point)

Example 2 with InputPointers

use of com.android.inputmethod.latin.common.InputPointers in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class BinaryDictionary method getSuggestions.

@Override
public ArrayList<SuggestedWordInfo> getSuggestions(final ComposedData composedData, final NgramContext ngramContext, final long proximityInfoHandle, final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId, final float weightForLocale, final float[] inOutWeightOfLangModelVsSpatialModel) {
    if (!isValidDictionary()) {
        return null;
    }
    final DicTraverseSession session = getTraverseSession(sessionId);
    Arrays.fill(session.mInputCodePoints, Constants.NOT_A_CODE);
    ngramContext.outputToArray(session.mPrevWordCodePointArrays, session.mIsBeginningOfSentenceArray);
    final InputPointers inputPointers = composedData.mInputPointers;
    final boolean isGesture = composedData.mIsBatchMode;
    final int inputSize;
    if (!isGesture) {
        inputSize = composedData.copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(session.mInputCodePoints);
        if (inputSize < 0) {
            return null;
        }
    } else {
        inputSize = inputPointers.getPointerSize();
    }
    session.mNativeSuggestOptions.setUseFullEditDistance(mUseFullEditDistance);
    session.mNativeSuggestOptions.setIsGesture(isGesture);
    session.mNativeSuggestOptions.setBlockOffensiveWords(settingsValuesForSuggestion.mBlockPotentiallyOffensive);
    session.mNativeSuggestOptions.setWeightForLocale(weightForLocale);
    if (inOutWeightOfLangModelVsSpatialModel != null) {
        session.mInputOutputWeightOfLangModelVsSpatialModel[0] = inOutWeightOfLangModelVsSpatialModel[0];
    } else {
        session.mInputOutputWeightOfLangModelVsSpatialModel[0] = Dictionary.NOT_A_WEIGHT_OF_LANG_MODEL_VS_SPATIAL_MODEL;
    }
    // TOOD: Pass multiple previous words information for n-gram.
    getSuggestionsNative(mNativeDict, proximityInfoHandle, getTraverseSession(sessionId).getSession(), inputPointers.getXCoordinates(), inputPointers.getYCoordinates(), inputPointers.getTimes(), inputPointers.getPointerIds(), session.mInputCodePoints, inputSize, session.mNativeSuggestOptions.getOptions(), session.mPrevWordCodePointArrays, session.mIsBeginningOfSentenceArray, ngramContext.getPrevWordCount(), session.mOutputSuggestionCount, session.mOutputCodePoints, session.mOutputScores, session.mSpaceIndices, session.mOutputTypes, session.mOutputAutoCommitFirstWordConfidence, session.mInputOutputWeightOfLangModelVsSpatialModel);
    if (inOutWeightOfLangModelVsSpatialModel != null) {
        inOutWeightOfLangModelVsSpatialModel[0] = session.mInputOutputWeightOfLangModelVsSpatialModel[0];
    }
    final int count = session.mOutputSuggestionCount[0];
    final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
    for (int j = 0; j < count; ++j) {
        final int start = j * DICTIONARY_MAX_WORD_LENGTH;
        int len = 0;
        while (len < DICTIONARY_MAX_WORD_LENGTH && session.mOutputCodePoints[start + len] != 0) {
            ++len;
        }
        if (len > 0) {
            suggestions.add(new SuggestedWordInfo(new String(session.mOutputCodePoints, start, len), "", /* prevWordsContext */
            (int) (session.mOutputScores[j] * weightForLocale), session.mOutputTypes[j], this, /* sourceDict */
            session.mSpaceIndices[j], /* indexOfTouchPointOfSecondWord */
            session.mOutputAutoCommitFirstWordConfidence[0]));
        }
    }
    return suggestions;
}
Also used : InputPointers(com.android.inputmethod.latin.common.InputPointers) SuggestedWordInfo(com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo) ArrayList(java.util.ArrayList)

Aggregations

InputPointers (com.android.inputmethod.latin.common.InputPointers)2 Point (android.graphics.Point)1 SuggestedWordInfo (com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo)1 ArrayList (java.util.ArrayList)1