Search in sources :

Example 6 with SpacingAndPunctuations

use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputConnectionAndTextRangeTests method helpTestGetSuggestionSpansAtWord.

private void helpTestGetSuggestionSpansAtWord(final int cursorPos) {
    final SpacingAndPunctuations SPACE = new SpacingAndPunctuations(mSpacingAndPunctuations, new int[] { Constants.CODE_SPACE });
    final MockInputMethodService mockInputMethodService = new MockInputMethodService();
    final RichInputConnection ic = new RichInputConnection(mockInputMethodService);
    final String[] SUGGESTIONS1 = { "swing", "strong" };
    final String[] SUGGESTIONS2 = { "storing", "strung" };
    // Test the usual case.
    SpannableString text = new SpannableString("This is a string for test");
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0), 10, /* start */
    16, /* end */
    0);
    mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos));
    TextRange r;
    SuggestionSpan[] suggestions;
    r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
    suggestions = r.getSuggestionSpansAtWord();
    assertEquals(suggestions.length, 1);
    MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1);
    // Test the case with 2 suggestion spans in the same place.
    text = new SpannableString("This is a string for test");
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0), 10, /* start */
    16, /* end */
    0);
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0), 10, /* start */
    16, /* end */
    0);
    mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos));
    r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
    suggestions = r.getSuggestionSpansAtWord();
    assertEquals(suggestions.length, 2);
    MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1);
    MoreAsserts.assertEquals(suggestions[1].getSuggestions(), SUGGESTIONS2);
    // Test a case with overlapping spans, 2nd extending past the start of the word
    text = new SpannableString("This is a string for test");
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0), 10, /* start */
    16, /* end */
    0);
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0), 5, /* start */
    16, /* end */
    0);
    mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos));
    r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
    suggestions = r.getSuggestionSpansAtWord();
    assertEquals(suggestions.length, 1);
    MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1);
    // Test a case with overlapping spans, 2nd extending past the end of the word
    text = new SpannableString("This is a string for test");
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0), 10, /* start */
    16, /* end */
    0);
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0), 10, /* start */
    20, /* end */
    0);
    mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos));
    r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
    suggestions = r.getSuggestionSpansAtWord();
    assertEquals(suggestions.length, 1);
    MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1);
    // Test a case with overlapping spans, 2nd extending past both ends of the word
    text = new SpannableString("This is a string for test");
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0), 10, /* start */
    16, /* end */
    0);
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0), 5, /* start */
    20, /* end */
    0);
    mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos));
    r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
    suggestions = r.getSuggestionSpansAtWord();
    assertEquals(suggestions.length, 1);
    MoreAsserts.assertEquals(suggestions[0].getSuggestions(), SUGGESTIONS1);
    // Test a case with overlapping spans, none right on the word
    text = new SpannableString("This is a string for test");
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS1, 0), 5, /* start */
    16, /* end */
    0);
    text.setSpan(new SuggestionSpan(Locale.ENGLISH, SUGGESTIONS2, 0), 5, /* start */
    20, /* end */
    0);
    mockInputMethodService.setInputConnection(new MockConnection(text, cursorPos));
    r = ic.getWordRangeAtCursor(SPACE, ScriptUtils.SCRIPT_LATIN);
    suggestions = r.getSuggestionSpansAtWord();
    assertEquals(suggestions.length, 0);
}
Also used : SpannableString(android.text.SpannableString) SpacingAndPunctuations(com.android.inputmethod.latin.settings.SpacingAndPunctuations) TextRange(com.android.inputmethod.latin.utils.TextRange) SpannableString(android.text.SpannableString) SuggestionSpan(android.text.style.SuggestionSpan)

Example 7 with SpacingAndPunctuations

use of com.android.inputmethod.latin.settings.SpacingAndPunctuations in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputConnectionAndTextRangeTests method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    final RunInLocale<SpacingAndPunctuations> job = new RunInLocale<SpacingAndPunctuations>() {

        @Override
        protected SpacingAndPunctuations job(final Resources res) {
            return new SpacingAndPunctuations(res);
        }
    };
    final Resources res = getContext().getResources();
    mSpacingAndPunctuations = job.runInLocale(res, Locale.ENGLISH);
}
Also used : SpacingAndPunctuations(com.android.inputmethod.latin.settings.SpacingAndPunctuations) Resources(android.content.res.Resources) RunInLocale(com.android.inputmethod.latin.utils.RunInLocale)

Aggregations

SpacingAndPunctuations (com.android.inputmethod.latin.settings.SpacingAndPunctuations)7 Resources (android.content.res.Resources)3 SpannableString (android.text.SpannableString)2 TextRange (com.android.inputmethod.latin.utils.TextRange)2 SuggestionSpan (android.text.style.SuggestionSpan)1 ExtractedText (android.view.inputmethod.ExtractedText)1 RunInLocale (com.android.inputmethod.latin.utils.RunInLocale)1