SDL keycodes now can be redefined by user
This commit is contained in:
2
build.sh
2
build.sh
@@ -15,5 +15,5 @@ if ( grep "package $AppFullName;" project/src/Globals.java > /dev/null && [ "`re
|
||||
touch project/src/Globals.java
|
||||
fi
|
||||
|
||||
cd project && env PATH=$NDKBUILDPATH nice -n10 ndk-build -j2 V=1 && ant `test -n "$1" && echo release || echo debug` && test -z "$1" && cd bin && adb install -r DemoActivity-debug.apk
|
||||
cd project && env PATH=$NDKBUILDPATH nice -n10 ndk-build -j4 V=1 && ant `test -n "$1" && echo release || echo debug` && test -z "$1" && cd bin && adb install -r DemoActivity-debug.apk
|
||||
|
||||
|
||||
@@ -81,8 +81,7 @@ class Globals {
|
||||
public static boolean KeepAspectRatio = false;
|
||||
public static int ClickScreenPressure = 0;
|
||||
public static int ClickScreenTouchspotSize = 0;
|
||||
public static Vector<Integer> RemapHwKeycodeJava = new Vector<Integer>();
|
||||
public static Vector<Integer> RemapHwKeycodeSdl = new Vector<Integer>();
|
||||
public static int RemapHwKeycode[] = new int[SDL_Keys.JAVA_KEYCODE_LAST];
|
||||
}
|
||||
|
||||
class LoadLibrary {
|
||||
|
||||
@@ -495,6 +495,8 @@ class SDL_Keys
|
||||
{
|
||||
public static String [] names = null;
|
||||
public static Integer [] values = null;
|
||||
|
||||
static final JAVA_KEYCODE_LAST = android.view.KeyEvent.KEYCODE_MUTE; // = 91
|
||||
|
||||
static
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MainActivity extends Activity {
|
||||
// fullscreen mode
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
if(Globals.InhibitSuspend)
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
|
||||
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
@@ -77,7 +77,7 @@ public class MainActivity extends Activity {
|
||||
|
||||
if(mAudioThread == null) // Starting from background (should not happen)
|
||||
{
|
||||
System.out.println("libSDL: Loading libraries");
|
||||
System.out.println("libSDL: Loading libraries");
|
||||
mLoadLibraryStub = new LoadLibrary();
|
||||
mAudioThread = new AudioThread(this);
|
||||
System.out.println("libSDL: Loading settings");
|
||||
|
||||
@@ -59,6 +59,11 @@ class Settings
|
||||
out.writeBoolean(Globals.KeepAspectRatio);
|
||||
out.writeInt(Globals.MoveMouseWithJoystickSpeed);
|
||||
out.writeInt(Globals.MoveMouseWithJoystickAccel);
|
||||
out.writeInt(SDL_Keys.JAVA_KEYCODE_LAST);
|
||||
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
|
||||
{
|
||||
out.writeInt(RemapHwKeycode[i]);
|
||||
}
|
||||
|
||||
out.close();
|
||||
settingsLoaded = true;
|
||||
@@ -75,6 +80,11 @@ class Settings
|
||||
return;
|
||||
}
|
||||
System.out.println("libSDL: Settings.Load(): enter");
|
||||
nativeInitKeymap();
|
||||
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
|
||||
{
|
||||
RemapHwKeycode[i] = nativeGetKeymapKey(i);
|
||||
}
|
||||
try {
|
||||
ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName ));
|
||||
Globals.DownloadToSdcard = settingsFile.readBoolean();
|
||||
@@ -101,6 +111,12 @@ class Settings
|
||||
Globals.KeepAspectRatio = settingsFile.readBoolean();
|
||||
Globals.MoveMouseWithJoystickSpeed = settingsFile.readInt();
|
||||
Globals.MoveMouseWithJoystickAccel = settingsFile.readInt();
|
||||
if( settingsFile.readInt() != SDL_Keys.JAVA_KEYCODE_LAST )
|
||||
throw new IOException();
|
||||
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
|
||||
{
|
||||
RemapHwKeycode[i] = settingsFile.readInt();
|
||||
}
|
||||
|
||||
settingsLoaded = true;
|
||||
|
||||
@@ -845,27 +861,20 @@ class Settings
|
||||
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
|
||||
}
|
||||
int keyIndex = keyCode;
|
||||
if( keyIndex < 0 )
|
||||
keyIndex = 0;
|
||||
if( keyIndex > SDL_Keys.JAVA_KEYCODE_LAST )
|
||||
keyIndex = 0;
|
||||
|
||||
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()
|
||||
builder.setSingleChoiceItems(SDL_Keys.names, Globals.RemapHwKeycode[keyIndex], new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
Globals.RemapHwKeycodeSdl.set(KeyIndexFinal, item);
|
||||
Globals.RemapHwKeycode[KeyIndexFinal] = item;
|
||||
|
||||
dialog.dismiss();
|
||||
showConfigMainMenu(p);
|
||||
@@ -910,6 +919,11 @@ class Settings
|
||||
Globals.AppNeedsTextInput ? 1 : 0 );
|
||||
}
|
||||
SetupTouchscreenKeyboardGraphics(p);
|
||||
for( int i = 0; i < SDL_Keys.JAVA_KEYCODE_LAST; i++ )
|
||||
{
|
||||
nativeSetKeymapKey(i, RemapHwKeycode[i]);
|
||||
}
|
||||
|
||||
String lang = new String(Locale.getDefault().getLanguage());
|
||||
if( Locale.getDefault().getCountry().length() > 0 )
|
||||
lang = lang + "_" + Locale.getDefault().getCountry();
|
||||
@@ -960,6 +974,9 @@ class Settings
|
||||
private static native void nativeSetTouchscreenKeyboardUsed();
|
||||
private static native void nativeSetupScreenKeyboard(int size, int theme, int nbuttons, int nbuttonsAutoFire, int showArrows, int showTextInput);
|
||||
private static native void nativeSetupScreenKeyboardButtons(byte[] img);
|
||||
private static native void nativeInitKeymap();
|
||||
private static native int nativeGetKeymapKey(int key);
|
||||
private static native void nativeSetKeymapKey(int javakey, int key);
|
||||
public static native void nativeSetEnv(final String name, final String value);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ RedefinedKeys="LCTRL m t h e"
|
||||
AppTouchscreenKeyboardKeysAmount=0
|
||||
AppTouchscreenKeyboardKeysAmountAutoFire=0
|
||||
MultiABI=n
|
||||
AppVersionCode=211405
|
||||
AppVersionName="2114.05"
|
||||
AppVersionCode=212506
|
||||
AppVersionName="2125.06"
|
||||
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'
|
||||
|
||||
@@ -1 +1 @@
|
||||
glxgears
|
||||
fheroes2
|
||||
@@ -1202,12 +1202,8 @@ void SDL_ANDROID_processMoveMouseWithKeyboard()
|
||||
SDL_ANDROID_MainThreadPushMouseMotion(moveMouseWithKbX, moveMouseWithKbY);
|
||||
};
|
||||
|
||||
|
||||
void ANDROID_InitOSKeymap()
|
||||
{
|
||||
int i;
|
||||
SDLKey * keymap = SDL_android_keymap;
|
||||
|
||||
#if (SDL_VERSION_ATLEAST(1,3,0))
|
||||
SDLKey defaultKeymap[SDL_NUM_SCANCODES];
|
||||
SDL_GetDefaultKeymap(defaultKeymap);
|
||||
@@ -1229,8 +1225,30 @@ void ANDROID_InitOSKeymap()
|
||||
touch.id = 0;
|
||||
|
||||
SDL_AddTouch(&touch, "Android touch screen");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKey) ( JNIEnv* env, jobject thiz, jint code)
|
||||
{
|
||||
if( code < 0 || code > KEYCODE_LAST )
|
||||
return SDL_KEY(UNKNOWN);
|
||||
return SDL_android_keymap[code];
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKey) ( JNIEnv* env, jobject thiz, jint javakey, jint key)
|
||||
{
|
||||
if( javakey < 0 || javakey > KEYCODE_LAST )
|
||||
return;
|
||||
SDL_android_keymap[javakey] = key;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(Settings_nativeInitKeymap) ( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
int i;
|
||||
SDLKey * keymap = SDL_android_keymap;
|
||||
|
||||
// TODO: keys are mapped rather randomly
|
||||
|
||||
@@ -1241,16 +1259,12 @@ void ANDROID_InitOSKeymap()
|
||||
|
||||
keymap[KEYCODE_BACK] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_5));
|
||||
|
||||
// TODO: make this configurable
|
||||
keymap[KEYCODE_MENU] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_4));
|
||||
|
||||
keymap[KEYCODE_DPAD_CENTER] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_1));
|
||||
keymap[KEYCODE_SEARCH] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_9));
|
||||
keymap[KEYCODE_CALL] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_10));
|
||||
|
||||
//keymap[KEYCODE_CALL] = SDL_KEY(RCTRL);
|
||||
//keymap[KEYCODE_DPAD_CENTER] = SDL_KEY(LALT);
|
||||
|
||||
keymap[KEYCODE_VOLUME_UP] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_2));
|
||||
keymap[KEYCODE_VOLUME_DOWN] = SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_KEYCODE_3));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user