• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

daquexian/FlexibleRichTextView: A view showing LaTeX, images, codes... You can c ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

daquexian/FlexibleRichTextView

开源软件地址(OpenSource Url):

https://github.com/daquexian/FlexibleRichTextView

开源编程语言(OpenSource Language):

Java 100.0%

开源软件介绍(OpenSource Introduction):

FlexibleRichTextView

中文版

Description

This library is used for showing various rich text, including LaTeX, images, codes, tables, and normal styles such as center, bold, italic and so on.

An interesting feature is, you can customize most tags as whatever you want.

It uses CodeView to support code highlight, and JLaTeXMath (as well as this fork) to support LaTeX.

The method to parse rich text is something like recursively descending. I'm open to PR that could improve performance, fix bugs and anything make this library better.

Screenshot:

Screenshot

Download

add in your root build.gradle :

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

then add

compile 'com.github.daquexian:FlexibleRichTextView:0.8.2'

in your app's build.gradle

Usage

You need initialize JLaTeXMath for LaTeX rendering by command:

AjLatexMath.init(context); // init library: load fonts, create paint, etc.

If you want to use code classifier to auto language recognizing just add to your Application

// train classifier on app start
CodeProcessor.init(this);

To show rich text, just invoke flexibleRichTextView.setText, such as

String richText = "[h][center]hi![/center][/h]" +
                "[quote]This is quote[/quote]" +
                "[code]print(\"Hello FlexibleRichTextView!\")[/code]" +
                "Hello FlexibleRichTextView!\n" +
                "This is LaTeX:\n" +
                "$e^{\\pi i} + 1 = 0$";
flexibleRichTextView.setText(richText);

Tags

You can see default tags in this. Try to customize your own tags by the series of set***Labels(String... labels) methods.

  • For image labels, \w represents width ,\h represents height and \u represents the url of image.

  • For attachment labels, \s repersents attachment id.

  • For color labels, \s represents color (e.g. red).

  • For url labels, \s represents url.

  • For quote labels, \p represents the id of the quoted content, \m represents the name of the person quoted.

For example, if you customize image label as <img height=\h width=\w>\u</img>, the text <img height=200 width=100>https://example.img</img> will be treated as a image, its height is 200, width is 100 and its url is https://example.img . And of course you can just customize image label as <img>\u</img>, then the original size of image will be respected.

Attachment

This library support attachment. If there are attachments to show, create a class and inherit abstract class Attachment, then invoke flexibleRichTextView.setText(String richText, List<Attachment> attachments).

If attachment.isImage() is true, the attachment will be shown as image, or it will be shown as a link (please implement getText() method whose return value is the link text, and getUrl() method whose return value is the url of image, see Callbacks for more information). Both images and links produced from attachments will be shown at the bottom of view.

If you need the attachment embedded in text, please implement getAttachmentId() method and provide the id in attachment tag.

For example, the default attachment tag is [attachment:\s], where \s represents attachment id. So you should invoke

String textWithAttachment = "This is an attachment\n" +
                            "[attachment:3918dbe1ac]\n" +
                            "The attachment is above";
flexibleRichTextView.setText(textWithAttachment, attachmentList);

If the list attachmentList contains an attachment whose id equals 3918dbe1ac, it will be shown embedded in text.

Quote

You can not only customize the tags of quote, but also the layout of QuoteView.

The default layout is this.

The root element of layout must be a QuoteView and the first child of it must be a FrameLayout. You can specify a button that takes the role of expanding or collapsing the QuoteView on click by adding app:buttonId=your_button_id in QuoteView. When the button is clicked, the onButtonClick(View view, boolean collapsed) method of OnViewListener will be invoked, you could modify the text of button or do other things according to the status of QuoteView.

LaTeX

See this for LaTeX tags. They cannot be customized temporarily.

Table

The grammer for table is the same as GitHub, except for the pipes on either end of the table cannot be omitted.

Callbacks

In interface FlexibleRichTextView.OnViewClickListener, three callbacks are declared, including OnImgClick(ImageView imageView), OnAttClick(Attachment attachment) and OnQuoteButtonClick(View view, boolean collapsed).

For attachments, if an attachment is shown as image, OnImgClick will be called when clicking the attachment, OnAttClick is only called when an attachment shown as link is clicked.

Lisence

This library is licensed under Apache 2.0. The full license text can be found in the LICENSE file.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap