From d356f9f54bbc78c06110ec47b594482b14a9e0ff Mon Sep 17 00:00:00 2001 From: lurebat <154669821+lurebat@users.noreply.github.com> Date: Mon, 16 Jun 2025 19:55:15 +0300 Subject: [PATCH] Add broadcast intent keys (#1675) This commit introduces three new keycodes: SEND_INTENT_ONE, SEND_INTENT_TWO, and SEND_INTENT_THREE. When these keys are pressed, a broadcast intent is sent with the action `helium314.keyboard.latin.ACTION_SEND_INTENT`. The intent includes an extra `EXTRA_NUMBER` (integer) indicating which of the three keys was pressed (1, 2, or 3). This functionality allows external applications to react to these specific key presses. --- .../keyboard_parser/floris/KeyCode.kt | 8 +++++- .../keyboard/latin/inputlogic/InputLogic.java | 3 +++ .../keyboard/latin/utils/IntentUtils.kt | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/helium314/keyboard/latin/utils/IntentUtils.kt diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt index cf34b4228..eccf62ebb 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/KeyCode.kt @@ -175,6 +175,12 @@ object KeyCode { const val META_LEFT = -10048 const val META_RIGHT = -10049 + + // Intents + const val SEND_INTENT_ONE = -20000 + const val SEND_INTENT_TWO = -20001 + const val SEND_INTENT_THREE = -20002 + /** to make sure a FlorisBoard code works when reading a JSON layout */ fun Int.checkAndConvertCode(): Int = if (this > 0) this else when (this) { // working @@ -190,7 +196,7 @@ object KeyCode { ACTION_NEXT, ACTION_PREVIOUS, NOT_SPECIFIED, CLIPBOARD_COPY_ALL, WORD_LEFT, WORD_RIGHT, PAGE_UP, PAGE_DOWN, META, TAB, ESCAPE, INSERT, SLEEP, MEDIA_PLAY, MEDIA_PAUSE, MEDIA_PLAY_PAUSE, MEDIA_NEXT, MEDIA_PREVIOUS, VOL_UP, VOL_DOWN, MUTE, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BACK, - TIMESTAMP, CTRL_LEFT, CTRL_RIGHT, ALT_LEFT, ALT_RIGHT, META_LEFT, META_RIGHT + TIMESTAMP, CTRL_LEFT, CTRL_RIGHT, ALT_LEFT, ALT_RIGHT, META_LEFT, META_RIGHT, SEND_INTENT_ONE, SEND_INTENT_TWO, SEND_INTENT_THREE, -> this // conversion diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index 058ad3792..28572fa2f 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -49,6 +49,7 @@ import helium314.keyboard.latin.settings.SpacingAndPunctuations; import helium314.keyboard.latin.suggestions.SuggestionStripViewAccessor; import helium314.keyboard.latin.utils.AsyncResultHolder; import helium314.keyboard.latin.utils.InputTypeUtils; +import helium314.keyboard.latin.utils.IntentUtils; import helium314.keyboard.latin.utils.Log; import helium314.keyboard.latin.utils.RecapitalizeStatus; import helium314.keyboard.latin.utils.ScriptUtils; @@ -778,6 +779,8 @@ public final class InputLogic { case KeyCode.TIMESTAMP: mLatinIME.onTextInput(TimestampKt.getTimestamp(mLatinIME)); break; + case KeyCode.SEND_INTENT_ONE, KeyCode.SEND_INTENT_TWO, KeyCode.SEND_INTENT_THREE: + IntentUtils.handleSendIntentKey(mLatinIME, event.getMKeyCode()); case KeyCode.IME_HIDE_UI: mLatinIME.requestHideSelf(0); break; diff --git a/app/src/main/java/helium314/keyboard/latin/utils/IntentUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/IntentUtils.kt new file mode 100644 index 000000000..da1b06bd8 --- /dev/null +++ b/app/src/main/java/helium314/keyboard/latin/utils/IntentUtils.kt @@ -0,0 +1,26 @@ +package helium314.keyboard.latin.utils + +import android.content.Context +import android.content.Intent +import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode +import helium314.keyboard.latin.inputlogic.InputLogic +import helium314.keyboard.latin.utils.Log.i + +object IntentUtils { + val TAG: String = InputLogic::class.java.simpleName + private val ACTION_SEND_INTENT = "helium314.keyboard.latin.ACTION_SEND_INTENT" + private val EXTRA_NUMBER = "EXTRA_NUMBER" + + @JvmStatic + fun handleSendIntentKey(context: Context, mKeyCode: Int) { + val intentNumber = (KeyCode.SEND_INTENT_ONE + 1) - mKeyCode; + + val intent: Intent = Intent(ACTION_SEND_INTENT).apply { + putExtra(EXTRA_NUMBER, intentNumber) + } + + context.sendBroadcast(intent) + i(TAG, "Sent broadcast for intent number: $intentNumber") + } +} +