|
@ -10,9 +10,12 @@ import android.support.annotation.Nullable; |
|
|
import android.support.design.widget.TextInputEditText; |
|
|
import android.support.design.widget.TextInputEditText; |
|
|
import android.support.design.widget.TextInputLayout; |
|
|
import android.support.design.widget.TextInputLayout; |
|
|
import android.support.v7.widget.AppCompatImageButton; |
|
|
import android.support.v7.widget.AppCompatImageButton; |
|
|
|
|
|
import android.support.v7.widget.GridLayoutManager; |
|
|
|
|
|
import android.support.v7.widget.RecyclerView; |
|
|
import android.text.Editable; |
|
|
import android.text.Editable; |
|
|
import android.text.TextUtils; |
|
|
import android.text.TextUtils; |
|
|
import android.util.AttributeSet; |
|
|
import android.util.AttributeSet; |
|
|
|
|
|
import android.util.DisplayMetrics; |
|
|
import android.util.SparseArray; |
|
|
import android.util.SparseArray; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.inputmethod.EditorInfo; |
|
|
import android.view.inputmethod.EditorInfo; |
|
@ -80,47 +83,6 @@ public class EditorView extends LinearLayout { |
|
|
return false; |
|
|
return false; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
emojiButton.setOnClickListener(view -> { |
|
|
|
|
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); |
|
|
|
|
|
assert imm != null; |
|
|
|
|
|
if (emojiKeyboardOwner.isEmojiKeyboardVisible()) { |
|
|
|
|
|
editText.requestFocus(); |
|
|
|
|
|
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); |
|
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_tag_faces_24dp); |
|
|
|
|
|
} else { |
|
|
|
|
|
imm.hideSoftInputFromWindow(getWindowToken(), 0); |
|
|
|
|
|
view.clearFocus(); |
|
|
|
|
|
emojiButton.setImageResource(R.drawable.ic_keyboard_24dp); |
|
|
|
|
|
} |
|
|
|
|
|
emojiKeyboardOwner.setEmojiKeyboardVisible(!emojiKeyboardOwner.isEmojiKeyboardVisible()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
submitButton = findViewById(R.id.submit_button); |
|
|
|
|
|
findViewById(R.id.bold_button).setOnClickListener(view -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[b]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/b]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
}); |
|
|
|
|
|
findViewById(R.id.italic_button).setOnClickListener(view -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[i]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/i]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
}); |
|
|
|
|
|
findViewById(R.id.underline_button).setOnClickListener(view -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[u]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/u]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
}); |
|
|
|
|
|
findViewById(R.id.strikethrough_button).setOnClickListener(view -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[s]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/s]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
colors.append(R.id.black, "black"); |
|
|
colors.append(R.id.black, "black"); |
|
|
colors.append(R.id.red, "red"); |
|
|
colors.append(R.id.red, "red"); |
|
|
colors.append(R.id.yellow, "yellow"); |
|
|
colors.append(R.id.yellow, "yellow"); |
|
@ -136,114 +98,181 @@ public class EditorView extends LinearLayout { |
|
|
colors.append(R.id.maroon, "maroon"); |
|
|
colors.append(R.id.maroon, "maroon"); |
|
|
colors.append(R.id.lime_green, "limegreen"); |
|
|
colors.append(R.id.lime_green, "limegreen"); |
|
|
|
|
|
|
|
|
findViewById(R.id.text_color_button).setOnClickListener(view -> { |
|
|
RecyclerView formatButtonsRecyclerview = findViewById(R.id.buttons_recyclerview); |
|
|
PopupWindow popupWindow = new PopupWindow(view.getContext()); |
|
|
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); |
|
|
popupWindow.setHeight(LayoutParams.WRAP_CONTENT); |
|
|
float itemWidth = getResources().getDimension(R.dimen.editor_format_button_size) + |
|
|
popupWindow.setWidth(LayoutParams.WRAP_CONTENT); |
|
|
getResources().getDimension(R.dimen.editor_format_button_margin_between); |
|
|
popupWindow.setFocusable(true); |
|
|
int columns = (int) Math.floor(displayMetrics.widthPixels / itemWidth); |
|
|
ScrollView colorPickerScrollview = (ScrollView) LayoutInflater.from(context).inflate(R.layout.editor_view_color_picker, null); |
|
|
formatButtonsRecyclerview.setLayoutManager(new GridLayoutManager(context, columns)); |
|
|
LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0); |
|
|
formatButtonsRecyclerview.setAdapter(new FormatButtonsAdapter((view, drawableId) -> { |
|
|
popupWindow.setContentView(colorPickerScrollview); |
|
|
switch (drawableId) { |
|
|
for (int i = 0; i < colorPicker.getChildCount(); i++) { |
|
|
case R.drawable.ic_format_bold: { |
|
|
TextView child = (TextView) colorPicker.getChildAt(i); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
child.setOnClickListener(v -> { |
|
|
getText().insert(editText.getSelectionStart(), "[b]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/b]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_italic: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[i]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/i]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_underlined: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[u]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/u]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_strikethrough_s: { |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]"); |
|
|
getText().insert(editText.getSelectionStart(), "[s]"); |
|
|
getText().insert(editText.getSelectionEnd(), "[/color]"); |
|
|
getText().insert(editText.getSelectionEnd(), "[/s]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_color_text: { |
|
|
|
|
|
PopupWindow popupWindow = new PopupWindow(view.getContext()); |
|
|
|
|
|
popupWindow.setHeight(LayoutParams.WRAP_CONTENT); |
|
|
|
|
|
popupWindow.setWidth(LayoutParams.WRAP_CONTENT); |
|
|
|
|
|
popupWindow.setFocusable(true); |
|
|
|
|
|
ScrollView colorPickerScrollview = (ScrollView) LayoutInflater.from(context).inflate(R.layout.editor_view_color_picker, null); |
|
|
|
|
|
LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0); |
|
|
|
|
|
popupWindow.setContentView(colorPickerScrollview); |
|
|
|
|
|
for (int i = 0; i < colorPicker.getChildCount(); i++) { |
|
|
|
|
|
TextView child = (TextView) colorPicker.getChildAt(i); |
|
|
|
|
|
child.setOnClickListener(v -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/color]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); |
|
|
|
|
|
popupWindow.dismiss(); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
popupWindow.showAsDropDown(view); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_size: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[size=10pt]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/size]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_text_format: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[font=Verdana]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/font]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_list_bulleted: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[list]\n[li]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/li]\n[li][/li]\n[/list]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() - 13 : editText.getSelectionStart() - 23); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_align_left: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[left]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/left]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_align_center: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[center]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/center]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 9); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
case R.drawable.ic_format_align_right: { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[right]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/right]"); |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); |
|
|
popupWindow.dismiss(); |
|
|
break; |
|
|
}); |
|
|
} |
|
|
} |
|
|
case R.drawable.ic_insert_link: { |
|
|
popupWindow.showAsDropDown(view); |
|
|
LinearLayout dialogBody = (LinearLayout) LayoutInflater.from(context) |
|
|
}); |
|
|
.inflate(R.layout.dialog_create_link, null); |
|
|
findViewById(R.id.text_size_button).setOnClickListener(view -> { |
|
|
TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
linkUrl.setOnClickListener(view1 -> linkUrl.setError(null)); |
|
|
getText().insert(editText.getSelectionStart(), "[size=10pt]"); |
|
|
TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input); |
|
|
getText().insert(editText.getSelectionEnd(), "[/size]"); |
|
|
linkText.setOnClickListener(view2 -> linkText.setError(null)); |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
}); |
|
|
int start = editText.getSelectionStart(), end = editText.getSelectionEnd(); |
|
|
findViewById(R.id.font_button).setOnClickListener(view -> { |
|
|
if (editText.hasSelection()) { |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
linkText.getEditText().setText( |
|
|
getText().insert(editText.getSelectionStart(), "[font=Verdana]"); |
|
|
editText.getText().toString().substring(editText.getSelectionStart(), editText.getSelectionEnd())); |
|
|
getText().insert(editText.getSelectionEnd(), "[/font]"); |
|
|
} |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog) |
|
|
}); |
|
|
.setTitle(R.string.dialog_create_link_title) |
|
|
findViewById(R.id.unordered_list_button).setOnClickListener(view -> { |
|
|
.setView(dialogBody) |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
.setPositiveButton(R.string.ok, (dialog, which) -> { |
|
|
getText().insert(editText.getSelectionStart(), "[list]\n[li]"); |
|
|
if (TextUtils.isEmpty(Objects.requireNonNull(linkUrl.getEditText()).getText().toString())) { |
|
|
getText().insert(editText.getSelectionEnd(), "[/li]\n[li][/li]\n[/list]"); |
|
|
linkUrl.setError(context.getString(R.string.input_field_required)); |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() - 13 : editText.getSelectionStart() - 23); |
|
|
return; |
|
|
}); |
|
|
} |
|
|
findViewById(R.id.align_left_button).setOnClickListener(view -> { |
|
|
if (TextUtils.isEmpty(Objects.requireNonNull(linkText.getEditText()).getText().toString())) { |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
linkUrl.setError(context.getString(R.string.input_field_required)); |
|
|
getText().insert(editText.getSelectionStart(), "[left]"); |
|
|
return; |
|
|
getText().insert(editText.getSelectionEnd(), "[/left]"); |
|
|
} |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
|
|
|
}); |
|
|
if (hadTextSelection) editText.getText().delete(start, end); |
|
|
findViewById(R.id.align_center_button).setOnClickListener(view -> { |
|
|
getText().insert(editText.getSelectionStart(), "[url=" + |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
Objects.requireNonNull(linkUrl.getEditText()).getText().toString() + "]" + |
|
|
getText().insert(editText.getSelectionStart(), "[center]"); |
|
|
Objects.requireNonNull(linkText.getEditText()).getText().toString() + "[/url]"); |
|
|
getText().insert(editText.getSelectionEnd(), "[/center]"); |
|
|
}) |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 9); |
|
|
.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) |
|
|
}); |
|
|
.show(); |
|
|
findViewById(R.id.align_right_button).setOnClickListener(view -> { |
|
|
break; |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
} |
|
|
getText().insert(editText.getSelectionStart(), "[right]"); |
|
|
case R.drawable.ic_format_quote: { |
|
|
getText().insert(editText.getSelectionEnd(), "[/right]"); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); |
|
|
getText().insert(editText.getSelectionStart(), "[quote]"); |
|
|
}); |
|
|
getText().insert(editText.getSelectionEnd(), "[/quote]"); |
|
|
findViewById(R.id.link_button).setOnClickListener(view -> { |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); |
|
|
LinearLayout dialogBody = (LinearLayout) LayoutInflater.from(context) |
|
|
break; |
|
|
.inflate(R.layout.dialog_create_link, null); |
|
|
} |
|
|
TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input); |
|
|
case R.drawable.ic_code: { |
|
|
linkUrl.setOnClickListener(view1 -> linkUrl.setError(null)); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input); |
|
|
getText().insert(editText.getSelectionStart(), "[code]"); |
|
|
linkText.setOnClickListener(view2 -> linkText.setError(null)); |
|
|
getText().insert(editText.getSelectionEnd(), "[/code]"); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
int start = editText.getSelectionStart(), end = editText.getSelectionEnd(); |
|
|
break; |
|
|
if (editText.hasSelection()) { |
|
|
} |
|
|
linkText.getEditText().setText( |
|
|
case R.drawable.ic_functions: { |
|
|
editText.getText().toString().substring(editText.getSelectionStart(), editText.getSelectionEnd())); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[tex]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/tex]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 6); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
default: throw new IllegalArgumentException("Unknown format button click"); |
|
|
} |
|
|
} |
|
|
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 (hadTextSelection) editText.getText().delete(start, end); |
|
|
emojiButton.setOnClickListener(view -> { |
|
|
getText().insert(editText.getSelectionStart(), "[url=" + |
|
|
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); |
|
|
Objects.requireNonNull(linkUrl.getEditText()).getText().toString() + "]" + |
|
|
assert imm != null; |
|
|
Objects.requireNonNull(linkText.getEditText()).getText().toString() + "[/url]"); |
|
|
if (emojiKeyboardOwner.isEmojiKeyboardVisible()) { |
|
|
}) |
|
|
editText.requestFocus(); |
|
|
.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) |
|
|
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); |
|
|
.show(); |
|
|
emojiButton.setImageResource(R.drawable.ic_tag_faces_24dp); |
|
|
}); |
|
|
} else { |
|
|
findViewById(R.id.quote_button).setOnClickListener(view -> { |
|
|
imm.hideSoftInputFromWindow(getWindowToken(), 0); |
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
view.clearFocus(); |
|
|
getText().insert(editText.getSelectionStart(), "[quote]"); |
|
|
emojiButton.setImageResource(R.drawable.ic_keyboard_24dp); |
|
|
getText().insert(editText.getSelectionEnd(), "[/quote]"); |
|
|
} |
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); |
|
|
emojiKeyboardOwner.setEmojiKeyboardVisible(!emojiKeyboardOwner.isEmojiKeyboardVisible()); |
|
|
}); |
|
|
|
|
|
findViewById(R.id.code_button).setOnClickListener(view -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[code]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/code]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); |
|
|
|
|
|
}); |
|
|
|
|
|
findViewById(R.id.math_button).setOnClickListener(view -> { |
|
|
|
|
|
boolean hadTextSelection = editText.hasSelection(); |
|
|
|
|
|
getText().insert(editText.getSelectionStart(), "[tex]"); |
|
|
|
|
|
getText().insert(editText.getSelectionEnd(), "[/tex]"); |
|
|
|
|
|
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 6); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
submitButton = findViewById(R.id.submit_button); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public TextInputEditText getEditText() { |
|
|
public TextInputEditText getEditText() { |
|
|