@@ -97,8 +97,6 @@ public abstract class NativeActivity extends Activity {
97
97
98
98
private Vibrator vibrator ;
99
99
100
- private boolean isXperiaPlay ;
101
-
102
100
// This is to avoid losing the game/menu state etc when we are just
103
101
// switched-away from or rotated etc.
104
102
private boolean shuttingDown ;
@@ -136,6 +134,8 @@ public abstract class NativeActivity extends Activity {
136
134
public static final int REQUEST_CODE_CAMERA_PERMISSION = 3 ;
137
135
public static final int REQUEST_CODE_MICROPHONE_PERMISSION = 4 ;
138
136
137
+ public static boolean useModernMouseEvents = false ;
138
+
139
139
// Functions for the app activity to override to change behaviour.
140
140
141
141
public native void registerCallbacks ();
@@ -275,7 +275,7 @@ private static ArrayList<String> getSdCardPaths(final Context context) {
275
275
for (String var : varNames ) {
276
276
Log .i (TAG , "getSdCardPaths: Checking env " + var );
277
277
String secStore = System .getenv ("SECONDARY_STORAGE" );
278
- if (secStore != null && secStore .length () > 0 ) {
278
+ if (secStore != null && ! secStore .isEmpty () ) {
279
279
list = new ArrayList <String >();
280
280
list .add (secStore );
281
281
break ;
@@ -399,8 +399,6 @@ public void Initialize() {
399
399
// All other device types are treated the same.
400
400
}
401
401
402
- isXperiaPlay = IsXperiaPlay ();
403
-
404
402
String extStorageState = Environment .getExternalStorageState ();
405
403
String extStorageDir = Environment .getExternalStorageDirectory ().getAbsolutePath ();
406
404
File externalFiles = this .getExternalFilesDir (null );
@@ -573,10 +571,8 @@ private void updateSystemUiVisibility() {
573
571
// Need API 11 to check for existence of a vibrator? Zany.
574
572
@ TargetApi (Build .VERSION_CODES .HONEYCOMB )
575
573
public void checkForVibrator () {
576
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB ) {
577
- if (!vibrator .hasVibrator ()) {
578
- vibrator = null ;
579
- }
574
+ if (!vibrator .hasVibrator ()) {
575
+ vibrator = null ;
580
576
}
581
577
}
582
578
@@ -780,7 +776,7 @@ protected void onDestroy() {
780
776
do {
781
777
try {
782
778
Thread .sleep (10 );
783
- } catch (InterruptedException e ) {
779
+ } catch (InterruptedException ignored ) {
784
780
}
785
781
tries --;
786
782
} while (nativeRenderer .isRenderingFrame () && tries > 0 );
@@ -973,7 +969,7 @@ protected String getInputDeviceDebugString() {
973
969
for (InputDeviceState input : inputPlayers ) {
974
970
buffer += input .getDebugString ();
975
971
}
976
- if (buffer .length () == 0 ) {
972
+ if (buffer .isEmpty () ) {
977
973
buffer = "(no devices)" ;
978
974
}
979
975
return buffer ;
@@ -982,15 +978,28 @@ protected String getInputDeviceDebugString() {
982
978
}
983
979
}
984
980
985
- public boolean IsXperiaPlay () {
986
- return android .os .Build .MODEL .equals ("R800a" ) || android .os .Build .MODEL .equals ("R800i" ) || android .os .Build .MODEL .equals ("R800x" ) || android .os .Build .MODEL .equals ("R800at" ) || android .os .Build .MODEL .equals ("SO-01D" ) || android .os .Build .MODEL .equals ("zeus" );
987
- }
988
-
989
981
// We grab the keys before onKeyDown/... even see them. This is also better because it lets us
990
982
// distinguish devices.
991
983
@ Override
992
984
public boolean dispatchKeyEvent (KeyEvent event ) {
993
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB_MR1 && !isXperiaPlay ) {
985
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB_MR1 ) {
986
+ Log .i (TAG , "key event" + event .getSource ());
987
+ if (NativeSurfaceView .isFromSource (event , InputDevice .SOURCE_MOUSE )) {
988
+ Log .i (TAG , "Forwarding key event from mouse" );
989
+ if (event .getKeyCode () == KeyEvent .KEYCODE_BACK && !useModernMouseEvents ) {
990
+ // Probably a right click
991
+ switch (event .getAction ()) {
992
+ case KeyEvent .ACTION_DOWN :
993
+ NativeApp .mouse (-1 , -1 , 2 , 1 );
994
+ break ;
995
+ case KeyEvent .ACTION_UP :
996
+ NativeApp .mouse (-1 , -1 , 2 , 2 );
997
+ break ;
998
+ }
999
+ }
1000
+ return true ;
1001
+ }
1002
+
994
1003
InputDeviceState state = getInputDeviceState (event );
995
1004
if (state == null ) {
996
1005
return super .dispatchKeyEvent (event );
@@ -1022,12 +1031,14 @@ public boolean dispatchKeyEvent(KeyEvent event) {
1022
1031
if (!passThrough ) {
1023
1032
switch (event .getAction ()) {
1024
1033
case KeyEvent .ACTION_DOWN :
1034
+ Log .i (TAG , "KeyEvent Down" );
1025
1035
if (state .onKeyDown (event )) {
1026
1036
return true ;
1027
1037
}
1028
1038
break ;
1029
1039
1030
1040
case KeyEvent .ACTION_UP :
1041
+ Log .i (TAG , "KeyEvent Up" );
1031
1042
if (state .onKeyUp (event )) {
1032
1043
return true ;
1033
1044
}
@@ -1055,23 +1066,24 @@ public static String getInputDesc(InputDevice input) {
1055
1066
1056
1067
@ TargetApi (Build .VERSION_CODES .N )
1057
1068
void sendMouseDelta (float dx , float dy ) {
1058
- NativeApp .mouseDelta (dx , dy );
1069
+ // Ignore zero deltas.
1070
+ if (Math .abs (dx ) > 0.001 || Math .abs (dx ) > 0.001 ) {
1071
+ NativeApp .mouseDelta (dx , dy );
1072
+ }
1059
1073
}
1060
1074
1061
1075
@ Override
1062
1076
@ TargetApi (Build .VERSION_CODES .HONEYCOMB_MR1 )
1063
1077
public boolean onGenericMotionEvent (MotionEvent event ) {
1064
- // Log.d (TAG, "onGenericMotionEvent: " + event);
1078
+ // Log.i (TAG, "NativeActivity onGenericMotionEvent: " + event);
1065
1079
if (InputDeviceState .inputSourceIsJoystick (event .getSource ())) {
1066
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .HONEYCOMB_MR1 ) {
1067
- InputDeviceState state = getInputDeviceState (event );
1068
- if (state == null ) {
1069
- Log .w (TAG , "Joystick event but failed to get input device state." );
1070
- return super .onGenericMotionEvent (event );
1071
- }
1072
- state .onJoystickMotion (event );
1073
- return true ;
1080
+ InputDeviceState state = getInputDeviceState (event );
1081
+ if (state == null ) {
1082
+ Log .w (TAG , "Joystick event but failed to get input device state." );
1083
+ return super .onGenericMotionEvent (event );
1074
1084
}
1085
+ state .onJoystickMotion (event );
1086
+ return true ;
1075
1087
}
1076
1088
1077
1089
if ((event .getSource () & InputDevice .SOURCE_CLASS_POINTER ) != 0 ) {
@@ -1081,15 +1093,38 @@ public boolean onGenericMotionEvent(MotionEvent event) {
1081
1093
float dy = event .getAxisValue (MotionEvent .AXIS_RELATIVE_Y );
1082
1094
sendMouseDelta (dx , dy );
1083
1095
}
1096
+ switch (event .getAction ()) {
1097
+ case MotionEvent .ACTION_HOVER_MOVE :
1098
+ Log .i (TAG , "Action Hover Move" );
1099
+ // process the mouse hover movement...
1100
+ NativeApp .mouse (event .getX (), event .getY (), 0 , 0 );
1101
+ return true ;
1102
+ case MotionEvent .ACTION_SCROLL :
1103
+ float scrollX = event .getAxisValue (MotionEvent .AXIS_HSCROLL );
1104
+ float scrollY = event .getAxisValue (MotionEvent .AXIS_VSCROLL );
1105
+ Log .i (TAG , "Action Scroll: " + scrollX + " " + scrollY );
1106
+ NativeApp .mouseWheelEvent (scrollX , scrollY );
1107
+ return true ;
1108
+ }
1084
1109
}
1110
+ }
1085
1111
1086
- switch (event .getAction ()) {
1087
- case MotionEvent .ACTION_HOVER_MOVE :
1088
- // process the mouse hover movement...
1089
- return true ;
1090
- case MotionEvent .ACTION_SCROLL :
1091
- NativeApp .mouseWheelEvent (event .getAxisValue (MotionEvent .AXIS_HSCROLL ), event .getAxisValue (MotionEvent .AXIS_VSCROLL ));
1092
- return true ;
1112
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
1113
+ int button = event .getActionButton ();
1114
+ switch (event .getActionMasked ()) {
1115
+ case MotionEvent .ACTION_BUTTON_PRESS : {
1116
+ Log .i (TAG , "action button press: button: " + button );
1117
+ useModernMouseEvents = true ;
1118
+ NativeApp .mouse (event .getX (), event .getY (), button , 1 );
1119
+ return true ;
1120
+ }
1121
+ case MotionEvent .ACTION_BUTTON_RELEASE : {
1122
+ Log .i (TAG , "action button release: button: " + button );
1123
+ NativeApp .mouse (event .getX (), event .getY (), button , 2 );
1124
+ return true ;
1125
+ }
1126
+ default :
1127
+ break ;
1093
1128
}
1094
1129
}
1095
1130
return super .onGenericMotionEvent (event );
0 commit comments