Text editor android github
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android .
- Bold
- Italic
- Subscript
- Superscript
- Strikethrough
- Underline
- Justify Left
- Justify Center
- Justify Right
- Blockquote
- Heading 1
- Heading 2
- Heading 3
- Heading 4
- Heading 5
- Heading 6
- Undo
- Redo
- Indent
- Outdent
- Insert Image
- Insert Youtube
- Insert Video
- Insert Audio
- Insert Link
- Checkbox
- Text Color
- Text Background Color
- Text Font Size
- Unordered List (Bullets)
- Ordered List (Numbers)
Источник
Text editor android github
Android simple generic text editor. The app is available from F-Droid and here
There have been a number of issues raised on this app where users have obviously not read this README, looked at the documentation, or looked at old closed issues. Please read the README, read the docs, and look at the old issues before raising another one, you can search the issues from the box at the top.
This is a fairly simple generic text editor which may be used standalone or to show or edit any sort of text file from another app. If you select a text file in a file manager or similar app you will be offered the option of using this editor along with whatever other apps you have installed that can show or edit a text file. Files will initially be opened read only, long touch on the display or touch the edit item in the toolbar to enable editing.
There are five toolbar items which may appear:
- Edit – Edit the current read only file
- View – View the current file read only
- Save – Save the current file if modified
- New – Start a new empty file
- Open – Open a text file using a chooser
And on the menu:
- Open recent – Pop up a list of recent files
- Clear list – Clear list of recent files
- Search – Interactive search of text using a regular expression
- Find all – Find all recent files containing search text
- Save as – Save the current file with a new name
- Charset – Change the current character set, shows current set
- View markdown – View markdown in browser or html viewer
- View files – Open files read only for viewing
- Auto save – Save the current file on app pause
- Word wrap – Limit text width to screen width and word wrap
- Suggestions – Text input and spelling suggestions
- Highlight syntax – Highlight programming language syntax
- Theme – Choose theme
- Light
- Dark
- Black
- Retro
- Text size – Choose text size
- Small
- Medium
- Large
- Typeface – Choose typeface
- Monospace
- Proportional
- About – Show version, copyright and licence
Источник
Text editor android github
The Android RTEditor is a rich text editor component for Android that can be used as a drop in for EditText.
The editor offers the following character formatting options:
- Bold
- Italic
- Underline
Strike through- Superscript
- Subscript
- Different fonts
- Text size
- Text color
- Background color
- Undo/Redo
It also supports the following paragraph formatting:
Add this to your Gradle build file:
Add this to your manifest:
If you use Proguard in your app, please add the following lines to your configuration file:
The «Signature» attribute is required to be able to access generic type, which the rich text editor code does:
The toolbar uses a couple of custom attributes that need to be defined or it will crash when being inflated. You need to use a theme based on either RTE_ThemeLight or RTE_ThemeDark or define all rich text editor attributes (rte_toolbar_themes.xml) in your own theme. These two themes inherit from Theme.AppCompat.Light / Theme.AppCompat.
Make sure to call setTheme before setContentView (or set the theme in the manifest):
The 3 main components
is the EditText drop in component. Add it to your layout like you would EditText:
In code you would typically use methods to set and get the text content:
- set text: RTEditText.setRichTextEditing(true, «My content»);
- get text: RTEditText.getText(RTFormat.HTML)
is an interface for the toolbar used to apply text and paragraph formatting and other features listed above. The actual RTToolbar implementation is in a separate module and is a scrollable ribbon but alternative implementations aren’t too hard to realize (popup, action buttons, floating buttons. ). The toolbar implementation is easy to integrate into your layout:
or if you want to have two ribbons for character and paragraph formatting:
Note that inflating the toolbar might take a moment (noticable) on certain devices because the included icons are high-resolution and each one comes in three different states (pressed, checked, normal). There’s no workaround for this except using different icons with lower resolution.
In code you’d typically not interact with the toolbar (see RTManager below for the one exception).
is the glue that holds the rich text editors (RTEditText), the toolbar and your app together. Each rich text editor and each toolbar needs to be registered with the RTManager before they are functional. Multiple editors and multiple toolbars can be registered. The RTManager is instantiated by your app in code usually in the onCreate passing in an RTApi object that gives the rich text editor access to its context (your app). A typical initialization process looks like this (normally in the onCreate method):
To retrieve the edited text in html format you’d do:
The RTManager also needs to be called in onSaveInstanceState and in onDestroy:
The isSaved parameter passed into RTManager.onDestroy(boolean) is important. If it’s true then media files inserted into the text (images at the moment) will remain untouched. If the parameter is false (text content is dismissed), media files will be deleted. Note that the rich text editor copies the original file to a dedicated area according to the MediaFactory configuration, meaning the original will remain untouched.
If you read the previous section («The 3 main components») you might have noticed the RTApi object. The RTApi is a convenience class giving the various rich text editor components access to the application context and to RTProxy and RTMediaFactory methods.
The first parameter is merely a Context object (Application or Activity context). The RTApi will only store the Application context so no issue with leaking the Activity context here.
The RTProxy allows the rich text editor to call Activity related methods like:
- startActivityForResult/runOnUiThread and Toast methods: for picking images to embed in the text
- Fragment related methods: for the link dialog (LinkFragment)
RTProxyImpl is the standard implementation for RTProxy and there’s usually no need to use a custom implementation. RTProxyImpl stores the Activity context in a SoftReference.
The most interesting class is RTMediaFactory. By overriding it, different storage scenarios for embedded images (and potentially videos and audio files in the future) can be implemented (SQLite database, file system, cloud storage, access through ContentProvider etc.).
The rich text editor supports fonts that are part of the Android device it’s running on. It’s reading all ttf fonts in the /system/fonts, /system/font and /data/fonts and shows them in the editor.
A lot of frequently used fonts have a copyright and can therefore not be included in this library but you can use any true type font you want by adding them to the assets folder of the demo app (just make sure you don’t infringe on someone else’s copyright). The fonts can be put anywhere in the assets folder (root or subdirectories). Since reading the directory structure of the assets folder during run-time is pretty slow (see here) a Gradle script generates an index of all ttf files during build time. In order to create that file during build time, please copy the following code to your build.gradle:
Note that loading the fonts can take a moment. That’s why you should pre-load them in your Application class (it’s an asynchronous call):
The project consists of four different modules:
- ColorPicker: a color picker based on this: https://github.com/LarsWerkman/HoloColorPicker. The RTEditor uses an enhanced version that allows to enter ARGB values, includes a ColorPickerPreference that can be used in preference screens and shows a white and gray chessboard pattern behind the color visible when the the alpha channel is changed and the color becomes (partly) transparent.
- RTEditor: the actual rich text editor (excluding the toolbar implementation).
- RTEditor-Toolbar: the toolbar implementation.
- RTEditor-Demo: this module isn’t part of the actual rich text editor component but contains a sample app that shows how to use the component.
The demo app can also be found on Google Play: Demo App
If you have an issues with this library, please open a issue here: https://github.com/1gravity/Android-RTEditor/issues and provide enough information to reproduce it reliably. The following information needs to be provided:
- Which version of the SDK are you using?
- Which Android build are you using? (e.g. MPZ44Q)
- What device are you using?
- What steps will reproduce the problem? (Please provide the minimal reproducible test case.)
- What is the expected output?
- What do you see instead?
- Relevant logcat output.
- Optional: Link to any screenshot(s) that demonstrate the issue (shared privately in Drive.)
- Optional: Link to your APK (either downloadable in Drive or in the Play Store.)
Copyright 2015-2021 Emanuel Moecklin
Licensed under the Apache License, Version 2.0 (the «License»); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an «AS IS» BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
About
The Android RTEditor is a rich text editor component for Android that can be used as a drop in for EditText
Источник
Text editor android github
Android Rich text Editor (中文说明见这里)
If you are looking for a good rich text editor on Android, DON’T MISS THIS ONE!
It’s still in progress now, welcome fork and join me!
I published colorpicker and emojipicker as standalone components so they can be reused in other projects easily.
Hey guys! If you’re reading this, I believe you are kind of struggling to find out some solution for rich text editor on Android, and specifically, you want to use the Android native APIs to implement. If I was right, maybe I can help. But starting from the very beginning of this project, I open-sourced all of the code, and have helped tens to even hundreds of friends out from their troubles, for free! Now I have to charge for the future helps, starting from $49 per feature implementation; $19 per feature contact. And the improvement will all be open-source to help others out. Reach out 329055754@qq.com for details. Thank you!
This is implemented by Java
- Bold
- Italic
- Underline
- Strikethrough
- Numeric list
- Bullet list
- Align left
- Align center
- Align right
- Insert image
- Background color
- Hyper link
- @
- Quote
- Foreground color
- Emoji icon
- Superscript
- Subscript
- Font size
- Video
- Image from internet
- Dividing line
- All styles support save as HTML file
- Load from HTML then continue editing or displaying — New in 0.1.0
Released 0.2.0: migrated to AndroidX
- Update Glide to 4.11.0
- The last non-androidx version is 0.1.10
Released 0.1.8: added support for multiple ARE instances in one page
Released 0.1.7: update glide to 4.9.0
- Maintain release, includes:
- Added foreground color style to ARE_Toolbar_Default
- Added background color style to ARE_Toolbar_Default
- Bugs fixing
Plan for next version:
Let me know what features you want to have in the next version if there is any, thanks.
Two usage modes
AREditor. EditText (the input area) and Toolbar (the styling tools) are in the same component. I.e.: if you include in layout XML, you’ll see the input area and styling tools (Bold / Italic / Alignment / Bullet list / etc..) in your activity.
AREditText + IARE_Toolbar (it’s an interface). EditText (the input area) and Toolbar (the styling tools) are standalone component themselves. I.e.: you have the choice to decide whether to show the Toolbar, and where to place it, below or bottom of the AREditText, left or right to the AREditText, or any other alignment because the toolbar itself is a HorizontalScrollView (default implementation is ARE_ToolbarDefault ), and also you can decide what toolitem to be added to the toolbar.
Inside these two modes:
AREditor: it extends RelativeLayout , it contains two child components: AREditText and ARE_Toolbar .
AREditText extends AppCompatEditText , in its afterTextChanged method of TextWatcher , it calls the applyStyle of IARE_Style .
ARE_Toolbar extends LinearLayout , the tool items inside are IARE_Style instances, each instance contains an ImageView , which is being shown in the toolbar.
No need to repeat about AREditText
IARE_Toolbar , it is an interface, which defines what a toolbar needs to implement. Such as: addToolbarItem , getToolItems , etc.. Inside are , there is a default implementation: ARE_ToolbarDefault , it extends HorizontalScrollView , and has the implementation of all the methods in the IARE_Toolbar interface.
ARE_ToolbarDefault , it is just a toolbar, i.e.: tool item container, what the component does the real work is IARE_ToolItem , which is another interface defines the behaviors of a tool item should have, like: getView returns a view to be shown in the toolbar, getStyle returns an IARE_Style to response to the text change. Currently there are 19 toolitems implementation:
ARE_ToolItem_Abstract ARE_ToolItem_AlignmentCenter ARE_ToolItem_AlignmentLeft ARE_ToolItem_AlignmentRight ARE_ToolItem_At ARE_ToolItem_Bold ARE_ToolItem_Hr ARE_ToolItem_Image ARE_ToolItem_Italic ARE_ToolItem_Link ARE_ToolItem_ListBullet ARE_ToolItem_ListNumber ARE_ToolItem_Quote ARE_ToolItem_Strikethrough ARE_ToolItem_Subscript ARE_ToolItem_Superscript ARE_ToolItem_Underline ARE_ToolItem_UpdaterDefault ARE_ToolItem_Video
The above tool items can be added to toolbar by calling: addToolbarItem(IARE_ToolItem toolItem)
If you want to add your own tool item, you just need to implement your IARE_ToolItem , for example, if you want to add a tool item to change font family, then you can define ARE_ToolItem_FontFamily and implements the methods in IARE_ToolItem . You can check out any of the above ToolItems as reference.
Specially if you want to add a new feature like @ , such as ## , check out ARE_ToolItem_At.java, which is a demo for tool item without an image at toolbar.
All styles are based on Android Spans
In your gradle.build of app module, add this in the dependencies:
or, as are is still not stable enough to handle kinds of issues in different business scenarios, I’d like recommend to import are into your project directly and add it as a local module dependency.
Documentation for AREditor in layout XML
Name | Format | Description |
---|---|---|
expandMode | enum | FULL (default: Full screen editor) / MIN (min height editor, maxLines = 3) |
hideToolbar | boolean | Whether to hide the toolbar, by default toolbar will be shown. You may want to set it as true when you use MIN expand mode, @ feature will still be available but other features won’t work because those styles on toolbar has been hidden with toolbar. |
toolbarAlignment | enum | BOTTOM (default: at bottom of AREditor) / TOP (at top of AREditor) |
APIs for AREditor in Java
Class | Method | Params | Description |
---|---|---|---|
AREditor | setExpandMode | AREditor.ExpandMode | Sets the edit area mode. Possible values are: ExpandMode.FULL (default) / ExpandMode.MIN |
AREditor | setHideToolbar | boolean | Sets as true to hide toolbar; sets false will show toolbar |
AREditor | setToolbarAlignment | AREditor.ToolbarAlignment | Sets the toolbar position. Possible values are: ToolbarAlignment.BOTTOM (default) / ToolbarAlignment.TOP |
Samples for AREditor
AREditText it self is an AppCompatEditText subclass, so anything applies to AppCompatEditText also works for AREditText .
Documentation for ARE_ToolbarDefault
It extends HorizontalScrollView , so anything applies to HorizontalScrollView also works for ARE_ToolbarDefault .
APIs for IARE_Toolbar
Class | Method | Params | Description |
---|---|---|---|
IARE_Toolbar | addToolbarItem | IARE_ToolItem | Add a toolbar item to toolbar |
IARE_Toolbar | getToolItems | -none- | Returns all of the tool items in the toolbar |
IARE_Toolbar | setEditText | AREditText | Binds AREditText with toolbar |
IARE_Toolbar | getEditText | -none- | Returns the bound AREditText |
IARE_Toolbar | onActivityResult | requestCode(int) resultCode(int) data(Intent) | For some styles like insert image or video or @ feature, you need open a new Activity, and need to handle the data via onActivityResult, in this method you can dispatch to the specific styles. |
APIs for IARE_ToolItem
Class | Method | Params | Description |
---|---|---|---|
IARE_ToolItem | getStyle | -none- | Each tool item is a style, and a style combines with specific span. |
IARE_ToolItem | getView | Context | Each tool item has a view. If context is null, return the generated view. |
IARE_ToolItem | onSelectionChanged | int selStart, int selEnd | Selection changed call back. Update tool item checked status |
IARE_ToolItem | getToolbar | -none- | Returns the toolbar of this tool item. |
IARE_ToolItem | setToolbar | IARE_Toolbar | Sets the toolbar for this tool item. |
IARE_ToolItem | getToolItemUpdater | -none- | Gets the tool item updater instance, will be called when style being checked and unchecked. |
IARE_ToolItem | setToolItemUpdater | IARE_ToolItem_Updater | Sets the tool item updater. |
IARE_ToolItem | onActivityResult | requestCode(int) resultCode(int) data(Intent) | Handle the dispatched event from IARE_Toolbar |
Sample in Java for setting up custom toolbar
In this release, you have a new usage with ARE.
AREditText + ARE_Toolbar, you are now able to control the position of the input area and where to put the toolbar at and, what ToolItems you’d like to have in the toolbar.
You can not only define the Toolbar (and it’s style), you can also add your own ARE_ToolItem with your style into ARE.
Why not give it a try now?
APIs for AREditor
Class | Method | Params | Description |
---|---|---|---|
AREditor | fromHtml | String | Load html to AREditor |
AREditor | getHtml | -none- | Returns the HTML source of current content in AREditor |
AREditor | getARE | -none- | Returns the AREditText instance in this AREditor |
APIs for AREditText
Class | Method | Params | Description |
---|---|---|---|
AREditText | fromHtml | -none- | Load html to AREditor |
AREditText | getHtml | -none- | Returns the HTML source of current content in AREditor |
AREditText | setToolbar | IARE_Toolbar | Sets the IARE_Toolbar instance (only necessary when works as separated component and works together with custom toolbar) |
Available features demo:
In progress items:
- Audio
- Font family
- Indent right
- Indent left
- Save editings to local SQLite
- Notes list
- Headline — deferred, can be done with font size and center style
You can download the APK here:
- Background color — cursor invisible when put it in the range of BackgroundColorSpan
Thanks @Yasujizr providing the logo for ARE. @Yasujizr I hope to get a new logo now 🙂 Could you please help me?
If you find my work is helpful to you or you are start using my code, you don’t need to buy me a coffee, just could you please send me a » ✨ «? Your * encourages me to make more features open source, thanks for your support. You can contact me at 329055754@qq.com if you need any customization or any suggestion.
About
Android Rich Text Editor With customized spans — 富文本编辑器 — Don’t miss this one 🙂
Источник