Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

In this page you can find the example usage for android.text SpannableString setSpan.

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:org.de.jmg.learn._MainActivity.java

public void SetActionBarTitle() throws Exception {
    if (mainView == null)
        return;//from   w  w w .  j  a  v  a 2 s .c o  m
    if (_vok.getGesamtzahl() > 0) {
        String FName = "";
        if (!libString.IsNullOrEmpty(_vok.getFileName())) {
            FName = new File(_vok.getFileName()).getName();
        } else if (_vok.getURI() != null) {
            String path = lib.dumpUriMetaData(_main, _vok.getURI());
            if (path.contains(":"))
                path = path.split(":")[0];
            int li = path.lastIndexOf("/");
            if (li > -1) {
                FName = path.substring(path.lastIndexOf("/"));
            } else {
                FName = "/" + path;
            }
        } else if (!libString.IsNullOrEmpty(_vok.getURIName())) {
            FName = _vok.getURIName();
        }
        if (FName.length() > 15 && _isSmallDevice) {
            FName = FName.substring(0, 15);
        } else if (FName.length() > 30) {
            FName = FName.substring(0, 30);
        }
        String title = "" + FName + " " + getString(R.string.number) + ": " + _vok.getIndex() + "/"
                + (_vok.getVokabeln().size() - 1) + " " + getString(R.string.counter) + ": "
                + _vok.getZaehler();
        String Right = " " + _vok.AnzRichtig;
        String Wrong = " " + _vok.AnzFalsch;
        SpannableString spnTitle = new SpannableString(title);
        SpannableString spnRight = new SpannableString(Right);
        SpannableString spnWrong = new SpannableString(Wrong);
        spnRight.setSpan(new ForegroundColorSpan(Color.GREEN), 0, spnRight.length(),
                SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        spnWrong.setSpan(new ForegroundColorSpan(Color.RED), 0, spnWrong.length(),
                SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        TextView txtStatus = (TextView) (findViewById(R.id.txtStatus));
        if (txtStatus != null)
            txtStatus.setText(TextUtils.concat(spnTitle, spnRight, spnWrong));
        //getSupportActionBar().setTitle(
        //      TextUtils.concat(spnTitle, spnRight, spnWrong));

    } else {
        Log.d("Vok", "empty");
        /*
         * String title = "Learn " + "empty._vok" + " " +
         * getString(R.string.number) + ": " + _vok.getIndex() + " " +
         * getString(R.string.counter) + ": " + _vok.getZaehler(); String
         * Right = " " + _vok.AnzRichtig; String Wrong = " " + _vok.AnzFalsch;
         * SpannableString spnTitle = new SpannableString(title);
         * SpannableString spnRight = new SpannableString(Right);
         * SpannableString spnWrong = new SpannableString(Wrong);
         * spnRight.setSpan(new ForegroundColorSpan(Color.GREEN), 0,
         * spnRight.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
         * spnWrong.setSpan(new ForegroundColorSpan(Color.RED), 0,
         * spnWrong.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
         *
         * getSupportActionBar().setTitle( TextUtils.concat(spnTitle,
         * spnRight, spnWrong));
         */
    }
    resizeActionbar(0);
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Handles the manual selection of suggestions from the suggestion bar
 * @param index the position of the suggestion in the suggestion list
 *//*from   w  w w  .  j  av  a2  s .  c  om*/
public void pickSuggestionManually(int index) {
    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 (mComposing.length() >= 0) {

        String picked;
        if (!replacemode)
            picked = suggestions.get(index) + " ";
        else
            picked = suggestions.get(index);

        //Log.i("Suggestion picked 2", picked);

        //ic.commitText(picked, picked.length());

        getCurrentInputEditorInfo();

        //colour the text according to user preferences
        SpannableString text = new SpannableString(picked);
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        if (sharedPrefs.getBoolean("suggestion_highlight", false))
            text.setSpan(new BackgroundColorSpan(suggestion), 0, picked.length() - 1,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        currentSession.nSuggestionsPicked++;

        if (replacemode) {
            replacemode = false;
            //remove from list of autocorrected words.
            //Log.i("PickSuggestion", "Removed "+autocorrected_words.remove(text.toString()));

            //find the current word
            extr = ic.getExtractedText(new ExtractedTextRequest(), 0);
            WordDetails w = findWord(extr.selectionStart, extr.text);
            //Log.i("FindWord", w.word+", "+w.wordStart+" - "+w.wordEnd);
            ic.setComposingRegion(w.wordStart, w.wordEnd);
            text.setSpan(null, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            /*
            //clear any spans       
            BackgroundColorSpan[] spans=(new SpannableString(extr.text.toString())).getSpans(w.wordStart, w.wordEnd, BackgroundColorSpan.class);
            for(int i=0; i<spans.length; i++){
              text.removeSpan(spans[i]);
            }*/

            //commit the update
            ic.commitText(text, 1);

        } else
            ic.commitText(text, picked.length());

        coreEngine.resetCoreString();
        coreEngine.insertText(picked);
        mComposing.setLength(0);
        updateCandidates();
    }
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * handle the receipt of suggestions from the spell checker
 * colour the text in the editor as required
 * pass information to the keyboard view so it can draw the colour bar
 * initiate audio and haptic feedback as required
 *///w  ww . jav  a2s  .  c  o  m
@Override
public void onGetSuggestions(SuggestionsInfo[] results) {
    // TODO Auto-generated method stub
    int colortype = -1;
    final StringBuilder sb = new StringBuilder();

    if (updateSuggestionList) {
        updateSuggestionList = false;
        ArrayList<String> s = new ArrayList<String>();
        for (int i = 0; i < results.length; ++i) {
            final int length = results[i].getSuggestionsCount();
            for (int j = 0; j < length; ++j) {
                s.add(results[i].getSuggestionAt(j));
            }
        }
        updateSuggestionListWithSpellChecker(s);
    } else {

        for (int i = 0; i < results.length; ++i) {
            // Returned suggestions are contained in SuggestionsInfo

            final int len = results[i].getSuggestionsCount();
            sb.append("Suggestion Attribs: " + results[i].getSuggestionsAttributes());
            if ((results[i].getSuggestionsAttributes()
                    & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) == SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) {
                sb.append("The word was found in the dictionary\n");
                mInputView.wordcompletedtype = 3;
            } else {

                if ((results[i].getSuggestionsAttributes()
                        & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) == SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) {
                    if ((results[i].getSuggestionsAttributes()
                            & SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS) == SuggestionsInfo.RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS) {
                        colortype = 1; //yellow
                        mInputView.wordcompletedtype = 1;
                        sb.append("There are strong candidates for this word\n");
                        currentSession.nLowErrors++;
                    } else {
                        colortype = 2; //red
                        mInputView.wordcompletedtype = 2;
                        sb.append("The word looks like a typo\n");
                        currentSession.nHighErrors++;

                    }
                }

            }

            sb.append("\n--These are the suggestions--\n");
            for (int j = 0; j < len; ++j) {
                sb.append("," + results[i].getSuggestionAt(j));
            }
            sb.append(" (" + len + ")");
        }
        //Log.i("Spelling suggestions", sb.toString());

        //this comes after a word separator, hence just add 1 to the cursor
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

        SpannableString text = new SpannableString(mComposingTemp);

        if (sharedPrefs.getBoolean("highlightwords", true)) {
            switch (colortype) {
            case 1:
                text.setSpan(new BackgroundColorSpan(small_err), 0, mComposingTemp.length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                break;
            case 2:
                text.setSpan(new BackgroundColorSpan(big_err), 0, mComposingTemp.length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                break;
            default:
                break;
            }
        }

        if (sharedPrefs.getBoolean("autocorrect", true) && mInputView.wordcompletedtype == 1) //handle autocorrection
        {
            SpannableString autoc = autocorrect(results);
            autocorrected_words.put(autoc.toString(), text.toString()); //autocorrected word, original input
            //Log.i("Autocorrecting","Key= "+autoc.toString()+", Value= "+text.toString());
            text = autoc;
            if (sharedPrefs.getBoolean("highlightwords", true))
                text.setSpan(new BackgroundColorSpan(autocorrect), 0, text.length(),
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mInputView.wordcompletedtype = 4;
        } else //autocorrection is turned off
        {
            if (!sharedPrefs.getBoolean("autocorrect", true) && colortype >= 1) //a mistake word
            {
                //Log.i("OnGetSentenceSuggestions","Key= "+text.toString()+", Value= "+text.toString());
                //no autocorrects, just put the word in and itself as the replacement
                autocorrected_words.put(text.toString(), text.toString());
            }
        }

        if (sharedPrefs.getBoolean("vibrator", false)) {
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
            final int on_time = Integer.parseInt(sharedPrefs.getString("shortvibe", "35"));

            switch (mInputView.wordcompletedtype) {
            case 1: //small err
                // Vibrate for 300 milliseconds
                v.vibrate(on_time);
                break;
            case 2: //big err
                //v.vibrate(Integer.parseInt(sharedPrefs.getString("longvibe", "300")));
                v.vibrate(new long[] { 0, on_time, 200, on_time }, -1);
                break;
            case 4: //autocorr
                v.vibrate(on_time);
                break;
            default:
                break;

            }
        }

        if (sharedPrefs.getBoolean("audio", false)) {
            final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
            switch (mInputView.wordcompletedtype) {
            case 1: //small err
                tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                break;
            case 2: //big err
                tg.startTone(ToneGenerator.TONE_PROP_BEEP2);
                break;
            case 4: //autocorr
                tg.startTone(ToneGenerator.TONE_PROP_BEEP);
                break;
            default:
                break;

            }
        }

        mInputView.invalidateAllKeys();
        ic.commitText(text, 1);
        sendKey(wordSeparatorKeyCode);
        coreEngine.resetCoreString();
        updateCandidates();
    }

}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

/**
 * Mark the OP submitter comments//from  w  ww .ja  va  2s. c o  m
 */
void markSubmitterComments() {
    if (getOpThingInfo() == null || mCommentsAdapter == null)
        return;

    SpannableString authorSS = new SpannableString(getOpThingInfo().getAuthor() + " [S]");
    ForegroundColorSpan fcs;
    if (Util.isLightTheme(mSettings.getTheme()))
        fcs = new ForegroundColorSpan(getResources().getColor(R.color.blue));
    else
        fcs = new ForegroundColorSpan(getResources().getColor(R.color.pale_blue));
    authorSS.setSpan(fcs, 0, authorSS.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    for (int i = 0; i < mCommentsAdapter.getCount(); i++) {
        ThingInfo ci = mCommentsAdapter.getItem(i);
        // if it's the OP, mark his name
        if (getOpThingInfo().getAuthor().equalsIgnoreCase(ci.getAuthor()))
            ci.setSSAuthor(authorSS);
    }
}

From source file:com.android.mms.ui.MessageUtils.java

public static CharSequence formatMsgContent(String subject, String body, String displayAddress) {
    StringBuilder buf = new StringBuilder(
            displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' '));
    buf.append(':').append(' ');

    int offset = buf.length();
    if (!TextUtils.isEmpty(subject)) {
        subject = subject.replace('\n', ' ').replace('\r', ' ');
        buf.append(subject);/*from ww  w. ja va2  s.co  m*/
        buf.append(' ');
    }

    if (!TextUtils.isEmpty(body)) {
        body = body.replace('\n', ' ').replace('\r', ' ');
        buf.append(body);
    }

    SpannableString spanText = new SpannableString(buf.toString());
    spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanText;
}

From source file:com.android.ex.chips.RecipientEditTextView.java

void createMoreChipPlainText() {
    // Take the first <= CHIP_LIMIT addresses and get to the end of the second one.
    final Editable text = getText();
    int start = 0;
    int end = start;
    for (int i = 0; i < CHIP_LIMIT; i++) {
        end = movePastTerminators(mTokenizer.findTokenEnd(text, start));
        start = end; // move to the next token and get its end.
    }/*from w ww  .ja  v a  2 s  .  c  om*/
    // Now, count total addresses.
    start = 0;
    final int tokenCount = countTokens(text);
    final MoreImageSpan moreSpan = createMoreSpan(tokenCount - CHIP_LIMIT);
    final SpannableString chipText = new SpannableString(text.subSequence(end, text.length()));
    chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.replace(end, text.length(), chipText);
    mMoreChip = moreSpan;
}

From source file:com.android.ex.chips.RecipientEditTextView.java

/**
 * Create the more chip. The more chip is text that replaces any chips that do not fit in the pre-defined available
 * space when the RecipientEditTextView loses focus.
 *//*  w  w  w. j av a 2s . c  o  m*/
// Visible for testing.
/* package */void createMoreChip() {
    if (mNoChips) {
        createMoreChipPlainText();
        return;
    }
    if (!mShouldShrink)
        return;
    final ImageSpan[] tempMore = getSpannable().getSpans(0, getText().length(), MoreImageSpan.class);
    if (tempMore.length > 0)
        getSpannable().removeSpan(tempMore[0]);
    final DrawableRecipientChip[] recipients = getSortedRecipients();
    if (recipients == null || recipients.length <= CHIP_LIMIT) {
        mMoreChip = null;
        return;
    }
    final Spannable spannable = getSpannable();
    final int numRecipients = recipients.length;
    final int overage = numRecipients - CHIP_LIMIT;
    final MoreImageSpan moreSpan = createMoreSpan(overage);
    mRemovedSpans = new ArrayList<DrawableRecipientChip>();
    int totalReplaceStart = 0;
    int totalReplaceEnd = 0;
    final Editable text = getText();
    for (int i = numRecipients - overage; i < recipients.length; i++) {
        mRemovedSpans.add(recipients[i]);
        if (i == numRecipients - overage)
            totalReplaceStart = spannable.getSpanStart(recipients[i]);
        if (i == recipients.length - 1)
            totalReplaceEnd = spannable.getSpanEnd(recipients[i]);
        if (mTemporaryRecipients == null || !mTemporaryRecipients.contains(recipients[i])) {
            final int spanStart = spannable.getSpanStart(recipients[i]);
            final int spanEnd = spannable.getSpanEnd(recipients[i]);
            recipients[i].setOriginalText(text.toString().substring(spanStart, spanEnd));
        }
        spannable.removeSpan(recipients[i]);
    }
    if (totalReplaceEnd < text.length())
        totalReplaceEnd = text.length();
    final int end = Math.max(totalReplaceStart, totalReplaceEnd);
    final int start = Math.min(totalReplaceStart, totalReplaceEnd);
    final SpannableString chipText = new SpannableString(text.subSequence(start, end));
    chipText.setSpan(moreSpan, 0, chipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.replace(start, end, chipText);
    mMoreChip = moreSpan;
    // If adding the +more chip goes over the limit, resize accordingly.
    if (!isPhoneQuery() && getLineCount() > mMaxLines)
        setMaxLines(getLineCount());
}

From source file:org.de.jmg.learn._MainActivity.java

public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt)
        throws Exception {

    if (iv != null) {
        iv.setVisibility(View.GONE);
    }// www  .ja v a  2s  .  c o m
    if (iv2 != null)
        iv2.setVisibility(View.GONE);
    try {
        if (_btnRight == null)
            return;
        EndEdit(DontPrompt);
        setBtnsEnabled(true);
        if (showBeds && _vok.getIndex() >= 1) {
            _btnRight.setEnabled(true);
            _btnWrong.setEnabled(true);
            _btnEdit.setEnabled(true);
            _btnSkip.setEnabled(true);
            _btnView.setEnabled(true);
        } else {
            _btnRight.setEnabled(false);
            _btnWrong.setEnabled(false);
            if (_vok.getIndex() < 1) {
                _btnEdit.setEnabled(false);
                _btnSkip.setEnabled(false);
                _btnView.setEnabled(false);
            }
        }
        if (LoadNext)
            _vok.setLernIndex((short) (_vok.getLernIndex() + 1));

        View v;
        TextView t;
        String txtBed = getString(R.string.cloze);

        if (showBeds) {
            v = findViewById(R.id.txtMeaning1);
            t = (TextView) v;
            assert t != null;
            t.setText(lib.getSpanableString(_vok.getBedeutung1()));
            txtBed = t.getText().toString();
        }

        v = findViewById(R.id.word);
        t = (TextView) v;
        assert t != null;
        String txtWord = getString(R.string.cloze);
        if (!_vok.reverse || showBeds) {
            t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE);
            txtWord = t.getText().toString();
            txtWord = replaceClozes(txtWord, txtBed);
            speak(txtWord, _vok.getLangWord(), "word", true);
        } else {
            t.setText("");
        }

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedWord.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedWord.setTypeface(Typeface.DEFAULT);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.Comment);
        t = (TextView) v;
        assert t != null;
        t.setVisibility(View.VISIBLE);

        SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar());
        URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class);
        for (final URLSpan span : urlSpans) {
            int start = tspanKom.getSpanStart(span);
            int end = tspanKom.getSpanEnd(span);
            String txt = tspanKom.toString().substring(start, end);
            if (txtIsPicture(txt)) {
                tspanKom.removeSpan(span);
                tspanKom.setSpan(new urlclickablespan(span.getURL()) {
                    @Override
                    public void onClick(View widget) {
                        Bitmap b;
                        try {
                            b = lib.downloadpicture(this.url);
                        } catch (Exception ex) {
                            b = null;
                        }
                        if (b != null) {
                            if (iv == null) {
                                iv = new ImageView(context);
                                SetTouchListener(iv);
                            }
                            b = resizeBM(b);
                            iv.setImageBitmap(b);
                            if (iv.getParent() == null) {
                                try {
                                    LayoutParams p = _txtMeaning1.getLayoutParams();
                                    //p.width = LayoutParams.WRAP_CONTENT;
                                    //p.height = LayoutParams.WRAP_CONTENT;
                                    rellayoutMain.addView(iv, p);
                                } catch (Exception ex) {
                                    Log.e("addImageView", ex.getMessage(), ex);
                                }
                            } else {
                                Log.d("ImageView", "exists");
                            }
                            _txtMeaning1.setVisibility(View.GONE);
                            iv.setVisibility(View.VISIBLE);
                        }
                    }
                }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        t.setText(tspanKom, TextView.BufferType.SPANNABLE);

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedKom.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedKom.setTypeface(Typeface.DEFAULT);
        }
        if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) {
            t.setVisibility(View.GONE);
        } else {
            t.setVisibility(View.VISIBLE);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning1);
        t = (TextView) v;
        assert t != null;
        if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) {
            t.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        }
        if (_vok.reverse || showBeds) {
            SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1());
            //final String picname = _main.getString(R.string.picture);
            t.setVisibility(View.VISIBLE);
            if (txtIsPicture(tspan.toString())) {
                URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class);
                for (URLSpan url : urlspn) {
                    Bitmap b;
                    try {
                        b = lib.downloadpicture(url.getURL());
                    } catch (Exception ex) {
                        b = null;
                    }
                    if (b != null) {
                        if (iv == null) {
                            iv = new ImageView(context);
                            SetTouchListener(iv);
                        }
                        b = resizeBM(b);
                        iv.setImageBitmap(b);
                        if (iv.getParent() == null) {
                            try {
                                LayoutParams p = t.getLayoutParams();
                                //p.width = LayoutParams.WRAP_CONTENT;
                                //p.height = LayoutParams.WRAP_CONTENT;
                                rellayoutMain.addView(iv, p);
                            } catch (Exception ex) {
                                Log.e("Imagview", ex.getMessage(), ex);
                            }
                        } else {
                            Log.d("ImageView", "exists");
                        }
                        t.setVisibility(View.GONE);
                        iv.setVisibility(View.VISIBLE);
                    }
                }

            } else {
                // iv.setVisibility(View.GONE);
                t.setVisibility(View.VISIBLE);
            }

            t.setText(tspan);
        } else {
            t.setText(Vokabel.getComment(_vok.getBedeutung1()));
        }
        if (_vok.reverse || showBeds) {
            String txt = t.getText().toString();
            txt = replaceClozes(txt, txtWord);
            speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse);
        }
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        t.setOnFocusChangeListener(FocusListenerMeaning1);
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning2);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning2");
            }
        }

        v = findViewById(R.id.txtMeaning3);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning3");
            }
        }

        if (_vok.reverse && showBeds)
            speak(txtWord, _vok.getLangWord(), "word");

        lib.setBgEditText(_txtMeaning1, _MeaningBG);
        lib.setBgEditText(_txtMeaning2, _MeaningBG);
        lib.setBgEditText(_txtMeaning3, _MeaningBG);
        if (!_isSmallDevice && !requestFocusEdWord) {
            _txtMeaning1.requestFocus();
        } else {
            if (!requestFocusEdWord)
                _txtWord.requestFocus();
            else
                _txtedWord.requestFocus();
        }
        SetActionBarTitle();

        _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {

                lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this);
                hideKeyboard();
                if (showBeds) {
                    _scrollView.scrollTo(0, _txtMeaning1.getTop());
                } else {
                    _txtWord.requestFocus();
                    _scrollView.fullScroll(View.FOCUS_UP);
                }
            }
        });

    } catch (Exception e) {

        lib.ShowException(_main, e);
    }

}

From source file:com.ichi2.anki.AbstractFlashcardViewer.java

protected void updateScreenCounts() {
    if (mCurrentCard == null) {
        return;//w  ww. j a  v a  2  s .c o m
    }

    try {
        String[] title = getCol().getDecks().get(mCurrentCard.getDid()).getString("name").split("::");
        getSupportActionBar().setTitle(title[title.length - 1]);
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }

    int[] counts = mSched.counts(mCurrentCard);

    int eta = mSched.eta(counts, false);
    getSupportActionBar()
            .setSubtitle(getResources().getQuantityString(R.plurals.reviewer_window_title, eta, eta));

    SpannableString newCount = new SpannableString(String.valueOf(counts[0]));
    SpannableString lrnCount = new SpannableString(String.valueOf(counts[1]));
    SpannableString revCount = new SpannableString(String.valueOf(counts[2]));
    if (mPrefHideDueCount) {
        revCount = new SpannableString("???");
    }

    switch (mSched.countIdx(mCurrentCard)) {
    case Card.TYPE_NEW:
        newCount.setSpan(new UnderlineSpan(), 0, newCount.length(), 0);
        break;
    case Card.TYPE_LRN:
        lrnCount.setSpan(new UnderlineSpan(), 0, lrnCount.length(), 0);
        break;
    case Card.TYPE_REV:
        revCount.setSpan(new UnderlineSpan(), 0, revCount.length(), 0);
        break;
    }

    mTextBarNew.setText(newCount);
    mTextBarLearn.setText(lrnCount);
    mTextBarReview.setText(revCount);
}

From source file:com.android.ex.chips.RecipientEditTextView.java

private CharSequence createChip(final RecipientEntry entry, final boolean pressed) {
    final String displayText = createAddressText(entry);
    if (TextUtils.isEmpty(displayText))
        return null;
    SpannableString chipText = null;
    // Always leave a blank space at the end of a chip.
    final int textLength = displayText.length() - 1;
    chipText = new SpannableString(displayText);
    if (!mNoChips)
        try {//from   w  w w  .j a  v a 2  s  .  c  o  m
            final DrawableRecipientChip chip = constructChipSpan(entry, pressed, false /*
                                                                                        * leave space for contact
                                                                                        * icon
                                                                                        */);
            chipText.setSpan(chip, 0, textLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            chip.setOriginalText(chipText.toString());
        } catch (final NullPointerException e) {
            Log.e(TAG, e.getMessage(), e);
            return null;
        }
    return chipText;
}