Search in sources :

Example 41 with ImageSpan

use of android.text.style.ImageSpan in project android_frameworks_base by crdroidandroid.

the class HtmlToSpannedConverter method startImg.

private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img) {
    String src = attributes.getValue("", "src");
    Drawable d = null;
    if (img != null) {
        d = img.getDrawable(src);
    }
    if (d == null) {
        d = Resources.getSystem().getDrawable(com.android.internal.R.drawable.unknown_image);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    }
    int len = text.length();
    text.append("");
    text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : Drawable(android.graphics.drawable.Drawable) ImageSpan(android.text.style.ImageSpan)

Example 42 with ImageSpan

use of android.text.style.ImageSpan in project JustAndroid by chinaltz.

the class PraiseListView method setImageSpan.

private SpannableString setImageSpan() {
    String text = "  ";
    SpannableString imgSpanText = new SpannableString(text);
    imgSpanText.setSpan(new ImageSpan(MyApplication.getContext(), R.drawable.icon_praise, DynamicDrawableSpan.ALIGN_BASELINE), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return imgSpanText;
}
Also used : SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) ImageSpan(android.text.style.ImageSpan)

Example 43 with ImageSpan

use of android.text.style.ImageSpan in project android_frameworks_base by crdroidandroid.

the class SmileyParser method getSpannableString.

/**
     * Retrieves the parsed text as a spannable string object.
     * @param context the context for fetching smiley resources.
     * @return the spannable string as CharSequence.
     */
public CharSequence getSpannableString(Context context) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    if (getPartCount() == 0) {
        return "";
    }
    // should have only one part since we parse smiley only
    Part part = getPart(0);
    ArrayList<Token> tokens = part.getTokens();
    int len = tokens.size();
    for (int i = 0; i < len; i++) {
        Token token = tokens.get(i);
        int start = builder.length();
        builder.append(token.getRawText());
        if (token.getType() == AbstractMessageParser.Token.Type.SMILEY) {
            int resid = mRes.getSmileyRes(token.getRawText());
            if (resid != -1) {
                builder.setSpan(new ImageSpan(context, resid), start, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
    return builder;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 44 with ImageSpan

use of android.text.style.ImageSpan in project android_frameworks_base by crdroidandroid.

the class RestrictedLockUtils method setTextViewPadlock.

public static void setTextViewPadlock(Context context, TextView textView, boolean showPadlock) {
    final SpannableStringBuilder sb = new SpannableStringBuilder(textView.getText());
    removeExistingRestrictedSpans(sb);
    if (showPadlock) {
        final ImageSpan image = new RestrictedLockImageSpan(context);
        sb.append(" ", image, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    textView.setText(sb);
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 45 with ImageSpan

use of android.text.style.ImageSpan in project android_frameworks_base by crdroidandroid.

the class ViewPropertyAlphaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_properties);
    getWindow().getDecorView().postDelayed(new Runnable() {

        @Override
        public void run() {
            startAnim(R.id.button);
            startAnim(R.id.textview);
            startAnim(R.id.spantext);
            startAnim(R.id.edittext);
            startAnim(R.id.selectedtext);
            startAnim(R.id.textviewbackground);
            startAnim(R.id.layout);
            startAnim(R.id.imageview);
            startAnim(myViewAlphaDefault);
            startAnim(myViewAlphaHandled);
            EditText selectedText = (EditText) findViewById(R.id.selectedtext);
            selectedText.setSelection(3, 8);
        }
    }, 2000);
    Button invalidator = (Button) findViewById(R.id.invalidateButton);
    invalidator.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            findViewById(R.id.textview).invalidate();
            findViewById(R.id.spantext).invalidate();
        }
    });
    TextView textView = (TextView) findViewById(R.id.spantext);
    if (textView != null) {
        SpannableStringBuilder text = new SpannableStringBuilder("Now this is a short text message with spans");
        text.setSpan(new BackgroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ForegroundColorSpan(Color.BLUE), 4, 9, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new SuggestionSpan(this, new String[] { "longer" }, 3), 11, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new UnderlineSpan(), 17, 20, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        text.setSpan(new ImageSpan(this, R.drawable.icon), 21, 22, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(text);
    }
    LinearLayout container = (LinearLayout) findViewById(R.id.container);
    myViewAlphaDefault = new MyView(this, false);
    myViewAlphaDefault.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaDefault);
    myViewAlphaHandled = new MyView(this, true);
    myViewAlphaHandled.setLayoutParams(new LinearLayout.LayoutParams(75, 75));
    container.addView(myViewAlphaHandled);
}
Also used : EditText(android.widget.EditText) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TextView(android.widget.TextView) View(android.view.View) UnderlineSpan(android.text.style.UnderlineSpan) Button(android.widget.Button) TextView(android.widget.TextView) SuggestionSpan(android.text.style.SuggestionSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan) LinearLayout(android.widget.LinearLayout) ImageSpan(android.text.style.ImageSpan)

Aggregations

ImageSpan (android.text.style.ImageSpan)98 SpannableStringBuilder (android.text.SpannableStringBuilder)53 Drawable (android.graphics.drawable.Drawable)29 ForegroundColorSpan (android.text.style.ForegroundColorSpan)23 BackgroundColorSpan (android.text.style.BackgroundColorSpan)14 TextView (android.widget.TextView)14 SpannableString (android.text.SpannableString)12 View (android.view.View)11 UnderlineSpan (android.text.style.UnderlineSpan)10 RelativeSizeSpan (android.text.style.RelativeSizeSpan)7 StyleSpan (android.text.style.StyleSpan)7 Bitmap (android.graphics.Bitmap)6 LinearLayout (android.widget.LinearLayout)6 Application (android.app.Application)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 CharacterStyle (android.text.style.CharacterStyle)5 SuggestionSpan (android.text.style.SuggestionSpan)5 URLSpan (android.text.style.URLSpan)5 MenuItem (android.view.MenuItem)5 Button (android.widget.Button)5