Skip to content

Instantly share code, notes, and snippets.

@NightWhistler
Created May 1, 2013 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NightWhistler/5494758 to your computer and use it in GitHub Desktop.
Save NightWhistler/5494758 to your computer and use it in GitHub Desktop.
private Context context;
private TextExpansionListener listener;
public ExpandHandler(Context context, TextExpansionListener listener){
this.context = context;
this.listener = listener;
}
public void handleTagNode(TagNode node, final SpannableStringBuilder builder,
final int start, final int end) {
final CharSequence text = builder.subSequence(start, end);
builder.delete(start, end);
builder.insert(start, " ");
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream(context.getAssets().open("ic_launcher.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
drawable.setBounds(0, 0, bitmap.getWidth() - 1,
bitmap.getHeight() - 1);
builder.setSpan(new ImageSpan(drawable), start, start+1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ClickableSpan click_span = new ClickableSpan() {
@Override
public void onClick(View arg0) {
Toast.makeText(context, "Image clicked", Toast.LENGTH_SHORT).show();
this.expansionListener.expandText( text, start, end );
}
};
builder.setSpan(click_span, start, start+1,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment