14
14
import org .mozilla .vrbrowser .ui .widgets .Widget ;
15
15
import org .mozilla .vrbrowser .utils .SystemUtils ;
16
16
17
+ import java .util .Arrays ;
18
+ import java .util .List ;
19
+
17
20
public class MotionEventGenerator {
18
21
static final String LOGTAG = SystemUtils .createLogtag (MotionEventGenerator .class );
19
22
static class Device {
@@ -24,6 +27,7 @@ static class Device {
24
27
long mDownTime ;
25
28
MotionEvent .PointerProperties mProperties [];
26
29
MotionEvent .PointerCoords mCoords [];
30
+ MotionEvent .PointerCoords mMouseOutCoords [];
27
31
28
32
Device (final int aDevice ) {
29
33
mDevice = aDevice ;
@@ -33,24 +37,34 @@ static class Device {
33
37
mProperties [0 ].toolType = MotionEvent .TOOL_TYPE_FINGER ;
34
38
mCoords = new MotionEvent .PointerCoords [1 ];
35
39
mCoords [0 ] = new MotionEvent .PointerCoords ();
36
- mCoords [0 ].toolMajor = 2 ;
37
- mCoords [0 ].toolMinor = 2 ;
38
- mCoords [0 ].touchMajor = 2 ;
39
- mCoords [0 ].touchMinor = 2 ;
40
+ mMouseOutCoords = new MotionEvent .PointerCoords [1 ];
41
+ for (MotionEvent .PointerCoords [] coords : Arrays .asList (mCoords , mMouseOutCoords )) {
42
+ coords [0 ] = new MotionEvent .PointerCoords ();
43
+ coords [0 ].toolMajor = 2 ;
44
+ coords [0 ].toolMinor = 2 ;
45
+ coords [0 ].touchMajor = 2 ;
46
+ coords [0 ].touchMinor = 2 ;
47
+ }
48
+ mMouseOutCoords [0 ].x = -10 ;
49
+ mMouseOutCoords [0 ].y = -10 ;
40
50
}
41
51
}
42
52
43
53
private static SparseArray <Device > devices = new SparseArray <>();
44
54
45
55
46
56
private static void generateEvent (Widget aWidget , Device aDevice , int aAction , boolean aGeneric ) {
57
+ generateEvent (aWidget , aDevice , aAction , aGeneric , aDevice .mCoords );
58
+ }
59
+
60
+ private static void generateEvent (Widget aWidget , Device aDevice , int aAction , boolean aGeneric , MotionEvent .PointerCoords [] aCoords ) {
47
61
MotionEvent event = MotionEvent .obtain (
48
62
/*mDownTime*/ aDevice .mDownTime ,
49
63
/*eventTime*/ SystemClock .uptimeMillis (),
50
64
/*action*/ aAction ,
51
65
/*pointerCount*/ 1 ,
52
66
/*pointerProperties*/ aDevice .mProperties ,
53
- /*pointerCoords*/ aDevice . mCoords ,
67
+ /*pointerCoords*/ aCoords ,
54
68
/*metaState*/ 0 ,
55
69
/*buttonState*/ 0 ,
56
70
/*xPrecision*/ 0 ,
@@ -88,7 +102,7 @@ public static void dispatch(Widget aWidget, int aDevice, boolean aPressed, float
88
102
generateEvent (device .mPreviousWidget , device , MotionEvent .ACTION_CANCEL , false );
89
103
device .mWasPressed = false ;
90
104
}
91
- generateEvent (device .mPreviousWidget , device , MotionEvent .ACTION_HOVER_EXIT , true );
105
+ generateEvent (device .mPreviousWidget , device , MotionEvent .ACTION_HOVER_EXIT , true , device . mMouseOutCoords );
92
106
device .mPreviousWidget = null ;
93
107
}
94
108
if (aWidget == null ) {
0 commit comments