From f30966128956b1c3b30047ae181ddc8fa09a39f1 Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Sat, 25 Aug 2018 18:01:07 +0300 Subject: [PATCH] editor code, font, link --- .../gr/thmmy/mthmmy/utils/EditorView.java | 52 +++++++++++++++++++ .../main/res/drawable/ic_code_grey_36dp.xml | 5 ++ .../res/drawable/ic_insert_link_gre_36dp.xml | 5 ++ .../res/drawable/ic_text_format_grey_36dp.xml | 5 ++ .../main/res/layout/dialog_create_link.xml | 27 ++++++++++ app/src/main/res/layout/editor_view.xml | 24 +++++++++ app/src/main/res/values/strings.xml | 7 ++- 7 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/ic_code_grey_36dp.xml create mode 100644 app/src/main/res/drawable/ic_insert_link_gre_36dp.xml create mode 100644 app/src/main/res/drawable/ic_text_format_grey_36dp.xml create mode 100644 app/src/main/res/layout/dialog_create_link.xml diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java index 20aba7a7..90cf54b3 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java @@ -1,9 +1,12 @@ package gr.thmmy.mthmmy.utils; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; +import android.support.design.widget.TextInputLayout; import android.support.v7.widget.AppCompatImageButton; import android.text.Editable; +import android.text.TextUtils; import android.util.AttributeSet; import android.util.SparseArray; import android.view.LayoutInflater; @@ -14,6 +17,8 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.PopupWindow; +import java.util.Objects; + import gr.thmmy.mthmmy.R; public class EditorView extends LinearLayout { @@ -135,6 +140,12 @@ public class EditorView extends LinearLayout { getText().insert(editText.getSelectionStart(), "[size=10pt][/size]"); editText.setSelection(editText.getSelectionStart() - 7); }); + findViewById(R.id.font_button).setOnClickListener(view -> { + if (editText.hasSelection()) + editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); + getText().insert(editText.getSelectionStart(), "[font=Verdana][/font]"); + editText.setSelection(editText.getSelectionStart() - 7); + }); findViewById(R.id.unordered_list_button).setOnClickListener(view -> { if (editText.hasSelection()) editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); @@ -159,6 +170,47 @@ public class EditorView extends LinearLayout { getText().insert(editText.getSelectionStart(), "[right][/right]"); editText.setSelection(editText.getSelectionStart() - 8); }); + findViewById(R.id.link_button).setOnClickListener(view -> { + LinearLayout dialogBody = (LinearLayout) LayoutInflater.from(context) + .inflate(R.layout.dialog_create_link, null); + TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input); + linkUrl.setOnClickListener(view1 -> linkUrl.setError(null)); + TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input); + linkText.setOnClickListener(view2 -> linkText.setError(null)); + new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog) + .setTitle(R.string.dialog_create_link_title) + .setView(dialogBody) + .setPositiveButton(R.string.ok, (dialog, which) -> { + if (TextUtils.isEmpty(Objects.requireNonNull(linkUrl.getEditText()).getText().toString())) { + linkUrl.setError(context.getString(R.string.input_field_required)); + return; + } + if (TextUtils.isEmpty(Objects.requireNonNull(linkText.getEditText()).getText().toString())) { + linkUrl.setError(context.getString(R.string.input_field_required)); + return; + } + + if (editText.hasSelection()) + editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); + getText().insert(editText.getSelectionStart(), "[url=" + + Objects.requireNonNull(linkUrl.getEditText()).getText().toString() + "]" + + Objects.requireNonNull(linkText.getEditText()).getText().toString() + "[/url]"); + }) + .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) + .show(); + }); + findViewById(R.id.quote_button).setOnClickListener(view -> { + if (editText.hasSelection()) + editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); + getText().insert(editText.getSelectionStart(), "[quote][/quote]"); + editText.setSelection(editText.getSelectionStart() - 8); + }); + findViewById(R.id.code_button).setOnClickListener(view -> { + if (editText.hasSelection()) + editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); + getText().insert(editText.getSelectionStart(), "[code][/code]"); + editText.setSelection(editText.getSelectionStart() - 7); + }); findViewById(R.id.math_button).setOnClickListener(view -> { if (editText.hasSelection()) editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); diff --git a/app/src/main/res/drawable/ic_code_grey_36dp.xml b/app/src/main/res/drawable/ic_code_grey_36dp.xml new file mode 100644 index 00000000..382786f1 --- /dev/null +++ b/app/src/main/res/drawable/ic_code_grey_36dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_insert_link_gre_36dp.xml b/app/src/main/res/drawable/ic_insert_link_gre_36dp.xml new file mode 100644 index 00000000..ca131ec9 --- /dev/null +++ b/app/src/main/res/drawable/ic_insert_link_gre_36dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_text_format_grey_36dp.xml b/app/src/main/res/drawable/ic_text_format_grey_36dp.xml new file mode 100644 index 00000000..83b2e497 --- /dev/null +++ b/app/src/main/res/drawable/ic_text_format_grey_36dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/dialog_create_link.xml b/app/src/main/res/layout/dialog_create_link.xml new file mode 100644 index 00000000..1901ed8b --- /dev/null +++ b/app/src/main/res/layout/dialog_create_link.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/editor_view.xml b/app/src/main/res/layout/editor_view.xml index f58d618d..04d02d30 100644 --- a/app/src/main/res/layout/editor_view.xml +++ b/app/src/main/res/layout/editor_view.xml @@ -46,6 +46,12 @@ android:layout_height="wrap_content" app:srcCompat="@drawable/ic_format_size_black_36dp"/> + + + + + + + + Home Bookmarks Info + OK + Cancel thmmy.gr @@ -101,7 +103,6 @@ File \"%1$s\" already exists. Download again?" Download Symbol - Cancel Open Download @@ -172,4 +173,8 @@ Navy Maroon Lime Green + Create link + Link URL + Link text + Required