diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.java b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.java index bb7e6558e593..0076023c3927 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.java @@ -1913,8 +1913,7 @@ private void updateToolbar() { // 0th button shows as '1' and is Ctrl + 1 int visualIndex = b.getIndex() + 1; - String text = Integer.toString(visualIndex); - Drawable bmp = mToolbar.createDrawableForString(text); + Drawable bmp = mToolbar.createDrawableForString(b.getIcon()); View v = mToolbar.insertItem(0, bmp, b.toFormatter()); @@ -1946,14 +1945,14 @@ private void saveToolbarButtons(ArrayList buttons) { .apply(); } - private void addToolbarButton(String prefix, String suffix) { - if (TextUtils.isEmpty(prefix) && TextUtils.isEmpty(suffix)) { + private void addToolbarButton(String icon, String prefix, String suffix) { + if (TextUtils.isEmpty(icon) && TextUtils.isEmpty(prefix) && TextUtils.isEmpty(suffix)) { return; } ArrayList toolbarButtons = getToolbarButtons(); - toolbarButtons.add(new CustomToolbarButton(toolbarButtons.size(), prefix, suffix)); + toolbarButtons.add(new CustomToolbarButton(toolbarButtons.size(), icon, prefix, suffix)); saveToolbarButtons(toolbarButtons); updateToolbar(); @@ -1988,10 +1987,11 @@ private void displayAddToolbarDialog() { .onNeutral((m, v) -> openUrl(Uri.parse(getString(R.string.link_manual_note_format_toolbar)))) .onPositive((m, v) -> { View view = m.getView(); + EditText etIcon = view.findViewById(R.id.note_editor_toolbar_item_icon); EditText et = view.findViewById(R.id.note_editor_toolbar_before); EditText et2 = view.findViewById(R.id.note_editor_toolbar_after); - addToolbarButton(et.getText().toString(), et2.getText().toString()); + addToolbarButton(etIcon.getText().toString(), et.getText().toString(), et2.getText().toString()); }) .show(); } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/CustomToolbarButton.kt b/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/CustomToolbarButton.kt index 7b1fb061cdf3..876d7e67eb90 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/CustomToolbarButton.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/noteeditor/CustomToolbarButton.kt @@ -22,7 +22,7 @@ import com.ichi2.utils.HashUtil.HashSetInit import timber.log.Timber import java.util.* -class CustomToolbarButton(var index: Int, private val prefix: String, private val suffix: String) { +class CustomToolbarButton(var index: Int, var icon: String, private val prefix: String, private val suffix: String) { fun toFormatter(): Toolbar.TextFormatter { return TextWrapper(prefix, suffix) } @@ -34,7 +34,7 @@ class CustomToolbarButton(var index: Int, private val prefix: String, private va return null } val fields = s.split(Consts.FIELD_SEPARATOR.toRegex(), KEEP_EMPTY_ENTRIES.coerceAtLeast(0)).toTypedArray() - if (fields.size != 3) { + if (fields.size != 4) { return null } val index: Int = try { @@ -43,7 +43,7 @@ class CustomToolbarButton(var index: Int, private val prefix: String, private va Timber.w(e) return null } - return CustomToolbarButton(index, fields[1], fields[2]) + return CustomToolbarButton(index, fields[1], fields[2], fields[3]) } @JvmStatic @@ -66,7 +66,7 @@ class CustomToolbarButton(var index: Int, private val prefix: String, private va fun toStringSet(buttons: ArrayList): Set { val ret = HashSetInit(buttons.size) for (b in buttons) { - val values = arrayOf(b.index.toString(), b.prefix, b.suffix) + val values = arrayOf(b.index.toString(), b.icon, b.prefix, b.suffix) for (i in values.indices) { values[i] = values[i].replace(Consts.FIELD_SEPARATOR, "") } diff --git a/AnkiDroid/src/main/res/layout/note_editor_toolbar_add_custom_item.xml b/AnkiDroid/src/main/res/layout/note_editor_toolbar_add_custom_item.xml index f4ae5b76acde..61d46b87adcd 100644 --- a/AnkiDroid/src/main/res/layout/note_editor_toolbar_add_custom_item.xml +++ b/AnkiDroid/src/main/res/layout/note_editor_toolbar_add_custom_item.xml @@ -26,6 +26,20 @@ android:text="@string/toolbar_item_explain_remove" android:paddingBottom="15dp"/> + + + + + + Insert MathJax Equation Insert Cloze Deletion + Character As Icon HTML Before Selection HTML After Selection Create Toolbar Item