Search in sources :

Example 51 with ImageSpan

use of android.text.style.ImageSpan in project SmartAndroidSource by jaychou2012.

the class SearchView method getDecoratedHint.

private CharSequence getDecoratedHint(CharSequence hintText) {
    // the hint
    if (!mIconifiedByDefault)
        return hintText;
    // for
    SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
    // the
    // icon
    ssb.append(hintText);
    Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId());
    int textSize = (int) (mQueryTextView.getTextSize() * 1.25);
    searchIcon.setBounds(0, 0, textSize, textSize);
    ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return ssb;
}
Also used : Drawable(android.graphics.drawable.Drawable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 52 with ImageSpan

use of android.text.style.ImageSpan in project Klyph by jonathangerbaud.

the class EmojiUtil method getSpannableForText.

public static Spannable getSpannableForText(Context context, String text, boolean addLinks) {
    SpannableStringBuilder ssb = new SpannableStringBuilder(text);
    Linkify.addLinks(ssb, Linkify.WEB_URLS);
    for (String key : EMOJIS.keySet()) {
        int index = text.indexOf(key);
        while (index != -1) {
            if (ssb.getSpans(index, index + 1, Object.class).length == 0)
                /* && ssb.getSpans(index, index + 1, URLSpan.class).length == 0*/
                ssb.setSpan(new ImageSpan(context, EMOJIS.get(key)), index, index + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            index = text.indexOf(key, index + key.length());
        }
    }
    if (!addLinks) {
        URLSpan[] spans = ssb.getSpans(0, text.length() - 1, URLSpan.class);
        for (URLSpan urlSpan : spans) {
            ssb.removeSpan(urlSpan);
        }
    }
    return ssb;
}
Also used : URLSpan(android.text.style.URLSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 53 with ImageSpan

use of android.text.style.ImageSpan in project android-gif-drawable by koral--.

the class GifSourcesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final GifSourceItemHolder holder, int position) {
    final String[] descriptions = holder.itemView.getResources().getStringArray(R.array.sources);
    position %= descriptions.length;
    final GifDrawable existingOriginalDrawable = (GifDrawable) holder.gifImageViewOriginal.getDrawable();
    final GifDrawable existingSampledDrawable = (GifDrawable) holder.gifImageViewSampled.getDrawable();
    final GifDrawableBuilder builder = new GifDrawableBuilder().with(existingOriginalDrawable);
    try {
        mGifSourcesResolver.bindSource(position, builder);
        final GifDrawable fullSizeDrawable = builder.build();
        holder.gifImageViewOriginal.setImageDrawable(fullSizeDrawable);
        holder.gifImageViewOriginal.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (fullSizeDrawable.isPlaying())
                    fullSizeDrawable.stop();
                else
                    fullSizeDrawable.start();
            }
        });
        builder.with(existingSampledDrawable).sampleSize(3);
        mGifSourcesResolver.bindSource(position, builder);
        final GifDrawable subsampledDrawable = builder.build();
        final SpannableStringBuilder stringBuilder = new SpannableStringBuilder(descriptions[position] + '');
        stringBuilder.setSpan(new ImageSpan(subsampledDrawable), stringBuilder.length() - 1, stringBuilder.length(), 0);
        holder.descriptionTextView.setText(stringBuilder);
        holder.gifImageViewSampled.setImageDrawable(subsampledDrawable);
        subsampledDrawable.setCallback(holder.multiCallback);
        holder.multiCallback.addView(holder.gifImageViewSampled);
        holder.multiCallback.addView(holder.descriptionTextView);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : GifDrawableBuilder(pl.droidsonroids.gif.GifDrawableBuilder) GifDrawable(pl.droidsonroids.gif.GifDrawable) IOException(java.io.IOException) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 54 with ImageSpan

use of android.text.style.ImageSpan in project chipsedittext by kpbird.

the class ChipsMultiAutoCompleteTextview method setChips.

/*This function has whole logic for chips generate*/
public void setChips() {
    if (// check comman in string
    getText().toString().contains(",")) {
        SpannableStringBuilder ssb = new SpannableStringBuilder(getText());
        // split string wich comma
        String[] chips = getText().toString().trim().split(",");
        int x = 0;
        // loop will generate ImageSpan for every country name separated by comma
        for (String c : chips) {
            // inflate chips_edittext layout 
            LayoutInflater lf = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            TextView textView = (TextView) lf.inflate(R.layout.chips_edittext, null);
            // set text
            textView.setText(c);
            // set flag image
            setFlags(textView, c);
            // capture bitmapt of genreated textview
            int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
            textView.measure(spec, spec);
            textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
            Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(b);
            canvas.translate(-textView.getScrollX(), -textView.getScrollY());
            textView.draw(canvas);
            textView.setDrawingCacheEnabled(true);
            Bitmap cacheBmp = textView.getDrawingCache();
            Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
            // destory drawable
            textView.destroyDrawingCache();
            // create bitmap drawable for imagespan
            BitmapDrawable bmpDrawable = new BitmapDrawable(viewBmp);
            bmpDrawable.setBounds(0, 0, bmpDrawable.getIntrinsicWidth(), bmpDrawable.getIntrinsicHeight());
            // create and set imagespan 
            ssb.setSpan(new ImageSpan(bmpDrawable), x, x + c.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            x = x + c.length() + 1;
        }
        // set chips span 
        setText(ssb);
        // move cursor to last 
        setSelection(getText().length());
    }
}
Also used : Bitmap(android.graphics.Bitmap) LayoutInflater(android.view.LayoutInflater) Canvas(android.graphics.Canvas) MultiAutoCompleteTextView(android.widget.MultiAutoCompleteTextView) TextView(android.widget.TextView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 55 with ImageSpan

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

the class EmojiUtils method addSmiles.

public static boolean addSmiles(Context context, Spannable spannable) {
    boolean hasChanges = false;
    for (Map.Entry<Pattern, Integer> entry : emoticons.entrySet()) {
        Matcher matcher = entry.getKey().matcher(spannable);
        while (matcher.find()) {
            boolean set = true;
            for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end())
                spannable.removeSpan(span);
            else {
                set = false;
                break;
            }
            if (set) {
                hasChanges = true;
                int scale = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, textSize + 2, context.getResources().getDisplayMetrics());
                try {
                    Bitmap bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(res, entry.getValue()), scale, scale, true);
                    spannable.setSpan(new ImageSpan(context, bitmap, ImageSpan.ALIGN_BOTTOM), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                } catch (OutOfMemoryError e) {
                    return false;
                }
            }
        }
    }
    return hasChanges;
}
Also used : Pattern(java.util.regex.Pattern) Bitmap(android.graphics.Bitmap) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Map(java.util.Map) ImageSpan(android.text.style.ImageSpan)

Aggregations

ImageSpan (android.text.style.ImageSpan)96 SpannableStringBuilder (android.text.SpannableStringBuilder)52 Drawable (android.graphics.drawable.Drawable)28 ForegroundColorSpan (android.text.style.ForegroundColorSpan)23 BackgroundColorSpan (android.text.style.BackgroundColorSpan)14 TextView (android.widget.TextView)13 SpannableString (android.text.SpannableString)12 UnderlineSpan (android.text.style.UnderlineSpan)10 View (android.view.View)10 RelativeSizeSpan (android.text.style.RelativeSizeSpan)7 StyleSpan (android.text.style.StyleSpan)7 Bitmap (android.graphics.Bitmap)6 Button (android.widget.Button)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