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