WYSIWYG editor for Android and JavaFX with a rich set of supported formatting options.
Based on https://github.com/wasabeef/richeditor-android, but with more options like setting the font and text foreground and background color.
And it also has ready to use UI elements implemented for these.
publicclassMainActivityextendsAppCompatActivity {
private RichTextEditor editor;
private GroupedCommandsEditorToolbar bottomGroupedCommandsToolbar;
privateIPermissionsServicepermissionsService=newPermissionsService(this);
@OverridepublicvoidonCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_main);
editor = (RichTextEditor) findViewById(R.id.editor);
// this is needed if you like to insert images so that the user gets asked for permission to access external storage if needed// see also onRequestPermissionsResult() below
editor.setPermissionsService(permissionsService);
bottomGroupedCommandsToolbar = (GroupedCommandsEditorToolbar) findViewById(R.id.bottomGroupedCommandsToolbar);
bottomGroupedCommandsToolbar.setEditor(editor);
// you can adjust predefined toolbars by removing single commands// bottomGroupedCommandsToolbar.removeCommandFromGroupedCommandsView(CommandName.TOGGLE_GROUPED_TEXT_STYLES_COMMANDS_VIEW, CommandName.BOLD);// bottomGroupedCommandsToolbar.removeSearchView();
editor.setEditorFontSize(20);
editor.setPadding((4 * (int) getResources().getDisplayMetrics().density));
// some properties you also can set on editor// editor.setEditorBackgroundColor(Color.YELLOW)// editor.setEditorFontColor(Color.MAGENTA)// editor.setEditorFontFamily("cursive")// show keyboard right at start up// editor.focusEditorAndShowKeyboardDelayed()// only needed if you allow to automatically download remote images
editor.setDownloadImageConfig(newDownloadImageConfig(DownloadImageUiSetting.AllowSelectDownloadFolderInCode,
newFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "downloaded_images")));
/* Set listeners on RichTextEditor */// get informed when edited HTML changed
editor.addDidHtmlChangeListener(newDidHtmlChangeListener() {
@OverridepublicvoiddidHtmlChange(boolean didHtmlChange) {
// e.g. set save button to enabled / disabled// btnSave.setEnabled(didHtmlChange);
}
});
// use this listener with care, it may decreases performance tremendously
editor.addHtmlChangedListener(newHtmlChangedListener() {
@OverridepublicvoidhtmlChangedAsync(@NotNull String html) {
// htmlChangedAsync() gets called on a background thread, so if you want to use it on UI thread you have to call runOnUiThread()
}
});
}
// Important: Overwrite onBackPressed and pass it to toolbar.There's no other way that it can get informed of back button presses.@OverridepublicvoidonBackPressed() {
if(bottomGroupedCommandsToolbar.handlesBackButtonPress() == false) {
super.onBackPressed();
}
}
// only needed if you like to insert images from local device so the user gets asked for permission to access external storage if needed@OverridepublicvoidonRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNullint[] grantResults) {
permissionsService.onRequestPermissionsResult(requestCode, permissions, grantResults);
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
// then when you want to do something with edited htmlprivatevoidsave() {
editor.getCurrentHtmlAsync(newGetCurrentHtmlCallback() {
@OverridepublicvoidhtmlRetrieved(@NotNull String html) {
saveHtml(html);
}
});
}
privatevoidsaveHtml(String html) {
// ...
}
}
For an example see MainActivity in DemoApp project (it's written in Kotlin).
License
Copyright 2017 dankito
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
WYSIWYG editor for Android supporting all common formatting options.
We found that net.dankito.richtexteditor:richtexteditor-android demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Package last updated on 29 Dec 2020
Did you know?
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.
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.