From 51a41ec90af505b153cc7a016de3c1e8a18dc427 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 30 Dec 2023 00:56:55 +0100 Subject: Voice IME chooser popup Bring a popup for choosing the voice IME when the voice key is pressed for the first time or the list of voice IMEs installed on the device change. A preference stores the last selected IME and the last seen list of IMEs. --- srcs/juloo.keyboard2/Utils.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 srcs/juloo.keyboard2/Utils.java (limited to 'srcs/juloo.keyboard2/Utils.java') diff --git a/srcs/juloo.keyboard2/Utils.java b/srcs/juloo.keyboard2/Utils.java new file mode 100644 index 0000000..cd28dfa --- /dev/null +++ b/srcs/juloo.keyboard2/Utils.java @@ -0,0 +1,30 @@ +package juloo.keyboard2; + +import android.app.AlertDialog; +import android.os.IBinder; +import android.view.Window; +import android.view.WindowManager; + +class Utils +{ + /** Turn the first letter of a string uppercase. */ + public static String capitalize_string(String s) + { + // Make sure not to cut a code point in half + int i = s.offsetByCodePoints(0, 1); + return s.substring(0, i).toUpperCase() + s.substring(i); + } + + /** Like [dialog.show()] but properly configure layout params when called + from an IME. [token] is the input view's [getWindowToken()]. */ + public static void show_dialog_on_ime(AlertDialog dialog, IBinder token) + { + Window win = dialog.getWindow(); + WindowManager.LayoutParams lp = win.getAttributes(); + lp.token = token; + lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; + win.setAttributes(lp); + win.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); + dialog.show(); + } +} -- cgit v1.2.3