Search in sources :

Example 6 with SpannableString

use of android.text.SpannableString in project MPAndroidChart by PhilJay.

the class PiePolylineChartActivity method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
    s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
    s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
    s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
    s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 7 with SpannableString

use of android.text.SpannableString in project MPAndroidChart by PhilJay.

the class RealmDatabaseActivityPie method generateCenterSpannableText.

private SpannableString generateCenterSpannableText() {
    SpannableString s = new SpannableString("Realm.io\nmobile database");
    s.setSpan(new ForegroundColorSpan(Color.rgb(240, 115, 126)), 0, 8, 0);
    s.setSpan(new RelativeSizeSpan(2.2f), 0, 8, 0);
    s.setSpan(new StyleSpan(Typeface.ITALIC), 9, s.length(), 0);
    s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 9, s.length(), 0);
    s.setSpan(new RelativeSizeSpan(0.85f), 9, s.length(), 0);
    return s;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) StyleSpan(android.text.style.StyleSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan)

Example 8 with SpannableString

use of android.text.SpannableString in project HoloEverywhere by Prototik.

the class SuggestionsAdapter method formatUrl.

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }
    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}
Also used : SpannableString(android.text.SpannableString) TextAppearanceSpan(android.text.style.TextAppearanceSpan) TypedValue(android.util.TypedValue)

Example 9 with SpannableString

use of android.text.SpannableString in project HoloEverywhere by Prototik.

the class ProgressDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.AlertDialog, R.attr.alertDialogStyle, R.style.Holo_AlertDialog);
    View view;
    if (mProgressStyle == ProgressDialog.STYLE_HORIZONTAL) {
        mViewUpdateHandler = new Handler() {

            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                int progress = mProgress.getProgress();
                int max = mProgress.getMax();
                if (mProgressNumberFormat != null) {
                    String format = mProgressNumberFormat;
                    mProgressNumber.setText(String.format(format, progress, max));
                } else {
                    mProgressNumber.setText("");
                }
                if (mProgressPercentFormat != null) {
                    double percent = (double) progress / (double) max;
                    SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
                    tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, tmp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    mProgressPercent.setText(tmp);
                } else {
                    mProgressPercent.setText("");
                }
            }
        };
        view = getLayoutInflater().inflate(a.getResourceId(R.styleable.AlertDialog_horizontalProgressLayout, R.layout.alert_dialog_progress_holo));
        mProgress = (ProgressBar) view.findViewById(R.id.progress);
        mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
        mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
    } else {
        view = getLayoutInflater().inflate(a.getResourceId(R.styleable.AlertDialog_progressLayout, R.layout.progress_dialog_holo));
        mProgress = (ProgressBar) view.findViewById(R.id.progress);
        mMessageView = (TextView) view.findViewById(R.id.message);
    }
    setView(view);
    a.recycle();
    if (mMax > 0) {
        setMax(mMax);
    }
    if (mProgressVal > 0) {
        setProgress(mProgressVal);
    }
    if (mSecondaryProgressVal > 0) {
        setSecondaryProgress(mSecondaryProgressVal);
    }
    if (mIncrementBy > 0) {
        incrementProgressBy(mIncrementBy);
    }
    if (mIncrementSecondaryBy > 0) {
        incrementSecondaryProgressBy(mIncrementSecondaryBy);
    }
    if (mProgressDrawable != null) {
        setProgressDrawable(mProgressDrawable);
    }
    if (mIndeterminateDrawable != null) {
        setIndeterminateDrawable(mIndeterminateDrawable);
    }
    if (mMessage != null) {
        setMessage(mMessage);
    }
    setIndeterminate(mIndeterminate);
    onProgressChanged();
    super.onCreate(savedInstanceState);
}
Also used : SpannableString(android.text.SpannableString) Message(android.os.Message) TypedArray(android.content.res.TypedArray) StyleSpan(android.text.style.StyleSpan) Handler(android.os.Handler) SpannableString(android.text.SpannableString) TextView(android.widget.TextView) View(android.view.View)

Example 10 with SpannableString

use of android.text.SpannableString in project Anki-Android by Ramblurr.

the class PreviewClass method displayCardAnswer.

private void displayCardAnswer() {
    // prevent answering (by e.g. gestures) before card is loaded
    if (mCurrentCard == null) {
        return;
    }
    sDisplayAnswer = true;
    String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
    answer = typeAnsAnswerFilter(answer);
    String displayString = "";
    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(answer);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        Sound.stopSounds();
        if (mPrefFixArabic) {
            // reshape
            answer = ArabicUtilities.reshapeSentence(answer, true);
        }
        // If the user wrote an answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.GONE);
            if (mCurrentCard != null) {
                if (mPrefFixArabic) {
                    // reshape
                    mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
                }
                // Obtain the user answer and the correct answer
                String userAnswer = mAnswerField.getText().toString();
                Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
                String correctAnswer = matcher.replaceAll("");
                matcher = sBrPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("\n");
                matcher = Sound.sSoundPattern.matcher(correctAnswer);
                correctAnswer = matcher.replaceAll("");
                // Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);
                // Obtain the diff and send it to updateCard
                DiffEngine diff = new DiffEngine();
                StringBuffer span = new StringBuffer();
                span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ").append(12).append("px\">");
                span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
                span.append("</span>");
                span.append("<br/>").append(answer);
                displayString = enrichWithQADiv(span.toString(), true);
            }
            // Hide soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
        } else {
            displayString = enrichWithQADiv(answer, true);
        }
    }
    updateCard(displayString);
}
Also used : SpannableString(android.text.SpannableString) DiffEngine(com.ichi2.utils.DiffEngine) Matcher(java.util.regex.Matcher) StyleSpan(android.text.style.StyleSpan) InputMethodManager(android.view.inputmethod.InputMethodManager) SpannedString(android.text.SpannedString) SpannableString(android.text.SpannableString)

Aggregations

SpannableString (android.text.SpannableString)319 Spannable (android.text.Spannable)60 TextView (android.widget.TextView)60 View (android.view.View)56 StyleSpan (android.text.style.StyleSpan)53 ForegroundColorSpan (android.text.style.ForegroundColorSpan)45 TextPaint (android.text.TextPaint)25 Spanned (android.text.Spanned)22 TextAppearanceSpan (android.text.style.TextAppearanceSpan)21 Paint (android.graphics.Paint)20 ImageView (android.widget.ImageView)19 RelativeSizeSpan (android.text.style.RelativeSizeSpan)18 Bundle (android.os.Bundle)17 TypedValue (android.util.TypedValue)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)16 Intent (android.content.Intent)15 SpannableStringBuilder (android.text.SpannableStringBuilder)15 ClickableSpan (android.text.style.ClickableSpan)13 URLSpan (android.text.style.URLSpan)13 LayoutInflater (android.view.LayoutInflater)13