Browse Source

bold, italic, underline, strikethrough, text align left, center, right on EditorView

pull/45/head
Thodoris1999 6 years ago
parent
commit
bcc20f0baf
  1. 51
      app/src/main/java/gr/thmmy/mthmmy/utils/EditorView.java
  2. 5
      app/src/main/res/drawable/ic_format_align_center_grey_36dp.xml
  3. 5
      app/src/main/res/drawable/ic_format_align_left_grey_36dp.xml
  4. 5
      app/src/main/res/drawable/ic_format_align_right_grey_36dp.xml
  5. 9
      app/src/main/res/drawable/ic_format_bold_grey_36dp.xml
  6. 4
      app/src/main/res/drawable/ic_format_italic_grey_36dp.xml
  7. 5
      app/src/main/res/drawable/ic_format_list_bulleted_black_36dp.xml
  8. 5
      app/src/main/res/drawable/ic_format_underlined_grey_36dp.xml
  9. 5
      app/src/main/res/drawable/ic_strikethrough_s_grey_36dp.xml
  10. 57
      app/src/main/res/layout/editor_view.xml

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

@ -17,7 +17,7 @@ import gr.thmmy.mthmmy.R;
public class EditorView extends LinearLayout { public class EditorView extends LinearLayout {
private EditText editText; private EditText editText;
AppCompatImageButton emojiButton; private AppCompatImageButton emojiButton;
private AppCompatImageButton submitButton; private AppCompatImageButton submitButton;
private EmojiKeyboard.EmojiKeyboardOwner emojiKeyboardOwner; private EmojiKeyboard.EmojiKeyboardOwner emojiKeyboardOwner;
private boolean emojiKeyboardVisible = false; private boolean emojiKeyboardVisible = false;
@ -39,6 +39,7 @@ public class EditorView extends LinearLayout {
private void init(Context context, AttributeSet attrs) { private void init(Context context, AttributeSet attrs) {
LayoutInflater.from(context).inflate(R.layout.editor_view, this, true); LayoutInflater.from(context).inflate(R.layout.editor_view, this, true);
setOrientation(VERTICAL);
editText = findViewById(R.id.editor_edittext); editText = findViewById(R.id.editor_edittext);
emojiButton = findViewById(R.id.emoji_keyboard_button); emojiButton = findViewById(R.id.emoji_keyboard_button);
@ -65,6 +66,54 @@ public class EditorView extends LinearLayout {
}); });
submitButton = findViewById(R.id.submit_button); submitButton = findViewById(R.id.submit_button);
findViewById(R.id.bold_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[b][/b]");
editText.setSelection(editText.getSelectionStart() - 4);
});
findViewById(R.id.italic_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[i][/i]");
editText.setSelection(editText.getSelectionStart() - 4);
});
findViewById(R.id.underline_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[u][/u]");
editText.setSelection(editText.getSelectionStart() - 4);
});
findViewById(R.id.strikethrough_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[s][/s]");
editText.setSelection(editText.getSelectionStart() - 4);
});
findViewById(R.id.unordered_list_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[list]\n[li][/li]\n[li][/li]\n[li][/li]\n[/list]");
editText.setSelection(editText.getSelectionStart() - 33);
});
findViewById(R.id.align_left_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[left][/left]");
editText.setSelection(editText.getSelectionStart() - 7);
});
findViewById(R.id.align_center_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[center][/center]");
editText.setSelection(editText.getSelectionStart() - 9);
});
findViewById(R.id.align_right_button).setOnClickListener(view -> {
if (editText.hasSelection())
editText.getText().delete(editText.getSelectionStart(), editText.getSelectionEnd());
getText().insert(editText.getSelectionStart(), "[right][/right]");
editText.setSelection(editText.getSelectionStart() - 8);
});
} }
public Editable getText() { public Editable getText() {

5
app/src/main/res/drawable/ic_format_align_center_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="M7,15v2h10v-2L7,15zM3,21h18v-2L3,19v2zM3,13h18v-2L3,11v2zM7,7v2h10L17,7L7,7zM3,3v2h18L21,3L3,3z"/>
</vector>

5
app/src/main/res/drawable/ic_format_align_left_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="M15,15L3,15v2h12v-2zM15,7L3,7v2h12L15,7zM3,13h18v-2L3,11v2zM3,21h18v-2L3,19v2zM3,3v2h18L21,3L3,3z"/>
</vector>

5
app/src/main/res/drawable/ic_format_align_right_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="M3,21h18v-2L3,19v2zM9,17h12v-2L9,15v2zM3,13h18v-2L3,11v2zM9,9h12L21,7L9,7v2zM3,3v2h18L21,3L3,3z"/>
</vector>

9
app/src/main/res/drawable/ic_format_bold_grey_36dp.xml

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF4B4B4B"
android:pathData="M15.6,10.79c0.97,-0.67 1.65,-1.77 1.65,-2.79 0,-2.26 -1.75,-4 -4,-4L7,4v14h7.04c2.09,0 3.71,-1.7 3.71,-3.79 0,-1.52 -0.86,-2.82 -2.15,-3.42zM10,6.5h3c0.83,0 1.5,0.67 1.5,1.5s-0.67,1.5 -1.5,1.5h-3v-3zM13.5,15.5L10,15.5v-3h3.5c0.83,0 1.5,0.67 1.5,1.5s-0.67,1.5 -1.5,1.5z"/>
</vector>

4
app/src/main/res/drawable/ic_format_italic_grey_36dp.xml

@ -0,0 +1,4 @@
<vector android:height="36dp" android:viewportHeight="24.0"
android:viewportWidth="24.0" android:width="36dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF4B4B4B" android:pathData="M10,4v3h2.21l-3.42,8H6v3h8v-3h-2.21l3.42,-8H18V4z"/>
</vector>

5
app/src/main/res/drawable/ic_format_list_bulleted_black_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="M4,10.5c-0.83,0 -1.5,0.67 -1.5,1.5s0.67,1.5 1.5,1.5 1.5,-0.67 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM4,4.5c-0.83,0 -1.5,0.67 -1.5,1.5S3.17,7.5 4,7.5 5.5,6.83 5.5,6 4.83,4.5 4,4.5zM4,16.5c-0.83,0 -1.5,0.68 -1.5,1.5s0.68,1.5 1.5,1.5 1.5,-0.68 1.5,-1.5 -0.67,-1.5 -1.5,-1.5zM7,19h14v-2L7,17v2zM7,13h14v-2L7,11v2zM7,5v2h14L21,5L7,5z"/>
</vector>

5
app/src/main/res/drawable/ic_format_underlined_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="M12,17c3.31,0 6,-2.69 6,-6L18,3h-2.5v8c0,1.93 -1.57,3.5 -3.5,3.5S8.5,12.93 8.5,11L8.5,3L6,3v8c0,3.31 2.69,6 6,6zM5,19v2h14v-2L5,19z"/>
</vector>

5
app/src/main/res/drawable/ic_strikethrough_s_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="#010101" android:pathData="M7.24,8.75c-0.26,-0.48 -0.39,-1.03 -0.39,-1.67 0,-0.61 0.13,-1.16 0.4,-1.67 0.26,-0.5 0.63,-0.93 1.11,-1.29 0.48,-0.35 1.05,-0.63 1.7,-0.83 0.66,-0.19 1.39,-0.29 2.18,-0.29 0.81,0 1.54,0.11 2.21,0.34 0.66,0.22 1.23,0.54 1.69,0.94 0.47,0.4 0.83,0.88 1.08,1.43 0.25,0.55 0.38,1.15 0.38,1.81h-3.01c0,-0.31 -0.05,-0.59 -0.15,-0.85 -0.09,-0.27 -0.24,-0.49 -0.44,-0.68 -0.2,-0.19 -0.45,-0.33 -0.75,-0.44 -0.3,-0.1 -0.66,-0.16 -1.06,-0.16 -0.39,0 -0.74,0.04 -1.03,0.13 -0.29,0.09 -0.53,0.21 -0.72,0.36 -0.19,0.16 -0.34,0.34 -0.44,0.55 -0.1,0.21 -0.15,0.43 -0.15,0.66 0,0.48 0.25,0.88 0.74,1.21 0.38,0.25 0.77,0.48 1.41,0.7H7.39c-0.05,-0.08 -0.11,-0.17 -0.15,-0.25zM21,12v-2H3v2h9.62c0.18,0.07 0.4,0.14 0.55,0.2 0.37,0.17 0.66,0.34 0.87,0.51 0.21,0.17 0.35,0.36 0.43,0.57 0.07,0.2 0.11,0.43 0.11,0.69 0,0.23 -0.05,0.45 -0.14,0.66 -0.09,0.2 -0.23,0.38 -0.42,0.53 -0.19,0.15 -0.42,0.26 -0.71,0.35 -0.29,0.08 -0.63,0.13 -1.01,0.13 -0.43,0 -0.83,-0.04 -1.18,-0.13s-0.66,-0.23 -0.91,-0.42c-0.25,-0.19 -0.45,-0.44 -0.59,-0.75 -0.14,-0.31 -0.25,-0.76 -0.25,-1.21H6.4c0,0.55 0.08,1.13 0.24,1.58 0.16,0.45 0.37,0.85 0.65,1.21 0.28,0.35 0.6,0.66 0.98,0.92 0.37,0.26 0.78,0.48 1.22,0.65 0.44,0.17 0.9,0.3 1.38,0.39 0.48,0.08 0.96,0.13 1.44,0.13 0.8,0 1.53,-0.09 2.18,-0.28s1.21,-0.45 1.67,-0.79c0.46,-0.34 0.82,-0.77 1.07,-1.27s0.38,-1.07 0.38,-1.71c0,-0.6 -0.1,-1.14 -0.31,-1.61 -0.05,-0.11 -0.11,-0.23 -0.17,-0.33H21z"/>
</vector>

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

@ -5,10 +5,65 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<!--bold, italic, etc buttons--> <!--bold, italic, etc buttons-->
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/bold_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_bold_grey_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/italic_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_italic_grey_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/underline_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_underlined_grey_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/strikethrough_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_strikethrough_s_grey_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/unordered_list_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_list_bulleted_black_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/align_left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_align_left_grey_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/align_center_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_align_center_grey_36dp"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/align_right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_format_align_right_grey_36dp"
android:padding="4dp"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

Loading…
Cancel
Save