[DISCONTINUED] Rrich text editor for android platform. 安卓富文本编辑器,暂停维护

Overview

icarus-android

Maybe the best rich text editor on android platform. Base on Simditor

demo

Features

  • Alignment (left/center/right)
  • Bold
  • Blockquote
  • Code
  • Horizontal ruler
  • Italic
  • Image
  • Indent
  • Link
  • Outdent
  • Ordered List
  • Unordered List
  • Underline
  • Raw html (Insert anything to any selection range that you want via API)

Usage

Add this line to your build.gradle file under your module directory.

compile 'com.github.mr5:icarus:0.1.14'

Java codes:

import android.app.Activity;
import android.webkit.WebView;
import android.widget.TextView;

import com.github.mr5.icarus.entity.Options;
import com.github.mr5.icarus.button.TextViewButton;
class EditorActivity extends Activity {
	protected WebView webView;
    protected Icarus icarus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get WebView from your layout, or create it manually.
        setContentView(R.layout.activity_main);
        webView = (WebView) findViewById(R.id.editor);
        // I offered a toolbar to manage editor buttons which implements TextView that with icon fonts. 
        // It's just a collection, not an Android View implementation. 
        // TextViewToolbar will listen click events on all buttons that added to it. 
        // You can implement your own `Toolbar`, to prevent these default behaviors.
        TextViewToolbar toolbar = new TextViewToolbar();
        Options options = new Options();
        options.setPlaceholder("Placeholder...");
        icarus = new Icarus(toolbar, options, webView);
        TextView boldButton = new TextViewButton()
        boldButton.setName(Button.NAME_BOLD);
		toolbar.addButton(boldButton);
        icarus.render();
    }
 }

Sample

Button Names

see Button.java

Options

placeholder: String

Placeholder of Editor. Use the placeholder attribute value of the textarea by default.

default: "Icarus editor."

Example:

options.setPlaceholder("Input something...");

defaultImage: String

Default image placeholder. Used when inserting pictures in Edtior.

default: "images/image.png"

Example:

options.setDefaultImage("file:///android_asset/xxx.jpg");

cleanPaste: Boolean

Remove all styles in paste content automatically.

default: false

Example:

options.setCleanPaste(true);

allowedTags: String[]

Tags that are allowed in Editor

default: {"br", "span", "a", "img", "b", "strong", "i", "strike", "u", "font", "p", "ul", "ol", "li", "blockquote", "pre", "code", "h1", "h2", "h3", "h4", "hr"}

Example:

// option replacement.
options.setAllowedTags(Arrays.asList("a", "span", "img");
// add tag to current tag list.
options.addAllowedTag("pre");

allowedAttributes: Map<String, List<String>>

Whitelist of tag attributes. Note that custom whitelist will be merged into the default one.

default:

img: {"src", "alt", "width", "height", "data-non-image"}
a: {"href", "target"}
font: {"color"}
code: {"class"}

Example:

// option replacement.
options.setAllowedAttributes(new HashMap<String, List<String>>());
// add new attribute to current tag list.
options.addAllowedAttributes("a", Arrays.asList("class", "src", "alt", "data-type"));

Load Javascript or Stylesheet files.

icarus.loadCSS("file:///android_asset/editor.css");
icarus.loadJs("file:///android_asset/test.js");

Popover

Some buttons depend user's actions, such as Button.NAME_LINK, Button.NAME_IMAGE. So you want to show a popover for user to do these actions. Icarus offered 3 Popover Implementations, HtmlPopoverImpl, ImagePopoverImpl, LinkPopoverImpl,

popover

Samples:

TextView imageButtonTextView = (TextView) findViewById(R.id.button_image);
imageButtonTextView.setTypeface(iconfont);
TextViewButton imageButton = new TextViewButton(imageButtonTextView, icarus);
imageButton.setName(Button.NAME_IMAGE);
imageButton.setPopover(new ImagePopoverImpl(imageButtonTextView, icarus));

toolbar.addButton(imageButton);

You can implement your own popover to handler user's actions.

Insert html to current selection

icarus.insertHtml("<iframe src=\\"xxx\\"></iframe>");

Contents getting and setting

// Get contents
icarus.getContent(new Callback() {
                @Override
                public void run(String params) {
	                Gson gson = new Gson();
			        Html html = gson.fromJson(params, Html.class);
					Log.d("Content gotten", html.getContent());
                }
            });


// Set contents
icarus.setContent("new content");

License

MIT

Android Arsenal

Comments
  • 插入图片后关闭Activity报Activity has leaked window

    插入图片后关闭Activity报Activity has leaked window

     E/WindowManager: android.view.WindowLeaked: Activity com.olsplus.balancemall.app.merchant.goods.RichTextActivity has leaked window android.widget.PopupWindow$PopupDecorView{24829e V.E...... ......ID 0,0-53,63} that was originally added here
                                                                                at android.view.ViewRootImpl.<init>(ViewRootImpl.java:417)
                                                                                at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
                                                                                at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
                                                                                at android.widget.PopupWindow.invokePopup(PopupWindow.java:1380)
                                                                                at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1156)
                                                                                at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1119)
                                                                                at org.chromium.content.browser.input.PopupTouchHandleDrawable.show(PopupTouchHandleDrawable.java:455)
                                                                                at org.chromium.android_webview.AwContents.nativeOnDraw(Native Method)
                                                                                at org.chromium.android_webview.AwContents.access$4700(AwContents.java:100)
                                                                                at org.chromium.android_webview.AwContents$AwViewMethodsImpl.onDraw(AwContents.java:3000)
                                                                                at com.android.webview.chromium.WebViewChromium.onDraw(WebViewChromium.java:31329)
                                                                                at android.webkit.WebView.onDraw(WebView.java:2534)
                                                                                at android.view.View.draw(View.java:17070)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16052)
                                                                                at android.view.View.draw(View.java:16836)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16047)
                                                                                at android.view.View.draw(View.java:16836)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16047)
                                                                                at android.view.View.draw(View.java:16836)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16047)
                                                                                at android.view.View.draw(View.java:16836)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16047)
                                                                                at android.view.View.draw(View.java:16836)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16047)
                                                                                at android.view.View.draw(View.java:16836)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3764)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3550)
                                                                                at android.view.View.draw(View.java:17073)
                                                                                at com.android.internal.policy.DecorView.draw(DecorView.java:751)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:16052)
                                                                                at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:656)
                                                                                at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:662)
                                                                                at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:770)
                                                                                at android.view.ViewRootImpl.draw(ViewRootImpl.java:2796)
                                                                                at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2604)
                                                                                at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2211)
                                                                                at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
                                                                                at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
                                                                                at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
                                                                                at android.view.Choreographer.doCallbacks(Choreographer.java:683)
                                                                                at android.view.Choreographer.doFrame(Choreographer.java:619)
                                                                                at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
                                                                                at android.os.Handler.handleCallback(Handler.java:751)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                at android.os.Looper.loop(Looper.java:154)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
    
    opened by linceln 4
  • 增加setHtml和getHtml方法

    增加setHtml和getHtml方法

    测试发现,一段html文本:

    <h1>正则表达式</h1><p>&nbsp; &nbsp; &nbsp; <span style="text-decoration: underline;">正则表达式</span>,又称规则表达式。(英语:<em>Regular Expression</em>,在代码中常简写为regex、regexp或RE),计算机科学的一个<strong>概念</strong>。正则表通常被用来检索、替换那些符合某个模式(规则)的文本。
    

    通过setContent插入,span的style="text-decoration: underline;无法生效。 而通过insertHTML插入则正常,但是会默认选中一堆文字。

    此外getContent方法也会造成一些style="text-decoration: underline;类的样式丢失。

    是否能够增加setHtml和getHtml方法,满足此需求。

    opened by hongyangAndroid 3
  • How can I disable the editing function.

    How can I disable the editing function.

    Hi!! As the issue named, I want to use the same set of layout style in another view to display what I just typed in. Is there a way I can disable the cursor and toolbar, so the editor just looks like a text view?

    I need help 
    opened by xiaoyifan 3
  • Attempt to invoke virtual method android.webkit.WebView.setWebViewClient

    Attempt to invoke virtual method android.webkit.WebView.setWebViewClient

    Hello, thanks for your library, im migrating to react-native, but having some issues, i want to know if you can help me.

    The error is this.

    
    Attempt to invoke virtual method 'void android.webkit.WebView.setWebViewClient(android.webkit.WebViewClient)' on a null object reference
    initialize
        Icarus.java:130
    render
        Icarus.java:208
    
    public class KnifeViewManager extends SimpleViewManager<WebView> {
        public static final String REACT_CLASS = "RCTKnifeView";
        protected WebView webView;
        
        @Override public String getName() {
            return REACT_CLASS;
        }
    
        @Override public WebView createViewInstance(ThemedReactContext context){
            //return new WebView(context);
    
            TextViewToolbar toolbar = new TextViewToolbar();
            Options options = new Options();
            options.setPlaceholder("Write Here ...");
    
            options.addAllowedAttributes("img", Arrays.asList("data-type", "data-id", "class", "src", "alt", "width", "height", "data-non-image"));
            options.addAllowedAttributes("iframe", Arrays.asList("data-type", "data-id", "class", "src", "width", "height"));
            options.addAllowedAttributes("a", Arrays.asList("data-type", "data-id", "class", "href", "target", "title"));
    
            Icarus icarus = new Icarus(toolbar, options, webView);
            //TextViewButton boldButton = new TextViewButton();
            //boldButton.setName(Button.NAME_BOLD);
            //toolbar.addButton(boldButton);
            //icarus.insertHtml("<img src='http://lorempixel.com/200/200' />");
            icarus.render();
    
    
            return webView;
        }
    }
    

    any idea?

    opened by cinder92 0
  • Bug: toggle buttons are not intuitive

    Bug: toggle buttons are not intuitive

    1.type 2. enable bold 3. type Bug: it doesn't write in bold. device-2018-02-12-113534.zip

    Also:

    1. enable bold
    2. type stuff. 3.disable bold. 4.type Bug: It gets the new text bold still, and the toggle gets turned on again. See video:
    opened by AndroidDeveloperLB 0
  • Bug: unable to use right-alignment+list

    Bug: unable to use right-alignment+list

    Steps:

    1. write something.
    2. make it in a list.
    3. change alignment, to be on the right or even center.

    The bug is that it stays on the left. This occurs for both types of lists (numbered or bullets), and even with a language that should be aligned to the right (Hebrew).

    Attached video to show issue. device-2018-02-11-150058.zip

    opened by AndroidDeveloperLB 0
Owner
Dyson Woo
Dyson Woo
Jetpack Compose Rich Text Editor

An all-in-one Jetpack Compose component to handle text styling inside TextFields

Paweł Chochura 26 Dec 14, 2022
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

mehran elyasi 4 Feb 14, 2022
👨‍💻 Squircle IDE is a fast and free multi-language code editor for Android

Squircle IDE is a fast and free multi-language code editor for Android. Table of Contents EditorKit Gradle Dependency The Basics More Opt

Dmitry Rubtsov 573 Jan 4, 2023
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
Circular timer on Android platform.

CircleTimerView [No Longer Support] Circle timer on Android platform. System Requirement Android v2.2+ TODO Developed by AndroidStudio Usage <com.gith

Abbott 515 Nov 19, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven <dependency

Evgeny Safronov 600 Nov 29, 2022
An address-autocompleting text field for Android

android-PlacesAutocompleteTextView An AutocompleteTextView that interacts with the Google Maps Places API to provide location results and caches selec

SeatGeek 283 Dec 28, 2022
Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I develop easy to understand , modify and integrate Chips Edit Text widget for Android

Chips EditText Library Chips EditText, Token EditText, Bubble EditText, Spannable EditText and etc.. There are many names of this control. Here I deve

kpbird 381 Nov 20, 2022
AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.

AutoscaleEditText AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size. Latest Version How to use

Txus Ballesteros 354 Nov 28, 2022
Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.

MaskFormatter MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.

Azimo Labs 161 Nov 25, 2022
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Aditya Pradana Sugiarto 76 Nov 29, 2022
Markdown Text for Android Jetpack Compose 📋.

Markdown Text for Android Jetpack Compose ??.

Jeziel Lago 250 Jan 4, 2023
Dealing with Android Text by simple way to get high performance.

Gapo Android RichText RichText supports Hashtag, Mention, Url, Phone Number, Email, Markdown, Custom Span, SeeMore/SeeLess by limited line or length,

GapoWork 8 Oct 20, 2021
Android Custom View for prevent the view behind on-screen keyboard when edit text is focused

Group Focusable Prevent the view behind on-screen keyboard when edit text is focused in Android UI Download Gradle implementation 'com.akexorcist:grou

Akexorcist 8 Jun 22, 2022
Dealing with Android Text by simple way to get high performance.

Gapo Android RichText RichText supports Hashtag, Mention, Url, Phone Number, Email, Markdown, Custom Span, SeeMore/SeeLess by limited line or length,

GapoWork 8 Oct 20, 2021
A simple Android library to protect part of text using Span

Text Protector A simple Android library to "protect" part of text using Span What is this? This is a small library for replacing part of a text in a T

Oleg Nestyuk 4 May 16, 2022