Browse Source

editor code, font, link

pull/45/head
Thodoris1999 6 years ago
parent
commit
f309661289
  1. 52
      app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
  2. 5
      app/src/main/res/drawable/ic_code_grey_36dp.xml
  3. 5
      app/src/main/res/drawable/ic_insert_link_gre_36dp.xml
  4. 5
      app/src/main/res/drawable/ic_text_format_grey_36dp.xml
  5. 27
      app/src/main/res/layout/dialog_create_link.xml
  6. 24
      app/src/main/res/layout/editor_view.xml
  7. 7
      app/src/main/res/values/strings.xml

52
app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java

@ -1,9 +1,12 @@
package gr.thmmy.mthmmy.utils; package gr.thmmy.mthmmy.utils;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.AppCompatImageButton; import android.support.v7.widget.AppCompatImageButton;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -14,6 +17,8 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
public class EditorView extends LinearLayout { public class EditorView extends LinearLayout {
@ -135,6 +140,12 @@ public class EditorView extends LinearLayout {
getText().insert(editText.getSelectionStart(), "[size=10pt][/size]"); getText().insert(editText.getSelectionStart(), "[size=10pt][/size]");
editText.setSelection(editText.getSelectionStart() - 7); 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 -> { findViewById(R.id.unordered_list_button).setOnClickListener(view -> {
if (editText.hasSelection()) if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
@ -159,6 +170,47 @@ public class EditorView extends LinearLayout {
getText().insert(editText.getSelectionStart(), "[right][/right]"); getText().insert(editText.getSelectionStart(), "[right][/right]");
editText.setSelection(editText.getSelectionStart() - 8); 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 -> { findViewById(R.id.math_button).setOnClickListener(view -> {
if (editText.hasSelection()) if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd()); editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());

5
app/src/main/res/drawable/ic_code_grey_36dp.xml

@ -0,0 +1,5 @@
<vector android:height="36dp" android:tint="#4B4B4B"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="36dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/>
</vector>

5
app/src/main/res/drawable/ic_insert_link_gre_36dp.xml

@ -0,0 +1,5 @@
<vector android:height="36dp" android:tint="#4B4B4B"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="36dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M3.9,12c0,-1.71 1.39,-3.1 3.1,-3.1h4L11,7L7,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5h4v-1.9L7,15.1c-1.71,0 -3.1,-1.39 -3.1,-3.1zM8,13h8v-2L8,11v2zM17,7h-4v1.9h4c1.71,0 3.1,1.39 3.1,3.1s-1.39,3.1 -3.1,3.1h-4L13,17h4c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5z"/>
</vector>

5
app/src/main/res/drawable/ic_text_format_grey_36dp.xml

@ -0,0 +1,5 @@
<vector android:height="36dp" android:tint="#4B4B4B"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="36dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M5,17v2h14v-2L5,17zM9.5,12.8h5l0.9,2.2h2.1L12.75,4h-1.5L6.5,15h2.1l0.9,-2.2zM12,5.98L13.87,11h-3.74L12,5.98z"/>
</vector>

27
app/src/main/res/layout/dialog_create_link.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:id="@+id/link_url_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/dialog_link_url_hint">
<android.support.design.widget.TextInputEditText
android:layout_width="256dp"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/link_text_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/dialog_link_text_hint">
<android.support.design.widget.TextInputEditText
android:layout_width="256dp"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>

24
app/src/main/res/layout/editor_view.xml

@ -46,6 +46,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_size_black_36dp"/> app:srcCompat="@drawable/ic_format_size_black_36dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/font_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_text_format_grey_36dp"/>
<android.support.v7.widget.AppCompatImageButton <android.support.v7.widget.AppCompatImageButton
android:id="@+id/unordered_list_button" android:id="@+id/unordered_list_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -70,6 +76,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_align_right_grey_36dp" /> app:srcCompat="@drawable/ic_format_align_right_grey_36dp" />
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/link_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_insert_link_gre_36dp" />
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/quote_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_quote_unchecked_grey_24dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/code_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_code_grey_36dp"/>
<android.support.v7.widget.AppCompatImageButton <android.support.v7.widget.AppCompatImageButton
android:id="@+id/math_button" android:id="@+id/math_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"

7
app/src/main/res/values/strings.xml

@ -12,6 +12,8 @@
<string name="home">Home</string> <string name="home">Home</string>
<string name="bookmark">Bookmarks</string> <string name="bookmark">Bookmarks</string>
<string name="info">Info</string> <string name="info">Info</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<!--Login Activity--> <!--Login Activity-->
<string name="thmmy_img_description">thmmy.gr</string> <string name="thmmy_img_description">thmmy.gr</string>
@ -101,7 +103,6 @@
<!--Download Prompt--> <!--Download Prompt-->
<string name="downloadPromptText">File \"%1$s\" already exists. Download again?"</string> <string name="downloadPromptText">File \"%1$s\" already exists. Download again?"</string>
<string name="download_symbol">Download Symbol</string> <string name="download_symbol">Download Symbol</string>
<string name="cancel">Cancel</string>
<string name="open">Open</string> <string name="open">Open</string>
<string name="download">Download</string> <string name="download">Download</string>
@ -172,4 +173,8 @@
<string name="navy">Navy</string> <string name="navy">Navy</string>
<string name="maroon">Maroon</string> <string name="maroon">Maroon</string>
<string name="lime_green">Lime Green</string> <string name="lime_green">Lime Green</string>
<string name="dialog_create_link_title">Create link</string>
<string name="dialog_link_url_hint">Link URL</string>
<string name="dialog_link_text_hint">Link text</string>
<string name="input_field_required">Required</string>
</resources> </resources>

Loading…
Cancel
Save