Android ImageSpan - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ImageSpan class.

This code example shows how to use the following methods:
        // Then pass a SpannedString, which is immutable, but the method should still work. 
        checkPostProcess(HtmlUtils.postprocess(getContext(), new SpannedString(builder)));
    } 
 
    private void setSpans(SpannableStringBuilder builder) {
        builder.setSpan(new ImageSpan(new ColorDrawable(), ImageSpan.ALIGN_BOTTOM), 0, 2, 0);
        builder.setSpan(new QuoteSpan(), 2, 4, 0);
        builder.setSpan(new CustomSpan(), 4, builder.length(), 0);
    } 
 
    private void checkPostProcess(Spanned ret) {
        // Newlines should be trimmed. 
        assertEquals("01234", ret.toString());
 
        // First, check the image span. 
        // - Vertical alignment should be changed to ALIGN_BASELINE 
        // - Drawable shouldn't be changed. 
        ImageSpan[] imageSpans = ret.getSpans(0, ret.length(), ImageSpan.class);
        assertEquals(1, imageSpans.length);
        assertEquals(ImageSpan.ALIGN_BASELINE, imageSpans[0].getVerticalAlignment());
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		} 
 
		int len = mSB.length();
		mSB.append("\uFFFC");
 
		mSB.setSpan(new ImageSpan(d, src), len, mSB.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	} 
 
	private void endFont(TagMarker tm) {
		int end = mSB.length();
		int start = tm.getStart();
		if (start != end) {
			String color = tm.getAttributes().getValue("", "color");
			String face = tm.getAttributes().getValue("", "face");
			String size = tm.getAttributes().getValue("", "size");
			if (!TextUtils.isEmpty(color)) {
				int c = Util.getHtmlColor(color);
				if (c != -1) {
					mSB.setSpan(new ForegroundColorSpan(c | 0xFF000000), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        // Then pass a SpannedString, which is immutable, but the method should still work. 
        checkPostProcess(HtmlUtils.postprocess(getContext(), new SpannedString(builder)));
    } 
 
    private void setSpans(SpannableStringBuilder builder) {
        builder.setSpan(new ImageSpan(new ColorDrawable(), ImageSpan.ALIGN_BOTTOM), 0, 2, 0);
        builder.setSpan(new QuoteSpan(), 2, 4, 0);
        builder.setSpan(new CustomSpan(), 4, builder.length(), 0);
    } 
 
    private void checkPostProcess(Spanned ret) {
        // Newlines should be trimmed. 
        assertEquals("01234", ret.toString());
 
        // First, check the image span. 
        // - Vertical alignment should be changed to ALIGN_BASELINE 
        // - Drawable shouldn't be changed. 
        ImageSpan[] imageSpans = ret.getSpans(0, ret.length(), ImageSpan.class);
        assertEquals(1, imageSpans.length);
        assertEquals(ImageSpan.ALIGN_BASELINE, imageSpans[0].getVerticalAlignment());
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
		if (bitmap != null) {
			Drawable drawable = new BitmapDrawable(bitmap);
			drawable.setBounds(0, 0, bitmap.getWidth() - 1,
					bitmap.getHeight() - 1);
			builder.setSpan(new ImageSpan(drawable), start, end,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		} 
	} 
 
	/** 
	 * Loads a Bitmap from the given url. 
	 *  
	 * @param url 
	 * @return a Bitmap, or null if it could not be loaded. 
	 */ 
	protected Bitmap loadBitmap(String url) {
		try { 
			return BitmapFactory.decodeStream(new URL(url).openStream());
		} catch (IOException io) {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		drawable.setBounds(0, 0, 35, 35);
		// ÐèÒª´¦ÀíµÄÎı¾£¬[smile]ÊÇÐèÒª±»Ìæ´úµÄÎı¾ 
		SpannableString spannable = new SpannableString(et.getText().toString()
				+ "[smile]"); 
		// ÒªÈÃͼƬÌæ´úÖ¸¶¨µÄÎÄ×Ö¾ÍÒªÓÃImageSpan 
		ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
		// ¿ªÊ¼Ìæ»»£¬×¢ÒâµÚ2ºÍµÚ3¸ö²ÎÊý±íʾ´ÓÄÄÀ↑ʼÌæ»»µ½ÄÄÀïÌæ»»½áÊø£¨startºÍend£© 
		// ×îºóÒ»¸ö²ÎÊýÀàËÆÊýѧÖеļ¯ºÏ,[5,12)±íʾ´Ó5µ½12£¬°üÀ¨5µ«²»°üÀ¨12 
		spannable.setSpan(span, et.getText().length(), et.getText().length()
				+ "[smile]".length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		et.setText(spannable);
	} 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
//			editable.insert(imgLocation, ss); 
//		} 
		 
		Drawable d = this.getResources().getDrawable(imgId);
		d.setBounds(0, 0, 80, 80);
		ImageSpan imageSpan = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
		SpannableString ss = new SpannableString("image");
		ss.setSpan(imageSpan, 0, 5, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		this.append(ss);
	} 
	 
	public void setImageIntoEditText(Bitmap bitmap) {
		Drawable d = new BitmapDrawable(bitmap);
		d.setBounds(0, 0, 80, 80);
		SpannableString ss = new SpannableString("bitmap");
		ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
		ss.setSpan(span, 0, 6, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		this.append(ss);
	} 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 public void insertIcon(int id) {
  SpannableString ss = new SpannableString(getText().toString()
    + "[smile]");//new一个SpannableString里面包含EditText已有内容,另外添加一个字符串[smile]用于在后面替换一个图片 
  Drawable d = getResources().getDrawable(id);
  d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);//将图片实例化为一个ImageSpan型
  ss.setSpan(span, getText().length(),
    getText().length() + "[smile]".length(),
    Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//将ImageSpan代替之前添加的[smile]字符串
  setText(ss);
 } 
} 
 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
This code example shows how to use the following methods:
    } 
	public void insertIcon(int id){
		SpannableString ss = new SpannableString(getText().toString()+"[smile]");  
        Drawable d = getResources().getDrawable(id);
        d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());  
        ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);  
        ss.setSpan(span, getText().length(), getText().length() + "[smile]".length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);  
        setText(ss);
	} 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
	public void insertIcon(int id, final Context context) {
		SpannableString ss = new SpannableString(getText().toString()+"[cat]");
		Drawable d = getResources().getDrawable(id);
		d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
		ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
		ss.setSpan(span, getText().length(),getText().length()+"[cat]".length(),
				Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		setText(ss);
 
		//ss.setSpan(new StyleSpan(Typeface.ITALIC), 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
		ClickableSpan clickableSpan = new ClickableSpan() {
			@Override 
			public void onClick(View textView) {
				Log.e("happy","congratulations!");
				Toast.makeText(context, "发送成功", Toast.LENGTH_SHORT).show();
			} 
		}; 
		ss.setSpan(clickableSpan, "HelloWorld".length(), ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		setText(ss);
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android ImageSpan Questions & Answers:

See Code Examples for Android ImageSpan Methods: