diff --git a/ChangeAppSettings.sh b/ChangeAppSettings.sh index 88c8c4e1f..1c2ed07b5 100755 --- a/ChangeAppSettings.sh +++ b/ChangeAppSettings.sh @@ -350,6 +350,11 @@ AppSharedLibrariesPath=/data/data/$AppFullName/lib ScreenOrientation1=portrait HorizontalOrientation=false +UsingSdl13=false +if [ "$LibSdlVersion" = "1.3" ] ; then + UsingSdl13=true +fi + if [ "$ScreenOrientation" = "h" ] ; then ScreenOrientation1=landscape HorizontalOrientation=true @@ -480,6 +485,7 @@ cd ../.. echo Patching project/src/Globals.java cat project/src/Globals.java | \ sed "s/public static String ApplicationName = .*;/public static String ApplicationName = \"$AppShortName\";/" | \ + sed "s/public static final boolean Using_SDL_1_3 = .*;/public static final boolean Using_SDL_1_3 = $UsingSdl13;/" | \ sed "s@public static String DataDownloadUrl = .*@public static String DataDownloadUrl = \"$AppDataDownloadUrl1\";@" | \ sed "s/public static boolean NeedDepthBuffer = .*;/public static boolean NeedDepthBuffer = $NeedDepthBuffer;/" | \ sed "s/public static boolean HorizontalOrientation = .*;/public static boolean HorizontalOrientation = $HorizontalOrientation;/" | \ diff --git a/project/java/Globals.java b/project/java/Globals.java index 2786be85f..d6460a079 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -3,10 +3,13 @@ package net.sourceforge.clonekeenplus; import android.app.Activity; import android.content.Context; +import java.util.Vector; class Globals { public static String ApplicationName = "CommanderGenius"; + public static final boolean Using_SDL_1_3 = false; + // Should be zip file public static String DataDownloadUrl = "Data files are 2 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-data.zip/download^High-quality GFX and music - 40 Mb|https://sourceforge.net/projects/libsdl-android/files/CommanderGenius/commandergenius-hqp.zip/download"; @@ -78,6 +81,8 @@ class Globals { public static boolean KeepAspectRatio = false; public static int ClickScreenPressure = 0; public static int ClickScreenTouchspotSize = 0; + public static Vector RemapHwKeycodeJava = new Vector(); + public static Vector RemapHwKeycodeSdl = new Vector(); } class LoadLibrary { diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index f8b31dba5..98ff21911 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -278,7 +278,12 @@ public class MainActivity extends Activity { if( !downloader.DownloadComplete ) onStop(); } - return true; + else + if( keyRemapTool != null ) + { + keyRemapTool.onKeyEvent(keyCode); + } + return true; } @Override @@ -302,8 +307,8 @@ public class MainActivity extends Activity { if( _btn != null ) return _btn.dispatchTouchEvent(ev); else - if( _touchMeasurementTool != null ) - _touchMeasurementTool.onTouchEvent(ev); + if( touchMeasurementTool != null ) + touchMeasurementTool.onTouchEvent(ev); return true; } @@ -369,7 +374,8 @@ public class MainActivity extends Activity { private FrameLayout _videoLayout = null; private EditText _screenKeyboard = null; private boolean sdlInited = false; - public Settings.TouchMeasurementTool _touchMeasurementTool = null; + public Settings.TouchEventsListener touchMeasurementTool = null; + public Settings.KeyEventsListener keyRemapTool = null; boolean _isPaused = false; } diff --git a/project/java/Settings.java b/project/java/Settings.java index cb044cb44..9b2f30f31 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -177,6 +177,11 @@ class Settings items.add(p.getResources().getString(R.string.audiobuf_question)); + if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE ) + items.add(p.getResources().getString(R.string.measurepressure)); + + items.add(p.getResources().getString(R.string.remap_hwkeys)); + items.add(p.getResources().getString(R.string.ok)); AlertDialog.Builder builder = new AlertDialog.Builder(p); @@ -242,9 +247,24 @@ class Settings if( item == selected ) showAudioConfig(p); selected++; + + if( ! ( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || + Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE ) ) + item += 1; + else + if( item == selected ) + showTouchPressureMeasurementTool(p); + selected++; + + if( item == selected ) + showRemapHwKeysConfig(p); + selected++; if( item == selected ) - showTouchPressureMeasurementTool(p); + { + Save(p); + p.startDownloader(); + } selected++; } }); @@ -734,21 +754,30 @@ class Settings alert.show(); } + public interface TouchEventsListener + { + public void onTouchEvent(final MotionEvent ev); + } + + public interface KeyEventsListener + { + public void onKeyEvent(final int keyCode); + } + static void showTouchPressureMeasurementTool(final MainActivity p) { if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickMethod == Globals.LEFT_CLICK_WITH_PRESSURE ) { p.setText(p.getResources().getString(R.string.measurepressure_touchplease)); - p._touchMeasurementTool = new TouchMeasurementTool(p); + p.touchMeasurementTool = new TouchMeasurementTool(p); } else { - Save(p); - p.startDownloader(); + showConfigMainMenu(p); } } - public static class TouchMeasurementTool + public static class TouchMeasurementTool implements TouchEventsListener { MainActivity p; ArrayList force = new ArrayList(); @@ -771,12 +800,11 @@ class Settings if( force.size() >= maxEventAmount ) { - p._touchMeasurementTool = null; + p.touchMeasurementTool = null; Globals.ClickScreenPressure = getAverageForce(); Globals.ClickScreenTouchspotSize = getAverageRadius(); System.out.println("SDL: measured average force " + Globals.ClickScreenPressure + " radius " + Globals.ClickScreenTouchspotSize); - Save(p); - p.startDownloader(); + showConfigMainMenu(p); } } @@ -800,6 +828,55 @@ class Settings } } + static void showRemapHwKeysConfig(final MainActivity p) + { + p.setText(p.getResources().getString(R.string.remap_hwkeys_press)); + p.keyRemapTool = new KeyRemapTool(p); + } + + public static class KeyRemapTool implements KeyEventsListener + { + MainActivity p; + public KeyRemapTool(MainActivity _p) + { + p = _p; + } + + public void onKeyEvent(final int keyCode) + { + p.keyRemapTool = null; + int keyIndex = -1; + for( int i = 0; i < Globals.RemapHwKeycodeJava.size(); i++ ) + { + if( Globals.RemapHwKeycodeJava.get(i) == keyCode ) + keyIndex = i; + } + if( keyIndex == -1 ) + { + keyIndex = Globals.RemapHwKeycodeJava.size(); + Globals.RemapHwKeycodeJava.add(keyCode); + Globals.RemapHwKeycodeSdl.add(0); // SDLK_UNKNOWN + } + + final int KeyIndexFinal = keyIndex; + AlertDialog.Builder builder = new AlertDialog.Builder(p); + builder.setTitle(R.string.remap_hwkeys_select); + builder.setSingleChoiceItems(SDL_Keys.names, Globals.RemapHwKeycodeSdl.get(keyIndex), new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int item) + { + Globals.RemapHwKeycodeSdl.set(KeyIndexFinal, item); + + dialog.dismiss(); + showConfigMainMenu(p); + } + }); + AlertDialog alert = builder.create(); + alert.setOwnerActivity(p); + alert.show(); + } + } + static void Apply(Activity p) { nativeIsSdcardUsed( Globals.DownloadToSdcard ? 1 : 0 ); diff --git a/project/java/translations/values/strings.xml b/project/java/translations/values/strings.xml index cee331b98..4e14f8c05 100644 --- a/project/java/translations/values/strings.xml +++ b/project/java/translations/values/strings.xml @@ -81,6 +81,7 @@ Move mouse with joystick acceleration None + Calibrate touchscreen pressure Please slide finger across the screen for two seconds Pressure %03d radius %03d @@ -90,4 +91,8 @@ Large (older devices, if sound is choppy) Size of audio buffer + Remap physical keys + Press any key except HOME and POWER, you may use volume keys + Select SDL keycode + diff --git a/project/jni/application/fheroes2/AndroidAppSettings.cfg b/project/jni/application/fheroes2/AndroidAppSettings.cfg index ccbd2fa8e..942cac1d0 100644 --- a/project/jni/application/fheroes2/AndroidAppSettings.cfg +++ b/project/jni/application/fheroes2/AndroidAppSettings.cfg @@ -21,8 +21,8 @@ RedefinedKeys="LCTRL m t h e" AppTouchscreenKeyboardKeysAmount=0 AppTouchscreenKeyboardKeysAmountAutoFire=0 MultiABI=n -AppVersionCode=211205 -AppVersionName="2112.05" +AppVersionCode=211405 +AppVersionName="2114.05" 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' 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 d176479c4..fbe8b9a6a 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 @@ -160,7 +160,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j if(pointerId > MAX_MULTITOUCH_POINTERS) pointerId = MAX_MULTITOUCH_POINTERS; - // The ouch is passed either to on-screen keyboard or as mouse event for all duration of touch between down and up, + // The touch is passed either to on-screen keyboard or as mouse event for all duration of touch between down and up, // even if the finger is not anymore above screen kb button it will not acr as mouse event, and if it's initially // touches the screen outside of screen kb it won't trigger button keypress - // I think it's more logical this way