Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.1gravity:android-rteditor-materialdialog

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.1gravity:android-rteditor-materialdialog

Android RTEditor is a rich text editor component used as drop-in for EditText

  • 1.1.2
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Android-RTEditor

The Android RTEditor is a rich text editor component for Android that can be used as a drop in for EditText.

Images

Features

The editor offers the following character formatting options:

  • Bold
  • Italic
  • Underline
  • Strike through
  • Superscript
  • Subscript
  • Text size
  • Text color
  • Background color

It also supports the following paragraph formatting:

  1. Numbered
  • Bullet points
    • Left alignment
      Center alignment
      Right alignment
    • Links
    • Images: Images
    • Undo/Redo

    The 3 main components

    ####RTEditText is the EditText drop in component. Add it to your layout like you would EditText:

      <com.onegravity.rteditor.RTEditText
        android:id="@+id/rtEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="actionDone|flagNoEnterAction"
        android:inputType="textMultiLine|textAutoCorrect|textCapSentences" />
    

    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)

    ####RTToolbar 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:

      <include android:id="@+id/rte_toolbar_container" layout="@layout/rte_toolbar" />
    

    or if you want to have two ribbons for character and paragraph formatting:

        <LinearLayout
            android:id="@+id/rte_toolbar_container"
        	android:orientation="vertical"
        	android:layout_width="match_parent"
        	android:layout_height="wrap_content">
    
        	<include layout="@layout/rte_toolbar_character" />
        	<include layout="@layout/rte_toolbar_paragraph" />
    
        </LinearLayout>
    

    In code you'd typically not interact with the toolbar (see RTManager below for the one exception).

    ####RTManager 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:

    // create RTManager
    RTApi rtApi = new RTApi(this, new RTProxyImpl(this), new RTMediaFactoryImpl(this, true));
    RTManager rtManager = new RTManager(rtApi, savedInstanceState);
    
    // register toolbar
    ViewGroup toolbarContainer = (ViewGroup) findViewById(R.id.rte_toolbar_container);
    HorizontalRTToolbar rtToolbar = (HorizontalRTToolbar) findViewById(R.id.rte_toolbar);
    if (rtToolbar != null) {
      rtManager.registerToolbar(toolbarContainer, rtToolbar);
    }
    
    // register editor & set text
    RTEditText rtEditText = (RTEditText) findViewById(R.id.rtEditText);
    rtManager.registerEditor(rtEditText, true);
    rtEditText.setRichTextEditing(true, message);
    

    To retrieve the edited text in html format you'd do:

    String text = rtEditText.getText(RTFormat.HTML);
    

    The RTManager also needs to be called in onSaveInstanceState and in onDestroy:

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    
        mRTManager.onSaveInstanceState(outState);
    
        outState.putBoolean("mUseDarkTheme", mUseDarkTheme);
        outState.putBoolean("mSplitToolbar", mSplitToolbar);
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        mRTManager.onDestroy(isFinishing());
    }
    
    

    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.

    Demo project

    The project consists of five 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.
    • MaterialDialog a library based on this: https://github.com/afollestad/material-dialogs. The RTEditor uses a trimmed-down version because it only uses a subset of its functionality for the link dialog. You can easily remove this module and use the standard Android dialog instead.
    • 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

    Issues

    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 or the issue will be closed without any further notice:

    • 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.)

    License

    Copyright 2015 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

    http://www.apache.org/licenses/LICENSE-2.0
    

    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.

    FAQs

    Package last updated on 23 Sep 2015

    Did you know?

    Socket

    Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

    Install

    Related posts

    SocketSocket SOC 2 Logo

    Product

    • Package Alerts
    • Integrations
    • Docs
    • Pricing
    • FAQ
    • Roadmap
    • Changelog

    Packages

    npm

    Stay in touch

    Get open source security insights delivered straight into your inbox.


    • Terms
    • Privacy
    • Security

    Made with ⚡️ by Socket Inc