SDLInputConnection.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using Android.Runtime;
  3. using Android.Views;
  4. using Android.Views.InputMethods;
  5. using Java.Lang;
  6. namespace Urho.Android
  7. {
  8. public class SDLInputConnection : BaseInputConnection
  9. {
  10. public SDLInputConnection(View targetView, bool fullEditor) : base(targetView, fullEditor)
  11. {
  12. }
  13. public override bool SendKeyEvent(KeyEvent e)
  14. {
  15. var keyCode = e.KeyCode;
  16. if (e.Action == KeyEventActions.Down)
  17. {
  18. if (e.IsPrintingKey)
  19. {
  20. CommitText(Java.Lang.String.ValueOf(e.GetUnicodeChar(0)), 1);
  21. }
  22. SDLActivity.onNativeKeyDown(keyCode);
  23. return true;
  24. }
  25. else if (e.Action == KeyEventActions.Up)
  26. {
  27. SDLActivity.onNativeKeyUp(keyCode);
  28. return true;
  29. }
  30. return base.SendKeyEvent(e);
  31. }
  32. public override bool DeleteSurroundingText(int beforeLength, int afterLength)
  33. {
  34. return base.DeleteSurroundingText(beforeLength, afterLength);
  35. }
  36. public override bool SetComposingText(ICharSequence text, int newCursorPosition)
  37. {
  38. return base.SetComposingText(text, newCursorPosition);
  39. }
  40. public native void nativeCommitText(String text, int newCursorPosition);
  41. public native void nativeSetComposingText(String text, int newCursorPosition);
  42. }
  43. }