diff --git a/project/default.properties b/project/default.properties index 0b9250e02..0cdab9561 100644 --- a/project/default.properties +++ b/project/default.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-8 +target=android-12 diff --git a/project/java/Globals.java b/project/java/Globals.java index 798ba0a72..03f34439d 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -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; diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index 60d22e605..855862c84 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -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 } diff --git a/project/java/Settings.java b/project/java/Settings.java index e5ffea09f..ce0cc6fc2 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -475,6 +475,8 @@ class Settings { ArrayList items = new ArrayList (); + 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); diff --git a/project/java/Video.java b/project/java/Video.java index 438442873..ee8df96c1 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -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(); }; diff --git a/project/java/translations/values/strings.xml b/project/java/translations/values/strings.xml index 95e72752b..6a0786d0c 100644 --- a/project/java/translations/values/strings.xml +++ b/project/java/translations/values/strings.xml @@ -145,4 +145,10 @@ Tap to start typing, press Back when done + Configure mouse depending on display size + Select your display size + Large (tablet) + Small (phone) + Tiny (Xperia Mini) + diff --git a/project/jni/application/fheroes2/AndroidAppSettings.cfg b/project/jni/application/fheroes2/AndroidAppSettings.cfg index af558f51a..04754e61e 100644 --- a/project/jni/application/fheroes2/AndroidAppSettings.cfg +++ b/project/jni/application/fheroes2/AndroidAppSettings.cfg @@ -23,8 +23,8 @@ AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 RedefinedKeysScreenKb="LCTRL M T H E C SPACE C S L" MultiABI=n -AppVersionCode=234913 -AppVersionName="2349.13" +AppVersionCode=235014 +AppVersionName="2350.14" CompiledLibraries="sdl_net sdl_mixer sdl_image sdl_ttf png intl" CustomBuildScript=n AppCflags='-finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_XML -DWITH_IMAGE -DWITH_TTF -DWITH_AI=simple -DWITH_NET' diff --git a/project/jni/application/openttd/AndroidAppSettings.cfg b/project/jni/application/openttd/AndroidAppSettings.cfg index 29cce8dc1..0178b4b70 100644 --- a/project/jni/application/openttd/AndroidAppSettings.cfg +++ b/project/jni/application/openttd/AndroidAppSettings.cfg @@ -23,8 +23,8 @@ AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 RedefinedKeysScreenKb="LALT RETURN KP_PLUS KP_MINUS SPACE DELETE KP_PLUS KP_MINUS 1 2" MultiABI=n -AppVersionCode=11012 -AppVersionName="1.1.0.12" +AppVersionCode=11013 +AppVersionName="1.1.0.13" CompiledLibraries="jpeg png freetype timidity lzma lzo2" CustomBuildScript=y AppCflags='' diff --git a/project/jni/application/src b/project/jni/application/src index 92362c4db..59d41f41e 120000 --- a/project/jni/application/src +++ b/project/jni/application/src @@ -1 +1 @@ -ufoai \ No newline at end of file +fheroes2 \ No newline at end of file diff --git a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c index a3715302e..2ca41746e 100644 --- a/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c +++ b/project/jni/sdl-1.3/src/video/android/SDL_androidinput.c @@ -208,6 +208,7 @@ void UpdateScreenUnderFingerRect(int x, int y) JNIEXPORT void JNICALL JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId, jint force, jint radius ) { + // TODO: this method is damn huge int i; #if SDL_VERSION_ATLEAST(1,3,0)