├── settings.gradle
├── art
├── demo.gif
└── demo2.gif
├── richeditor
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── assets
│ │ │ ├── editor.html
│ │ │ ├── style.css
│ │ │ ├── normalize.css
│ │ │ └── rich_editor.js
│ │ └── java
│ │ │ └── jp
│ │ │ └── wasabeef
│ │ │ └── richeditor
│ │ │ ├── Utils.java
│ │ │ └── RichEditor.java
│ └── androidTest
│ │ └── java
│ │ └── jp
│ │ └── wasabeef
│ │ └── richeditor
│ │ └── ApplicationTest.java
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── sample
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── bg.png
│ │ │ │ ├── h1.png
│ │ │ │ ├── h2.png
│ │ │ │ ├── h3.png
│ │ │ │ ├── h4.png
│ │ │ │ ├── h5.png
│ │ │ │ ├── h6.png
│ │ │ │ ├── bold.png
│ │ │ │ ├── redo.png
│ │ │ │ ├── undo.png
│ │ │ │ ├── indent.png
│ │ │ │ ├── italic.png
│ │ │ │ ├── outdent.png
│ │ │ │ ├── bg_color.png
│ │ │ │ ├── blockquote.png
│ │ │ │ ├── html_edit.png
│ │ │ │ ├── subscript.png
│ │ │ │ ├── txt_color.png
│ │ │ │ ├── underline.png
│ │ │ │ ├── insert_image.png
│ │ │ │ ├── insert_link.png
│ │ │ │ ├── justify_left.png
│ │ │ │ ├── superscript.png
│ │ │ │ ├── justify_center.png
│ │ │ │ ├── justify_right.png
│ │ │ │ └── strikethrough.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── jp
│ │ │ └── wasabeef
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── jp
│ │ └── wasabeef
│ │ └── sample
│ │ └── ApplicationTest.java
└── build.gradle
├── .gitignore
├── CHANGELOG.md
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':richeditor'
2 |
--------------------------------------------------------------------------------
/art/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/art/demo.gif
--------------------------------------------------------------------------------
/art/demo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/art/demo2.gif
--------------------------------------------------------------------------------
/richeditor/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/bg.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/h1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/h1.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/h2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/h2.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/h3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/h3.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/h4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/h4.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/h5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/h5.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/h6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/h6.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/bold.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/bold.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/redo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/redo.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/undo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/undo.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/indent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/indent.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/italic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/italic.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/outdent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/outdent.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/bg_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/bg_color.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/blockquote.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/blockquote.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/html_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/html_edit.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/subscript.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/subscript.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/txt_color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/txt_color.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/underline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/underline.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/insert_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/insert_image.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/insert_link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/insert_link.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/justify_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/justify_left.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/superscript.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/superscript.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/justify_center.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/justify_center.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/justify_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/justify_right.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xxhdpi/strikethrough.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/luozhimin0918/richeditor-android/HEAD/sample/src/main/res/drawable-xxhdpi/strikethrough.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | richeditor-android
3 | RichEditor Demo
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Feb 11 00:41:58 JST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Built application files
3 | *.apk
4 | *.ap_
5 |
6 | # Files for the Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.2.0 *(2016-01-07)*
5 | ----------------------------
6 | Merge: Feature fontSize https://github.com/wasabeef/richeditor-android/pull/42
7 |
8 | Version 1.1.0 *(2016-01-07)*
9 | ----------------------------
10 | Merge: https://github.com/wasabeef/richeditor-android/pull/37
11 |
12 | Version 1.0.0 *(2015-11-10)*
13 | ----------------------------
14 |
15 | Product Release
--------------------------------------------------------------------------------
/sample/src/androidTest/java/jp/wasabeef/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 |
11 | public ApplicationTest() {
12 | super(Application.class);
13 | }
14 | }
--------------------------------------------------------------------------------
/richeditor/src/androidTest/java/jp/wasabeef/richeditor/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.richeditor;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 |
11 | public ApplicationTest() {
12 | super(Application.class);
13 | }
14 | }
--------------------------------------------------------------------------------
/richeditor/src/main/assets/editor.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/richeditor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion COMPILE_SDK_VERSION as int
6 | buildToolsVersion BUILD_TOOLS_VERSION
7 |
8 | defaultConfig {
9 | minSdkVersion MIN_SDK_VERSION as int
10 | targetSdkVersion TARGET_SDK_VERSION as int
11 | versionCode VERSION_CODE as int
12 | versionName VERSION_NAME
13 | }
14 | }
15 |
16 | publish {
17 | userOrg = POM_DEVELOPER_ID
18 | groupId = GROUP
19 | artifactId = ARTIFACT_ID
20 | publishVersion = VERSION_NAME
21 | desc = POM_DESCRIPTION
22 | website = POM_URL
23 | }
24 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.2.0
2 | VERSION_CODE=18
3 | GROUP=jp.wasabeef
4 | ARTIFACT_ID=richeditor-android
5 |
6 | COMPILE_SDK_VERSION=23
7 | BUILD_TOOLS_VERSION=23.0.2
8 | TARGET_SDK_VERSION=23
9 | MIN_SDK_VERSION=14
10 |
11 | POM_DESCRIPTION=RichEditor for Android is a beautiful Rich Text WYSIWYG Editor
12 | POM_URL=https://github.com/wasabeef/richeditor-android
13 | POM_SCM_URL=git@github.com:wasabeef/richeditor-android.git
14 | POM_SCM_CONNECTION=git@github.com:wasabeef/richeditor-android.git
15 | POM_SCM_DEV_CONNECTION=scm:git@github.com:wasabeef/richeditor-android.git
16 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
17 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
18 | POM_LICENCE_DIST=repo
19 | POM_DEVELOPER_ID=wasabeef
20 | POM_DEVELOPER_NAME=Wasabeef
21 | POM_DEVELOPER_EMAIL=dadadada.chop@gmail.com
22 | POM_DEVELOPER_URL=wasabeef.jp
23 | ISSUE_URL=https://github.com/wasabeef/richeditor-android/issues
24 |
25 | SUPPORT_PACKAGE_VERSION=23.0.1
--------------------------------------------------------------------------------
/richeditor/src/main/assets/style.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 Wasabeef
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | @charset "UTF-8";
18 |
19 |
20 | html {
21 | height: 100%;
22 | }
23 |
24 | body {
25 | overflow: hidden;
26 | display: table;
27 | table-layout: fixed;
28 | width: 100%;
29 | }
30 |
31 | #editor {
32 | display: table-cell;
33 |
34 | -webkit-user-select: auto !important;
35 | -webkit-user-modify: read-write !important;
36 |
37 | outline: 0px solid transparent;
38 | background-repeat: no-repeat;
39 | background-position: center;
40 | background-size: cover;
41 | }
42 |
43 | #editor[placeholder]:empty:not(:focus):before {
44 | content: attr(placeholder);
45 | opacity: .2;
46 | }}
47 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 | buildToolsVersion BUILD_TOOLS_VERSION
6 |
7 | defaultConfig {
8 | minSdkVersion MIN_SDK_VERSION as int
9 | targetSdkVersion TARGET_SDK_VERSION as int
10 | versionCode VERSION_CODE as int
11 | versionName VERSION_NAME
12 | }
13 |
14 | signingConfigs {
15 | release {
16 | storeFile file(keyStoreProperty)
17 | keyAlias keyAliasProperty
18 | storePassword keyStorePasswordProperty
19 | keyPassword keyAliasPasswordProperty
20 | }
21 | }
22 |
23 | buildTypes {
24 | debug {
25 | debuggable true
26 | zipAlignEnabled true
27 | }
28 | release {
29 | debuggable false
30 | zipAlignEnabled true
31 | signingConfig signingConfigs.release
32 | }
33 | }
34 | }
35 |
36 | def getKeyStoreProperty() {
37 | return hasProperty('WASABEEF_KEYSTORE') ? WASABEEF_KEYSTORE : "debug.keystore"
38 | }
39 |
40 | def getKeyAliasProperty() {
41 | return hasProperty('WASABEEF_KEYALIAS') ? WASABEEF_KEYALIAS : "android"
42 | }
43 |
44 | def getKeyStorePasswordProperty() {
45 | return hasProperty('WASABEEF_KEYSTOREPASSWORD') ? WASABEEF_KEYSTOREPASSWORD : "androiddebugkey"
46 | }
47 |
48 | def getKeyAliasPasswordProperty() {
49 | return hasProperty('WASABEEF_KEYALIASPASSWORD') ? WASABEEF_KEYALIASPASSWORD : "android"
50 | }
51 |
52 | dependencies {
53 | compile project(':richeditor')
54 | compile "com.android.support:appcompat-v7:${SUPPORT_PACKAGE_VERSION}"
55 | }
56 |
--------------------------------------------------------------------------------
/richeditor/src/main/java/jp/wasabeef/richeditor/Utils.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.richeditor;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Canvas;
7 | import android.graphics.drawable.BitmapDrawable;
8 | import android.graphics.drawable.Drawable;
9 | import android.util.Base64;
10 | import java.io.ByteArrayOutputStream;
11 |
12 | /**
13 | * Copyright (C) 2015 Wasabeef
14 | *
15 | * Licensed under the Apache License, Version 2.0 (the "License");
16 | * you may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at
18 | *
19 | * http://www.apache.org/licenses/LICENSE-2.0
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an "AS IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | */
27 |
28 | public final class Utils {
29 |
30 | public static String toBase64(Bitmap bitmap) {
31 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
32 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
33 | byte[] bytes = baos.toByteArray();
34 |
35 | return Base64.encodeToString(bytes, Base64.NO_WRAP);
36 | }
37 |
38 | public static Bitmap toBitmap(Drawable drawable) {
39 | if (drawable instanceof BitmapDrawable) {
40 | return ((BitmapDrawable) drawable).getBitmap();
41 | }
42 |
43 | int width = drawable.getIntrinsicWidth();
44 | width = width > 0 ? width : 1;
45 | int height = drawable.getIntrinsicHeight();
46 | height = height > 0 ? height : 1;
47 |
48 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
49 | Canvas canvas = new Canvas(bitmap);
50 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
51 | drawable.draw(canvas);
52 |
53 | return bitmap;
54 | }
55 |
56 | public static Bitmap decodeResource(Context context, int resId) {
57 | return BitmapFactory.decodeResource(context.getResources(), resId);
58 | }
59 |
60 | public static long getCurrentTime() {
61 | return System.currentTimeMillis();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | RichEditor for Android
2 | =============
3 | [](https://android-arsenal.com/details/1/1696)
4 | [](https://www.apache.org/licenses/LICENSE-2.0)
5 | [](https://bintray.com/wasabeef/maven/richeditor-android/_latestVersion)
6 |
7 | `RichEditor for Android` is a beautiful Rich Text `WYSIWYG Editor` for `Android`.
8 |
9 | - _Looking for iOS? Check out_ [cjwirth/RichEditorView](https://github.com/cjwirth/RichEditorView)
10 |
11 | Supported Functions
12 | ---
13 |
14 | 
15 |
16 | - [x] Bold
17 | - [x] Italic
18 | - [x] Subscript
19 | - [x] Superscript
20 | - [x] Strikethrough
21 | - [x] Underline
22 | - [x] Justify Left
23 | - [x] Justify Center
24 | - [x] Justify Right
25 | - [x] Blockquote
26 | - [x] Heading 1
27 | - [x] Heading 2
28 | - [x] Heading 3
29 | - [x] Heading 4
30 | - [x] Heading 5
31 | - [x] Heading 6
32 | - [x] Undo
33 | - [x] Redo
34 | - [x] Indent
35 | - [x] Outdent
36 | - [x] Insert Image
37 | - [x] Insert Link
38 | - [x] Checkbox
39 | - [x] Text Color
40 | - [x] Text Background Color
41 | - [x] Text Font Size
42 | - [x] Unordered List (Bullets)
43 | - [x] Ordered List (Numbers)
44 |
45 | Attribute change of editor
46 | ---
47 | - [x] Font Size
48 | - [x] Background Color
49 | - [x] Width
50 | - [x] Height
51 | - [x] Placeholder
52 | - [x] Load CSS
53 | - [x] State Callback
54 |
55 | **Milestone**
56 |
57 | - [ ] Font Family
58 |
59 | Demo
60 | ---
61 |
62 | 
63 |
64 | Samples
65 | ---
66 |
67 |
68 |
69 | How do I use it?
70 | ---
71 |
72 | ### Setup
73 |
74 | ##### Gradle
75 | ```groovy
76 | repositories {
77 | jcenter()
78 | }
79 |
80 | dependencies {
81 | compile 'jp.wasabeef:richeditor-android:1.2.0'
82 | }
83 | ```
84 | ### Default Setting for Editor
85 | ---
86 |
87 | **Height**
88 | ```java
89 | editor.setEditorHeight(200);
90 | ```
91 |
92 | **Font**
93 | ```java
94 | editor.setEditorFontSize(22);
95 | editor.setEditorFontColor(Color.RED);
96 | ```
97 |
98 | **Background**
99 | ```java
100 | editor.setEditorBackgroundColor(Color.BLUE);
101 | editor.setBackgroundColor(Color.BLUE);
102 | editor.setBackgroundResource(R.drawable.bg);
103 | editor.setBackground("https://raw.githubusercontent.com/wasabeef/art/master/chip.jpg");
104 | ```
105 |
106 | **Padding**
107 | ```java
108 | editor.setPadding(10, 10, 10, 10);
109 | ```
110 |
111 | **Placeholder**
112 | ```java
113 | editor.setPlaceholder("Insert text here...");
114 | ```
115 |
116 | **Others**
117 | Please refer the [samples](https://github.com/wasabeef/richeditor-android/blob/master/sample/src/main/java/jp/wasabeef/sample/MainActivity.java) for usage.
118 |
119 | ### Functions for ContentEditable
120 | ---
121 |
122 | **Bold**
123 | ```java
124 | editor.setBold();
125 | ```
126 |
127 | **Italic**
128 | ```java
129 | editor.setItalic();
130 | ```
131 |
132 | **Insert Image**
133 | ```java
134 | editor.insertImage("https://raw.githubusercontent.com/wasabeef/art/master/twitter.png","twitter");
135 | ```
136 |
137 | **Text Change Listener**
138 | ```java
139 | RichEditor editor = (RichEditor) findViewById(R.id.editor);
140 | editor. setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
141 | @Override
142 | public void onTextChange(String text) {
143 | // Do Something
144 | Log.d("RichEditor", "Preview " + text);
145 | }
146 | });
147 | ```
148 |
149 | **Others**
150 | Please refer the [samples](https://github.com/wasabeef/richeditor-android/blob/master/sample/src/main/java/jp/wasabeef/sample/MainActivity.java) for usage.
151 |
152 | Requirements
153 | --------------
154 | Android 4+
155 |
156 | Applications using RichEditor for Android
157 | ---
158 |
159 | Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here.
160 |
161 | Icon | Application
162 | ------------ | -------------
163 | | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
164 | | [ScorePal](https://play.google.com/store/apps/details?id=com.hfd.scorepal)
165 |
166 | Developed By
167 | -------
168 | Daichi Furiya (Wasabeef) -
169 |
170 |
171 |
173 |
174 |
175 | Thanks
176 | -------
177 |
178 | * Inspired by `ZSSRichTextEditor` in [nnhubbard](https://github.com/nnhubbard/ZSSRichTextEditor).
179 |
180 | License
181 | -------
182 |
183 | Copyright 2015 Wasabeef
184 |
185 | Licensed under the Apache License, Version 2.0 (the "License");
186 | you may not use this file except in compliance with the License.
187 | You may obtain a copy of the License at
188 |
189 | http://www.apache.org/licenses/LICENSE-2.0
190 |
191 | Unless required by applicable law or agreed to in writing, software
192 | distributed under the License is distributed on an "AS IS" BASIS,
193 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
194 | See the License for the specific language governing permissions and
195 | limitations under the License.
196 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/sample/src/main/java/jp/wasabeef/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.sample;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.TextView;
8 | import jp.wasabeef.richeditor.RichEditor;
9 |
10 | public class MainActivity extends AppCompatActivity {
11 |
12 | private RichEditor mEditor;
13 | private TextView mPreview;
14 |
15 | @Override protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | mEditor = (RichEditor) findViewById(R.id.editor);
19 | mEditor.setEditorHeight(500);
20 | mEditor.setEditorFontSize(22);
21 | mEditor.setEditorFontColor(Color.RED);
22 | //mEditor.setEditorBackgroundColor(Color.BLUE);
23 | //mEditor.setBackgroundColor(Color.BLUE);
24 | //mEditor.setBackgroundResource(R.drawable.bg);
25 | mEditor.setPadding(10, 10, 10, 10);
26 | // mEditor.setBackground("https://raw.githubusercontent.com/wasabeef/art/master/chip.jpg");
27 | mEditor.setPlaceholder("Insert text here...");
28 |
29 | mPreview = (TextView) findViewById(R.id.preview);
30 | mEditor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
31 | @Override public void onTextChange(String text) {
32 | mPreview.setText(text);
33 | }
34 | });
35 |
36 | findViewById(R.id.action_undo).setOnClickListener(new View.OnClickListener() {
37 | @Override public void onClick(View v) {
38 | mEditor.undo();
39 | }
40 | });
41 |
42 | findViewById(R.id.action_redo).setOnClickListener(new View.OnClickListener() {
43 | @Override public void onClick(View v) {
44 | mEditor.redo();
45 | }
46 | });
47 |
48 | findViewById(R.id.action_bold).setOnClickListener(new View.OnClickListener() {
49 | @Override public void onClick(View v) {
50 | mEditor.setBold();
51 | }
52 | });
53 |
54 | findViewById(R.id.action_italic).setOnClickListener(new View.OnClickListener() {
55 | @Override public void onClick(View v) {
56 | mEditor.setItalic();
57 | }
58 | });
59 |
60 | findViewById(R.id.action_subscript).setOnClickListener(new View.OnClickListener() {
61 | @Override public void onClick(View v) {
62 | mEditor.setSubscript();
63 | }
64 | });
65 |
66 | findViewById(R.id.action_superscript).setOnClickListener(new View.OnClickListener() {
67 | @Override public void onClick(View v) {
68 | mEditor.setSuperscript();
69 | }
70 | });
71 |
72 | findViewById(R.id.action_strikethrough).setOnClickListener(new View.OnClickListener() {
73 | @Override public void onClick(View v) {
74 | mEditor.setStrikeThrough();
75 | }
76 | });
77 |
78 | findViewById(R.id.action_underline).setOnClickListener(new View.OnClickListener() {
79 | @Override public void onClick(View v) {
80 | mEditor.setUnderline();
81 | }
82 | });
83 |
84 | findViewById(R.id.action_heading1).setOnClickListener(new View.OnClickListener() {
85 | @Override public void onClick(View v) {
86 | mEditor.setHeading(1);
87 | }
88 | });
89 |
90 | findViewById(R.id.action_heading2).setOnClickListener(new View.OnClickListener() {
91 | @Override public void onClick(View v) {
92 | mEditor.setHeading(2);
93 | }
94 | });
95 |
96 | findViewById(R.id.action_heading3).setOnClickListener(new View.OnClickListener() {
97 | @Override public void onClick(View v) {
98 | mEditor.setHeading(3);
99 | }
100 | });
101 |
102 | findViewById(R.id.action_heading4).setOnClickListener(new View.OnClickListener() {
103 | @Override public void onClick(View v) {
104 | mEditor.setHeading(4);
105 | }
106 | });
107 |
108 | findViewById(R.id.action_heading5).setOnClickListener(new View.OnClickListener() {
109 | @Override public void onClick(View v) {
110 | mEditor.setHeading(5);
111 | }
112 | });
113 |
114 | findViewById(R.id.action_heading6).setOnClickListener(new View.OnClickListener() {
115 | @Override public void onClick(View v) {
116 | mEditor.setHeading(6);
117 | }
118 | });
119 |
120 | findViewById(R.id.action_txt_color).setOnClickListener(new View.OnClickListener() {
121 | boolean isChanged;
122 |
123 | @Override public void onClick(View v) {
124 | mEditor.setTextColor(isChanged ? Color.BLACK : Color.RED);
125 | isChanged = !isChanged;
126 | }
127 | });
128 |
129 | findViewById(R.id.action_bg_color).setOnClickListener(new View.OnClickListener() {
130 | boolean isChanged;
131 |
132 | @Override public void onClick(View v) {
133 | mEditor.setTextBackgroundColor(isChanged ? Color.TRANSPARENT : Color.YELLOW);
134 | isChanged = !isChanged;
135 | }
136 | });
137 |
138 | findViewById(R.id.action_indent).setOnClickListener(new View.OnClickListener() {
139 | @Override public void onClick(View v) {
140 | mEditor.setIndent();
141 | }
142 | });
143 |
144 | findViewById(R.id.action_outdent).setOnClickListener(new View.OnClickListener() {
145 | @Override public void onClick(View v) {
146 | mEditor.setOutdent();
147 | }
148 | });
149 |
150 | findViewById(R.id.action_align_left).setOnClickListener(new View.OnClickListener() {
151 | @Override public void onClick(View v) {
152 | mEditor.setAlignLeft();
153 | }
154 | });
155 |
156 | findViewById(R.id.action_align_center).setOnClickListener(new View.OnClickListener() {
157 | @Override public void onClick(View v) {
158 | mEditor.setAlignCenter();
159 | }
160 | });
161 |
162 | findViewById(R.id.action_align_right).setOnClickListener(new View.OnClickListener() {
163 | @Override public void onClick(View v) {
164 | mEditor.setAlignRight();
165 | }
166 | });
167 |
168 | findViewById(R.id.action_blockquote).setOnClickListener(new View.OnClickListener() {
169 | @Override public void onClick(View v) {
170 | mEditor.setBlockquote();
171 | }
172 | });
173 |
174 | findViewById(R.id.action_insert_image).setOnClickListener(new View.OnClickListener() {
175 | @Override public void onClick(View v) {
176 | mEditor.insertImage("http://www.1honeywan.com/dachshund/image/7.21/7.21_3_thumb.JPG",
177 | "dachshund");
178 | }
179 | });
180 |
181 | findViewById(R.id.action_insert_link).setOnClickListener(new View.OnClickListener() {
182 | @Override public void onClick(View v) {
183 | mEditor.insertLink("https://github.com/wasabeef", "wasabeef");
184 | }
185 | });
186 | findViewById(R.id.action_insert_checkbox).setOnClickListener(new View.OnClickListener() {
187 | @Override public void onClick(View v) {
188 | mEditor.insertTodo();
189 | }
190 | });
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
15 |
16 |
21 |
22 |
27 |
28 |
36 |
37 |
45 |
46 |
54 |
55 |
63 |
64 |
72 |
73 |
81 |
82 |
90 |
91 |
99 |
100 |
108 |
109 |
117 |
118 |
126 |
127 |
135 |
136 |
144 |
145 |
153 |
154 |
162 |
163 |
171 |
172 |
173 |
181 |
182 |
190 |
191 |
199 |
200 |
208 |
209 |
217 |
218 |
226 |
227 |
235 |
236 |
244 |
245 |
253 |
254 |
255 |
256 |
257 |
265 |
266 |
273 |
274 |
275 |
--------------------------------------------------------------------------------
/richeditor/src/main/assets/normalize.css:
--------------------------------------------------------------------------------
1 | /*! normalize.css v3.0.2 | MIT License | git.io/normalize */
2 |
3 | /**
4 | * 1. Set default font family to sans-serif.
5 | * 2. Prevent iOS text size adjust after orientation change, without disabling
6 | * user zoom.
7 | */
8 |
9 | html {
10 | font-family: sans-serif; /* 1 */
11 | -webkit-text-size-adjust: 100%; /* 2 */
12 | }
13 |
14 | /**
15 | * Remove default margin.
16 | */
17 |
18 | body {
19 | margin: 0;
20 | }
21 |
22 | /* HTML5 display definitions
23 | ========================================================================== */
24 |
25 | /**
26 | * Correct `block` display not defined for any HTML5 element in IE 8/9.
27 | * Correct `block` display not defined for `details` or `summary` in IE 10/11
28 | * and Firefox.
29 | * Correct `block` display not defined for `main` in IE 11.
30 | */
31 |
32 | article,
33 | aside,
34 | details,
35 | figcaption,
36 | figure,
37 | footer,
38 | header,
39 | hgroup,
40 | main,
41 | menu,
42 | nav,
43 | section,
44 | summary {
45 | display: block;
46 | }
47 |
48 | /**
49 | * 1. Correct `inline-block` display not defined in IE 8/9.
50 | * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
51 | */
52 |
53 | audio,
54 | canvas,
55 | progress,
56 | video {
57 | display: inline-block; /* 1 */
58 | vertical-align: baseline; /* 2 */
59 | }
60 |
61 | /**
62 | * Prevent modern browsers from displaying `audio` without controls.
63 | * Remove excess height in iOS 5 devices.
64 | */
65 |
66 | audio:not([controls]) {
67 | display: none;
68 | height: 0;
69 | }
70 |
71 | /**
72 | * Address `[hidden]` styling not present in IE 8/9/10.
73 | * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22.
74 | */
75 |
76 | [hidden],
77 | template {
78 | display: none;
79 | }
80 |
81 | /* Links
82 | ========================================================================== */
83 |
84 | /**
85 | * Remove the gray background color from active links in IE 10.
86 | */
87 |
88 | a {
89 | background-color: transparent;
90 | }
91 |
92 | /**
93 | * Improve readability when focused and also mouse hovered in all browsers.
94 | */
95 |
96 | a:active,
97 | a:hover {
98 | outline: 0;
99 | }
100 |
101 | /* Text-level semantics
102 | ========================================================================== */
103 |
104 | /**
105 | * Address styling not present in IE 8/9/10/11, Safari, and Chrome.
106 | */
107 |
108 | abbr[title] {
109 | border-bottom: 1px dotted;
110 | }
111 |
112 | /**
113 | * Address style set to `bolder` in Firefox 4+, Safari, and Chrome.
114 | */
115 |
116 | b,
117 | strong {
118 | font-weight: bold;
119 | }
120 |
121 | /**
122 | * Address styling not present in Safari and Chrome.
123 | */
124 |
125 | dfn {
126 | font-style: italic;
127 | }
128 |
129 | /**
130 | * Address variable `h1` font-size and margin within `section` and `article`
131 | * contexts in Firefox 4+, Safari, and Chrome.
132 | */
133 |
134 | h1 {
135 | font-size: 2em;
136 | margin: 0.67em 0;
137 | }
138 |
139 | /**
140 | * Address styling not present in IE 8/9.
141 | */
142 |
143 | mark {
144 | background: #ff0;
145 | color: #000;
146 | }
147 |
148 | /**
149 | * Address inconsistent and variable font size in all browsers.
150 | */
151 |
152 | small {
153 | font-size: 80%;
154 | }
155 |
156 | /**
157 | * Prevent `sub` and `sup` affecting `line-height` in all browsers.
158 | */
159 |
160 | sub,
161 | sup {
162 | font-size: 75%;
163 | line-height: 0;
164 | position: relative;
165 | vertical-align: baseline;
166 | }
167 |
168 | sup {
169 | top: -0.5em;
170 | }
171 |
172 | sub {
173 | bottom: -0.25em;
174 | }
175 |
176 | /* Embedded content
177 | ========================================================================== */
178 |
179 | /**
180 | * Remove border when inside `a` element in IE 8/9/10.
181 | */
182 |
183 | img {
184 | border: 0;
185 | }
186 |
187 | /**
188 | * Correct overflow not hidden in IE 9/10/11.
189 | */
190 |
191 | svg:not(:root) {
192 | overflow: hidden;
193 | }
194 |
195 | /* Grouping content
196 | ========================================================================== */
197 |
198 | /**
199 | * Address margin not present in IE 8/9 and Safari.
200 | */
201 |
202 | figure {
203 | margin: 1em 40px;
204 | }
205 |
206 | /**
207 | * Address differences between Firefox and other browsers.
208 | */
209 |
210 | hr {
211 | box-sizing: content-box;
212 | height: 0;
213 | }
214 |
215 | /**
216 | * Contain overflow in all browsers.
217 | */
218 |
219 | pre {
220 | overflow: auto;
221 | }
222 |
223 | /**
224 | * Address odd `em`-unit font size rendering in all browsers.
225 | */
226 |
227 | code,
228 | kbd,
229 | pre,
230 | samp {
231 | font-family: monospace, monospace;
232 | font-size: 1em;
233 | }
234 |
235 | /* Forms
236 | ========================================================================== */
237 |
238 | /**
239 | * Known limitation: by default, Chrome and Safari on OS X allow very limited
240 | * styling of `select`, unless a `border` property is set.
241 | */
242 |
243 | /**
244 | * 1. Correct color not being inherited.
245 | * Known issue: affects color of disabled elements.
246 | * 2. Correct font properties not being inherited.
247 | * 3. Address margins set differently in Firefox 4+, Safari, and Chrome.
248 | */
249 |
250 | button,
251 | input,
252 | optgroup,
253 | select,
254 | textarea {
255 | color: inherit; /* 1 */
256 | font: inherit; /* 2 */
257 | margin: 0; /* 3 */
258 | }
259 |
260 | /**
261 | * Address `overflow` set to `hidden` in IE 8/9/10/11.
262 | */
263 |
264 | button {
265 | overflow: visible;
266 | }
267 |
268 | /**
269 | * Address inconsistent `text-transform` inheritance for `button` and `select`.
270 | * All other form control elements do not inherit `text-transform` values.
271 | * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera.
272 | * Correct `select` style inheritance in Firefox.
273 | */
274 |
275 | button,
276 | select {
277 | text-transform: none;
278 | }
279 |
280 | /**
281 | * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
282 | * and `video` controls.
283 | * 2. Correct inability to style clickable `input` types in iOS.
284 | * 3. Improve usability and consistency of cursor style between image-type
285 | * `input` and others.
286 | */
287 |
288 | button,
289 | html input[type="button"], /* 1 */
290 | input[type="reset"],
291 | input[type="submit"] {
292 | -webkit-appearance: button; /* 2 */
293 | cursor: pointer; /* 3 */
294 | }
295 |
296 | /**
297 | * Re-set default cursor for disabled elements.
298 | */
299 |
300 | button[disabled],
301 | html input[disabled] {
302 | cursor: default;
303 | }
304 |
305 | /**
306 | * Address Firefox 4+ setting `line-height` on `input` using `!important` in
307 | * the UA stylesheet.
308 | */
309 |
310 | input {
311 | line-height: normal;
312 | }
313 |
314 | /**
315 | * It's recommended that you don't attempt to style these elements.
316 | * Firefox's implementation doesn't respect box-sizing, padding, or width.
317 | *
318 | * 1. Address box sizing set to `content-box` in IE 8/9/10.
319 | * 2. Remove excess padding in IE 8/9/10.
320 | */
321 |
322 | input[type="checkbox"],
323 | input[type="radio"] {
324 | box-sizing: border-box; /* 1 */
325 | padding: 0; /* 2 */
326 | }
327 |
328 | /**
329 | * Fix the cursor style for Chrome's increment/decrement buttons. For certain
330 | * `font-size` values of the `input`, it causes the cursor style of the
331 | * decrement button to change from `default` to `text`.
332 | */
333 |
334 | input[type="number"]::-webkit-inner-spin-button,
335 | input[type="number"]::-webkit-outer-spin-button {
336 | height: auto;
337 | }
338 |
339 | /**
340 | * 1. Address `appearance` set to `searchfield` in Safari and Chrome.
341 | * 2. Address `box-sizing` set to `border-box` in Safari and Chrome
342 | */
343 |
344 | input[type="search"] {
345 | -webkit-appearance: textfield; /* 1 */
346 | -webkit-box-sizing: content-box; /* 2 */
347 | box-sizing: content-box;
348 | }
349 |
350 | /**
351 | * Remove inner padding and search cancel button in Safari and Chrome on OS X.
352 | * Safari (but not Chrome) clips the cancel button when the search input has
353 | * padding (and `textfield` appearance).
354 | */
355 |
356 | input[type="search"]::-webkit-search-cancel-button,
357 | input[type="search"]::-webkit-search-decoration {
358 | -webkit-appearance: none;
359 | }
360 |
361 | /**
362 | * Define consistent border, margin, and padding.
363 | */
364 |
365 | fieldset {
366 | border: 1px solid #c0c0c0;
367 | margin: 0 2px;
368 | padding: 0.35em 0.625em 0.75em;
369 | }
370 |
371 | /**
372 | * 1. Correct `color` not being inherited in IE 8/9/10/11.
373 | * 2. Remove padding so people aren't caught out if they zero out fieldsets.
374 | */
375 |
376 | legend {
377 | border: 0; /* 1 */
378 | padding: 0; /* 2 */
379 | }
380 |
381 | /**
382 | * Remove default vertical scrollbar in IE 8/9/10/11.
383 | */
384 |
385 | textarea {
386 | overflow: auto;
387 | }
388 |
389 | /**
390 | * Don't inherit the `font-weight` (applied by a rule above).
391 | * NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
392 | */
393 |
394 | optgroup {
395 | font-weight: bold;
396 | }
397 |
398 | /* Tables
399 | ========================================================================== */
400 |
401 | /**
402 | * Remove most spacing between table cells.
403 | */
404 |
405 | table {
406 | border-collapse: collapse;
407 | border-spacing: 0;
408 | }
409 |
410 | td,
411 | th {
412 | padding: 0;
413 | }
--------------------------------------------------------------------------------
/richeditor/src/main/assets/rich_editor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 Wasabeef
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | var RE = {};
18 |
19 | RE.currentSelection = {
20 | "startContainer": 0,
21 | "startOffset": 0,
22 | "endContainer": 0,
23 | "endOffset": 0};
24 |
25 | RE.editor = document.getElementById('editor');
26 |
27 | document.addEventListener("selectionchange", function() { RE.backuprange(); });
28 |
29 | // Initializations
30 | RE.callback = function() {
31 | window.location.href = "re-callback://" + encodeURI(RE.getHtml());
32 | }
33 |
34 | RE.setHtml = function(contents) {
35 | RE.editor.innerHTML = decodeURIComponent(contents.replace(/\+/g, '%20'));
36 | }
37 |
38 | RE.getHtml = function() {
39 | return RE.editor.innerHTML;
40 | }
41 |
42 | RE.getText = function() {
43 | return RE.editor.innerText;
44 | }
45 |
46 | RE.setBaseTextColor = function(color) {
47 | RE.editor.style.color = color;
48 | }
49 |
50 | RE.setBaseFontSize = function(size) {
51 | RE.editor.style.fontSize = size;
52 | }
53 |
54 | RE.setPadding = function(left, top, right, bottom) {
55 | RE.editor.style.paddingLeft = left;
56 | RE.editor.style.paddingTop = top;
57 | RE.editor.style.paddingRight = right;
58 | RE.editor.style.paddingBottom = bottom;
59 | }
60 |
61 | RE.setBackgroundColor = function(color) {
62 | document.body.style.backgroundColor = color;
63 | }
64 |
65 | RE.setBackgroundImage = function(image) {
66 | RE.editor.style.backgroundImage = image;
67 | }
68 |
69 | RE.setWidth = function(size) {
70 | RE.editor.style.minWidth = size;
71 | }
72 |
73 | RE.setHeight = function(size) {
74 | document.body.style.minHeight = size;
75 | }
76 |
77 | RE.setTextAlign = function(align) {
78 | RE.editor.style.textAlign = align;
79 | }
80 |
81 | RE.setVerticalAlign = function(align) {
82 | RE.editor.style.verticalAlign = align;
83 | }
84 |
85 | RE.setPlaceholder = function(placeholder) {
86 | RE.editor.setAttribute("placeholder", placeholder);
87 | }
88 |
89 | RE.undo = function() {
90 | document.execCommand('undo', false, null);
91 | }
92 |
93 | RE.redo = function() {
94 | document.execCommand('redo', false, null);
95 | }
96 |
97 | RE.setBold = function() {
98 | document.execCommand('bold', false, null);
99 | }
100 |
101 | RE.setItalic = function() {
102 | document.execCommand('italic', false, null);
103 | }
104 |
105 | RE.setSubscript = function() {
106 | document.execCommand('subscript', false, null);
107 | }
108 |
109 | RE.setSuperscript = function() {
110 | document.execCommand('superscript', false, null);
111 | }
112 |
113 | RE.setStrikeThrough = function() {
114 | document.execCommand('strikeThrough', false, null);
115 | }
116 |
117 | RE.setUnderline = function() {
118 | document.execCommand('underline', false, null);
119 | }
120 |
121 | RE.setBullets = function() {
122 | document.execCommand('InsertUnorderedList', false, null);
123 | }
124 |
125 | RE.setNumbers = function() {
126 | document.execCommand('InsertOrderedList', false, null);
127 | }
128 |
129 | RE.setTextColor = function(color) {
130 | RE.restorerange();
131 | document.execCommand("styleWithCSS", null, true);
132 | document.execCommand('foreColor', false, color);
133 | document.execCommand("styleWithCSS", null, false);
134 | }
135 |
136 | RE.setTextBackgroundColor = function(color) {
137 | RE.restorerange();
138 | document.execCommand("styleWithCSS", null, true);
139 | document.execCommand('hiliteColor', false, color);
140 | document.execCommand("styleWithCSS", null, false);
141 | }
142 |
143 | RE.setFontSize = function(fontSize){
144 | document.execCommand("fontSize", false, fontSize);
145 | }
146 |
147 | RE.setHeading = function(heading) {
148 | document.execCommand('formatBlock', false, '');
149 | }
150 |
151 | RE.setIndent = function() {
152 | document.execCommand('indent', false, null);
153 | }
154 |
155 | RE.setOutdent = function() {
156 | document.execCommand('outdent', false, null);
157 | }
158 |
159 | RE.setJustifyLeft = function() {
160 | document.execCommand('justifyLeft', false, null);
161 | }
162 |
163 | RE.setJustifyCenter = function() {
164 | document.execCommand('justifyCenter', false, null);
165 | }
166 |
167 | RE.setJustifyRight = function() {
168 | document.execCommand('justifyRight', false, null);
169 | }
170 |
171 | RE.setBlockquote = function() {
172 | document.execCommand('formatBlock', false, '
');
173 | }
174 |
175 | RE.insertImage = function(url, alt) {
176 | var html = '';
177 | RE.insertHTML(html);
178 | }
179 |
180 | RE.insertHTML = function(html) {
181 | RE.restorerange();
182 | document.execCommand('insertHTML', false, html);
183 | }
184 |
185 | RE.insertLink = function(url, title) {
186 | RE.restorerange();
187 | var sel = document.getSelection();
188 | if (sel.toString().length == 0) {
189 | document.execCommand("insertHTML",false,""+title+"");
190 | } else if (sel.rangeCount) {
191 | var el = document.createElement("a");
192 | el.setAttribute("href", url);
193 | el.setAttribute("title", title);
194 |
195 | var range = sel.getRangeAt(0).cloneRange();
196 | range.surroundContents(el);
197 | sel.removeAllRanges();
198 | sel.addRange(range);
199 | }
200 | RE.callback();
201 | }
202 |
203 | RE.setTodo = function(text) {
204 | var html = ' ';
205 | document.execCommand('insertHTML', false, html);
206 | }
207 |
208 | RE.prepareInsert = function() {
209 | RE.backuprange();
210 | }
211 |
212 | RE.backuprange = function(){
213 | var selection = window.getSelection();
214 | if (selection.rangeCount > 0) {
215 | var range = selection.getRangeAt(0);
216 | RE.currentSelection = {
217 | "startContainer": range.startContainer,
218 | "startOffset": range.startOffset,
219 | "endContainer": range.endContainer,
220 | "endOffset": range.endOffset};
221 | }
222 | }
223 |
224 | RE.restorerange = function(){
225 | var selection = window.getSelection();
226 | selection.removeAllRanges();
227 | var range = document.createRange();
228 | range.setStart(RE.currentSelection.startContainer, RE.currentSelection.startOffset);
229 | range.setEnd(RE.currentSelection.endContainer, RE.currentSelection.endOffset);
230 | selection.addRange(range);
231 | }
232 |
233 | RE.enabledEditingItems = function(e) {
234 | var items = [];
235 | if (document.queryCommandState('bold')) {
236 | items.push('bold');
237 | }
238 | if (document.queryCommandState('italic')) {
239 | items.push('italic');
240 | }
241 | if (document.queryCommandState('subscript')) {
242 | items.push('subscript');
243 | }
244 | if (document.queryCommandState('superscript')) {
245 | items.push('superscript');
246 | }
247 | if (document.queryCommandState('strikeThrough')) {
248 | items.push('strikeThrough');
249 | }
250 | if (document.queryCommandState('underline')) {
251 | items.push('underline');
252 | }
253 | if (document.queryCommandState('insertOrderedList')) {
254 | items.push('orderedList');
255 | }
256 | if (document.queryCommandState('insertUnorderedList')) {
257 | items.push('unorderedList');
258 | }
259 | if (document.queryCommandState('justifyCenter')) {
260 | items.push('justifyCenter');
261 | }
262 | if (document.queryCommandState('justifyFull')) {
263 | items.push('justifyFull');
264 | }
265 | if (document.queryCommandState('justifyLeft')) {
266 | items.push('justifyLeft');
267 | }
268 | if (document.queryCommandState('justifyRight')) {
269 | items.push('justifyRight');
270 | }
271 | if (document.queryCommandState('insertHorizontalRule')) {
272 | items.push('horizontalRule');
273 | }
274 | var formatBlock = document.queryCommandValue('formatBlock');
275 | if (formatBlock.length > 0) {
276 | items.push(formatBlock);
277 | }
278 |
279 | window.location.href = "re-state://" + encodeURI(items.join(','));
280 | }
281 |
282 | RE.focus = function() {
283 | var range = document.createRange();
284 | range.selectNodeContents(RE.editor);
285 | range.collapse(false);
286 | var selection = window.getSelection();
287 | selection.removeAllRanges();
288 | selection.addRange(range);
289 | RE.editor.focus();
290 | }
291 |
292 | RE.blurFocus = function() {
293 | RE.editor.blur();
294 | }
295 |
296 | RE.removeFormat = function() {
297 | execCommand('removeFormat', false, null);
298 | }
299 |
300 | // Event Listeners
301 | RE.editor.addEventListener("input", RE.callback);
302 | RE.editor.addEventListener("keyup", function(e) {
303 | var KEY_LEFT = 37, KEY_RIGHT = 39;
304 | if (e.which == KEY_LEFT || e.which == KEY_RIGHT) {
305 | RE.enabledEditingItems(e);
306 | }
307 | });
308 | RE.editor.addEventListener("click", RE.enabledEditingItems);
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/richeditor/src/main/java/jp/wasabeef/richeditor/RichEditor.java:
--------------------------------------------------------------------------------
1 | package jp.wasabeef.richeditor;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.TypedArray;
6 | import android.graphics.Bitmap;
7 | import android.graphics.drawable.Drawable;
8 | import android.os.Build;
9 | import android.text.TextUtils;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.Gravity;
13 | import android.webkit.WebChromeClient;
14 | import android.webkit.WebView;
15 | import android.webkit.WebViewClient;
16 | import java.io.UnsupportedEncodingException;
17 | import java.net.URLDecoder;
18 | import java.net.URLEncoder;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import java.util.Locale;
22 |
23 | /**
24 | * Copyright (C) 2015 Wasabeef
25 | *
26 | * Licensed under the Apache License, Version 2.0 (the "License");
27 | * you may not use this file except in compliance with the License.
28 | * You may obtain a copy of the License at
29 | *
30 | * http://www.apache.org/licenses/LICENSE-2.0
31 | *
32 | * Unless required by applicable law or agreed to in writing, software
33 | * distributed under the License is distributed on an "AS IS" BASIS,
34 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 | * See the License for the specific language governing permissions and
36 | * limitations under the License.
37 | */
38 |
39 | public class RichEditor extends WebView {
40 |
41 | public enum Type {
42 | BOLD,
43 | ITALIC,
44 | SUBSCRIPT,
45 | SUPERSCRIPT,
46 | STRIKETHROUGH,
47 | UNDERLINE,
48 | H1,
49 | H2,
50 | H3,
51 | H4,
52 | H5,
53 | H6
54 | }
55 |
56 | public interface OnTextChangeListener {
57 |
58 | void onTextChange(String text);
59 | }
60 |
61 | public interface OnDecorationStateListener {
62 |
63 | void onStateChangeListener(String text, List types);
64 | }
65 |
66 | public interface AfterInitialLoadListener {
67 |
68 | void onAfterInitialLoad(boolean isReady);
69 | }
70 |
71 | private static final String SETUP_HTML = "file:///android_asset/editor.html";
72 | private static final String CALLBACK_SCHEME = "re-callback://";
73 | private static final String STATE_SCHEME = "re-state://";
74 | private boolean isReady = false;
75 | private String mContents;
76 | private OnTextChangeListener mTextChangeListener;
77 | private OnDecorationStateListener mDecorationStateListener;
78 | private AfterInitialLoadListener mLoadListener;
79 |
80 | public RichEditor(Context context) {
81 | this(context, null);
82 | }
83 |
84 | public RichEditor(Context context, AttributeSet attrs) {
85 | this(context, attrs, android.R.attr.webViewStyle);
86 | }
87 |
88 | @SuppressLint("SetJavaScriptEnabled")
89 | public RichEditor(Context context, AttributeSet attrs, int defStyleAttr) {
90 | super(context, attrs, defStyleAttr);
91 |
92 | setVerticalScrollBarEnabled(false);
93 | setHorizontalScrollBarEnabled(false);
94 | getSettings().setJavaScriptEnabled(true);
95 | setWebChromeClient(new WebChromeClient());
96 | setWebViewClient(createWebviewClient());
97 | loadUrl(SETUP_HTML);
98 |
99 | applyAttributes(context, attrs);
100 | }
101 |
102 | protected EditorWebViewClient createWebviewClient() {
103 | return new EditorWebViewClient();
104 | }
105 |
106 | public void setOnTextChangeListener(OnTextChangeListener listener) {
107 | mTextChangeListener = listener;
108 | }
109 |
110 | public void setOnDecorationChangeListener(OnDecorationStateListener listener) {
111 | mDecorationStateListener = listener;
112 | }
113 |
114 | public void setOnInitialLoadListener(AfterInitialLoadListener listener) {
115 | mLoadListener = listener;
116 | }
117 |
118 | private void callback(String text) {
119 | mContents = text.replaceFirst(CALLBACK_SCHEME, "");
120 | if (mTextChangeListener != null) {
121 | mTextChangeListener.onTextChange(mContents);
122 | }
123 | }
124 |
125 | private void stateCheck(String text) {
126 | String state = text.replaceFirst(STATE_SCHEME, "").toUpperCase(Locale.ENGLISH);
127 | List types = new ArrayList<>();
128 | for (Type type : Type.values()) {
129 | if (TextUtils.indexOf(state, type.name()) != -1) {
130 | types.add(type);
131 | }
132 | }
133 |
134 | if (mDecorationStateListener != null) {
135 | mDecorationStateListener.onStateChangeListener(state, types);
136 | }
137 | }
138 |
139 | private void applyAttributes(Context context, AttributeSet attrs) {
140 | final int[] attrsArray = new int[] {
141 | android.R.attr.gravity
142 | };
143 | TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
144 |
145 | int gravity = ta.getInt(0, NO_ID);
146 | switch (gravity) {
147 | case Gravity.LEFT:
148 | exec("javascript:RE.setTextAlign(\"left\")");
149 | break;
150 | case Gravity.RIGHT:
151 | exec("javascript:RE.setTextAlign(\"right\")");
152 | break;
153 | case Gravity.TOP:
154 | exec("javascript:RE.setVerticalAlign(\"top\")");
155 | break;
156 | case Gravity.BOTTOM:
157 | exec("javascript:RE.setVerticalAlign(\"bottom\")");
158 | break;
159 | case Gravity.CENTER_VERTICAL:
160 | exec("javascript:RE.setVerticalAlign(\"middle\")");
161 | break;
162 | case Gravity.CENTER_HORIZONTAL:
163 | exec("javascript:RE.setTextAlign(\"center\")");
164 | break;
165 | case Gravity.CENTER:
166 | exec("javascript:RE.setVerticalAlign(\"middle\")");
167 | exec("javascript:RE.setTextAlign(\"center\")");
168 | break;
169 | }
170 |
171 | ta.recycle();
172 | }
173 |
174 | public void setHtml(String contents) {
175 | if (contents == null) {
176 | contents = "";
177 | }
178 | try {
179 | exec("javascript:RE.setHtml('" + URLEncoder.encode(contents, "UTF-8") + "');");
180 | } catch (UnsupportedEncodingException e) {
181 | // No handling
182 | }
183 | mContents = contents;
184 | }
185 |
186 | public String getHtml() {
187 | return mContents;
188 | }
189 |
190 | public void setEditorFontColor(int color) {
191 | String hex = convertHexColorString(color);
192 | exec("javascript:RE.setBaseTextColor('" + hex + "');");
193 | }
194 |
195 | public void setEditorFontSize(int px) {
196 | exec("javascript:RE.setBaseFontSize('" + px + "px');");
197 | }
198 |
199 | @Override public void setPadding(int left, int top, int right, int bottom) {
200 | super.setPadding(left, top, right, bottom);
201 | exec("javascript:RE.setPadding('" + left + "px', '" + top + "px', '" + right + "px', '" + bottom
202 | + "px');");
203 | }
204 |
205 | @Override public void setPaddingRelative(int start, int top, int end, int bottom) {
206 | // still not support RTL.
207 | setPadding(start, top, end, bottom);
208 | }
209 |
210 | public void setEditorBackgroundColor(int color) {
211 | setBackgroundColor(color);
212 | }
213 |
214 | @Override public void setBackgroundColor(int color) {
215 | super.setBackgroundColor(color);
216 | }
217 |
218 | @Override public void setBackgroundResource(int resid) {
219 | Bitmap bitmap = Utils.decodeResource(getContext(), resid);
220 | String base64 = Utils.toBase64(bitmap);
221 | bitmap.recycle();
222 |
223 | exec("javascript:RE.setBackgroundImage('url(data:image/png;base64," + base64 + ")');");
224 | }
225 |
226 | @Override public void setBackground(Drawable background) {
227 | Bitmap bitmap = Utils.toBitmap(background);
228 | String base64 = Utils.toBase64(bitmap);
229 | bitmap.recycle();
230 |
231 | exec("javascript:RE.setBackgroundImage('url(data:image/png;base64," + base64 + ")');");
232 | }
233 |
234 | public void setBackground(String url) {
235 | exec("javascript:RE.setBackgroundImage('url(" + url + ")');");
236 | }
237 |
238 | public void setEditorWidth(int px) {
239 | exec("javascript:RE.setWidth('" + px + "px');");
240 | }
241 |
242 | public void setEditorHeight(int px) {
243 | exec("javascript:RE.setHeight('" + px + "px');");
244 | }
245 |
246 | public void setPlaceholder(String placeholder) {
247 | exec("javascript:RE.setPlaceholder('" + placeholder + "');");
248 | }
249 |
250 | public void loadCSS(String cssFile) {
251 | String jsCSSImport = "(function() {" +
252 | " var head = document.getElementsByTagName(\"head\")[0];" +
253 | " var link = document.createElement(\"link\");" +
254 | " link.rel = \"stylesheet\";" +
255 | " link.type = \"text/css\";" +
256 | " link.href = \"" + cssFile + "\";" +
257 | " link.media = \"all\";" +
258 | " head.appendChild(link);" +
259 | "}) ();";
260 | exec("javascript:" + jsCSSImport + "");
261 | }
262 |
263 | public void undo() {
264 | exec("javascript:RE.undo();");
265 | }
266 |
267 | public void redo() {
268 | exec("javascript:RE.redo();");
269 | }
270 |
271 | public void setBold() {
272 | exec("javascript:RE.setBold();");
273 | }
274 |
275 | public void setItalic() {
276 | exec("javascript:RE.setItalic();");
277 | }
278 |
279 | public void setSubscript() {
280 | exec("javascript:RE.setSubscript();");
281 | }
282 |
283 | public void setSuperscript() {
284 | exec("javascript:RE.setSuperscript();");
285 | }
286 |
287 | public void setStrikeThrough() {
288 | exec("javascript:RE.setStrikeThrough();");
289 | }
290 |
291 | public void setUnderline() {
292 | exec("javascript:RE.setUnderline();");
293 | }
294 |
295 | public void setTextColor(int color) {
296 | exec("javascript:RE.prepareInsert();");
297 |
298 | String hex = convertHexColorString(color);
299 | exec("javascript:RE.setTextColor('" + hex + "');");
300 | }
301 |
302 | public void setTextBackgroundColor(int color) {
303 | exec("javascript:RE.prepareInsert();");
304 |
305 | String hex = convertHexColorString(color);
306 | exec("javascript:RE.setTextBackgroundColor('" + hex + "');");
307 | }
308 |
309 | public void setFontSize(int fontSize) {
310 | if (fontSize > 7 || fontSize < 1) {
311 | Log.e("RichEditor", "Font size should have a value between 1-7");
312 | }
313 | exec("javascript:RE.setFontSize('" + fontSize + "');");
314 | }
315 |
316 | public void removeFormat() {
317 | exec("javascript:RE.removeFormat();");
318 | }
319 |
320 | public void setHeading(int heading) {
321 | exec("javascript:RE.setHeading('" + heading + "');");
322 | }
323 |
324 | public void setIndent() {
325 | exec("javascript:RE.setIndent();");
326 | }
327 |
328 | public void setOutdent() {
329 | exec("javascript:RE.setOutdent();");
330 | }
331 |
332 | public void setAlignLeft() {
333 | exec("javascript:RE.setJustifyLeft();");
334 | }
335 |
336 | public void setAlignCenter() {
337 | exec("javascript:RE.setJustifyCenter();");
338 | }
339 |
340 | public void setAlignRight() {
341 | exec("javascript:RE.setJustifyRight();");
342 | }
343 |
344 | public void setBlockquote() {
345 | exec("javascript:RE.setBlockquote();");
346 | }
347 |
348 | public void setBullets() {
349 | exec("javascript:RE.setBullets();");
350 | }
351 |
352 | public void setNumbers() {
353 | exec("javascript:RE.setNumbers();");
354 | }
355 |
356 | public void insertImage(String url, String alt) {
357 | exec("javascript:RE.prepareInsert();");
358 | exec("javascript:RE.insertImage('" + url + "', '" + alt + "');");
359 | }
360 |
361 | public void insertLink(String href, String title) {
362 | exec("javascript:RE.prepareInsert();");
363 | exec("javascript:RE.insertLink('" + href + "', '" + title + "');");
364 | }
365 |
366 | public void insertTodo() {
367 | exec("javascript:RE.prepareInsert();");
368 | exec("javascript:RE.setTodo('" + Utils.getCurrentTime() + "');");
369 | }
370 |
371 | public void focusEditor() {
372 | requestFocus();
373 | exec("javascript:RE.focus();");
374 | }
375 |
376 | public void clearFocusEditor() {
377 | exec("javascript:RE.blurFocus();");
378 | }
379 |
380 | private String convertHexColorString(int color) {
381 | return String.format("#%06X", (0xFFFFFF & color));
382 | }
383 |
384 | protected void exec(final String trigger) {
385 | if (isReady) {
386 | load(trigger);
387 | } else {
388 | postDelayed(new Runnable() {
389 | @Override public void run() {
390 | exec(trigger);
391 | }
392 | }, 100);
393 | }
394 | }
395 |
396 | private void load(String trigger) {
397 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
398 | evaluateJavascript(trigger, null);
399 | } else {
400 | loadUrl(trigger);
401 | }
402 | }
403 |
404 | protected class EditorWebViewClient extends WebViewClient {
405 | @Override public void onPageFinished(WebView view, String url) {
406 | isReady = url.equalsIgnoreCase(SETUP_HTML);
407 | if (mLoadListener != null) {
408 | mLoadListener.onAfterInitialLoad(isReady);
409 | }
410 | }
411 |
412 | @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
413 | String decode;
414 | try {
415 | decode = URLDecoder.decode(url, "UTF-8");
416 | } catch (UnsupportedEncodingException e) {
417 | // No handling
418 | return false;
419 | }
420 |
421 | if (TextUtils.indexOf(url, CALLBACK_SCHEME) == 0) {
422 | callback(decode);
423 | return true;
424 | } else if (TextUtils.indexOf(url, STATE_SCHEME) == 0) {
425 | stateCheck(decode);
426 | return true;
427 | }
428 |
429 | return super.shouldOverrideUrlLoading(view, url);
430 | }
431 | }
432 | }
--------------------------------------------------------------------------------