Support Android 3.1 bluetooth/USB mouse (not tested!), added new option to choose mouse settings depending on the screen size
This commit is contained in:
@@ -75,24 +75,11 @@ class Globals {
|
||||
public static int TrackballDampening = 0;
|
||||
public static int AudioBufferConfig = 0;
|
||||
public static boolean OptionalDataDownload[] = null;
|
||||
public static final int LEFT_CLICK_NORMAL = 0;
|
||||
public static final int LEFT_CLICK_NEAR_CURSOR = 1;
|
||||
public static final int LEFT_CLICK_WITH_MULTITOUCH = 2;
|
||||
public static final int LEFT_CLICK_WITH_PRESSURE = 3;
|
||||
public static final int LEFT_CLICK_WITH_KEY = 4;
|
||||
public static final int LEFT_CLICK_WITH_TIMEOUT = 5;
|
||||
public static final int LEFT_CLICK_WITH_TAP = 6;
|
||||
public static final int LEFT_CLICK_WITH_TAP_OR_TIMEOUT = 7;
|
||||
public static int LeftClickMethod = AppNeedsTwoButtonMouse ? LEFT_CLICK_WITH_TAP_OR_TIMEOUT : LEFT_CLICK_NORMAL;
|
||||
public static int LeftClickMethod = AppNeedsTwoButtonMouse ? Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT : Mouse.LEFT_CLICK_NORMAL;
|
||||
public static int LeftClickKey = KeyEvent.KEYCODE_DPAD_CENTER;
|
||||
public static int LeftClickTimeout = 3;
|
||||
public static final int RIGHT_CLICK_NONE = 0;
|
||||
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
|
||||
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
|
||||
public static final int RIGHT_CLICK_WITH_KEY = 3;
|
||||
public static final int RIGHT_CLICK_WITH_TIMEOUT = 4;
|
||||
public static int RightClickTimeout = 4;
|
||||
public static int RightClickMethod = AppNeedsTwoButtonMouse ? RIGHT_CLICK_WITH_MULTITOUCH : RIGHT_CLICK_NONE;
|
||||
public static int RightClickMethod = AppNeedsTwoButtonMouse ? Mouse.RIGHT_CLICK_WITH_MULTITOUCH : Mouse.RIGHT_CLICK_NONE;
|
||||
public static int RightClickKey = KeyEvent.KEYCODE_MENU;
|
||||
public static boolean MoveMouseWithJoystick = false;
|
||||
public static int MoveMouseWithJoystickSpeed = 0;
|
||||
|
||||
@@ -310,7 +310,8 @@ public class MainActivity extends Activity {
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, final KeyEvent event) {
|
||||
public boolean onKeyDown(int keyCode, final KeyEvent event)
|
||||
{
|
||||
// Overrides Back key to use in our app
|
||||
if(_screenKeyboard != null)
|
||||
_screenKeyboard.onKeyDown(keyCode, event);
|
||||
@@ -334,7 +335,8 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, final KeyEvent event) {
|
||||
public boolean onKeyUp(int keyCode, final KeyEvent event)
|
||||
{
|
||||
if(_screenKeyboard != null)
|
||||
_screenKeyboard.onKeyUp(keyCode, event);
|
||||
else
|
||||
@@ -344,7 +346,8 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(final MotionEvent ev) {
|
||||
public boolean dispatchTouchEvent(final MotionEvent ev)
|
||||
{
|
||||
if(_screenKeyboard != null)
|
||||
_screenKeyboard.dispatchTouchEvent(ev);
|
||||
else
|
||||
@@ -358,9 +361,16 @@ public class MainActivity extends Activity {
|
||||
touchListener.onTouchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchGenericMotionEvent (final MotionEvent ev)
|
||||
{
|
||||
return dispatchTouchEvent(ev);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
public void onConfigurationChanged(Configuration newConfig)
|
||||
{
|
||||
super.onConfigurationChanged(newConfig);
|
||||
// Do nothing here
|
||||
}
|
||||
|
||||
@@ -475,6 +475,8 @@ class Settings
|
||||
{
|
||||
ArrayList<CharSequence> items = new ArrayList<CharSequence> ();
|
||||
|
||||
items.add(p.getResources().getString(R.string.display_size_mouse));
|
||||
|
||||
items.add(p.getResources().getString(R.string.leftclick_question));
|
||||
|
||||
if( Globals.AppNeedsTwoButtonMouse )
|
||||
@@ -485,7 +487,7 @@ class Settings
|
||||
if( Globals.MoveMouseWithJoystick )
|
||||
items.add(p.getResources().getString(R.string.pointandclick_joystickmouse));
|
||||
|
||||
if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE )
|
||||
if( Globals.RightClickMethod == Mouse.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Mouse.LEFT_CLICK_WITH_PRESSURE )
|
||||
items.add(p.getResources().getString(R.string.measurepressure));
|
||||
|
||||
items.add(p.getResources().getString(R.string.calibrate_touchscreen));
|
||||
@@ -503,6 +505,10 @@ class Settings
|
||||
dialog.dismiss();
|
||||
int selected = 0;
|
||||
|
||||
if( item == selected )
|
||||
showDisplaySizeConfig(p);
|
||||
selected++;
|
||||
|
||||
if( item == selected )
|
||||
showLeftClickConfig(p);
|
||||
selected++;
|
||||
@@ -525,7 +531,7 @@ class Settings
|
||||
item++;
|
||||
selected++;
|
||||
|
||||
if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE ) {
|
||||
if( Globals.RightClickMethod == Mouse.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Mouse.LEFT_CLICK_WITH_PRESSURE ) {
|
||||
if( item == selected )
|
||||
showTouchPressureMeasurementTool(p);
|
||||
} else
|
||||
@@ -1031,14 +1037,8 @@ class Settings
|
||||
alert.show();
|
||||
}
|
||||
|
||||
static void showLeftClickConfig(final MainActivity p)
|
||||
static void showDisplaySizeConfig(final MainActivity p)
|
||||
{
|
||||
if( ! Globals.AppUsesMouse )
|
||||
{
|
||||
Globals.LeftClickMethod = Globals.LEFT_CLICK_NORMAL;
|
||||
showMouseConfigMainMenu(p);
|
||||
return;
|
||||
}
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.leftclick_normal),
|
||||
p.getResources().getString(R.string.leftclick_near_cursor),
|
||||
p.getResources().getString(R.string.leftclick_multitouch),
|
||||
@@ -1056,9 +1056,9 @@ class Settings
|
||||
{
|
||||
Globals.LeftClickMethod = item;
|
||||
dialog.dismiss();
|
||||
if( item == Globals.LEFT_CLICK_WITH_KEY )
|
||||
if( item == Mouse.LEFT_CLICK_WITH_KEY )
|
||||
p.keyListener = new KeyRemapToolMouseClick(p, true);
|
||||
else if( item == Globals.LEFT_CLICK_WITH_TIMEOUT || item == Globals.LEFT_CLICK_WITH_TAP_OR_TIMEOUT )
|
||||
else if( item == Mouse.LEFT_CLICK_WITH_TIMEOUT || item == Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT )
|
||||
showLeftClickTimeoutConfig(p);
|
||||
else
|
||||
showMouseConfigMainMenu(p);
|
||||
@@ -1076,6 +1076,54 @@ class Settings
|
||||
alert.show();
|
||||
}
|
||||
|
||||
static void showLeftClickConfig(final MainActivity p)
|
||||
{
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.display_size_large),
|
||||
p.getResources().getString(R.string.display_size_small) };
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle(R.string.display_size);
|
||||
builder.setSingleChoiceItems(items, (Globals.LeftClickMethod == Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT && ! Globals.RelativeMouseMovement) ? 0 : 1, new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
if( item == 0 )
|
||||
{
|
||||
Globals.LeftClickMethod = Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT;
|
||||
Globals.RelativeMouseMovement = false;
|
||||
Globals.ShowScreenUnderFinger = false;
|
||||
}
|
||||
if( item == 1 )
|
||||
{
|
||||
if( Globals.SwVideoMode )
|
||||
{
|
||||
Globals.LeftClickMethod = Mouse.LEFT_CLICK_NEAR_CURSOR;
|
||||
Globals.RelativeMouseMovement = false;
|
||||
Globals.ShowScreenUnderFinger = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// OpenGL does not support magnifying glass
|
||||
Globals.LeftClickMethod = Mouse.LEFT_CLICK_WITH_TAP_OR_TIMEOUT;
|
||||
Globals.RelativeMouseMovement = true;
|
||||
Globals.ShowScreenUnderFinger = false;
|
||||
}
|
||||
}
|
||||
showMouseConfigMainMenu(p);
|
||||
}
|
||||
});
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
|
||||
{
|
||||
public void onCancel(DialogInterface dialog)
|
||||
{
|
||||
showConfigMainMenu(p);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.setOwnerActivity(p);
|
||||
alert.show();
|
||||
}
|
||||
|
||||
static void showLeftClickTimeoutConfig(final MainActivity p) {
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.leftclick_timeout_time_0),
|
||||
p.getResources().getString(R.string.leftclick_timeout_time_1),
|
||||
@@ -1108,12 +1156,6 @@ class Settings
|
||||
|
||||
static void showRightClickConfig(final MainActivity p)
|
||||
{
|
||||
if( ! Globals.AppNeedsTwoButtonMouse )
|
||||
{
|
||||
Globals.RightClickMethod = Globals.RIGHT_CLICK_NONE;
|
||||
showMouseConfigMainMenu(p);
|
||||
return;
|
||||
}
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.rightclick_none),
|
||||
p.getResources().getString(R.string.rightclick_multitouch),
|
||||
p.getResources().getString(R.string.rightclick_pressure),
|
||||
@@ -1128,9 +1170,9 @@ class Settings
|
||||
{
|
||||
Globals.RightClickMethod = item;
|
||||
dialog.dismiss();
|
||||
if( item == Globals.RIGHT_CLICK_WITH_KEY )
|
||||
if( item == Mouse.RIGHT_CLICK_WITH_KEY )
|
||||
p.keyListener = new KeyRemapToolMouseClick(p, false);
|
||||
else if( item == Globals.RIGHT_CLICK_WITH_TIMEOUT )
|
||||
else if( item == Mouse.RIGHT_CLICK_WITH_TIMEOUT )
|
||||
showRightClickTimeoutConfig(p);
|
||||
else
|
||||
showMouseConfigMainMenu(p);
|
||||
|
||||
@@ -38,6 +38,24 @@ import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
class Mouse
|
||||
{
|
||||
public static final int LEFT_CLICK_NORMAL = 0;
|
||||
public static final int LEFT_CLICK_NEAR_CURSOR = 1;
|
||||
public static final int LEFT_CLICK_WITH_MULTITOUCH = 2;
|
||||
public static final int LEFT_CLICK_WITH_PRESSURE = 3;
|
||||
public static final int LEFT_CLICK_WITH_KEY = 4;
|
||||
public static final int LEFT_CLICK_WITH_TIMEOUT = 5;
|
||||
public static final int LEFT_CLICK_WITH_TAP = 6;
|
||||
public static final int LEFT_CLICK_WITH_TAP_OR_TIMEOUT = 7;
|
||||
|
||||
public static final int RIGHT_CLICK_NONE = 0;
|
||||
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
|
||||
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
|
||||
public static final int RIGHT_CLICK_WITH_KEY = 3;
|
||||
public static final int RIGHT_CLICK_WITH_TIMEOUT = 4;
|
||||
}
|
||||
|
||||
abstract class DifferentTouchInput
|
||||
{
|
||||
public static DifferentTouchInput getInstance()
|
||||
@@ -108,13 +126,19 @@ abstract class DifferentTouchInput
|
||||
{
|
||||
private static final MultiTouchInput sInstance = new MultiTouchInput();
|
||||
}
|
||||
|
||||
static final int SDL_FINGER_DOWN = 0;
|
||||
static final int SDL_FINGER_UP = 1;
|
||||
static final int SDL_FINGER_MOVE = 2;
|
||||
|
||||
public void process(final MotionEvent event)
|
||||
{
|
||||
int action = -1;
|
||||
|
||||
//System.out.println("Got motion event, type " + (int)(event.getAction()) + " X " + (int)event.getX() + " Y " + (int)event.getY());
|
||||
if( event.getAction() == MotionEvent.ACTION_UP )
|
||||
{
|
||||
action = 1;
|
||||
action = SDL_FINGER_UP;
|
||||
for( int i = 0; i < touchEventMax; i++ )
|
||||
{
|
||||
if( touchEvents[i].down )
|
||||
@@ -126,7 +150,7 @@ abstract class DifferentTouchInput
|
||||
}
|
||||
if( event.getAction() == MotionEvent.ACTION_DOWN )
|
||||
{
|
||||
action = 0;
|
||||
action = SDL_FINGER_DOWN;
|
||||
for( int i = 0; i < event.getPointerCount(); i++ )
|
||||
{
|
||||
int id = event.getPointerId(i);
|
||||
@@ -140,7 +164,6 @@ abstract class DifferentTouchInput
|
||||
DemoGLSurfaceView.nativeMouse( touchEvents[id].x, touchEvents[id].y, action, id, touchEvents[id].pressure, touchEvents[id].size );
|
||||
}
|
||||
}
|
||||
|
||||
if( event.getAction() == MotionEvent.ACTION_MOVE )
|
||||
{
|
||||
for( int i = 0; i < touchEventMax; i++ )
|
||||
@@ -156,7 +179,7 @@ abstract class DifferentTouchInput
|
||||
// Up event
|
||||
if( touchEvents[i].down )
|
||||
{
|
||||
action = 1;
|
||||
action = SDL_FINGER_UP;
|
||||
touchEvents[i].down = false;
|
||||
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size );
|
||||
}
|
||||
@@ -164,9 +187,9 @@ abstract class DifferentTouchInput
|
||||
else
|
||||
{
|
||||
if( touchEvents[i].down )
|
||||
action = 2;
|
||||
action = SDL_FINGER_MOVE;
|
||||
else
|
||||
action = 0;
|
||||
action = SDL_FINGER_DOWN;
|
||||
touchEvents[i].down = true;
|
||||
touchEvents[i].x = (int)event.getX(ii);
|
||||
touchEvents[i].y = (int)event.getY(ii);
|
||||
@@ -176,13 +199,29 @@ abstract class DifferentTouchInput
|
||||
}
|
||||
}
|
||||
}
|
||||
if( event.getAction() == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1
|
||||
{
|
||||
// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
|
||||
// TODO: need to check this on a device, the emulator does not return such event
|
||||
if( touchEvents[0].down )
|
||||
action = SDL_FINGER_UP;
|
||||
else
|
||||
action = SDL_FINGER_MOVE;
|
||||
action = 2;
|
||||
touchEvents[0].down = false;
|
||||
touchEvents[0].x = (int)event.getX();
|
||||
touchEvents[0].y = (int)event.getY();
|
||||
touchEvents[0].pressure = 0;
|
||||
touchEvents[0].size = 0;
|
||||
DemoGLSurfaceView.nativeMouse( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
|
||||
class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
{
|
||||
public DemoRenderer(MainActivity _context)
|
||||
{
|
||||
context = _context;
|
||||
@@ -331,6 +370,12 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
|
||||
return true;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onGenericMotionEvent (final MotionEvent ev)
|
||||
{
|
||||
return onTouchEvent(ev);
|
||||
}
|
||||
|
||||
public void exitApp() {
|
||||
mRenderer.exitApp();
|
||||
};
|
||||
|
||||
@@ -145,4 +145,10 @@
|
||||
|
||||
<string name="text_edit_click_here">Tap to start typing, press Back when done</string>
|
||||
|
||||
<string name="display_size_mouse">Configure mouse depending on display size</string>
|
||||
<string name="display_size">Select your display size</string>
|
||||
<string name="display_size_large">Large (tablet)</string>
|
||||
<string name="display_size_small">Small (phone)</string>
|
||||
<string name="display_size_tiny">Tiny (Xperia Mini)</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user