mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-28 11:49:56 +00:00
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.
This commit is contained in:
parent
9549389be7
commit
d356f9f54b
3 changed files with 36 additions and 1 deletions
|
@ -175,6 +175,12 @@ object KeyCode {
|
||||||
const val META_LEFT = -10048
|
const val META_LEFT = -10048
|
||||||
const val META_RIGHT = -10049
|
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 */
|
/** to make sure a FlorisBoard code works when reading a JSON layout */
|
||||||
fun Int.checkAndConvertCode(): Int = if (this > 0) this else when (this) {
|
fun Int.checkAndConvertCode(): Int = if (this > 0) this else when (this) {
|
||||||
// working
|
// working
|
||||||
|
@ -190,7 +196,7 @@ object KeyCode {
|
||||||
ACTION_NEXT, ACTION_PREVIOUS, NOT_SPECIFIED, CLIPBOARD_COPY_ALL, WORD_LEFT, WORD_RIGHT, PAGE_UP,
|
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,
|
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,
|
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
|
-> this
|
||||||
|
|
||||||
// conversion
|
// conversion
|
||||||
|
|
|
@ -49,6 +49,7 @@ import helium314.keyboard.latin.settings.SpacingAndPunctuations;
|
||||||
import helium314.keyboard.latin.suggestions.SuggestionStripViewAccessor;
|
import helium314.keyboard.latin.suggestions.SuggestionStripViewAccessor;
|
||||||
import helium314.keyboard.latin.utils.AsyncResultHolder;
|
import helium314.keyboard.latin.utils.AsyncResultHolder;
|
||||||
import helium314.keyboard.latin.utils.InputTypeUtils;
|
import helium314.keyboard.latin.utils.InputTypeUtils;
|
||||||
|
import helium314.keyboard.latin.utils.IntentUtils;
|
||||||
import helium314.keyboard.latin.utils.Log;
|
import helium314.keyboard.latin.utils.Log;
|
||||||
import helium314.keyboard.latin.utils.RecapitalizeStatus;
|
import helium314.keyboard.latin.utils.RecapitalizeStatus;
|
||||||
import helium314.keyboard.latin.utils.ScriptUtils;
|
import helium314.keyboard.latin.utils.ScriptUtils;
|
||||||
|
@ -778,6 +779,8 @@ public final class InputLogic {
|
||||||
case KeyCode.TIMESTAMP:
|
case KeyCode.TIMESTAMP:
|
||||||
mLatinIME.onTextInput(TimestampKt.getTimestamp(mLatinIME));
|
mLatinIME.onTextInput(TimestampKt.getTimestamp(mLatinIME));
|
||||||
break;
|
break;
|
||||||
|
case KeyCode.SEND_INTENT_ONE, KeyCode.SEND_INTENT_TWO, KeyCode.SEND_INTENT_THREE:
|
||||||
|
IntentUtils.handleSendIntentKey(mLatinIME, event.getMKeyCode());
|
||||||
case KeyCode.IME_HIDE_UI:
|
case KeyCode.IME_HIDE_UI:
|
||||||
mLatinIME.requestHideSelf(0);
|
mLatinIME.requestHideSelf(0);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue