Java Code Examples for android.text.Html#ImageGetter
The following examples show how to use
android.text.Html#ImageGetter .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XulSpannedLabelRender.java From starcor.xul with GNU Lesser General Public License v3.0 | 6 votes |
private Html.ImageGetter obtainImageGetter() { if (_imageGetter != null) { return _imageGetter; } _imageGetter = new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { if (_imageCache == null) { _imageCache = new XulCachedHashMap<String, SpannedLabelImage>(); } SpannedLabelImage spannedLabelImage = _imageCache.get(source); if (spannedLabelImage == null) { spannedLabelImage = new SpannedLabelImage(); spannedLabelImage._source = source; _imageCache.put(source, spannedLabelImage); _imageCacheChanged = true; } if (spannedLabelImage._drawable == null) { return null; } return spannedLabelImage._drawable; } }; return _imageGetter; }
Example 2
Source File: XulSpannableTextRenderer.java From starcor.xul with GNU Lesser General Public License v3.0 | 6 votes |
private Html.ImageGetter obtainImageGetter() { if (_imageGetter != null) { return _imageGetter; } _imageGetter = new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { if (_imageCache == null) { _imageCache = new XulCachedHashMap<String, SpannedLabelImage>(); } SpannedLabelImage spannedLabelImage = _imageCache.get(source); if (spannedLabelImage == null) { spannedLabelImage = new SpannedLabelImage(); spannedLabelImage._source = source; _imageCache.put(source, spannedLabelImage); _imageCacheChanged = true; } if (spannedLabelImage._drawable == null) { return null; } return spannedLabelImage._drawable; } }; return _imageGetter; }
Example 3
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 6 votes |
private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src); } if (d == null) { //d = Resources.getSystem(). // getDrawable(R.drawable.seek_thumb); //d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); return; } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example 4
Source File: HtmlTextView.java From v2ex with Apache License 2.0 | 6 votes |
/** * Parses String containing HTML to Android's Spannable format and displays it in this TextView. * * @param html String containing HTML, for example: "<b>Hello world!</b>" */ public void setHtmlFromString(String html, boolean useLocalDrawables) { Html.ImageGetter imgGetter; if (useLocalDrawables) { imgGetter = new LocalImageGetter(getContext()); } else { imgGetter = new UrlImageGetter(this, getContext()); } try { // this uses Android's Html class for basic parsing, and HtmlTagHandler setText(Html.fromHtml(html, imgGetter, new HtmlTagHandler())); } catch (RuntimeException e) { setText(""); } // make links work setMovementMethod(LinkMovementCheck.getInstance()); // no flickering when clicking textview for Android < 4, but overriders color... // text.setTextColor(getResources().getColor(android.R.color.secondary_text_dark_nodisable)); }
Example 5
Source File: MainActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private void startImg(SpannableStringBuilder text, String src, Html.ImageGetter img) { Drawable d = null; if (img != null) { d = img.getDrawable(src); } if (d == null) { d = getResources().getDrawable(R.mipmap.ic_launcher); 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 6
Source File: CustomHtmlToSpannedConverter.java From zulip-android with Apache License 2.0 | 6 votes |
private static void startImg(SpannableStringBuilder text, Attributes attributes, Html.ImageGetter img) { String cssClass = attributes.getValue("class"); String src = cssClass != null && attributes.getValue("", "src") == null ? cssClass.substring(cssClass.indexOf("-") + 1) : attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src); } if (d == null) { // don't draw anything return; } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example 7
Source File: AsyncLoadNetworkPic.java From nono-android with GNU General Public License v3.0 | 5 votes |
public AsyncLoadNetworkPic(Context context, TextView editText, String content, Html.ImageGetter imageGetter, Html.TagHandler htmlTagHandler){ this.context=context; this.editText = editText; this.content = content; this.imageGetter = imageGetter; this.htmlTagHandler = htmlTagHandler; }
Example 8
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 5 votes |
public HtmlToSpannedConverter(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler, Parser parser, int flags) { mSource = source; mSpannableStringBuilder = new SpannableStringBuilder(); mImageGetter = imageGetter; mTagHandler = tagHandler; mReader = parser; mFlags = flags; }
Example 9
Source File: MuPDFReflowRecyclerViewAdapter.java From Mupdf with Apache License 2.0 | 5 votes |
public void onBind(byte[] result) { String text = new String(result).trim(); //Log.d("text", text = UnicodeDecoder.unescape2(text)); Html.ImageGetter imageGetter = new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { //Log.d("text", source); Bitmap bitmap = StreamUtils.base64ToBitmap(source.replaceAll("data:image/(png|jpeg);base64,", "")/*.replaceAll("\\s", "")*/); if (null == bitmap || (bitmap.getWidth() < minImgHeight && bitmap.getHeight() < minImgHeight)) { Log.d("text", "bitmap decode failed."); return null; } float width = bitmap.getWidth() * systemScale; float height = bitmap.getHeight() * systemScale; if (width > screenWidth) { float ratio = screenWidth / width; height = ratio * height; width = screenWidth; } Drawable drawable = new BitmapDrawable(null, bitmap); drawable.setBounds(0, 0, (int) width, (int) height); return drawable; } }; Spanned spanned = AKHtml.fromHtml(text, imageGetter, null); textView.setText(spanned); }
Example 10
Source File: StringUtils.java From SteamGifts with MIT License | 5 votes |
/** * Wrapper around Html.fromHtml for deprecation. */ @SuppressWarnings("deprecation") private static CharSequence fromHtml(String source, Html.ImageGetter imageGetter, CustomHtmlTagHandler customHtmlTagHandler) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY, imageGetter, customHtmlTagHandler); } else { return Html.fromHtml(source, imageGetter, customHtmlTagHandler); } }
Example 11
Source File: CustomHtmlToSpannedConverter.java From zulip-android with Apache License 2.0 | 5 votes |
public CustomHtmlToSpannedConverter(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler, Parser parser, Html.ImageGetter emojiGetter, String baseUri, Context context) { mSource = source; mSpannableStringBuilder = new SpannableStringBuilder(); mImageGetter = imageGetter; mTagHandler = tagHandler; mReader = parser; mEmojiGetter = emojiGetter; mBaseUri = baseUri; userMentionColor = ContextCompat.getColor(context, R.color.dark_red); userMentionSelfColor = ContextCompat.getColor(context, R.color.self_mention_color); }
Example 12
Source File: MarkDown.java From Markdown with MIT License | 5 votes |
/** * 解析markdown文本并返回spanned * * @param reader BufferReader * @param imageGetter 图片获取回调 * @param textView textView * @return spanned */ public static Spanned fromMarkdown(BufferedReader reader, Html.ImageGetter imageGetter, TextView textView) { MarkDownParser parser = new MarkDownParser(reader, new StyleBuilderImpl(textView, imageGetter)); try { return parser.parse(); } catch (IOException e) { e.printStackTrace(); } return null; }
Example 13
Source File: MarkDown.java From Markdown with MIT License | 5 votes |
/** * 解析markdown文本并返回spanned * * @param inputStream 输入流 * @param imageGetter 图片获取回调 * @param textView textView * @return spanned */ public static Spanned fromMarkdown(InputStream inputStream, Html.ImageGetter imageGetter, TextView textView) { MarkDownParser parser = new MarkDownParser(inputStream, new StyleBuilderImpl(textView, imageGetter)); try { return parser.parse(); } catch (IOException e) { e.printStackTrace(); } return null; }
Example 14
Source File: MarkDown.java From Markdown with MIT License | 5 votes |
/** * 解析markdown文本并返回spanned * * @param source 源文本 * @param imageGetter 图片获取回调 * @param textView textView * @return spanned */ public static Spanned fromMarkdown(String source, Html.ImageGetter imageGetter, TextView textView) { MarkDownParser parser = new MarkDownParser(source, new StyleBuilderImpl(textView, imageGetter)); try { return parser.parse(); } catch (IOException e) { e.printStackTrace(); } return null; }
Example 15
Source File: StyleBuilderImpl.java From Markdown with MIT License | 5 votes |
public StyleBuilderImpl(TextView textView, Html.ImageGetter imageGetter) { this.textViewWeakReference = new WeakReference<>(textView); this.imageGetter = imageGetter; Context context = textView.getContext(); TypedArray a = context.obtainStyledAttributes(null, R.styleable.MarkdownTheme, R.attr.markdownStyle, 0); final boolean failed = !a.hasValue(0); if (failed) { Log.w("Markdown", "Missing markdownStyle in your theme, using hardcoded color."); h1_text_color = 0xdf000000; h6_text_color = 0x8a000000; quota_color = 0x4037474f; quota_text_color = 0x61000000; code_text_color = 0xd8000000; code_background_color = 0x0c37474f; link_color = 0xdc3e7bc9; h_under_line_color = 0x1837474f; } else { h1_text_color = a.getColor(R.styleable.MarkdownTheme_h1TextColor, 0); h6_text_color = a.getColor(R.styleable.MarkdownTheme_h6TextColor, 0); quota_color = a.getColor(R.styleable.MarkdownTheme_quotaColor, 0); quota_text_color = a.getColor(R.styleable.MarkdownTheme_quotaTextColor, 0); code_text_color = a.getColor(R.styleable.MarkdownTheme_codeTextColor, 0); code_background_color = a.getColor(R.styleable.MarkdownTheme_codeBackgroundColor, 0); link_color = a.getColor(R.styleable.MarkdownTheme_linkColor, 0); h_under_line_color = a.getColor(R.styleable.MarkdownTheme_underlineColor, 0); } a.recycle(); }
Example 16
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 4 votes |
static SpannableStringBuilder fromDocument( Context context, @NonNull Document document, boolean compress, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) { return fromDocument(context, document, true, compress, imageGetter, tagHandler); }
Example 17
Source File: TextViewFixTouchConsume.java From JianshuApp with GNU General Public License v3.0 | 4 votes |
public void setTextViewHTML(String html, Html.ImageGetter imgGetter) { SpannableStringBuilder strBuilder = new SpannableStringBuilder(Html.fromHtml(html, imgGetter, null)); removeUnderlines(strBuilder); setText(strBuilder); }
Example 18
Source File: HtmlHelper.java From FairEmail with GNU General Public License v3.0 | 4 votes |
static Spanned fromHtml(@NonNull String html, boolean compress, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) { Document document = JsoupEx.parse(html); return fromDocument(context, document, false, compress, imageGetter, tagHandler); }
Example 19
Source File: HtmlTextView.java From html-textview with Apache License 2.0 | 3 votes |
/** * Parses String containing HTML to Android's Spannable format and displays it in this TextView. * Using the implementation of Html.ImageGetter provided. * * @param html String containing HTML, for example: "<b>Hello world!</b>" * @param imageGetter for fetching images. Possible ImageGetter provided by this library: * HtmlLocalImageGetter and HtmlRemoteImageGetter */ public void setHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter) { setText(HtmlFormatter.formatHtml(html, imageGetter, clickableTableSpan, drawTableLinkSpan, onClickATagListener,indent, removeTrailingWhiteSpace)); // make links work setMovementMethod(LocalLinkMovementMethod.getInstance()); }
Example 20
Source File: AKHtml.java From Mupdf with Apache License 2.0 | 2 votes |
/** * Returns displayable styled text from the provided HTML string with the legacy flags * {@link #FROM_HTML_MODE_LEGACY}. * * @deprecated use {@link #fromHtml(String, int, Html.ImageGetter, Html.TagHandler)} instead. */ @Deprecated public static Spanned fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler) { return fromHtml(source, FROM_HTML_MODE_LEGACY, imageGetter, tagHandler); }