A game framework written with osu! in mind.
at master 1.9 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using Android.Views; 5using Android.Views.InputMethods; 6using Java.Lang; 7 8namespace osu.Framework.Android.Input 9{ 10 internal class AndroidInputConnection : BaseInputConnection 11 { 12 public AndroidGameView TargetView { get; set; } 13 14 public AndroidInputConnection(AndroidGameView targetView, bool fullEditor) 15 : base(targetView, fullEditor) 16 { 17 TargetView = targetView; 18 } 19 20 public override bool CommitText(ICharSequence text, int newCursorPosition) 21 { 22 if (text.Length() != 0) 23 { 24 TargetView.OnCommitText(text.ToString()); 25 return true; 26 } 27 28 return base.CommitText(text, newCursorPosition); 29 } 30 31 public override bool SendKeyEvent(KeyEvent e) 32 { 33 switch (e.Action) 34 { 35 case KeyEventActions.Down: 36 TargetView?.OnKeyDown(e.KeyCode, e); 37 return true; 38 39 case KeyEventActions.Up: 40 TargetView?.OnKeyUp(e.KeyCode, e); 41 return true; 42 43 case KeyEventActions.Multiple: 44 TargetView?.OnKeyDown(e.KeyCode, e); 45 TargetView?.OnKeyUp(e.KeyCode, e); 46 return true; 47 } 48 49 return base.SendKeyEvent(e); 50 } 51 52 public override bool DeleteSurroundingText(int beforeLength, int afterLength) 53 { 54 for (int i = 0; i < beforeLength; i++) 55 { 56 KeyEvent ed = new KeyEvent(KeyEventActions.Multiple, Keycode.Del); 57 SendKeyEvent(ed); 58 } 59 60 return true; 61 } 62 } 63}