Search in sources :

Example 1 with WordIterator

use of android.text.method.WordIterator in project android_frameworks_base by ParanoidAndroid.

the class SpellChecker method setLocale.

private void setLocale(Locale locale) {
    mCurrentLocale = locale;
    resetSession();
    if (locale != null) {
        // Change SpellParsers' wordIterator locale
        mWordIterator = new WordIterator(locale);
    }
    // This class is the listener for locale change: warn other locale-aware objects
    mTextView.onLocaleChanged();
}
Also used : WordIterator(android.text.method.WordIterator)

Example 2 with WordIterator

use of android.text.method.WordIterator in project platform_frameworks_base by android.

the class Editor method selectCurrentWord.

/**
     * Adjusts selection to the word under last touch offset. Return true if the operation was
     * successfully performed.
     */
private boolean selectCurrentWord() {
    if (!mTextView.canSelectText()) {
        return false;
    }
    if (needsToSelectAllToSelectWordOrParagraph()) {
        return mTextView.selectAllText();
    }
    long lastTouchOffsets = getLastTouchOffsets();
    final int minOffset = TextUtils.unpackRangeStartFromLong(lastTouchOffsets);
    final int maxOffset = TextUtils.unpackRangeEndFromLong(lastTouchOffsets);
    // Safety check in case standard touch event handling has been bypassed
    if (minOffset < 0 || minOffset > mTextView.getText().length())
        return false;
    if (maxOffset < 0 || maxOffset > mTextView.getText().length())
        return false;
    int selectionStart, selectionEnd;
    // If a URLSpan (web address, email, phone...) is found at that position, select it.
    URLSpan[] urlSpans = ((Spanned) mTextView.getText()).getSpans(minOffset, maxOffset, URLSpan.class);
    if (urlSpans.length >= 1) {
        URLSpan urlSpan = urlSpans[0];
        selectionStart = ((Spanned) mTextView.getText()).getSpanStart(urlSpan);
        selectionEnd = ((Spanned) mTextView.getText()).getSpanEnd(urlSpan);
    } else {
        // FIXME - We should check if there's a LocaleSpan in the text, this may be
        // something we should try handling or checking for.
        final WordIterator wordIterator = getWordIterator();
        wordIterator.setCharSequence(mTextView.getText(), minOffset, maxOffset);
        selectionStart = wordIterator.getBeginning(minOffset);
        selectionEnd = wordIterator.getEnd(maxOffset);
        if (selectionStart == BreakIterator.DONE || selectionEnd == BreakIterator.DONE || selectionStart == selectionEnd) {
            // Possible when the word iterator does not properly handle the text's language
            long range = getCharClusterRange(minOffset);
            selectionStart = TextUtils.unpackRangeStartFromLong(range);
            selectionEnd = TextUtils.unpackRangeEndFromLong(range);
        }
    }
    Selection.setSelection((Spannable) mTextView.getText(), selectionStart, selectionEnd);
    return selectionEnd > selectionStart;
}
Also used : WordIterator(android.text.method.WordIterator) URLSpan(android.text.style.URLSpan) Spanned(android.text.Spanned) Paint(android.graphics.Paint)

Example 3 with WordIterator

use of android.text.method.WordIterator in project platform_frameworks_base by android.

the class SpellChecker method setLocale.

private void setLocale(Locale locale) {
    mCurrentLocale = locale;
    resetSession();
    if (locale != null) {
        // Change SpellParsers' wordIterator locale
        mWordIterator = new WordIterator(locale);
    }
    // This class is the listener for locale change: warn other locale-aware objects
    mTextView.onLocaleChanged();
}
Also used : WordIterator(android.text.method.WordIterator)

Example 4 with WordIterator

use of android.text.method.WordIterator in project android_frameworks_base by DirtyUnicorns.

the class SpellChecker method setLocale.

private void setLocale(Locale locale) {
    mCurrentLocale = locale;
    resetSession();
    if (locale != null) {
        // Change SpellParsers' wordIterator locale
        mWordIterator = new WordIterator(locale);
    }
    // This class is the listener for locale change: warn other locale-aware objects
    mTextView.onLocaleChanged();
}
Also used : WordIterator(android.text.method.WordIterator)

Example 5 with WordIterator

use of android.text.method.WordIterator in project android_frameworks_base by AOSPA.

the class Editor method getWordIteratorWithText.

private WordIterator getWordIteratorWithText() {
    if (mWordIteratorWithText == null) {
        mWordIteratorWithText = new WordIterator(mTextView.getTextServicesLocale());
        mUpdateWordIteratorText = true;
    }
    if (mUpdateWordIteratorText) {
        // FIXME - Shouldn't copy all of the text as only the area of the text relevant
        // to the user's selection is needed. A possible solution would be to
        // copy some number N of characters near the selection and then when the
        // user approaches N then we'd do another copy of the next N characters.
        CharSequence text = mTextView.getText();
        mWordIteratorWithText.setCharSequence(text, 0, text.length());
        mUpdateWordIteratorText = false;
    }
    return mWordIteratorWithText;
}
Also used : WordIterator(android.text.method.WordIterator)

Aggregations

WordIterator (android.text.method.WordIterator)18 Paint (android.graphics.Paint)7 Spanned (android.text.Spanned)7 URLSpan (android.text.style.URLSpan)7 TextPaint (android.text.TextPaint)1