Code Monkey home page Code Monkey logo

icarus-android's Introduction

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

icarus-android's People

Contributors

mr5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

icarus-android's Issues

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?

增加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方法,满足此需求。

请问如何显示本地图片?

现在的需求是要先显示本地图片,等编辑完成再统一上传所有的图片,上传完获得url替换之前显示本地图片的部分。

自定义ImagePopoverImpl,点击插入图片按钮,不回调show方法

我自己implements Popover,实现了show和hide方法。

将示例中的代码修改如下:
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 ImgPopover());
toolbar.addButton(imageButton);

但当我点击这个按钮的时候并没有调用show方法,只是插入了一张tower的logo

我已经写好了相册选择,压缩上传等功能,想知道应该在什么地方调用这些功能

获取内容

获取内容的时候有没有实时的获取,及跟新了内容就可以获取到内容的回调;
另外获取的内容的方法有没有非异步的? ~

HELP: disable/enable editing

Hi how to enable or disable contentEditing of DIV ?
I tried this but nothing , it dont work
document.getElementsByClassName("simditor-body").contentEditable=flase; this.body.contentEditable=false;

How to create a function like this
Simditor.prototype.enableEditing= function(enable) { // Enable disable content editing };

Please help me, is very important for me

无法compile

Error:(26, 13) Failed to resolve: com.github.mr5:icarus:0.1.14

Get Content Sync...Because Loosing content on Screen Rotate

Hi there, first I want to thank you for this project, second is that I am having problems when screen rotates or when I go to another app and come back, mostr of the time the content of the Editor is cleaned (even though it is on a Fragment with setRetainInstance(true) ).

I tried to save the contents on onSaveInstanceState, but since I have to get the content async that isn't a trivial thing to do.

This is an important issue . Thanks in advance

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

插入图片问题

怎么让图片单独占一行并且居中,这个图片可以是上传之后的图片链接吗

Popover add link function does not work

Hello, first of all thank you for your this helpful library, it is really rich.

However, I faced an issue that I cannot add a new link in editor using your library propover. I add text and link, but after I press OK, just nothing happens. Does anyone know what a problem it can be?

插入图片后关闭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)

could not find com.github...

在build.gradle中加入compile 'com.github.mr5:icarus:0.1.14-SNAPSHOT'后报错
Error:Could not find com.github.mr5:icarus:0.1.14-SNAPSHOT.

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?

how to upload image

when i click image button will auto insert an default image, i can not find this code.
how can i get this event ?
i very like this rich editor~

Line to Line spacing adjustment

I tried that your library. I'm facing the issue line to line spacing is more. How can I adjust the spacing between the lines?

在光标位置插入文字显示不正常

输入一行中文,然后在文字中间插入图片,此时把光标移到末尾,输入文字并未追加到行末尾,但是纯英文输入的话是正常的

有图片网址,怎么插入

现在看demo点击图片的时候插入的是默认的图片,然后点击图片会弹出对话框,让输入链接,能修改图片,怎么能直接插入自己想插入的图片,且图片style:width=100%,铺满

音频插入问题

@mr5 你好,我想问一下这个编辑器如何做才能插入音频呢?我试了插入音频标签的内容,但是没法显示,想实现这个功能,求方法,或者思路,谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.