";
19 |
20 | Assert.assertEquals(test, decoded);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 |
6 | defaultConfig {
7 | minSdkVersion MIN_SDK_VERSION as int
8 | targetSdkVersion TARGET_SDK_VERSION as int
9 | versionCode VERSION_CODE as int
10 | versionName VERSION_NAME
11 | }
12 |
13 | // SigningConfigs
14 | apply from: '../signingConfigs/debug.gradle', to: android
15 | apply from: '../signingConfigs/release.gradle', to: android
16 |
17 | buildTypes {
18 | debug {
19 | debuggable true
20 | zipAlignEnabled true
21 | signingConfig signingConfigs.debug
22 | }
23 | release {
24 | debuggable false
25 | zipAlignEnabled true
26 | minifyEnabled true
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | shrinkResources true
29 | signingConfig signingConfigs.release
30 | }
31 | }
32 | }
33 |
34 | repositories {
35 | // maven { url = "https://oss.sonatype.org/content/repositories/snapshots"}
36 | }
37 |
38 | dependencies {
39 | implementation project(':richeditor')
40 | implementation "androidx.appcompat:appcompat:1.2.0"
41 | }
42 |
--------------------------------------------------------------------------------
/richeditor/src/main/assets/style.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2020 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: scroll;
26 | display: table;
27 | table-layout: fixed;
28 | width: 100%;
29 | min-height:100%;
30 | }
31 |
32 | #editor {
33 | display: table-cell;
34 | outline: 0px solid transparent;
35 | background-repeat: no-repeat;
36 | background-position: center;
37 | background-size: cover;
38 | }
39 |
40 | #editor[placeholder]:empty:not(:focus):before {
41 | content: attr(placeholder);
42 | opacity: .5;
43 | }
44 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | org.gradle.parallel=true
14 | org.gradle.daemon=true
15 | org.gradle.configureondemand=true
16 | org.gradle.caching=true
17 | android.enableBuildCache=true
18 | android.useAndroidX=true
19 | android.enableJetifier=true
20 | android.enableR8.fullMode=true
21 |
22 | VERSION_NAME=2.0.0
23 | VERSION_CODE=200
24 | GROUP=jp.wasabeef
25 | ARTIFACT_ID=richeditor-android
26 | COMPILE_SDK_VERSION=30
27 | TARGET_SDK_VERSION=30
28 | MIN_SDK_VERSION=14
29 |
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Mac OS
2 | .DS_store
3 |
4 | # Built application files
5 | *.apk
6 | *.ap_
7 |
8 | # Files for the ART/Dalvik VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # Generated files
15 | bin/
16 | gen/
17 | out/
18 |
19 | # Gradle files
20 | .gradle/
21 | build/
22 |
23 | # Local configuration file (sdk path, etc)
24 | local.properties
25 |
26 | # Proguard folder generated by Eclipse
27 | proguard/
28 |
29 | # Log Files
30 | *.log
31 |
32 | # Android Studio Navigation editor temp files
33 | .navigation/
34 |
35 | # Android Studio captures folder
36 | captures/
37 |
38 | # IntelliJ
39 | *.iml
40 | .idea/workspace.xml
41 | .idea/tasks.xml
42 | .idea/gradle.xml
43 | .idea/assetWizardSettings.xml
44 | .idea/dictionaries
45 | .idea/libraries
46 | .idea/caches
47 | .idea/misc.xml
48 | .idea/modules.xml
49 | .idea/navEditor.xml
50 | .idea/markdown*
51 | .idea/jarRepositories.xml
52 | .idea/inspectionProfiles/Project_Default.xml
53 | .idea/compiler.xml
54 | .idea/vcs.xml
55 | projectFilesBackup/
56 |
57 | # Keystore files
58 | # Uncomment the following line if you do not want to check your keystore files in.
59 | #*.jks
60 |
61 | # External native build folder generated in Android Studio 2.2 and later
62 | .externalNativeBuild
63 |
64 | # Google Services (e.g. APIs or Firebase)
65 | google-services.json
66 |
67 |
--------------------------------------------------------------------------------
/richeditor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 |
6 | defaultConfig {
7 | minSdkVersion MIN_SDK_VERSION as int
8 | targetSdkVersion TARGET_SDK_VERSION as int
9 | versionCode VERSION_CODE as int
10 | versionName VERSION_NAME
11 | }
12 | }
13 |
14 |
15 | dependencies {
16 | testImplementation "junit:junit:4.13"
17 | testImplementation "org.robolectric:robolectric:4.3.1"
18 | }
19 |
20 | ext {
21 | bintrayRepo = 'maven'
22 | bintrayName = 'richeditor-android'
23 | bintrayUserOrg = 'wasabeef'
24 | publishedGroupId = 'jp.wasabeef'
25 | libraryName = 'richeditor-android'
26 | artifact = 'richeditor-android'
27 | libraryDescription = 'RichEditor for Android is a beautiful Rich Text WYSIWYG Editor'
28 | siteUrl = 'https://github.com/richeditor-android'
29 | gitUrl = 'https://github.com/richeditor-android.git'
30 | issueUrl = 'https://github.com/richeditor-android/issues'
31 | libraryVersion = VERSION_NAME
32 | developerId = 'wasabeef'
33 | developerName = 'Wasabeef'
34 | developerEmail = 'dadadada.chop@gmail.com'
35 | licenseName = 'The Apache Software License, Version 2.0'
36 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
37 | allLicenses = ["Apache-2.0"]
38 | }
39 |
40 | // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
41 | // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
42 | // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'
43 |
44 | apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle'
45 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 2.0.0 *(2020-09-16)*
5 | ----------------------------
6 |
7 | Feature:
8 | - Supported Image can set size params [#176](https://github.com/wasabeef/richeditor-android/pull/176)
9 | - Supported Youtube, Video, Audio tag [#189](https://github.com/wasabeef/richeditor-android/pull/189)
10 |
11 | Update:
12 | - Compile / Target SDK Version 25 -> 30
13 | - [Normalize.css](https://necolas.github.io/normalize.css/) to 8.0.1
14 |
15 | Bugfix:
16 | - Fixed placeholder [#240](https://github.com/wasabeef/richeditor-android/pull/240)
17 | - Fixed typp [#194](https://github.com/wasabeef/richeditor-android/pull/194)
18 | - Fixed Url decoding [#123](https://github.com/wasabeef/richeditor-android/pull/123)
19 | - Fixed shouldOverrideUrlLoading [#133](https://github.com/wasabeef/richeditor-android/pull/133)
20 | - Use encodeURIComponent() [#145](https://github.com/wasabeef/richeditor-android/pull/145)
21 |
22 | Version 1.2.2 *(2017-03-21)*
23 | ----------------------------
24 |
25 | Feature:
26 | - [Add ability to disable input on editor making it readonly #101](https://github.com/wasabeef/richeditor-android/pull/101)
27 |
28 | Update:
29 | - Compile / Target SDK Version 23 -> 25
30 | - Build Tools 24.0.2 -> 25.0.2
31 | - Support Library 23.4.0 -> 25.3.0
32 |
33 | Bug Fix:
34 | - [Fixed missing document for removeFormat #99](https://github.com/wasabeef/richeditor-android/pull/99)
35 | - [Additional resource cleanup in RSBlur #45](https://github.com/wasabeef/richeditor-android/pull/99)
36 |
37 | Version 1.2.1 *(2016-08-04)*
38 | ----------------------------
39 | Merge: Fixed some type missing https://github.com/wasabeef/richeditor-android/pull/63
40 | Change: Samples
41 |
42 | Version 1.2.0 *(2016-01-07)*
43 | ----------------------------
44 | Merge: Feature fontSize https://github.com/wasabeef/richeditor-android/pull/42
45 |
46 | Version 1.1.0 *(2016-01-07)*
47 | ----------------------------
48 | Merge: https://github.com/wasabeef/richeditor-android/pull/37
49 |
50 | Version 1.0.0 *(2015-11-10)*
51 | ----------------------------
52 |
53 | Product Release
54 |
--------------------------------------------------------------------------------
/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 |
11 | import java.io.ByteArrayOutputStream;
12 |
13 | /**
14 | * Copyright (C) 2020 Wasabeef
15 | *
16 | * Licensed under the Apache License, Version 2.0 (the "License");
17 | * you may not use this file except in compliance with the License.
18 | * You may obtain a copy of the License at
19 | *
22 | * Unless required by applicable law or agreed to in writing, software
23 | * distributed under the License is distributed on an "AS IS" BASIS,
24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 | * See the License for the specific language governing permissions and
26 | * limitations under the License.
27 | */
28 |
29 | public final class Utils {
30 |
31 | private Utils() throws InstantiationException {
32 | throw new InstantiationException("This class is not for instantiation");
33 | }
34 |
35 | public static String toBase64(Bitmap bitmap) {
36 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
37 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
38 | byte[] bytes = baos.toByteArray();
39 |
40 | return Base64.encodeToString(bytes, Base64.NO_WRAP);
41 | }
42 |
43 | public static Bitmap toBitmap(Drawable drawable) {
44 | if (drawable instanceof BitmapDrawable) {
45 | return ((BitmapDrawable) drawable).getBitmap();
46 | }
47 |
48 | int width = drawable.getIntrinsicWidth();
49 | width = width > 0 ? width : 1;
50 | int height = drawable.getIntrinsicHeight();
51 | height = height > 0 ? height : 1;
52 |
53 | Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
54 | Canvas canvas = new Canvas(bitmap);
55 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
56 | drawable.draw(canvas);
57 |
58 | return bitmap;
59 | }
60 |
61 | public static Bitmap decodeResource(Context context, int resId) {
62 | return BitmapFactory.decodeResource(context.getResources(), resId);
63 | }
64 |
65 | public static long getCurrentTime() {
66 | return System.currentTimeMillis();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
17 |
18 | `RichEditor for Android` is a beautiful Rich Text `WYSIWYG Editor` for `Android`.
19 |
20 | - _Looking for iOS? Check out_ [cjwirth/RichEditorView](https://github.com/cjwirth/RichEditorView)
21 |
22 | Supported Functions
23 | ---
24 |
25 | 
26 |
27 | - [x] Bold
28 | - [x] Italic
29 | - [x] Subscript
30 | - [x] Superscript
31 | - [x] Strikethrough
32 | - [x] Underline
33 | - [x] Justify Left
34 | - [x] Justify Center
35 | - [x] Justify Right
36 | - [x] Blockquote
37 | - [x] Heading 1
38 | - [x] Heading 2
39 | - [x] Heading 3
40 | - [x] Heading 4
41 | - [x] Heading 5
42 | - [x] Heading 6
43 | - [x] Undo
44 | - [x] Redo
45 | - [x] Indent
46 | - [x] Outdent
47 | - [x] Insert Image
48 | - [x] Insert Youtube
49 | - [x] Insert Video
50 | - [x] Insert Audio
51 | - [x] Insert Link
52 | - [x] Checkbox
53 | - [x] Text Color
54 | - [x] Text Background Color
55 | - [x] Text Font Size
56 | - [x] Unordered List (Bullets)
57 | - [x] Ordered List (Numbers)
58 |
59 | Attribute change of editor
60 | ---
61 | - [x] Font Size
62 | - [x] Background Color
63 | - [x] Width
64 | - [x] Height
65 | - [x] Placeholder
66 | - [x] Load CSS
67 | - [x] State Callback
68 |
69 | **Milestone**
70 |
71 | - [ ] Font Family
72 |
73 | Demo
74 | ---
75 |
76 | 
77 |
78 | How do I use it?
79 | ---
80 |
81 | ### Setup
82 |
83 | ##### Gradle
84 | ```groovy
85 | repositories {
86 | mavenCentral()
87 | }
88 |
89 | dependencies {
90 | implementation 'jp.wasabeef:richeditor-android:2.0.0'
91 | }
92 | ```
93 | ### Default Setting for Editor
94 | ---
95 |
96 | **Height**
97 | ```java
98 | editor.setEditorHeight(200);
99 | ```
100 |
101 | **Font**
102 | ```java
103 | editor.setEditorFontSize(22);
104 | editor.setEditorFontColor(Color.RED);
105 | ```
106 |
107 | **Background**
108 | ```java
109 | editor.setEditorBackgroundColor(Color.BLUE);
110 | editor.setBackgroundColor(Color.BLUE);
111 | editor.setBackgroundResource(R.drawable.bg);
112 | editor.setBackground("https://raw.githubusercontent.com/wasabeef/art/master/chip.jpg");
113 | ```
114 |
115 | **Padding**
116 | ```java
117 | editor.setPadding(10, 10, 10, 10);
118 | ```
119 |
120 | **Placeholder**
121 | ```java
122 | editor.setPlaceholder("Insert text here...");
123 | ```
124 |
125 | **Others**
126 | Please refer the [samples](https://github.com/wasabeef/richeditor-android/blob/master/sample/src/main/java/jp/wasabeef/sample/MainActivity.java) for usage.
127 |
128 | ### Functions for ContentEditable
129 | ---
130 |
131 | **Bold**
132 | ```java
133 | editor.setBold();
134 | ```
135 |
136 | **Italic**
137 | ```java
138 | editor.setItalic();
139 | ```
140 |
141 | **Insert Image**
142 | ```java
143 | editor.insertImage("https://raw.githubusercontent.com/wasabeef/art/master/twitter.png","twitter");
144 | ```
145 |
146 | **Text Change Listener**
147 | ```java
148 | RichEditor editor = (RichEditor) findViewById(R.id.editor);
149 | editor. setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
150 | @Override
151 | public void onTextChange(String text) {
152 | // Do Something
153 | Log.d("RichEditor", "Preview " + text);
154 | }
155 | });
156 | ```
157 |
158 | **Others**
159 | Please refer the [samples](https://github.com/wasabeef/richeditor-android/blob/master/sample/src/main/java/jp/wasabeef/sample/MainActivity.java) for usage.
160 |
161 | Requirements
162 | --------------
163 | Android 4+
164 |
165 | Applications using RichEditor for Android
166 | ---
167 |
168 | Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here.
169 |
170 | Icon | Application
171 | ------------ | -------------
172 | | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid)
173 | | [ScorePal](https://play.google.com/store/apps/details?id=com.hfd.scorepal)
174 |
175 | Developed By
176 | -------
177 | Daichi Furiya (Wasabeef) -
178 |
179 |
180 |
182 |
183 |
184 | Thanks
185 | -------
186 |
187 | * Inspired by `ZSSRichTextEditor` in [nnhubbard](https://github.com/nnhubbard/ZSSRichTextEditor).
188 |
189 | License
190 | -------
191 |
192 | Copyright (C) 2020 Wasabeef
193 |
194 | Licensed under the Apache License, Version 2.0 (the "License");
195 | you may not use this file except in compliance with the License.
196 | You may obtain a copy of the License at
197 |
198 | http://www.apache.org/licenses/LICENSE-2.0
199 |
200 | Unless required by applicable law or agreed to in writing, software
201 | distributed under the License is distributed on an "AS IS" BASIS,
202 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
203 | See the License for the specific language governing permissions and
204 | limitations under the License.
205 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/richeditor/src/main/assets/normalize.css:
--------------------------------------------------------------------------------
1 | /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
2 |
3 | /* Document
4 | ========================================================================== */
5 |
6 | /**
7 | * 1. Correct the line height in all browsers.
8 | * 2. Prevent adjustments of font size after orientation changes in iOS.
9 | */
10 |
11 | html {
12 | line-height: 1.15; /* 1 */
13 | -webkit-text-size-adjust: 100%; /* 2 */
14 | }
15 |
16 | /* Sections
17 | ========================================================================== */
18 |
19 | /**
20 | * Remove the margin in all browsers.
21 | */
22 |
23 | body {
24 | margin: 0;
25 | }
26 |
27 | /**
28 | * Render the `main` element consistently in IE.
29 | */
30 |
31 | main {
32 | display: block;
33 | }
34 |
35 | /**
36 | * Correct the font size and margin on `h1` elements within `section` and
37 | * `article` contexts in Chrome, Firefox, and Safari.
38 | */
39 |
40 | h1 {
41 | font-size: 2em;
42 | margin: 0.67em 0;
43 | }
44 |
45 | /* Grouping content
46 | ========================================================================== */
47 |
48 | /**
49 | * 1. Add the correct box sizing in Firefox.
50 | * 2. Show the overflow in Edge and IE.
51 | */
52 |
53 | hr {
54 | box-sizing: content-box; /* 1 */
55 | height: 0; /* 1 */
56 | overflow: visible; /* 2 */
57 | }
58 |
59 | /**
60 | * 1. Correct the inheritance and scaling of font size in all browsers.
61 | * 2. Correct the odd `em` font sizing in all browsers.
62 | */
63 |
64 | pre {
65 | font-family: monospace, monospace; /* 1 */
66 | font-size: 1em; /* 2 */
67 | }
68 |
69 | /* Text-level semantics
70 | ========================================================================== */
71 |
72 | /**
73 | * Remove the gray background on active links in IE 10.
74 | */
75 |
76 | a {
77 | background-color: transparent;
78 | }
79 |
80 | /**
81 | * 1. Remove the bottom border in Chrome 57-
82 | * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
83 | */
84 |
85 | abbr[title] {
86 | border-bottom: none; /* 1 */
87 | text-decoration: underline; /* 2 */
88 | text-decoration: underline dotted; /* 2 */
89 | }
90 |
91 | /**
92 | * Add the correct font weight in Chrome, Edge, and Safari.
93 | */
94 |
95 | b,
96 | strong {
97 | font-weight: bolder;
98 | }
99 |
100 | /**
101 | * 1. Correct the inheritance and scaling of font size in all browsers.
102 | * 2. Correct the odd `em` font sizing in all browsers.
103 | */
104 |
105 | code,
106 | kbd,
107 | samp {
108 | font-family: monospace, monospace; /* 1 */
109 | font-size: 1em; /* 2 */
110 | }
111 |
112 | /**
113 | * Add the correct font size in all browsers.
114 | */
115 |
116 | small {
117 | font-size: 80%;
118 | }
119 |
120 | /**
121 | * Prevent `sub` and `sup` elements from affecting the line height in
122 | * all browsers.
123 | */
124 |
125 | sub,
126 | sup {
127 | font-size: 75%;
128 | line-height: 0;
129 | position: relative;
130 | vertical-align: baseline;
131 | }
132 |
133 | sub {
134 | bottom: -0.25em;
135 | }
136 |
137 | sup {
138 | top: -0.5em;
139 | }
140 |
141 | /* Embedded content
142 | ========================================================================== */
143 |
144 | /**
145 | * Remove the border on images inside links in IE 10.
146 | */
147 |
148 | img {
149 | border-style: none;
150 | }
151 |
152 | /* Forms
153 | ========================================================================== */
154 |
155 | /**
156 | * 1. Change the font styles in all browsers.
157 | * 2. Remove the margin in Firefox and Safari.
158 | */
159 |
160 | button,
161 | input,
162 | optgroup,
163 | select,
164 | textarea {
165 | font-family: inherit; /* 1 */
166 | font-size: 100%; /* 1 */
167 | line-height: 1.15; /* 1 */
168 | margin: 0; /* 2 */
169 | }
170 |
171 | /**
172 | * Show the overflow in IE.
173 | * 1. Show the overflow in Edge.
174 | */
175 |
176 | button,
177 | input { /* 1 */
178 | overflow: visible;
179 | }
180 |
181 | /**
182 | * Remove the inheritance of text transform in Edge, Firefox, and IE.
183 | * 1. Remove the inheritance of text transform in Firefox.
184 | */
185 |
186 | button,
187 | select { /* 1 */
188 | text-transform: none;
189 | }
190 |
191 | /**
192 | * Correct the inability to style clickable types in iOS and Safari.
193 | */
194 |
195 | button,
196 | [type="button"],
197 | [type="reset"],
198 | [type="submit"] {
199 | -webkit-appearance: button;
200 | }
201 |
202 | /**
203 | * Remove the inner border and padding in Firefox.
204 | */
205 |
206 | button::-moz-focus-inner,
207 | [type="button"]::-moz-focus-inner,
208 | [type="reset"]::-moz-focus-inner,
209 | [type="submit"]::-moz-focus-inner {
210 | border-style: none;
211 | padding: 0;
212 | }
213 |
214 | /**
215 | * Restore the focus styles unset by the previous rule.
216 | */
217 |
218 | button:-moz-focusring,
219 | [type="button"]:-moz-focusring,
220 | [type="reset"]:-moz-focusring,
221 | [type="submit"]:-moz-focusring {
222 | outline: 1px dotted ButtonText;
223 | }
224 |
225 | /**
226 | * Correct the padding in Firefox.
227 | */
228 |
229 | fieldset {
230 | padding: 0.35em 0.75em 0.625em;
231 | }
232 |
233 | /**
234 | * 1. Correct the text wrapping in Edge and IE.
235 | * 2. Correct the color inheritance from `fieldset` elements in IE.
236 | * 3. Remove the padding so developers are not caught out when they zero out
237 | * `fieldset` elements in all browsers.
238 | */
239 |
240 | legend {
241 | box-sizing: border-box; /* 1 */
242 | color: inherit; /* 2 */
243 | display: table; /* 1 */
244 | max-width: 100%; /* 1 */
245 | padding: 0; /* 3 */
246 | white-space: normal; /* 1 */
247 | }
248 |
249 | /**
250 | * Add the correct vertical alignment in Chrome, Firefox, and Opera.
251 | */
252 |
253 | progress {
254 | vertical-align: baseline;
255 | }
256 |
257 | /**
258 | * Remove the default vertical scrollbar in IE 10+.
259 | */
260 |
261 | textarea {
262 | overflow: auto;
263 | }
264 |
265 | /**
266 | * 1. Add the correct box sizing in IE 10.
267 | * 2. Remove the padding in IE 10.
268 | */
269 |
270 | [type="checkbox"],
271 | [type="radio"] {
272 | box-sizing: border-box; /* 1 */
273 | padding: 0; /* 2 */
274 | }
275 |
276 | /**
277 | * Correct the cursor style of increment and decrement buttons in Chrome.
278 | */
279 |
280 | [type="number"]::-webkit-inner-spin-button,
281 | [type="number"]::-webkit-outer-spin-button {
282 | height: auto;
283 | }
284 |
285 | /**
286 | * 1. Correct the odd appearance in Chrome and Safari.
287 | * 2. Correct the outline style in Safari.
288 | */
289 |
290 | [type="search"] {
291 | -webkit-appearance: textfield; /* 1 */
292 | outline-offset: -2px; /* 2 */
293 | }
294 |
295 | /**
296 | * Remove the inner padding in Chrome and Safari on macOS.
297 | */
298 |
299 | [type="search"]::-webkit-search-decoration {
300 | -webkit-appearance: none;
301 | }
302 |
303 | /**
304 | * 1. Correct the inability to style clickable types in iOS and Safari.
305 | * 2. Change font properties to `inherit` in Safari.
306 | */
307 |
308 | ::-webkit-file-upload-button {
309 | -webkit-appearance: button; /* 1 */
310 | font: inherit; /* 2 */
311 | }
312 |
313 | /* Interactive
314 | ========================================================================== */
315 |
316 | /*
317 | * Add the correct display in Edge, IE 10+, and Firefox.
318 | */
319 |
320 | details {
321 | display: block;
322 | }
323 |
324 | /*
325 | * Add the correct display in all browsers.
326 | */
327 |
328 | summary {
329 | display: list-item;
330 | }
331 |
332 | /* Misc
333 | ========================================================================== */
334 |
335 | /**
336 | * Add the correct display in IE 10+.
337 | */
338 |
339 | template {
340 | display: none;
341 | }
342 |
343 | /**
344 | * Add the correct display in IE 10.
345 | */
346 |
347 | [hidden] {
348 | display: none;
349 | }
350 |
--------------------------------------------------------------------------------
/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.view.View;
6 | import android.widget.TextView;
7 |
8 | import androidx.appcompat.app.AppCompatActivity;
9 |
10 | import jp.wasabeef.richeditor.RichEditor;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | private RichEditor mEditor;
15 | private TextView mPreview;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | mEditor = (RichEditor) findViewById(R.id.editor);
22 | mEditor.setEditorHeight(200);
23 | mEditor.setEditorFontSize(22);
24 | mEditor.setEditorFontColor(Color.RED);
25 | //mEditor.setEditorBackgroundColor(Color.BLUE);
26 | //mEditor.setBackgroundColor(Color.BLUE);
27 | //mEditor.setBackgroundResource(R.drawable.bg);
28 | mEditor.setPadding(10, 10, 10, 10);
29 | //mEditor.setBackground("https://raw.githubusercontent.com/wasabeef/art/master/chip.jpg");
30 | mEditor.setPlaceholder("Insert text here...");
31 | //mEditor.setInputEnabled(false);
32 |
33 | mPreview = (TextView) findViewById(R.id.preview);
34 | mEditor.setOnTextChangeListener(new RichEditor.OnTextChangeListener() {
35 | @Override
36 | public void onTextChange(String text) {
37 | mPreview.setText(text);
38 | }
39 | });
40 |
41 | findViewById(R.id.action_undo).setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | mEditor.undo();
45 | }
46 | });
47 |
48 | findViewById(R.id.action_redo).setOnClickListener(new View.OnClickListener() {
49 | @Override
50 | public void onClick(View v) {
51 | mEditor.redo();
52 | }
53 | });
54 |
55 | findViewById(R.id.action_bold).setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | mEditor.setBold();
59 | }
60 | });
61 |
62 | findViewById(R.id.action_italic).setOnClickListener(new View.OnClickListener() {
63 | @Override
64 | public void onClick(View v) {
65 | mEditor.setItalic();
66 | }
67 | });
68 |
69 | findViewById(R.id.action_subscript).setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View v) {
72 | mEditor.setSubscript();
73 | }
74 | });
75 |
76 | findViewById(R.id.action_superscript).setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | mEditor.setSuperscript();
80 | }
81 | });
82 |
83 | findViewById(R.id.action_strikethrough).setOnClickListener(new View.OnClickListener() {
84 | @Override
85 | public void onClick(View v) {
86 | mEditor.setStrikeThrough();
87 | }
88 | });
89 |
90 | findViewById(R.id.action_underline).setOnClickListener(new View.OnClickListener() {
91 | @Override
92 | public void onClick(View v) {
93 | mEditor.setUnderline();
94 | }
95 | });
96 |
97 | findViewById(R.id.action_heading1).setOnClickListener(new View.OnClickListener() {
98 | @Override
99 | public void onClick(View v) {
100 | mEditor.setHeading(1);
101 | }
102 | });
103 |
104 | findViewById(R.id.action_heading2).setOnClickListener(new View.OnClickListener() {
105 | @Override
106 | public void onClick(View v) {
107 | mEditor.setHeading(2);
108 | }
109 | });
110 |
111 | findViewById(R.id.action_heading3).setOnClickListener(new View.OnClickListener() {
112 | @Override
113 | public void onClick(View v) {
114 | mEditor.setHeading(3);
115 | }
116 | });
117 |
118 | findViewById(R.id.action_heading4).setOnClickListener(new View.OnClickListener() {
119 | @Override
120 | public void onClick(View v) {
121 | mEditor.setHeading(4);
122 | }
123 | });
124 |
125 | findViewById(R.id.action_heading5).setOnClickListener(new View.OnClickListener() {
126 | @Override
127 | public void onClick(View v) {
128 | mEditor.setHeading(5);
129 | }
130 | });
131 |
132 | findViewById(R.id.action_heading6).setOnClickListener(new View.OnClickListener() {
133 | @Override
134 | public void onClick(View v) {
135 | mEditor.setHeading(6);
136 | }
137 | });
138 |
139 | findViewById(R.id.action_txt_color).setOnClickListener(new View.OnClickListener() {
140 | private boolean isChanged;
141 |
142 | @Override
143 | public void onClick(View v) {
144 | mEditor.setTextColor(isChanged ? Color.BLACK : Color.RED);
145 | isChanged = !isChanged;
146 | }
147 | });
148 |
149 | findViewById(R.id.action_bg_color).setOnClickListener(new View.OnClickListener() {
150 | private boolean isChanged;
151 |
152 | @Override
153 | public void onClick(View v) {
154 | mEditor.setTextBackgroundColor(isChanged ? Color.TRANSPARENT : Color.YELLOW);
155 | isChanged = !isChanged;
156 | }
157 | });
158 |
159 | findViewById(R.id.action_indent).setOnClickListener(new View.OnClickListener() {
160 | @Override
161 | public void onClick(View v) {
162 | mEditor.setIndent();
163 | }
164 | });
165 |
166 | findViewById(R.id.action_outdent).setOnClickListener(new View.OnClickListener() {
167 | @Override
168 | public void onClick(View v) {
169 | mEditor.setOutdent();
170 | }
171 | });
172 |
173 | findViewById(R.id.action_align_left).setOnClickListener(new View.OnClickListener() {
174 | @Override
175 | public void onClick(View v) {
176 | mEditor.setAlignLeft();
177 | }
178 | });
179 |
180 | findViewById(R.id.action_align_center).setOnClickListener(new View.OnClickListener() {
181 | @Override
182 | public void onClick(View v) {
183 | mEditor.setAlignCenter();
184 | }
185 | });
186 |
187 | findViewById(R.id.action_align_right).setOnClickListener(new View.OnClickListener() {
188 | @Override
189 | public void onClick(View v) {
190 | mEditor.setAlignRight();
191 | }
192 | });
193 |
194 | findViewById(R.id.action_blockquote).setOnClickListener(new View.OnClickListener() {
195 | @Override
196 | public void onClick(View v) {
197 | mEditor.setBlockquote();
198 | }
199 | });
200 |
201 | findViewById(R.id.action_insert_bullets).setOnClickListener(new View.OnClickListener() {
202 | @Override
203 | public void onClick(View v) {
204 | mEditor.setBullets();
205 | }
206 | });
207 |
208 | findViewById(R.id.action_insert_numbers).setOnClickListener(new View.OnClickListener() {
209 | @Override
210 | public void onClick(View v) {
211 | mEditor.setNumbers();
212 | }
213 | });
214 |
215 | findViewById(R.id.action_insert_image).setOnClickListener(new View.OnClickListener() {
216 | @Override
217 | public void onClick(View v) {
218 | mEditor.insertImage("https://raw.githubusercontent.com/wasabeef/art/master/chip.jpg",
219 | "dachshund", 320);
220 | }
221 | });
222 |
223 | findViewById(R.id.action_insert_youtube).setOnClickListener(new View.OnClickListener() {
224 | @Override
225 | public void onClick(View v) {
226 | mEditor.insertYoutubeVideo("https://www.youtube.com/embed/pS5peqApgUA");
227 | }
228 | });
229 |
230 | findViewById(R.id.action_insert_audio).setOnClickListener(new View.OnClickListener() {
231 | @Override
232 | public void onClick(View v) {
233 | mEditor.insertAudio("https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_5MG.mp3");
234 | }
235 | });
236 |
237 | findViewById(R.id.action_insert_video).setOnClickListener(new View.OnClickListener() {
238 | @Override
239 | public void onClick(View v) {
240 | mEditor.insertVideo("https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_10MB.mp4", 360);
241 | }
242 | });
243 |
244 | findViewById(R.id.action_insert_link).setOnClickListener(new View.OnClickListener() {
245 | @Override
246 | public void onClick(View v) {
247 | mEditor.insertLink("https://github.com/wasabeef", "wasabeef");
248 | }
249 | });
250 | findViewById(R.id.action_insert_checkbox).setOnClickListener(new View.OnClickListener() {
251 | @Override
252 | public void onClick(View v) {
253 | mEditor.insertTodo();
254 | }
255 | });
256 | }
257 | }
258 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
10 |
11 |
15 |
16 |
23 |
24 |
31 |
32 |
39 |
40 |
47 |
48 |
55 |
56 |
63 |
64 |
71 |
72 |
79 |
80 |
87 |
88 |
95 |
96 |
103 |
104 |
111 |
112 |
119 |
120 |
127 |
128 |
135 |
136 |
143 |
144 |
145 |
152 |
153 |
160 |
161 |
168 |
169 |
176 |
177 |
184 |
185 |
192 |
193 |
200 |
201 |
208 |
209 |
216 |
217 |
224 |
225 |
232 |
233 |
240 |
241 |
248 |
249 |
256 |
257 |
258 |
259 |
260 |
264 |
265 |
271 |
272 |
277 |
278 |
279 |
--------------------------------------------------------------------------------
/richeditor/src/main/assets/rich_editor.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2020 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 | /**
18 | * See about document.execCommand: https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
19 | */
20 |
21 | var RE = {};
22 |
23 | RE.currentSelection = {
24 | "startContainer": 0,
25 | "startOffset": 0,
26 | "endContainer": 0,
27 | "endOffset": 0};
28 |
29 | RE.editor = document.getElementById('editor');
30 |
31 | document.addEventListener("selectionchange", function() { RE.backuprange(); });
32 |
33 | // Initializations
34 | RE.callback = function() {
35 | window.location.href = "re-callback://" + encodeURIComponent(RE.getHtml());
36 | }
37 |
38 | RE.setHtml = function(contents) {
39 | RE.editor.innerHTML = decodeURIComponent(contents.replace(/\+/g, '%20'));
40 | }
41 |
42 | RE.getHtml = function() {
43 | return RE.editor.innerHTML;
44 | }
45 |
46 | RE.getText = function() {
47 | return RE.editor.innerText;
48 | }
49 |
50 | RE.setBaseTextColor = function(color) {
51 | RE.editor.style.color = color;
52 | }
53 |
54 | RE.setBaseFontSize = function(size) {
55 | RE.editor.style.fontSize = size;
56 | }
57 |
58 | RE.setPadding = function(left, top, right, bottom) {
59 | RE.editor.style.paddingLeft = left;
60 | RE.editor.style.paddingTop = top;
61 | RE.editor.style.paddingRight = right;
62 | RE.editor.style.paddingBottom = bottom;
63 | }
64 |
65 | RE.setBackgroundColor = function(color) {
66 | document.body.style.backgroundColor = color;
67 | }
68 |
69 | RE.setBackgroundImage = function(image) {
70 | RE.editor.style.backgroundImage = image;
71 | }
72 |
73 | RE.setWidth = function(size) {
74 | RE.editor.style.minWidth = size;
75 | }
76 |
77 | RE.setHeight = function(size) {
78 | RE.editor.style.height = size;
79 | }
80 |
81 | RE.setTextAlign = function(align) {
82 | RE.editor.style.textAlign = align;
83 | }
84 |
85 | RE.setVerticalAlign = function(align) {
86 | RE.editor.style.verticalAlign = align;
87 | }
88 |
89 | RE.setPlaceholder = function(placeholder) {
90 | RE.editor.setAttribute("placeholder", placeholder);
91 | }
92 |
93 | RE.setInputEnabled = function(inputEnabled) {
94 | RE.editor.contentEditable = String(inputEnabled);
95 | }
96 |
97 | RE.undo = function() {
98 | document.execCommand('undo', false, null);
99 | }
100 |
101 | RE.redo = function() {
102 | document.execCommand('redo', false, null);
103 | }
104 |
105 | RE.setBold = function() {
106 | document.execCommand('bold', false, null);
107 | }
108 |
109 | RE.setItalic = function() {
110 | document.execCommand('italic', false, null);
111 | }
112 |
113 | RE.setSubscript = function() {
114 | document.execCommand('subscript', false, null);
115 | }
116 |
117 | RE.setSuperscript = function() {
118 | document.execCommand('superscript', false, null);
119 | }
120 |
121 | RE.setStrikeThrough = function() {
122 | document.execCommand('strikeThrough', false, null);
123 | }
124 |
125 | RE.setUnderline = function() {
126 | document.execCommand('underline', false, null);
127 | }
128 |
129 | RE.setBullets = function() {
130 | document.execCommand('insertUnorderedList', false, null);
131 | }
132 |
133 | RE.setNumbers = function() {
134 | document.execCommand('insertOrderedList', false, null);
135 | }
136 |
137 | RE.setTextColor = function(color) {
138 | RE.restorerange();
139 | document.execCommand("styleWithCSS", null, true);
140 | document.execCommand('foreColor', false, color);
141 | document.execCommand("styleWithCSS", null, false);
142 | }
143 |
144 | RE.setTextBackgroundColor = function(color) {
145 | RE.restorerange();
146 | document.execCommand("styleWithCSS", null, true);
147 | document.execCommand('hiliteColor', false, color);
148 | document.execCommand("styleWithCSS", null, false);
149 | }
150 |
151 | RE.setFontSize = function(fontSize){
152 | document.execCommand("fontSize", false, fontSize);
153 | }
154 |
155 | RE.setHeading = function(heading) {
156 | document.execCommand('formatBlock', false, '');
157 | }
158 |
159 | RE.setIndent = function() {
160 | document.execCommand('indent', false, null);
161 | }
162 |
163 | RE.setOutdent = function() {
164 | document.execCommand('outdent', false, null);
165 | }
166 |
167 | RE.setJustifyLeft = function() {
168 | document.execCommand('justifyLeft', false, null);
169 | }
170 |
171 | RE.setJustifyCenter = function() {
172 | document.execCommand('justifyCenter', false, null);
173 | }
174 |
175 | RE.setJustifyRight = function() {
176 | document.execCommand('justifyRight', false, null);
177 | }
178 |
179 | RE.setBlockquote = function() {
180 | document.execCommand('formatBlock', false, '
');
181 | }
182 |
183 | RE.insertImage = function(url, alt) {
184 | var html = '';
185 | RE.insertHTML(html);
186 | }
187 |
188 | RE.insertImageW = function(url, alt, width) {
189 | var html = '';
190 | RE.insertHTML(html);
191 | }
192 |
193 | RE.insertImageWH = function(url, alt, width, height) {
194 | var html = '';
195 | RE.insertHTML(html);
196 | }
197 |
198 | RE.insertVideo = function(url, alt) {
199 | var html = ' ';
200 | RE.insertHTML(html);
201 | }
202 |
203 | RE.insertVideoW = function(url, width) {
204 | var html = ' ';
205 | RE.insertHTML(html);
206 | }
207 |
208 | RE.insertVideoWH = function(url, width, height) {
209 | var html = ' ';
210 | RE.insertHTML(html);
211 | }
212 |
213 | RE.insertAudio = function(url, alt) {
214 | var html = ' ';
215 | RE.insertHTML(html);
216 | }
217 |
218 | RE.insertYoutubeVideo = function(url) {
219 | var html = ' '
220 | RE.insertHTML(html);
221 | }
222 |
223 | RE.insertYoutubeVideoW = function(url, width) {
224 | var html = ' '
225 | RE.insertHTML(html);
226 | }
227 |
228 | RE.insertYoutubeVideoWH = function(url, width, height) {
229 | var html = ' '
230 | RE.insertHTML(html);
231 | }
232 |
233 | RE.insertHTML = function(html) {
234 | RE.restorerange();
235 | document.execCommand('insertHTML', false, html);
236 | }
237 |
238 | RE.insertLink = function(url, title) {
239 | RE.restorerange();
240 | var sel = document.getSelection();
241 | if (sel.toString().length == 0) {
242 | document.execCommand("insertHTML",false,""+title+"");
243 | } else if (sel.rangeCount) {
244 | var el = document.createElement("a");
245 | el.setAttribute("href", url);
246 | el.setAttribute("title", title);
247 |
248 | var range = sel.getRangeAt(0).cloneRange();
249 | range.surroundContents(el);
250 | sel.removeAllRanges();
251 | sel.addRange(range);
252 | }
253 | RE.callback();
254 | }
255 |
256 | RE.setTodo = function(text) {
257 | var html = ' ';
258 | document.execCommand('insertHTML', false, html);
259 | }
260 |
261 | RE.prepareInsert = function() {
262 | RE.backuprange();
263 | }
264 |
265 | RE.backuprange = function(){
266 | var selection = window.getSelection();
267 | if (selection.rangeCount > 0) {
268 | var range = selection.getRangeAt(0);
269 | RE.currentSelection = {
270 | "startContainer": range.startContainer,
271 | "startOffset": range.startOffset,
272 | "endContainer": range.endContainer,
273 | "endOffset": range.endOffset};
274 | }
275 | }
276 |
277 | RE.restorerange = function(){
278 | var selection = window.getSelection();
279 | selection.removeAllRanges();
280 | var range = document.createRange();
281 | range.setStart(RE.currentSelection.startContainer, RE.currentSelection.startOffset);
282 | range.setEnd(RE.currentSelection.endContainer, RE.currentSelection.endOffset);
283 | selection.addRange(range);
284 | }
285 |
286 | RE.enabledEditingItems = function(e) {
287 | var items = [];
288 | if (document.queryCommandState('bold')) {
289 | items.push('bold');
290 | }
291 | if (document.queryCommandState('italic')) {
292 | items.push('italic');
293 | }
294 | if (document.queryCommandState('subscript')) {
295 | items.push('subscript');
296 | }
297 | if (document.queryCommandState('superscript')) {
298 | items.push('superscript');
299 | }
300 | if (document.queryCommandState('strikeThrough')) {
301 | items.push('strikeThrough');
302 | }
303 | if (document.queryCommandState('underline')) {
304 | items.push('underline');
305 | }
306 | if (document.queryCommandState('insertOrderedList')) {
307 | items.push('orderedList');
308 | }
309 | if (document.queryCommandState('insertUnorderedList')) {
310 | items.push('unorderedList');
311 | }
312 | if (document.queryCommandState('justifyCenter')) {
313 | items.push('justifyCenter');
314 | }
315 | if (document.queryCommandState('justifyFull')) {
316 | items.push('justifyFull');
317 | }
318 | if (document.queryCommandState('justifyLeft')) {
319 | items.push('justifyLeft');
320 | }
321 | if (document.queryCommandState('justifyRight')) {
322 | items.push('justifyRight');
323 | }
324 | if (document.queryCommandState('insertHorizontalRule')) {
325 | items.push('horizontalRule');
326 | }
327 | var formatBlock = document.queryCommandValue('formatBlock');
328 | if (formatBlock.length > 0) {
329 | items.push(formatBlock);
330 | }
331 |
332 | window.location.href = "re-state://" + encodeURI(items.join(','));
333 | }
334 |
335 | RE.focus = function() {
336 | var range = document.createRange();
337 | range.selectNodeContents(RE.editor);
338 | range.collapse(false);
339 | var selection = window.getSelection();
340 | selection.removeAllRanges();
341 | selection.addRange(range);
342 | RE.editor.focus();
343 | }
344 |
345 | RE.blurFocus = function() {
346 | RE.editor.blur();
347 | }
348 |
349 | RE.removeFormat = function() {
350 | document.execCommand('removeFormat', false, null);
351 | }
352 |
353 | // Event Listeners
354 | RE.editor.addEventListener("input", RE.callback);
355 | RE.editor.addEventListener("keyup", function(e) {
356 | var KEY_LEFT = 37, KEY_RIGHT = 39;
357 | if (e.which == KEY_LEFT || e.which == KEY_RIGHT) {
358 | RE.enabledEditingItems(e);
359 | }
360 | });
361 | RE.editor.addEventListener("click", RE.enabledEditingItems);
362 |
--------------------------------------------------------------------------------
/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.annotation.TargetApi;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Bitmap;
8 | import android.graphics.drawable.Drawable;
9 | import android.net.Uri;
10 | import android.os.Build;
11 | import android.text.TextUtils;
12 | import android.util.AttributeSet;
13 | import android.util.Log;
14 | import android.view.Gravity;
15 | import android.webkit.WebChromeClient;
16 | import android.webkit.WebResourceRequest;
17 | import android.webkit.WebView;
18 | import android.webkit.WebViewClient;
19 |
20 | import java.io.UnsupportedEncodingException;
21 | import java.net.URLEncoder;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 | import java.util.Locale;
25 |
26 | /**
27 | * Copyright (C) 2020 Wasabeef
28 | *
29 | * Licensed under the Apache License, Version 2.0 (the "License");
30 | * you may not use this file except in compliance with the License.
31 | * You may obtain a copy of the License at
32 | *