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);
}
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);
}
Aggregations