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;
}
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;
}
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);
}
}
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());
}
}
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;
}
Aggregations