package com.github.irshulx.wysiwyg; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.text.Editable; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; import com.github.irshulx.Editor; import com.github.irshulx.EditorListener; import com.github.irshulx.models.EditorContent; import com.github.irshulx.models.EditorTextStyle; import java.io.IOException; import java.util.HashMap; import java.util.Locale; import java.util.Map; import top.defaults.colorpicker.ColorPickerPopup; public class EditorTestActivity extends AppCompatActivity { Editor editor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_editor_test); editor = findViewById(R.id.editor); setUpEditor(); } private void setUpEditor() { findViewById(R.id.action_h1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.H1); } }); findViewById(R.id.action_h2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.H2); } }); findViewById(R.id.action_h3).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.H3); } }); findViewById(R.id.action_bold).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.BOLD); } }); findViewById(R.id.action_Italic).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.ITALIC); } }); findViewById(R.id.action_indent).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.INDENT); } }); findViewById(R.id.action_blockquote).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.BLOCKQUOTE); } }); findViewById(R.id.action_outdent).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.updateTextStyle(EditorTextStyle.OUTDENT); } }); findViewById(R.id.action_bulleted).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.insertList(false); } }); findViewById(R.id.action_unordered_numbered).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.insertList(true); } }); findViewById(R.id.action_hr).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.insertDivider(); } }); findViewById(R.id.action_color).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new ColorPickerPopup.Builder(EditorTestActivity.this) .initialColor(Color.RED) // Set initial color .enableAlpha(true) // Enable alpha slider or not .okTitle("Choose") .cancelTitle("Cancel") .showIndicator(true) .showValue(true) .build() .show(findViewById(android.R.id.content), new ColorPickerPopup.ColorPickerObserver() { @Override public void onColorPicked(int color) { Toast.makeText(EditorTestActivity.this, "picked" + colorHex(color), Toast.LENGTH_LONG).show(); editor.updateTextColor(colorHex(color)); } @Override public void onColor(int color, boolean fromUser) { } }); } }); findViewById(R.id.action_insert_image).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.openImagePicker(); } }); findViewById(R.id.action_insert_link).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.insertLink(); } }); findViewById(R.id.action_erase).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editor.clearAllContents(); } }); //editor.dividerBackground=R.drawable.divider_background_dark; //editor.setFontFace(R.string.fontFamily__serif); Map headingTypeface = getHeadingTypeface(); Map contentTypeface = getContentface(); editor.setHeadingTypeface(headingTypeface); editor.setContentTypeface(contentTypeface); editor.setDividerLayout(R.layout.tmpl_divider_layout); editor.setEditorImageLayout(R.layout.tmpl_image_view); editor.setListItemLayout(R.layout.tmpl_list_item); //editor.setNormalTextSize(10); // editor.setEditorTextColor("#FF3333"); //editor.StartEditor(); editor.setEditorListener(new EditorListener() { @Override public void onTextChanged(EditText editText, Editable text) { // Toast.makeText(EditorTestActivity.this, text, Toast.LENGTH_SHORT).show(); } @Override public void onUpload(Bitmap image, String uuid) { Toast.makeText(EditorTestActivity.this, uuid, Toast.LENGTH_LONG).show(); /** * TODO do your upload here from the bitmap received and all onImageUploadComplete(String url); to insert the result url to * let the editor know the upload has completed */ editor.onImageUploadComplete("http://www.videogamesblogger.com/wp-content/uploads/2015/08/metal-gear-solid-5-the-phantom-pain-cheats-640x325.jpg", uuid); // editor.onImageUploadFailed(uuid); } @Override public View onRenderMacro(String name, Map props, int index) { View view = getLayoutInflater().inflate(R.layout.layout_authored_by, null); return view; } }); /** * rendering serialized content // */ // String serialized = "{\"nodes\":[{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003etextline 1 a great time and I will branch office is closed on Sundays\\u003c/p\\u003e\\n\"],\"contentStyles\":[\"H1\"],\"textSettings\":{\"textColor\":\"#c00000\"},\"type\":\"INPUT\"},{\"content\":[],\"type\":\"hr\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003ethe only one that you have received the stream free and open minded person to discuss a business opportunity to discuss my background.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"childs\":[{\"content\":[\"it is a great weekend and we will have the same to me that the same a great time\"],\"contentStyles\":[\"BOLD\"],\"textSettings\":{\"textColor\":\"#FF0000\"},\"type\":\"IMG_SUB\"}],\"content\":[\"http://www.videogamesblogger.com/wp-content/uploads/2015/08/metal-gear-solid-5-the-phantom-pain-cheats-640x325.jpg\"],\"type\":\"img\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eI have a place where I have a great time and I will branch manager state to boast a new job in a few weeks and we can host or domain to get to know.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"childs\":[{\"content\":[\"the stream of water in a few weeks and we can host in the stream free and no ippo\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#5E5E5E\"},\"type\":\"IMG_SUB\"}],\"content\":[\"http://www.videogamesblogger.com/wp-content/uploads/2015/08/metal-gear-solid-5-the-phantom-pain-cheats-640x325.jpg\"],\"type\":\"img\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is that I can get it done today will online at location and I am not a big difference to me so that we are headed \\u003ca href\\u003d\\\"www.google.com\\\"\\u003ewww.google.com\\u003c/a\\u003e it was the only way I.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is not a good day to get the latest version to blame it to the product the.\\u003c/p\\u003e\\n\"],\"contentStyles\":[\"BOLDITALIC\"],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is that I can send me your email to you and I am not able a great time and consideration I have to do the needful.\\u003c/p\\u003e\\n\"],\"contentStyles\":[\"INDENT\"],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eI will be a while ago to a great weekend a great time with the same.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"}]}"; // String serialized = "{\"nodes\":[{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003e\\u003cspan style\\u003d\\\"color:#000000;\\\"\\u003e\\u003cspan style\\u003d\\\"color:#000000;\\\"\\u003eit is not available beyond that statue in a few days and then we could\\u003c/span\\u003e\\u003c/span\\u003e\\u003c/p\\u003e\\n\"],\"contentStyles\":[\"H1\"],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[],\"type\":\"hr\"},{\"content\":[\"author-tag\"],\"macroSettings\":{\"data-author-name\":\"Alex Wong\",\"data-tag\":\"macro\",\"data-date\":\"12 July 2018\"},\"type\":\"macro\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is a free trial to get a great weekend a good day to you u can do that for.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is that I have to do the needful as early in life is not available beyond my imagination to be a good.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"childs\":[{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003e\\u003cb\\u003eit is not available in the next week or two and I have a place where I\\u003c/b\\u003e\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#006AFF\"},\"type\":\"IMG_SUB\"}],\"content\":[\"http://www.videogamesblogger.com/wp-content/uploads/2015/08/metal-gear-solid-5-the-phantom-pain-cheats-640x325.jpg\"],\"type\":\"img\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is not available in the next week to see you tomorrow morning to see you then.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[],\"type\":\"hr\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eit is not available in the next day delivery to you soon with it and.\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"}]}"; // EditorContent des = editor.getContentDeserialized(serialized); // editor.render(des); // Intent intent = new Intent(getApplicationContext(), RenderTestActivity.class); // intent.putExtra("content", serialized); // startActivity(intent); /** * Rendering html */ //render(); //editor.render(); // this method must be called to start the editor String text = "

textline 1 a great time and I will branch office is closed on Sundays


the only one that you have received the stream free and open minded person to discuss a business opportunity to discuss my background.

it is a great weekend and we will have the same to me that the same a great time

I have a place where I have a great time and I will branch manager state to boast a new job in a few weeks and we can host or domain to get to know.

the stream of water in a few weeks and we can host in the stream free and no ippo

it is that I can get it done today will online at location and I am not a big difference to me so that we are headed www.google.com it was the only way I.

I have to do the negotiation and a half years old story and I am looking forward in a few days.

it is not a good day to get the latest version to blame it to the product the.

  1. it is that I can send me your email to you and I am not able a great time and consideration I have to do the needful.
  2. I have to do the needful and send to me and
  3. I will be a while ago to a great weekend a great time with the same.

it was u can do to make an offer for a good day I u u have been working with a new job to the stream free and no.

it was u disgraced our new home in time to get the chance I could not find a good idea for you have a great.

I have to do a lot to do the same a great time and I have a great.

"; //editor.render("

Hello man, whats up!

"); //String text = "

I have to do the needful and send to me and my husband is in a Apple has to offer a variety is not a.

I have to go with you will be highly grateful if we can get the latest

I have to do the negotiation and a half years old story and I am looking forward in a few days.

I have to do the needful at your to the product and the other to a new job is going well and that the same old stuff and a half day city is the stream and a good idea to get onboard the stream.

"; editor.render(text); findViewById(R.id.btnRender).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* Retrieve the content as serialized, you could also say getContentAsHTML(); */ String text = editor.getContentAsSerialized(); editor.getContentAsHTML(); Intent intent = new Intent(getApplicationContext(), RenderTestActivity.class); intent.putExtra("content", text); startActivity(intent); } }); /** * Since the endusers are typing the content, it's always considered good idea to backup the content every specific interval * to be safe. * private final long backupInterval = 10 * 1000; Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { String text = editor.getContentAsSerialized(); SharedPreferences.Editor preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit(); preferences.putString(String.format("backup-{0}", new SimpleDateFormat("dd-MM-yyyy hh:mm:ss").format(new Date())), text); preferences.apply(); } }, 0, backupInterval); */ } private View insertMacro() { View view = getLayoutInflater().inflate(R.layout.layout_authored_by, null); Map map = new HashMap<>(); map.put("author-name", "Alex Wong"); map.put("date","12 July 2018"); editor.insertMacro("author-tag",view, map); return view; } private String colorHex(int color) { int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return String.format(Locale.getDefault(), "#%02X%02X%02X", r, g, b); } public static void setGhost(Button button) { int radius = 4; GradientDrawable background = new GradientDrawable(); background.setShape(GradientDrawable.RECTANGLE); background.setStroke(4, Color.WHITE); background.setCornerRadius(radius); button.setBackgroundDrawable(background); } private void render() { String x = "

Installation

" + "

Requires HTML5 doctype

" + "

Bootstrap uses certain HTML elements and CSS properties which require HTML5 doctype. Include <!DOCTYPE html> in the beginning of all your projects.

" + "" + "

Integration

" + "

3rd parties available in django, rails, angular and so on.

" + "

Django

" + "

Handy update for your django admin page.

" + "" + "

Ruby On Rails

" + "

This gem was built to gemify the assets used in Summernote.

" + "" + "

AngularJS

" + "

AngularJS directive to Summernote.

" + "" + "

Apache Wicket

" + "

Summernote widget for Wicket Bootstrap.

" + "" + "

Webpack

" + "

Example about using summernote with webpack.

" + "" + "

Meteor

" + "

Example about using summernote with meteor.

" + "" + "


"; editor.render(x); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == editor.PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK && data != null && data.getData() != null) { Uri uri = data.getData(); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri); // Log.d(TAG, String.valueOf(bitmap)); editor.insertImage(bitmap); } catch (IOException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); e.printStackTrace(); } } else if (resultCode == Activity.RESULT_CANCELED) { //Write your code if there's no result Toast.makeText(getApplicationContext(), "Cancelled", Toast.LENGTH_SHORT).show(); // editor.RestoreState(); } } @Override public void onBackPressed() { new AlertDialog.Builder(this) .setTitle("Exit Editor?") .setMessage("Are you sure you want to exit the editor?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }) .setNegativeButton("No", null) .show(); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); setGhost((Button) findViewById(R.id.btnRender)); } public Map getHeadingTypeface() { Map typefaceMap = new HashMap<>(); typefaceMap.put(Typeface.NORMAL, "fonts/GreycliffCF-Bold.ttf"); typefaceMap.put(Typeface.BOLD, "fonts/GreycliffCF-Heavy.ttf"); typefaceMap.put(Typeface.ITALIC, "fonts/GreycliffCF-Heavy.ttf"); typefaceMap.put(Typeface.BOLD_ITALIC, "fonts/GreycliffCF-Bold.ttf"); return typefaceMap; } public Map getContentface() { Map typefaceMap = new HashMap<>(); typefaceMap.put(Typeface.NORMAL, "fonts/Lato-Medium.ttf"); typefaceMap.put(Typeface.BOLD, "fonts/Lato-Bold.ttf"); typefaceMap.put(Typeface.ITALIC, "fonts/Lato-MediumItalic.ttf"); typefaceMap.put(Typeface.BOLD_ITALIC, "fonts/Lato-BoldItalic.ttf"); return typefaceMap; } }