Java 类android.text.Html.ImageGetter 实例源码

项目:EntboostIM    文件:UIUtils.java   
/**
 * 展示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;
}
项目:android-customfonthtml    文件:CustomHtml.java   
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);
}
项目:ChipHellClient    文件:PostItemView.java   
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));
}
项目:silent-contacts-android    文件:ContactDetailDisplayUtils.java   
@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;
}
项目:youkes_vr    文件:EmoticonUtil.java   
/**
 * @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;
        }
    };
}
项目:android-customfonthtml    文件:CustomHtml.java   
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;
}
项目:github-v2    文件:MarkdownLoader.java   
/**
 * @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;
}
项目:github-v2    文件:HtmlUtils.java   
/**
 * 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);
}
项目:silent-contacts-android    文件:HtmlUtils.java   
/**
 * 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));
}
项目:acfun-new    文件:TextViewUtils.java   
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://");
}
项目:emojimenu    文件:EmojiParser.java   
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;
}
项目:detlef    文件:EpisodeListAdapter.java   
public FromHtmlCache() {
    dummyImageGetter = new ImageGetter() {

        @Override
        public Drawable getDrawable(String source) {
            return NOTHING;
        }
    };
}
项目:WeCenterMobile-Android    文件:TextShow.java   
@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;
}
项目:silent-contacts-android    文件:ContactDetailDisplayUtils.java   
public static Html.ImageGetter getImageGetter(Context context) {
    if (sImageGetter == null) {
        sImageGetter = new DefaultImageGetter(context.getPackageManager());
    }
    return sImageGetter;
}