Search in sources :

Example 21 with Spanned

use of android.text.Spanned in project Talon-for-Twitter by klinker24.

the class SettingsLinkDrawerClickListener method onItemClick.

@Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
    Intent intent;
    final int mPos = position;
    if (mPos < 2) {
        // one of the settings pages
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                mDrawerLayout.closeDrawer(Gravity.START);
            }
        }, 300);
        viewPager.setCurrentItem(mPos + 7, true);
    } else if (mPos == 2) {
        // changelog
        final ListView list = new ListView(context);
        list.setDividerHeight(0);
        new AsyncTask<Spanned[], Void, Spanned[]>() {

            @Override
            public Spanned[] doInBackground(Spanned[]... params) {
                return XmlChangelogUtils.parse(context);
            }

            @Override
            public void onPostExecute(Spanned[] result) {
                list.setAdapter(new ChangelogAdapter(context, result));
            }
        }.execute();
        new AlertDialog.Builder(context).setTitle(R.string.changelog).setView(list).setPositiveButton(R.string.ok, null).show();
    } else if (mPos == 3) {
        // rate it option
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
                Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                try {
                    context.startActivity(goToMarket);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(context, "Couldn't launch the market", Toast.LENGTH_SHORT).show();
                }
            }
        }, 200);
    }
}
Also used : AlertDialog(android.app.AlertDialog) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) Intent(android.content.Intent) Spanned(android.text.Spanned) Uri(android.net.Uri) ListView(android.widget.ListView) ActivityNotFoundException(android.content.ActivityNotFoundException) ChangelogAdapter(com.klinker.android.twitter.adapters.ChangelogAdapter)

Example 22 with Spanned

use of android.text.Spanned in project scdl by passy.

the class BuyAdFreeTeaserFragment method onActivityCreated.

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Spanned html = Html.fromHtml(getActivity().getString(R.string.buy_ad_free_teaser_text));
    mTeaserText.setText(html);
    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            requestPurchase();
        }
    });
}
Also used : OnClickListener(android.view.View.OnClickListener) Spanned(android.text.Spanned) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) View(android.view.View)

Example 23 with Spanned

use of android.text.Spanned in project material-calendarview by prolificinteractive.

the class DayView method setDayFormatter.

/**
     * Set the new label formatter and reformat the current label. This preserves current spans.
     *
     * @param formatter new label formatter
     */
public void setDayFormatter(DayFormatter formatter) {
    this.formatter = formatter == null ? DayFormatter.DEFAULT : formatter;
    CharSequence currentLabel = getText();
    Object[] spans = null;
    if (currentLabel instanceof Spanned) {
        spans = ((Spanned) currentLabel).getSpans(0, currentLabel.length(), Object.class);
    }
    SpannableString newLabel = new SpannableString(getLabel());
    if (spans != null) {
        for (Object span : spans) {
            newLabel.setSpan(span, 0, newLabel.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    setText(newLabel);
}
Also used : SpannableString(android.text.SpannableString) Spanned(android.text.Spanned)

Example 24 with Spanned

use of android.text.Spanned in project platform_frameworks_base by android.

the class IconMarginSpan method drawLeadingMargin.

public void drawLeadingMargin(Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout layout) {
    int st = ((Spanned) text).getSpanStart(this);
    int itop = layout.getLineTop(layout.getLineForOffset(st));
    if (dir < 0)
        x -= mBitmap.getWidth();
    c.drawBitmap(mBitmap, x, itop, p);
}
Also used : Spanned(android.text.Spanned) Paint(android.graphics.Paint)

Example 25 with Spanned

use of android.text.Spanned 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)

Aggregations

Spanned (android.text.Spanned)200 Paint (android.graphics.Paint)81 TextPaint (android.text.TextPaint)63 Spannable (android.text.Spannable)32 SpannableStringBuilder (android.text.SpannableStringBuilder)26 SuggestionSpan (android.text.style.SuggestionSpan)24 SpannableString (android.text.SpannableString)23 Editable (android.text.Editable)22 TextAppearanceSpan (android.text.style.TextAppearanceSpan)15 SpannedString (android.text.SpannedString)14 TypedArray (android.content.res.TypedArray)12 URLSpan (android.text.style.URLSpan)12 View (android.view.View)11 Context (android.content.Context)9 StyleSpan (android.text.style.StyleSpan)9 InputMethodManager (android.view.inputmethod.InputMethodManager)9 Parcelable (android.os.Parcelable)8 TextView (android.widget.TextView)8 WordIterator (android.text.method.WordIterator)7 CharacterStyle (android.text.style.CharacterStyle)7