diff --git a/project/java/Globals.java b/project/java/Globals.java index b6da27a95..ad31c9bf8 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -4,6 +4,7 @@ package net.sourceforge.clonekeenplus; import android.app.Activity; import android.content.Context; import java.util.Vector; +import android.view.KeyEvent; class Globals { public static String ApplicationName = "CommanderGenius"; @@ -65,13 +66,15 @@ class Globals { 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_DPAD = 4; + public static final int LEFT_CLICK_WITH_KEY = 4; public static int LeftClickMethod = LEFT_CLICK_NORMAL; + public static int LeftClickKey = KeyEvent.KEYCODE_DPAD_CENTER; 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_MENU_BUTTON = 3; + public static final int RIGHT_CLICK_WITH_KEY = 3; public static int RightClickMethod = RIGHT_CLICK_NONE; + public static int RightClickKey = KeyEvent.KEYCODE_MENU; public static boolean MoveMouseWithJoystick = false; public static int MoveMouseWithJoystickSpeed = 0; public static int MoveMouseWithJoystickAccel = 0; diff --git a/project/java/Settings.java b/project/java/Settings.java index 2f043c738..b86e1c4be 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -108,6 +108,8 @@ class Settings for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) for( int ii = 0; ii < 4; ii++ ) out.writeInt(Globals.ScreenKbControlsLayout[i][ii]); + out.writeInt(Globals.LeftClickKey); + out.writeInt(Globals.RightClickKey); out.close(); settingsLoaded = true; @@ -230,6 +232,8 @@ class Settings for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) for( int ii = 0; ii < 4; ii++ ) Globals.ScreenKbControlsLayout[i][ii] = settingsFile.readInt(); + Globals.LeftClickKey = settingsFile.readInt(); + Globals.RightClickKey = settingsFile.readInt(); settingsLoaded = true; @@ -876,7 +880,7 @@ class Settings p.getResources().getString(R.string.leftclick_near_cursor), p.getResources().getString(R.string.leftclick_multitouch), p.getResources().getString(R.string.leftclick_pressure), - p.getResources().getString(R.string.leftclick_dpadcenter) }; + p.getResources().getString(R.string.rightclick_key) }; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle(R.string.leftclick_question); @@ -886,7 +890,10 @@ class Settings { Globals.LeftClickMethod = item; dialog.dismiss(); - showMouseConfigMainMenu(p); + if( item == Globals.LEFT_CLICK_WITH_KEY ) + p.keyListener = new KeyRemapToolMouseClick(p, true); + else + showMouseConfigMainMenu(p); } }); AlertDialog alert = builder.create(); @@ -905,7 +912,7 @@ class Settings final CharSequence[] items = { p.getResources().getString(R.string.rightclick_none), p.getResources().getString(R.string.rightclick_multitouch), p.getResources().getString(R.string.rightclick_pressure), - p.getResources().getString(R.string.rightclick_menu) }; + p.getResources().getString(R.string.rightclick_key) }; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle(R.string.rightclick_question); @@ -915,7 +922,10 @@ class Settings { Globals.RightClickMethod = item; dialog.dismiss(); - showMouseConfigMainMenu(p); + if( item == Globals.RIGHT_CLICK_WITH_KEY ) + p.keyListener = new KeyRemapToolMouseClick(p, false); + else + showMouseConfigMainMenu(p); } }); AlertDialog alert = builder.create(); @@ -923,6 +933,35 @@ class Settings alert.show(); } + public static class KeyRemapToolMouseClick implements KeyEventsListener + { + MainActivity p; + boolean leftClick; + public KeyRemapToolMouseClick(MainActivity _p, boolean leftClick) + { + p = _p; + p.setText(p.getResources().getString(R.string.remap_hwkeys_press)); + this.leftClick = leftClick; + } + + public void onKeyEvent(final int keyCode) + { + p.touchListener = null; + int keyIndex = keyCode; + if( keyIndex < 0 ) + keyIndex = 0; + if( keyIndex > SDL_Keys.JAVA_KEYCODE_LAST ) + keyIndex = 0; + + if( leftClick ) + Globals.LeftClickKey = keyIndex; + else + Globals.RightClickKey = keyIndex; + + showMouseConfigMainMenu(p); + } + } + static void showAdditionalMouseConfig(final MainActivity p) { if( ! Globals.AppUsesMouse ) @@ -1597,7 +1636,9 @@ class Settings Globals.ClickScreenPressure, Globals.ClickScreenTouchspotSize, Globals.MoveMouseWithJoystickSpeed, - Globals.MoveMouseWithJoystickAccel ); + Globals.MoveMouseWithJoystickAccel, + Globals.LeftClickKey, + Globals.RightClickKey ); if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) ) nativeSetJoystickUsed(); if( Globals.AppUsesMultitouch ) @@ -1678,7 +1719,8 @@ class Settings private static native void nativeSetAccelerometerSettings(int sensitivity, int centerPos); private static native void nativeSetMouseUsed(int RightClickMethod, int ShowScreenUnderFinger, int LeftClickMethod, int MoveMouseWithJoystick, int ClickMouseWithDpad, int MaxForce, int MaxRadius, - int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel); + int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel, + int leftClickKeycode, int rightClickKeycode); private static native void nativeSetJoystickUsed(); private static native void nativeSetMultitouchUsed(); private static native void nativeSetTouchscreenKeyboardUsed(); diff --git a/project/java/translations/values-de/strings.xml b/project/java/translations/values-de/strings.xml index 4eab79c0c..6969aa712 100644 --- a/project/java/translations/values-de/strings.xml +++ b/project/java/translations/values-de/strings.xml @@ -107,4 +107,5 @@ Touch allen vier Rändern des Bildschirms, drücken Sie Menü, wenn Sie fertig Passen Sie auf dem Bildschirm Tastatur-Layout Slide-Bildschirm hinzufügen Taste, drücken Sie Menü zum letzten Knopf rückgängig machen +Physikalische Schlüssel diff --git a/project/java/translations/values-fi/strings.xml b/project/java/translations/values-fi/strings.xml index 61e240b9b..b4f3d0fa4 100644 --- a/project/java/translations/values-fi/strings.xml +++ b/project/java/translations/values-fi/strings.xml @@ -107,4 +107,5 @@ Touch kaikki neljä reunaa näytön, paina Valikko, kun olet valmis Mukauta-ruudun näppäimistö Työnnä näytön lisätä painikkeen, paina Menu kumota viimeksi painike +Fyysinen avain diff --git a/project/java/translations/values-fr/strings.xml b/project/java/translations/values-fr/strings.xml index 2cef936ea..0bf104b57 100644 --- a/project/java/translations/values-fr/strings.xml +++ b/project/java/translations/values-fr/strings.xml @@ -110,4 +110,5 @@ Touchez les quatre bords de l\u0026#39;écran, appuyez sur MENU lorsque vous avez terminé Personnalisation de la présentation du clavier à l\u0026#39;écran Faites glisser l\u0026#39;écran pour ajouter le bouton, appuyez sur Menu pour annuler le dernier bouton +Physique clés diff --git a/project/java/translations/values-ru/strings.xml b/project/java/translations/values-ru/strings.xml index 6b7895fab..3c6651bc6 100644 --- a/project/java/translations/values-ru/strings.xml +++ b/project/java/translations/values-ru/strings.xml @@ -100,4 +100,5 @@ Дотроньтесь до всех четырех краев экрана, потом нажмите MENU Настройка расположения кнопок Провезите по экрану, чтобы добавить кнопку, нажмите клавишу Меню, чтобы отменить последнюю кнопку +Физическая кнопка diff --git a/project/java/translations/values-uk/strings.xml b/project/java/translations/values-uk/strings.xml index 368c7182f..98a071178 100644 --- a/project/java/translations/values-uk/strings.xml +++ b/project/java/translations/values-uk/strings.xml @@ -100,4 +100,5 @@ Доторкнiться до всіх чотирьох країв екрану, потiм натисніть MENU Налаштування положення кнопок Провезiть по екрану, щоб додати кнопку, натисніть клавішу Меню, щоб скасувати останню кнопку +Фізична кнопка diff --git a/project/java/translations/values/strings.xml b/project/java/translations/values/strings.xml index b562223ec..f7d340d0e 100644 --- a/project/java/translations/values/strings.xml +++ b/project/java/translations/values/strings.xml @@ -71,6 +71,7 @@ Mouse emulation Right mouse click Menu key + Physical key Touch screen with second finger Touch screen with force Disable right mouse click diff --git a/project/jni/application/openttd/AndroidAppSettings.cfg b/project/jni/application/openttd/AndroidAppSettings.cfg index 68c9d2f68..990fd79f8 100644 --- a/project/jni/application/openttd/AndroidAppSettings.cfg +++ b/project/jni/application/openttd/AndroidAppSettings.cfg @@ -22,8 +22,8 @@ AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 RedefinedKeysScreenKb="LALT RETURN KP_PLUS KP_MINUS SPACE DELETE KP_PLUS KP_MINUS 1 2" MultiABI=n -AppVersionCode=10510 -AppVersionName="1.0.5.10" +AppVersionCode=10511 +AppVersionName="1.0.5.11" CompiledLibraries="jpeg png freetype timidity lzma lzo2" CustomBuildScript=y AppCflags='' diff --git a/project/jni/application/src b/project/jni/application/src index 59d41f41e..550b7b622 120000 --- a/project/jni/application/src +++ b/project/jni/application/src @@ -1 +1 @@ -fheroes2 \ No newline at end of file +openttd \ 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 2a66ef434..74e4a5ee5 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 @@ -57,10 +57,12 @@ static inline SDL_scancode TranslateKey(int scancode) static int isTrackballUsed = 0; static int isMouseUsed = 0; -enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, RIGHT_CLICK_WITH_MENU_BUTTON = 3 }; -enum { LEFT_CLICK_NORMAL = 0, LEFT_CLICK_NEAR_CURSOR = 1, LEFT_CLICK_WITH_MULTITOUCH = 2, LEFT_CLICK_WITH_PRESSURE = 3, LEFT_CLICK_WITH_DPAD = 4 }; +enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, RIGHT_CLICK_WITH_KEY = 3 }; +enum { LEFT_CLICK_NORMAL = 0, LEFT_CLICK_NEAR_CURSOR = 1, LEFT_CLICK_WITH_MULTITOUCH = 2, LEFT_CLICK_WITH_PRESSURE = 3, LEFT_CLICK_WITH_KEY = 4 }; static int leftClickMethod = LEFT_CLICK_NORMAL; static int rightClickMethod = RIGHT_CLICK_NONE; +static int leftClickKey = KEYCODE_DPAD_CENTER; +static int rightClickKey = KEYCODE_MENU; int SDL_ANDROID_ShowScreenUnderFinger = 0; SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect = {0, 0, 0, 0}, SDL_ANDROID_ShowScreenUnderFingerRectSrc = {0, 0, 0, 0}; static int moveMouseWithArrowKeys = 0; @@ -480,12 +482,12 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint if( isTrackballUsed ) if( processAndroidTrackball(key, action) ) return; - if( key == KEYCODE_MENU && rightClickMethod == RIGHT_CLICK_WITH_MENU_BUTTON ) + if( key == rightClickKey && rightClickMethod == RIGHT_CLICK_WITH_KEY ) { SDL_ANDROID_MainThreadPushMouseButton( action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT ); return; } - if( key == KEYCODE_DPAD_CENTER && ( clickMouseWithDpadCenter || leftClickMethod == LEFT_CLICK_WITH_DPAD ) ) + if( (key == leftClickKey && leftClickMethod == LEFT_CLICK_WITH_KEY) || (clickMouseWithDpadCenter && key == KEYCODE_DPAD_CENTER) ) { SDL_ANDROID_MainThreadPushMouseButton( action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT ); return; @@ -546,7 +548,8 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz, jint RightClickMethod, jint ShowScreenUnderFinger, jint LeftClickMethod, jint MoveMouseWithJoystick, jint ClickMouseWithDpad, jint MaxForce, jint MaxRadius, - jint MoveMouseWithJoystickSpeed, jint MoveMouseWithJoystickAccel) + jint MoveMouseWithJoystickSpeed, jint MoveMouseWithJoystickAccel, + jint LeftClickKeycode, jint RightClickKeycode) { isMouseUsed = 1; rightClickMethod = RightClickMethod; @@ -558,6 +561,8 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz, maxRadius = MaxRadius; moveMouseWithKbSpeed = MoveMouseWithJoystickSpeed + 1; moveMouseWithKbAccel = MoveMouseWithJoystickAccel; + leftClickKey = LeftClickKeycode; + rightClickKey = RightClickKeycode; } JNIEXPORT void JNICALL diff --git a/todo.txt b/todo.txt index 225af2e42..11054660b 100644 --- a/todo.txt +++ b/todo.txt @@ -11,7 +11,7 @@ Bugs to fix - Show/hide screen controls with longpress on Text Edit button. -- Right click by longpress, assign any HW key to do left/right click. +- Right click by longpress. - Calling SDL_SetVideoMode() with SDL 1.3 several times makes it crash.