@@ -353,6 +353,92 @@ public void handleMessage(Message msg) {
353353 }
354354 };
355355
356+ //DON'T CHANGE THESE!!!
357+ private static final String KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_DOWN_UP = "io.github.sds100.keymapper.inputmethod.ACTION_INPUT_DOWN_UP" ;
358+ private static final String KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_DOWN = "io.github.sds100.keymapper.inputmethod.ACTION_INPUT_DOWN" ;
359+ private static final String KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_UP = "io.github.sds100.keymapper.inputmethod.ACTION_INPUT_UP" ;
360+ private static final String KEY_MAPPER_INPUT_METHOD_ACTION_TEXT = "io.github.sds100.keymapper.inputmethod.ACTION_INPUT_TEXT" ;
361+
362+ private static final String KEY_MAPPER_INPUT_METHOD_EXTRA_TEXT = "io.github.sds100.keymapper.inputmethod.EXTRA_TEXT" ;
363+ private static final String KEY_MAPPER_INPUT_METHOD_EXTRA_KEY_EVENT = "io.github.sds100.keymapper.inputmethod.EXTRA_KEY_EVENT" ;
364+
365+ final static class KeyMapperBroadcastReceiver extends BroadcastReceiver {
366+ private final LatinIME mIms ;
367+
368+ public KeyMapperBroadcastReceiver (LatinIME ims ) {
369+ mIms = ims ;
370+ }
371+
372+ @ Override
373+ public void onReceive (Context context , Intent intent ) {
374+ final String action = intent .getAction ();
375+
376+ assert action != null ;
377+
378+ switch (action ) {
379+ case LatinIME .KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_DOWN_UP : {
380+ KeyEvent downEvent = intent .getParcelableExtra (KEY_MAPPER_INPUT_METHOD_EXTRA_KEY_EVENT );
381+
382+ InputConnection ic = mIms .getCurrentInputConnection ();
383+
384+ if (ic != null ) {
385+ ic .sendKeyEvent (downEvent );
386+ }
387+
388+ KeyEvent upEvent = KeyEvent .changeAction (downEvent , KeyEvent .ACTION_UP );
389+
390+ if (ic != null ) {
391+ ic .sendKeyEvent (upEvent );
392+ }
393+
394+ break ;
395+ }
396+
397+ case LatinIME .KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_DOWN : {
398+ KeyEvent downEvent = intent .getParcelableExtra (KEY_MAPPER_INPUT_METHOD_EXTRA_KEY_EVENT );
399+
400+ downEvent = KeyEvent .changeAction (downEvent , KeyEvent .ACTION_DOWN );
401+
402+ InputConnection ic = mIms .getCurrentInputConnection ();
403+
404+ if (ic != null ) {
405+ ic .sendKeyEvent (downEvent );
406+ }
407+
408+ break ;
409+ }
410+
411+ case LatinIME .KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_UP : {
412+ KeyEvent upEvent = intent .getParcelableExtra (KEY_MAPPER_INPUT_METHOD_EXTRA_KEY_EVENT );
413+
414+ upEvent = KeyEvent .changeAction (upEvent , KeyEvent .ACTION_UP );
415+
416+ InputConnection ic = mIms .getCurrentInputConnection ();
417+
418+ if (ic != null ) {
419+ ic .sendKeyEvent (upEvent );
420+ }
421+
422+ break ;
423+ }
424+
425+ case LatinIME .KEY_MAPPER_INPUT_METHOD_ACTION_TEXT : {
426+ String text = intent .getStringExtra (KEY_MAPPER_INPUT_METHOD_EXTRA_TEXT );
427+
428+ if (text == null ) return ;
429+
430+ if (mIms .getCurrentInputConnection () == null ) return ;
431+
432+ mIms .getCurrentInputConnection ().commitText (text , 1 );
433+
434+ break ;
435+ }
436+ }
437+ }
438+ }
439+
440+ final KeyMapperBroadcastReceiver mKeyMapperBroadcastReceiver = new KeyMapperBroadcastReceiver (this );
441+
356442 @ Override
357443 public void onCreate () {
358444 Log .i ("PCKeyboard" , "onCreate(), os.version=" + System .getProperty ("os.version" ));
@@ -434,6 +520,14 @@ public void onCreate() {
434520 registerReceiver (mReceiver , filter );
435521 prefs .registerOnSharedPreferenceChangeListener (this );
436522 setNotification (mKeyboardNotification );
523+
524+ final IntentFilter keyMapperIntentFilter = new IntentFilter ();
525+ keyMapperIntentFilter .addAction (KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_DOWN_UP );
526+ keyMapperIntentFilter .addAction (KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_DOWN );
527+ keyMapperIntentFilter .addAction (KEY_MAPPER_INPUT_METHOD_ACTION_INPUT_UP );
528+ keyMapperIntentFilter .addAction (KEY_MAPPER_INPUT_METHOD_ACTION_TEXT );
529+
530+ registerReceiver (mKeyMapperBroadcastReceiver , keyMapperIntentFilter );
437531 }
438532
439533 private int getKeyboardModeNum (int origMode , int override ) {
@@ -657,6 +751,7 @@ public void onDestroy() {
657751 unregisterReceiver (mNotificationReceiver );
658752 mNotificationReceiver = null ;
659753 }
754+ unregisterReceiver (mKeyMapperBroadcastReceiver );
660755 super .onDestroy ();
661756 }
662757
0 commit comments