Java Code Examples for android.view.inputmethod.CompletionInfo

The following are top voted examples for showing how to use android.view.inputmethod.CompletionInfo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: keepass2android   File: KP2AKeyboard.java   View source code 6 votes vote down vote up
@Override
public void onDisplayCompletions(CompletionInfo[] completions) {
    if (DEBUG) {
        Log.i("foo", "Received completions:");
        for (int i=0; i<(completions != null ? completions.length : 0); i++) {
            Log.i("foo", "  #" + i + ": " + completions[i]);
        }
    }
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            clearSuggestions();
            return;
        }

        List<CharSequence> stringList = new ArrayList<CharSequence>();
        for (int i=0; i<(completions != null ? completions.length : 0); i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText());
        }
        // When in fullscreen mode, show completions generated by the application
        setSuggestions(stringList, true, true, true);
        mBestWord = null;
        setCandidatesViewShown(true);
    }
}
 
Example 2
Project: behe-keyboard   File: PCKeyboard.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, false, false);
            return;
        }

        List<String> stringList = new ArrayList<String>();
        for (int i = 0; i < completions.length; i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, true, true);
    }
}
 
Example 3
Project: behe-keyboard   File: PCKeyboard.java   View source code 6 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {

        if (mPredictionOn && mSuggestions != null && index >= 0) {
            mComposing.replace(0, mComposing.length(), mSuggestions.get(index));
        }
        commitTyped(getCurrentInputConnection());

    }
}
 
Example 4
Project: javaide   File: TerminalKeyboard.java   View source code 6 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {
        // If we were generating candidate suggestions for the current
        // text, we would commit one of them here.  But for this sample,
        // we will just commit the current text.
        commitTyped(getCurrentInputConnection());
    }
}
 
Example 5
Project: QuranKeyboard   File: QuranKeyboardIME.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, false);
            return;
        }
        
        List<String> stringList = new ArrayList<>();
        for (CompletionInfo ci : completions) {
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, true);
    }
}
 
Example 6
Project: KeePass2Android   File: KP2AKeyboard.java   View source code 6 votes vote down vote up
@Override
public void onDisplayCompletions(CompletionInfo[] completions) {
    if (DEBUG) {
        Log.i("foo", "Received completions:");
        for (int i=0; i<(completions != null ? completions.length : 0); i++) {
            Log.i("foo", "  #" + i + ": " + completions[i]);
        }
    }
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            clearSuggestions();
            return;
        }

        List<CharSequence> stringList = new ArrayList<CharSequence>();
        for (int i=0; i<(completions != null ? completions.length : 0); i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText());
        }
        // When in fullscreen mode, show completions generated by the application
        setSuggestions(stringList, true, true, true);
        mBestWord = null;
        setCandidatesViewShown(true);
    }
}
 
Example 7
Project: tibetan-keyboard   File: SoftKeyboard.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, false, false);
            return;
        }
        
        List<String> stringList = new ArrayList<String>();
        for (int i=0; i<(completions != null ? completions.length : 0); i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, true, true);
    }
}
 
Example 8
Project: tibetan-keyboard   File: SoftKeyboard.java   View source code 6 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {
        // If we were generating candidate suggestions for the current
        // text, we would commit one of them here.  But for this sample,
        // we will just commit the current text.
        commitTyped(getCurrentInputConnection());
    }
}
 
Example 9
Project: accentype-android   File: SoftKeyboard.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, null, false, false);
            return;
        }

        List<String> stringList = new ArrayList<String>();
        for (int i = 0; i < completions.length; i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, null, true, true);
    }
}
 
Example 10
Project: literatim   File: SoftKeyboard.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions((List<Suggestion>) null, false, false);
            return;
        }

        List<Suggestion> suggestions = new ArrayList<Suggestion>();
        for (int i=0; i<(completions != null ? completions.length : 0); i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) suggestions.add(new Suggestion(0, ci.getText().toString()));
        }
        this.suggestions = null;
        setSuggestions(suggestions, true, true);
    }
}
 
Example 11
Project: accentype-android   File: SoftKeyboard.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, null, false, false);
            return;
        }

        List<String> stringList = new ArrayList<String>();
        for (int i = 0; i < completions.length; i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, null, true, true);
    }
}
 
Example 12
Project: sinovoice-pathfinder   File: Pathfinder.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override 
public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, false, false);
            return;
        }
        
        List<String> stringList = new ArrayList<String>();
        for (int i = 0; i < completions.length; i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, true, true);
    }
}
 
Example 13
Project: sinovoice-pathfinder   File: Pathfinder.java   View source code 6 votes vote down vote up
public void pickSuggestionManually(int index, String text) {
	mComposing.setLength(0);
	mComposing.append(text);
	
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
    } else if (mComposing.length() > 0) {
        // If we were generating candidate suggestions for the current
        // text, we would commit one of them here.  But for this sample,
        // we will just commit the current text.
        commitTyped(getCurrentInputConnection());
    }
}
 
Example 14
Project: ZShaolin   File: TerminalKeyboard.java   View source code 6 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {
        // If we were generating candidate suggestions for the current
        // text, we would commit one of them here.  But for this sample,
        // we will just commit the current text.
        commitTyped(getCurrentInputConnection());
    }
}
 
Example 15
Project: animal   File: AnimalKeyboard.java   View source code 6 votes vote down vote up
/**
 * This tells us about completions that the editor has determined based
 * on the current text in it.  We want to use this in fullscreen mode
 * to show the completions ourself, since the editor can not be seen
 * in that situation.
 */
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            setSuggestions(null, false, false);
            return;
        }
        
        List<String> stringList = new ArrayList<String>();
        for (int i = 0; i < completions.length; i++) {
            CompletionInfo ci = completions[i];
            if (ci != null) stringList.add(ci.getText().toString());
        }
        setSuggestions(stringList, true, true);
    }
}
 
Example 16
Project: animal   File: AnimalKeyboard.java   View source code 6 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        store("["+ci.getText().toString()+"]");
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {
        // If we were generating candidate suggestions for the current
        // text, we would commit one of them here.  But for this sample,
        // we will just commit the current text.
        commitTyped(getCurrentInputConnection());
    }
}
 
Example 17
Project: android-kioskime   File: RichInputConnection.java   View source code 6 votes vote down vote up
public void commitCompletion(final CompletionInfo completionInfo) {
    if (DEBUG_BATCH_NESTING) checkBatchEdit();
    if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
    CharSequence text = completionInfo.getText();
    // text should never be null, but just in case, it's better to insert nothing than to crash
    if (null == text) text = "";
    mCommittedTextBeforeComposingText.append(text);
    mCurrentCursorPosition += text.length() - mComposingText.length();
    mComposingText.setLength(0);
    if (null != mIC) {
        mIC.commitCompletion(completionInfo);
        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
            ResearchLogger.richInputConnection_commitCompletion(completionInfo);
        }
    }
    if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
}
 
Example 18
Project: AOSP-Kayboard-7.1.2   File: RichInputConnection.java   View source code 5 votes vote down vote up
public void commitCompletion(final CompletionInfo completionInfo) {
    if (DEBUG_BATCH_NESTING) checkBatchEdit();
    if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
    CharSequence text = completionInfo.getText();
    // text should never be null, but just in case, it's better to insert nothing than to crash
    if (null == text) text = "";
    mCommittedTextBeforeComposingText.append(text);
    mExpectedSelStart += text.length() - mComposingText.length();
    mExpectedSelEnd = mExpectedSelStart;
    mComposingText.setLength(0);
    if (isConnected()) {
        mIC.commitCompletion(completionInfo);
    }
    if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
}
 
Example 19
Project: AOSP-Kayboard-7.1.2   File: CompletionInfoUtils.java   View source code 5 votes vote down vote up
public static CompletionInfo[] removeNulls(final CompletionInfo[] src) {
    int j = 0;
    final CompletionInfo[] dst = new CompletionInfo[src.length];
    for (int i = 0; i < src.length; ++i) {
        if (null != src[i] && !TextUtils.isEmpty(src[i].getText())) {
            dst[j] = src[i];
            ++j;
        }
    }
    return Arrays.copyOfRange(dst, 0, j);
}
 
Example 20
Project: AOSP-Kayboard-7.1.2   File: LatinIME.java   View source code 5 votes vote down vote up
@Override
public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions) {
    if (DebugFlags.DEBUG_ENABLED) {
        Log.i(TAG, "Received completions:");
        if (applicationSpecifiedCompletions != null) {
            for (int i = 0; i < applicationSpecifiedCompletions.length; i++) {
                Log.i(TAG, "  #" + i + ": " + applicationSpecifiedCompletions[i]);
            }
        }
    }
    if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) {
        return;
    }
    // If we have an update request in flight, we need to cancel it so it does not override
    // these completions.
    mHandler.cancelUpdateSuggestionStrip();
    if (applicationSpecifiedCompletions == null) {
        setNeutralSuggestionStrip();
        return;
    }

    final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
            SuggestedWords.getFromApplicationSpecifiedCompletions(
                    applicationSpecifiedCompletions);
    final SuggestedWords suggestedWords = new SuggestedWords(applicationSuggestedWords,
            null /* rawSuggestions */,
            null /* typedWord */,
            false /* typedWordValid */,
            false /* willAutoCorrect */,
            false /* isObsoleteSuggestions */,
            SuggestedWords.INPUT_STYLE_APPLICATION_SPECIFIED /* inputStyle */,
            SuggestedWords.NOT_A_SEQUENCE_NUMBER);
    // When in fullscreen mode, show completions generated by the application forcibly
    setSuggestedWords(suggestedWords);
}
 
Example 21
Project: AOSP-Kayboard-7.1.2   File: SuggestedWords.java   View source code 5 votes vote down vote up
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
        final CompletionInfo[] infos) {
    final ArrayList<SuggestedWordInfo> result = new ArrayList<>();
    for (final CompletionInfo info : infos) {
        if (null == info || null == info.getText()) {
            continue;
        }
        result.add(new SuggestedWordInfo(info));
    }
    return result;
}
 
Example 22
Project: AOSP-Kayboard-7.1.2   File: SuggestedWords.java   View source code 5 votes vote down vote up
/**
 * Create a new suggested word info from an application-specified completion.
 * If the passed argument or its contained text is null, this throws a NPE.
 * @param applicationSpecifiedCompletion The application-specified completion info.
 */
public SuggestedWordInfo(final CompletionInfo applicationSpecifiedCompletion) {
    mWord = applicationSpecifiedCompletion.getText().toString();
    mPrevWordsContext = "";
    mApplicationSpecifiedCompletionInfo = applicationSpecifiedCompletion;
    mScore = SuggestedWordInfo.MAX_SCORE;
    mKindAndFlags = SuggestedWordInfo.KIND_APP_DEFINED;
    mSourceDict = Dictionary.DICTIONARY_APPLICATION_DEFINED;
    mCodePointCount = StringUtils.codePointCount(mWord);
    mIndexOfTouchPointOfSecondWord = SuggestedWordInfo.NOT_AN_INDEX;
    mAutoCommitFirstWordConfidence = SuggestedWordInfo.NOT_A_CONFIDENCE;
}
 
Example 23
Project: accentype-android   File: SoftKeyboard.java   View source code 5 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {
        commitTyped(getCurrentInputConnection(), index);
    }
}
 
Example 24
Project: hackerskeyboard   File: LatinIME.java   View source code 5 votes vote down vote up
@Override
public void onDisplayCompletions(CompletionInfo[] completions) {
    if (DEBUG) {
        Log.i("foo", "Received completions:");
        for (int i = 0; i < (completions != null ? completions.length : 0); i++) {
            Log.i("foo", "  #" + i + ": " + completions[i]);
        }
    }
    if (mCompletionOn) {
        mCompletions = completions;
        if (completions == null) {
            clearSuggestions();
            return;
        }

        List<CharSequence> stringList = new ArrayList<CharSequence>();
        for (int i = 0; i < (completions != null ? completions.length : 0); i++) {
            CompletionInfo ci = completions[i];
            if (ci != null)
                stringList.add(ci.getText());
        }
        // When in fullscreen mode, show completions generated by the
        // application
        setSuggestions(stringList, true, true, true);
        mBestWord = null;
        setCandidatesViewShown(true);
    }
}
 
Example 25
Project: literatim   File: SoftKeyboard.java   View source code 5 votes vote down vote up
public void pickCandidateManually(int index) {
    InputConnection ic = getCurrentInputConnection();
    if (mCompletionOn && mCompletions != null && index >= 0 && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        ic.commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (suggestions != null && index < suggestions.size()) {
        String text = lexicon.getSuggestionText(mComposing.toString(), suggestions.get(index));
        if (text.charAt(0) == '\'') {
            // test to make sure we don't insert double ''
            CharSequence lastChar = ic.getTextBeforeCursor(1, 0);
            if (lastChar.charAt(0) == '\'') {
                text = text.substring(1);
            }
        }
        mComposing.setLength(0);
        mComposing.append(text);
        commitWithSpacing(ic);

    }
    else if (mComposing.length() > 0) {
        // Strange error; just commit the current text
        commitWithSpacing(ic);
    }
}
 
Example 26
Project: accentype-android   File: SoftKeyboard.java   View source code 5 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (mCompletionOn && mCompletions != null && index >= 0
            && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (mComposing.length() > 0) {
        commitTyped(getCurrentInputConnection(), index);
    }
}
 
Example 27
Project: JotaTextEditor   File: EditableInputConnection.java   View source code 5 votes vote down vote up
public boolean commitCompletion(CompletionInfo text) {
    if (DEBUG) Log.v(TAG, "commitCompletion " + text);
    mTextView.beginBatchEdit();
    mTextView.onCommitCompletion(text);
    mTextView.endBatchEdit();
    return true;
}
 
Example 28
Project: adt-leanback-support   File: SearchBar.java   View source code 5 votes vote down vote up
/**
 * Update the completion list shown by the IME
 *
 * @param completions list of completions shown in the IME, can be null or empty to clear them
 */
public void displayCompletions(List<String> completions) {
    List<CompletionInfo> infos = new ArrayList<CompletionInfo>();
    if (null != completions) {
        for (String completion : completions) {
            infos.add(new CompletionInfo(infos.size(), infos.size(), completion));
        }
    }

    mInputMethodManager.displayCompletions(mSearchTextEditor,
            infos.toArray(new CompletionInfo[] {}));
}
 
Example 29
Project: gloomy-dungeons-2   File: AutoCompleteTextView.java   View source code 5 votes vote down vote up
private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = (InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[realCount] = new CompletionInfo(id,
                            realCount, convertSelectionToString(item));
                    realCount++;
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }

            imm.displayCompletions(this, completions);
        }
    }
}
 
Example 30
Project: laposte-android   File: AutoCompleteTextView.java   View source code 5 votes vote down vote up
private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = (InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[realCount] = new CompletionInfo(id,
                            realCount, convertSelectionToString(item));
                    realCount++;
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }

            imm.displayCompletions(this, completions);
        }
    }
}
 
Example 31
Project: BAGO_TS   File: KeyboardService.java   View source code 5 votes vote down vote up
@Override public void onDisplayCompletions(CompletionInfo[] completions) {
	if (CompletionOn) {
		Completions = completions;
		if (completions == null) {
			return;
		}

		List<String> stringList = new ArrayList<String>();
		for (int i=0; i<(completions != null ? completions.length : 0); i++) {
			CompletionInfo ci = completions[i];
			if (ci != null) stringList.add(ci.getText().toString());
		}
	}
}
 
Example 32
Project: BAGO_TS   File: KeyboardService.java   View source code 5 votes vote down vote up
public void pickSuggestionManually(int index) {
	if (CompletionOn && Completions != null && index >= 0
			&& index < Completions.length) {
		CompletionInfo ci = Completions[index];
		getCurrentInputConnection().commitCompletion(ci);
		/*if (mCandidateView != null) {
			mCandidateView.clear();
		}*/
		updateShiftKeyState(getCurrentInputEditorInfo());
	} else if (Composing.length() > 0) {
		commitTyped(getCurrentInputConnection());
	}
}
 
Example 33
Project: android-kioskime   File: ResearchLogger.java   View source code 5 votes vote down vote up
public static void latinIME_onDisplayCompletions(
        final CompletionInfo[] applicationSpecifiedCompletions) {
    // Note; passing an array as a single element in a vararg list.  Must create a new
    // dummy array around it or it will get expanded.
    getInstance().enqueueEvent(LOGSTATEMENT_LATINIME_ONDISPLAYCOMPLETIONS,
            new Object[] { applicationSpecifiedCompletions });
}
 
Example 34
Project: android-kioskime   File: JsonUtils.java   View source code 5 votes vote down vote up
static void writeJson(final CompletionInfo[] ci, final JsonWriter jsonWriter)
        throws IOException {
    jsonWriter.beginArray();
    for (int j = 0; j < ci.length; j++) {
        jsonWriter.value(ci[j].toString());
    }
    jsonWriter.endArray();
}
 
Example 35
Project: android-kioskime   File: CompletionInfoUtils.java   View source code 5 votes vote down vote up
public static CompletionInfo[] removeNulls(final CompletionInfo[] src) {
    int j = 0;
    final CompletionInfo[] dst = new CompletionInfo[src.length];
    for (int i = 0; i < src.length; ++i) {
        if (null != src[i] && !TextUtils.isEmpty(src[i].getText())) {
            dst[j] = src[i];
            ++j;
        }
    }
    return Arrays.copyOfRange(dst, 0, j);
}
 
Example 36
Project: android-kioskime   File: LatinIME.java   View source code 5 votes vote down vote up
@Override
public void onDisplayCompletions(final CompletionInfo[] applicationSpecifiedCompletions) {
    if (DEBUG) {
        Log.i(TAG, "Received completions:");
        if (applicationSpecifiedCompletions != null) {
            for (int i = 0; i < applicationSpecifiedCompletions.length; i++) {
                Log.i(TAG, "  #" + i + ": " + applicationSpecifiedCompletions[i]);
            }
        }
    }
    if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return;
    if (applicationSpecifiedCompletions == null) {
        clearSuggestionStrip();
        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
            ResearchLogger.latinIME_onDisplayCompletions(null);
        }
        return;
    }
    mApplicationSpecifiedCompletions =
            CompletionInfoUtils.removeNulls(applicationSpecifiedCompletions);

    final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
            SuggestedWords.getFromApplicationSpecifiedCompletions(
                    applicationSpecifiedCompletions);
    final SuggestedWords suggestedWords = new SuggestedWords(
            applicationSuggestedWords,
            false /* typedWordValid */,
            false /* hasAutoCorrectionCandidate */,
            false /* isPunctuationSuggestions */,
            false /* isObsoleteSuggestions */,
            false /* isPrediction */);
    // When in fullscreen mode, show completions generated by the application
    final boolean isAutoCorrection = false;
    setSuggestedWords(suggestedWords, isAutoCorrection);
    setAutoCorrectionIndicator(isAutoCorrection);
    setSuggestionStripShown(true);
    if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
        ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
    }
}
 
Example 37
Project: android-kioskime   File: SuggestedWords.java   View source code 5 votes vote down vote up
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
        final CompletionInfo[] infos) {
    final ArrayList<SuggestedWordInfo> result = CollectionUtils.newArrayList();
    for (final CompletionInfo info : infos) {
        if (info == null) continue;
        final CharSequence text = info.getText();
        if (null == text) continue;
        final SuggestedWordInfo suggestedWordInfo = new SuggestedWordInfo(text.toString(),
                SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_APP_DEFINED,
                Dictionary.TYPE_APPLICATION_DEFINED);
        result.add(suggestedWordInfo);
    }
    return result;
}
 
Example 38
Project: TflTravelAlerts   File: AutoCompleteTextView.java   View source code 5 votes vote down vote up
private void buildImeCompletions() {
    final ListAdapter adapter = mAdapter;
    if (adapter != null) {
        InputMethodManager imm = (InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            final int count = Math.min(adapter.getCount(), 20);
            CompletionInfo[] completions = new CompletionInfo[count];
            int realCount = 0;
            for (int i = 0; i < count; i++) {
                if (adapter.isEnabled(i)) {
                    Object item = adapter.getItem(i);
                    long id = adapter.getItemId(i);
                    completions[realCount] = new CompletionInfo(id,
                            realCount, convertSelectionToString(item));
                    realCount++;
                }
            }
            if (realCount != count) {
                CompletionInfo[] tmp = new CompletionInfo[realCount];
                System.arraycopy(completions, 0, tmp, 0, realCount);
                completions = tmp;
            }

            imm.displayCompletions(this, completions);
        }
    }
}
 
Example 39
Project: Auto.js   File: InputConnectProxy.java   View source code 4 votes vote down vote up
@Override
public boolean commitCompletion(CompletionInfo text) {
    return mInputConnection.commitCompletion(text);
}
 
Example 40
Project: QuranKeyboard   File: QuranKeyboardIME.java   View source code 4 votes vote down vote up
public void pickSuggestionManually(int index) {
    if (index < 0) {
        // assert
        return;
    }

    if (mCompletionOn && mCompletions != null && index < mCompletions.length) {
        CompletionInfo ci = mCompletions[index];
        getCurrentInputConnection().commitCompletion(ci);
        if (mCandidateView != null) {
            mCandidateView.clear();
        }
        return;
    }
    
    if (mComposing.length() > 0) {
        String s;
        // Commit the candidate suggestion for the current text.
        if(index < mSuggestions.size()) {
            s = mSuggestions.get(index);
            getCurrentInputConnection().commitText(s, s.length());
        }
        else if (index < mQuranSuggestions.size()) {
            AyaMatch m = mQuranSuggestions.get(index);
            SpannableStringBuilder txt = new SpannableStringBuilder(m.strBld);
            int len = m.len;

            txt.insert(0, "﴿");
            len++;
            txt.insert(len - m.slen, "﴾");
            len++;

            // separate Quran from following text with a dot
            txt.append('.');
            len++;
            if (getPrefRasm() == Rasm.UTHMANI /*&& mUthmaniTypeFace != null*/) {
                txt.setSpan(new CustomTypefaceSpan(getUthmaniTypeFace()), 0, len, 0);
            }
            Toast.makeText(this, txt.subSequence(0, len), Toast.LENGTH_LONG).show();

            for (int i = 0; i < mSavedPreSpaces; i++) txt.insert(0, " ");
            len += mSavedPreSpaces;
            getCurrentInputConnection().commitText(txt.subSequence(0, len), len);
            mSavedPreSpaces = 0;
        }
        mComposing.setLength(0);
        updateCandidates();
    }
}