Java Code Examples for android.text.Html.ImageGetter

The following are top voted examples for showing how to use android.text.Html.ImageGetter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: android-customfonthtml   File: CustomHtml.java   Source Code and License 6 votes vote down vote up
private static void startImg(SpannableStringBuilder text,
		Attributes attributes, Html.ImageGetter img) {
	String src = attributes.getValue("", "src");
	Drawable d = null;

	if (img != null) {
		d = img.getDrawable(src);
	}

	if (d == null) {
		// com.android.internal.R.drawable.unknown_image
		d = Resources.getSystem().getDrawable(
				android.R.drawable.ic_menu_help);
		d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
	}

	int len = text.length();
	text.append("\uFFFC");

	text.setSpan(new ImageSpan(d, src), len, text.length(),
			Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example 2
Project: ChipHellClient   File: PostItemView.java   Source Code and License 6 votes vote down vote up
public void bindValue(Post post) {
    ImageLoader.getInstance().displayImage(post.getAvatarUrl(), imageViewAvatar, Constants.avatarDisplayOption, animateFirstListener);
    textViewAuthi.setText(Html.fromHtml(post.getAuthi()));
    String content = post.getContent();
    if (post.getImgList() != null) {
        content += post.getImgList();
    }
    textViewContent.setText(Html.fromHtml(content, new ImageGetter() {

        @Override
        public Drawable getDrawable(String source) {
            if (!source.startsWith("http:")) {
                source = Constants.BASE_URL + source;
            }
            LogMessage.i("PostItemView", source);
            return new UrlDrawable(source, textViewContent);
        }
    }, null));
}
 
Example 3
Project: silent-contacts-android   File: ContactDetailDisplayUtils.java   Source Code and License 6 votes vote down vote up
@VisibleForTesting
static View addStreamItemText(Context context, StreamItemEntry streamItem, View rootView) {
    TextView htmlView = (TextView) rootView.findViewById(R.id.stream_item_html);
    TextView attributionView = (TextView) rootView.findViewById(R.id.stream_item_attribution);
    TextView commentsView = (TextView) rootView.findViewById(R.id.stream_item_comments);
    ImageGetter imageGetter = new DefaultImageGetter(context.getPackageManager());

    // Stream item text
    setDataOrHideIfNone(streamItem.getDecodedText(), htmlView);
    // Attribution
    setDataOrHideIfNone(ContactBadgeUtil.getSocialDate(streamItem, context),
            attributionView);
    // Comments
    setDataOrHideIfNone(streamItem.getDecodedComments(), commentsView);
    return rootView;
}
 
Example 4
Project: EntboostIM   File: UIUtils.java   Source Code and License 5 votes vote down vote up
/**
 * 展示html代码(包含图片)
 * 
 * @param res 系统资源对象
 * @param html 消息内容
 * @param smallEmotion 表情图标是否以小尺寸显示
 * @return
 */
public static CharSequence getTipCharSequence(final Resources res, final String html, final boolean smallEmotion) {
	if (StringUtils.isBlank(html)) {
		return "";
	}
	
	String newHtml = html.replaceAll("\r\n", "<br/>");
	newHtml = newHtml.replaceAll("\n", "<br/>");
	newHtml = newHtml.replaceAll("\r", "<br/>");
	CharSequence charSequence = Html.fromHtml(newHtml, new ImageGetter() {
		@Override
		public Drawable getDrawable(String source) {
			BitmapDrawable drawable = new BitmapDrawable(res, YIResourceUtils.getResourceBitmap(
					Long.valueOf(source), EB_RESOURCE_TYPE.EB_RESOURCE_EMOTION.ordinal()));
			
			int right = 60, bottom = 60;
			if (smallEmotion)
				right = bottom =40;
			
			drawable.setBounds(0, 0, right, bottom);// 设置表情图片的显示大小
			return drawable;
		}
	}, null);
	return charSequence;
}
 
Example 5
Project: youkes_vr   File: EmoticonUtil.java   Source Code and License 5 votes vote down vote up
/**
 * @param c
 * @return
 */
public static ImageGetter getImageGetter(final Context c) {
	return new ImageGetter() {

		public Drawable getDrawable(String source) {
			System.out.println("source ="+source);
			Integer resID=c.getResources().getIdentifier(source,"drawable", c.getPackageName());
			Drawable d = c.getResources().getDrawable(resID);
			d.setBounds(0, 0, 24, 24);
			return d;
		}
	};
}
 
Example 6
Project: android-customfonthtml   File: CustomHtml.java   Source Code and License 5 votes vote down vote up
public HtmlToSpannedConverter(String source,
		ICustomFontLoader fontLoader, Html.ImageGetter imageGetter,
		Html.TagHandler tagHandler, Parser parser) {
	mSource = source;
	mSpannableStringBuilder = new SpannableStringBuilder();
	mFontLoader = fontLoader;
	mImageGetter = imageGetter;
	mTagHandler = tagHandler;
	mReader = parser;
}
 
Example 7
Project: github-v2   File: MarkdownLoader.java   Source Code and License 5 votes vote down vote up
/**
 * @param context
 * @param repository
 * @param raw
 * @param imageGetter
 * @param encode
 */
public MarkdownLoader(Context context, IRepositoryIdProvider repository,
        String raw, ImageGetter imageGetter, boolean encode) {
    super(context);

    this.repository = repository;
    this.raw = raw;
    this.imageGetter = imageGetter;
    this.encode = encode;
}
 
Example 8
Project: github-v2   File: HtmlUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Encode HTML
 *
 * @param html
 * @param imageGetter
 * @return html
 */
public static CharSequence encode(final String html,
        final ImageGetter imageGetter) {
    if (TextUtils.isEmpty(html))
        return "";

    return android.text.Html.fromHtml(html, imageGetter, TAG_HANDLER);
}
 
Example 9
Project: silent-contacts-android   File: HtmlUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Converts HTML string to a {@link Spanned} text, adjusting formatting and using a custom
 * image getter. Any extra new line characters at the end of the text will be trimmed.
 */
public static CharSequence fromHtml(Context context, String text, ImageGetter imageGetter,
        TagHandler tagHandler) {
    if (TextUtils.isEmpty(text)) {
        return null;
    }
    return postprocess(context, Html.fromHtml(text, imageGetter, tagHandler));
}
 
Example 10
Project: acfun-new   File: TextViewUtils.java   Source Code and License 5 votes vote down vote up
public static void setCommentContent(final TextView comment, Comment c) {
    String text = c.content;
    text = replace(text);
    comment.setText(Html.fromHtml(text,new ImageGetter() {
        
        @Override
        public Drawable getDrawable(String source) {
            try {
                Drawable drawable = Drawable.createFromStream(comment.getContext().getAssets().open(source),source);
                if(drawable!=null)
                    drawable.setBounds(0, 0, drawable.getIntrinsicWidth()*(int)AcApp.density, drawable.getIntrinsicHeight()*(int)AcApp.density);
                return drawable;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
            
        }
    },new Html.TagHandler() {
        
        @Override
        public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
            int len = output.length();
            if(opening){
                if(tag.equalsIgnoreCase("strike")){
                    output.setSpan(new StrikethroughSpan(), len, len, Spannable.SPAN_MARK_MARK);
                }
            }else{
                if(tag.equalsIgnoreCase("strike")){
                    end((SpannableStringBuilder) output,StrikethroughSpan.class,new StrikethroughSpan());
                }
            }
        }
    }));
    comment.setTextColor(Color.BLACK);
    Pattern http = Pattern.compile("http://[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])?",
            Pattern.CASE_INSENSITIVE);
    Linkify.addLinks(comment, http, "http://");
    Linkify.addLinks(comment, Pattern.compile("(ac\\d{5,})", Pattern.CASE_INSENSITIVE), "av://");
}
 
Example 11
Project: emojimenu   File: EmojiParser.java   Source Code and License 5 votes vote down vote up
private Spanned insertEmoji(final String name) {
  ImageGetter imageGetter = new ImageGetter() {
    public Drawable getDrawable(String source) {
      Bitmap bitmap = emojiStore.getBitmap(name);
      Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 30, 30, true);
      Drawable d = new BitmapDrawable(
          emojiStore.getActivity().getResources(), scaledBitmap);
      d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
      return d;
    }
  };

  Spanned cs = Html.fromHtml("<img src ='" + name + "'/>", imageGetter, null);
  return cs;
}
 
Example 12
Project: detlef   File: EpisodeListAdapter.java   Source Code and License 5 votes vote down vote up
public FromHtmlCache() {
    dummyImageGetter = new ImageGetter() {

        @Override
        public Drawable getDrawable(String source) {
            return NOTHING;
        }
    };
}
 
Example 13
Project: WeCenterMobile-Android   File: TextShow.java   Source Code and License 4 votes vote down vote up
@Override
protected Spanned doInBackground(String... arg0) {
	// TODO Auto-generated method stub
	final Spanned spanned;

	ImageGetter imgGetter = new Html.ImageGetter() {
		@SuppressWarnings("deprecation")
		@Override
		public Drawable getDrawable(String source) {
			Drawable d = null;
			Bitmap bm = null;
			urlSpans.add(source);
			String url = source.replaceAll("[^\\w]", "");
			String imageurl = Environment
					.getExternalStorageDirectory()
					+ "/fanfantopic/" + url;
			
			try {
				if (!fileUtils.isFileExists(url)
						|| fileUtils.getFileSize(url) == 0) {
					InputStream is = null;
					HttpResponse httpResponse = new DefaultHttpClient()
							.execute(new HttpGet(source));
					if (httpResponse.getStatusLine().getStatusCode() == 200) {
						is = httpResponse.getEntity()
						.getContent();
					} else {
                          System.out.println("���粻��");
					}
							
					bm = BitmapFactory.decodeStream(is);
					fileUtils.saveBitmap(source.replaceAll("[^\\w]", ""),
							bm);
					is.close();
				} else {
					//ImageGet imageGet = new ImageGet();
					bm = BitmapFactory.decodeFile(imageurl);
					//bm = imageGet.getBitmap();
				}
				
				d = new BitmapDrawable(bm);
				if (bm.getWidth() >= screenW-100) {
					float so = ((float)(bm.getHeight())/bm.getWidth());
					float h =  (screenW-100)*so;
					d.setBounds(0, 0,(int)(screenW-100),(int)h);
				} else {
					start =  (int) (screenW - bm.getWidth())/2;
					d.setBounds(start, 0,bm.getWidth()+start,bm.getHeight());
				}
				

			} catch (Exception e) {
				e.printStackTrace();
			}
			return d;
		}
	};
	spanned = Html.fromHtml(text, imgGetter, new ImgTaghand());
	return spanned;
}
 
Example 14
Project: silent-contacts-android   File: ContactDetailDisplayUtils.java   Source Code and License 4 votes vote down vote up
public static Html.ImageGetter getImageGetter(Context context) {
    if (sImageGetter == null) {
        sImageGetter = new DefaultImageGetter(context.getPackageManager());
    }
    return sImageGetter;
}