Created
May 1, 2013 11:08
-
-
Save NightWhistler/5494758 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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