File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed
AnkiDroid/src/main/java/com/ichi2 Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ import com.ichi2.libanki.Notetypes
159159import com.ichi2.libanki.Notetypes.Companion.NOT_FOUND_NOTE_TYPE
160160import com.ichi2.libanki.Utils
161161import com.ichi2.themes.Themes
162+ import com.ichi2.utils.AndroidUiUtils.showSoftInput
162163import com.ichi2.utils.ClipboardUtil
163164import com.ichi2.utils.ClipboardUtil.MEDIA_MIME_TYPES
164165import com.ichi2.utils.ClipboardUtil.hasMedia
@@ -2464,7 +2465,15 @@ class NoteEditor :
24642465 text = b.buttonText
24652466 }
24662467 val bmp = toolbar.createDrawableForString(text)
2467- val v = toolbar.insertItem(0 , bmp, b.toFormatter())
2468+
2469+ val v =
2470+ toolbar.insertItem(0 , bmp) {
2471+ // Attempt to open keyboard for the currently focused view in the hosting Activity
2472+ val activity = context as ? Activity
2473+ activity.showSoftInput()
2474+
2475+ toolbar.onFormat(b.toFormatter())
2476+ }
24682477 v.contentDescription = text
24692478
24702479 // Allow Ctrl + 1...Ctrl + 0 for item 10.
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ import com.ichi2.anki.NoteEditor
5353import com.ichi2.anki.R
5454import com.ichi2.anki.preferences.sharedPrefs
5555import com.ichi2.compat.CompatHelper
56+ import com.ichi2.utils.AndroidUiUtils.showSoftInput
5657import com.ichi2.utils.ViewGroupUtils
5758import com.ichi2.utils.ViewGroupUtils.getAllChildrenRecursive
5859import com.ichi2.utils.dp
@@ -116,7 +117,13 @@ class Toolbar : FrameLayout {
116117 @IdRes id : Int ,
117118 prefix : String ,
118119 suffix : String ,
119- ) = findViewById<View >(id).setOnClickListener { onFormat(TextWrapper (prefix, suffix)) }
120+ ) = findViewById<View >(id).setOnClickListener {
121+ // Attempt to open keyboard for the currently focused view in the hosting Activity
122+ val activity = context as ? Activity
123+ activity.showSoftInput()
124+
125+ onFormat(TextWrapper (prefix, suffix))
126+ }
120127
121128 setupButtonWrappingText(R .id.note_editor_toolbar_button_bold, " <b>" , " </b>" )
122129 setupButtonWrappingText(R .id.note_editor_toolbar_button_italic, " <i>" , " </i>" )
Original file line number Diff line number Diff line change 1515 */
1616package com.ichi2.utils
1717
18+ import android.app.Activity
1819import android.content.Context
1920import android.view.View
2021import android.view.Window
2122import android.view.WindowManager
2223import android.view.inputmethod.InputMethodManager
2324
2425object AndroidUiUtils {
26+ /* *
27+ * Shows the soft keyboard for the current focused view in the activity.
28+ *
29+ * It's a good practice to ensure that the `currentFocus` is an
30+ * appropriate input field (e.g., EditText) before calling this function
31+ */
32+ fun Activity?.showSoftInput () {
33+ val currentFocus = this ?.currentFocus ? : return
34+ val imm = this .getSystemService(Context .INPUT_METHOD_SERVICE ) as InputMethodManager
35+ imm.showSoftInput(currentFocus, InputMethodManager .SHOW_IMPLICIT )
36+ }
37+
2538 /* *
2639 * This method is used for setting the focus on an EditText which is used in a dialog
2740 * and for opening the keyboard.
You can’t perform that action at this time.
0 commit comments