diff --git a/project/java/Settings.java b/project/java/Settings.java index bcbd82c89..4467879a0 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -984,7 +984,7 @@ public class Settings private static native void nativeSetCompatibilityHacks(); private static native void nativeSetVideoMultithreaded(); private static native void nativeSetVideoForceSoftwareMode(); - private static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int transparency, int floatingScreenJoystick, int buttonAmount); + public static native void nativeSetupScreenKeyboard(int size, int drawsize, int theme, int transparency, int floatingScreenJoystick, int buttonAmount); private static native void nativeSetupScreenKeyboardButtons(byte[] img); private static native void nativeInitKeymap(); private static native int nativeGetKeymapKey(int key); @@ -993,6 +993,7 @@ public class Settings private static native void nativeSetKeymapKeyScreenKb(int keynum, int key); private static native void nativeSetScreenKbKeyUsed(int keynum, int used); private static native void nativeSetScreenKbKeyLayout(int keynum, int x1, int y1, int x2, int y2); + public static native int nativeGetScreenKeyboardButtonLayout(int button, int coord); private static native int nativeGetKeymapKeyMultitouchGesture(int keynum); private static native void nativeSetKeymapKeyMultitouchGesture(int keynum, int key); private static native void nativeSetMultitouchGestureSensitivity(int sensitivity); diff --git a/project/java/SettingsMenuKeyboard.java b/project/java/SettingsMenuKeyboard.java index 3d83efe34..6619a7d35 100644 --- a/project/java/SettingsMenuKeyboard.java +++ b/project/java/SettingsMenuKeyboard.java @@ -57,6 +57,7 @@ import android.widget.EditText; import android.widget.ScrollView; import android.widget.Button; import android.view.View; +import android.view.Gravity; import android.widget.LinearLayout; import android.text.Editable; import android.text.SpannedString; @@ -625,8 +626,16 @@ class SettingsMenuKeyboard extends SettingsMenu void run (final MainActivity p) { p.setText(p.getResources().getString(R.string.screenkb_custom_layout_help)); - CustomizeScreenKbLayoutTool tool = new CustomizeScreenKbLayoutTool(p); - Globals.TouchscreenKeyboardSize = Globals.TOUCHSCREEN_KEYBOARD_CUSTOM; + if (Globals.ImmersiveMode) + DimSystemStatusBar.get().dim(p.getVideoLayout()); + p.getVideoLayout().getHandler().postDelayed(new Runnable() + { + public void run() + { + CustomizeScreenKbLayoutTool tool = new CustomizeScreenKbLayoutTool(p); + Globals.TouchscreenKeyboardSize = Globals.TOUCHSCREEN_KEYBOARD_CUSTOM; + } + }, 200); } static class CustomizeScreenKbLayoutTool implements View.OnTouchListener, View.OnKeyListener @@ -670,30 +679,27 @@ class SettingsMenuKeyboard extends SettingsMenu boundary.setImageBitmap(boundaryBmp); layout.addView(boundary); currentButton = -1; - if( Globals.TouchscreenKeyboardTheme == 2 ) - { - buttons = new int[] { - R.drawable.sun_dpad, - R.drawable.sun_keyboard, - R.drawable.sun_b1, - R.drawable.sun_b2, - R.drawable.sun_b3, - R.drawable.sun_b4, - R.drawable.sun_b5, - R.drawable.sun_b6, - R.drawable.sun_dpad, - R.drawable.sun_dpad - }; - } - int displayX = 800; - int displayY = 480; - try { - DisplayMetrics dm = new DisplayMetrics(); - p.getWindowManager().getDefaultDisplay().getMetrics(dm); - displayX = dm.widthPixels; - displayY = dm.heightPixels; - } catch (Exception eeeee) {} + final int displayX = p.getVideoLayout().getWidth(); + final int displayY = p.getVideoLayout().getHeight(); + + if( Globals.TouchscreenKeyboardSize != Globals.TOUCHSCREEN_KEYBOARD_CUSTOM ) + { + DemoRenderer.nativeResize(displayX, displayY, 0); + Settings.nativeSetupScreenKeyboard( Globals.TouchscreenKeyboardSize, + Globals.TouchscreenKeyboardDrawSize, + Globals.TouchscreenKeyboardTheme, + Globals.TouchscreenKeyboardTransparency, + Globals.FloatingScreenJoystick ? 1 : 0, + Globals.AppTouchscreenKeyboardKeysAmount ); + for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) + { + Globals.ScreenKbControlsLayout[i][0] = Settings.nativeGetScreenKeyboardButtonLayout(i, 0); + Globals.ScreenKbControlsLayout[i][1] = Settings.nativeGetScreenKeyboardButtonLayout(i, 1); + Globals.ScreenKbControlsLayout[i][2] = Settings.nativeGetScreenKeyboardButtonLayout(i, 2); + Globals.ScreenKbControlsLayout[i][3] = Settings.nativeGetScreenKeyboardButtonLayout(i, 3); + } + } for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ ) { @@ -701,37 +707,7 @@ class SettingsMenuKeyboard extends SettingsMenu continue; if( currentButton == -1 ) currentButton = i; - //Log.i("SDL", "Screen kb button " + i + " coords " + Globals.ScreenKbControlsLayout[i][0] + ":" + Globals.ScreenKbControlsLayout[i][1] + ":" + Globals.ScreenKbControlsLayout[i][2] + ":" + Globals.ScreenKbControlsLayout[i][3] ); - // Check if the button is off screen edge or shrunk to zero - if( Globals.ScreenKbControlsLayout[i][0] > Globals.ScreenKbControlsLayout[i][2] - displayY/12 ) - Globals.ScreenKbControlsLayout[i][0] = Globals.ScreenKbControlsLayout[i][2] - displayY/12; - if( Globals.ScreenKbControlsLayout[i][1] > Globals.ScreenKbControlsLayout[i][3] - displayY/12 ) - Globals.ScreenKbControlsLayout[i][1] = Globals.ScreenKbControlsLayout[i][3] - displayY/12; - if( Globals.ScreenKbControlsLayout[i][0] < Globals.ScreenKbControlsLayout[i][2] - displayY*2/3 ) - Globals.ScreenKbControlsLayout[i][0] = Globals.ScreenKbControlsLayout[i][2] - displayY*2/3; - if( Globals.ScreenKbControlsLayout[i][1] < Globals.ScreenKbControlsLayout[i][3] - displayY*2/3 ) - Globals.ScreenKbControlsLayout[i][1] = Globals.ScreenKbControlsLayout[i][3] - displayY*2/3; - if( Globals.ScreenKbControlsLayout[i][0] < 0 ) - { - Globals.ScreenKbControlsLayout[i][2] += -Globals.ScreenKbControlsLayout[i][0]; - Globals.ScreenKbControlsLayout[i][0] = 0; - } - if( Globals.ScreenKbControlsLayout[i][2] > displayX ) - { - Globals.ScreenKbControlsLayout[i][0] -= Globals.ScreenKbControlsLayout[i][2] - displayX; - Globals.ScreenKbControlsLayout[i][2] = displayX; - } - if( Globals.ScreenKbControlsLayout[i][1] < 0 ) - { - Globals.ScreenKbControlsLayout[i][3] += -Globals.ScreenKbControlsLayout[i][1]; - Globals.ScreenKbControlsLayout[i][1] = 0; - } - if( Globals.ScreenKbControlsLayout[i][3] > displayY ) - { - Globals.ScreenKbControlsLayout[i][1] -= Globals.ScreenKbControlsLayout[i][3] - displayY; - Globals.ScreenKbControlsLayout[i][3] = displayY; - } - //Log.i("SDL", "After bounds check coords " + Globals.ScreenKbControlsLayout[i][0] + ":" + Globals.ScreenKbControlsLayout[i][1] + ":" + Globals.ScreenKbControlsLayout[i][2] + ":" + Globals.ScreenKbControlsLayout[i][3] ); + Log.i("SDL", "Screen kb button " + i + " coords " + Globals.ScreenKbControlsLayout[i][0] + ":" + Globals.ScreenKbControlsLayout[i][1] + ":" + Globals.ScreenKbControlsLayout[i][2] + ":" + Globals.ScreenKbControlsLayout[i][3] ); imgs[i] = new ImageView(p); imgs[i].setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); @@ -752,6 +728,31 @@ class SettingsMenuKeyboard extends SettingsMenu onKey( null, KeyEvent.KEYCODE_BACK, null ); // All buttons disabled - do not show anything else setupButton(currentButton); + + final Button backButton = new Button(p); + backButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + backButton.setText(android.R.string.ok); + //backButton.setTop(displayY / 30); + //backButton.setLeft(displayX / 2); + backButton.setOnClickListener(new View.OnClickListener() + { + public void onClick(View v) + { + p.getVideoLayout().removeView(layout); + layout = null; + goBack(p); + } + }); + layout.addView(backButton, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, + Gravity.TOP | Gravity.CENTER_HORIZONTAL)); + layout.getHandler().postDelayed(new Runnable() + { + public void run() + { + //backButton.setLeft(displayX / 2 - backButton.getWidth() / 2); + //backButton.setLeft(displayX / 2); + } + }, 200); } void setupButton(int i) diff --git a/project/java/Video.java b/project/java/Video.java index 324a329d8..7c0eaf91b 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -1003,7 +1003,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer private native void nativeInitJavaCallbacks(); private native void nativeInit(String CurrentPath, String CommandLine, int multiThreadedVideo, int unused); - private native void nativeResize(int w, int h, int keepAspectRatio); + public static native void nativeResize(int w, int h, int keepAspectRatio); private native void nativeDone(); private native void nativeGlContextLost(); public native void nativeGlContextRecreated(); diff --git a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c index 186c76ed1..86a7d8662 100644 --- a/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c +++ b/project/jni/sdl-1.2/src/video/android/SDL_touchscreenkeyboard.c @@ -1363,12 +1363,10 @@ int SDLCALL SDL_ANDROID_SetScreenKeyboardTransparency(int alpha) static int ScreenKbRedefinedByUser = 0; -JNIEXPORT void JNICALL -JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz, jint keynum, jint x1, jint y1, jint x2, jint y2) +static int convertJavaKeyIdToC(int keynum) { - SDL_Rect rect = {x1, y1, x2-x1, y2-y1}; - int key = -1; // Why didn't I use consistent IDs between Java and C code? + int key = -1; if( keynum == 0 ) key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD; if( keynum == 1 ) @@ -1379,6 +1377,14 @@ JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2; if( keynum == SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3 ) // This one is consistent by chance key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3; + return key; +} + +JNIEXPORT void JNICALL +JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz, jint keynum, jint x1, jint y1, jint x2, jint y2) +{ + SDL_Rect rect = {x1, y1, x2-x1, y2-y1}; + int key = convertJavaKeyIdToC(keynum); if( key >= 0 ) { @@ -1387,6 +1393,28 @@ JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz } } +JNIEXPORT jint JNICALL +JAVA_EXPORT_NAME(Settings_nativeGetScreenKeyboardButtonLayout) ( JNIEnv* env, jobject thiz, jint keynum, jint coord ) +{ + SDL_Rect rect = {0, 0, 0, 0}; + int key = convertJavaKeyIdToC(keynum); + + if( key < 0 ) + return 0; + + SDL_ANDROID_GetScreenKeyboardButtonPos(key, &rect); + if( coord == 0 ) + return rect.x; + if( coord == 1 ) + return rect.y; + if( coord == 2 ) + return rect.x + rect.w; + if( coord == 3 ) + return rect.y + rect.h; + + return 0; +} + int SDL_ANDROID_GetScreenKeyboardRedefinedByUser() { return ScreenKbRedefinedByUser; diff --git a/project/res/drawable/b1.png b/project/res/drawable/b1.png index 6a6babc51..74b2ab671 100644 Binary files a/project/res/drawable/b1.png and b/project/res/drawable/b1.png differ diff --git a/project/res/drawable/b2.png b/project/res/drawable/b2.png index cb5f2e6cd..5e8a25a1e 100644 Binary files a/project/res/drawable/b2.png and b/project/res/drawable/b2.png differ diff --git a/project/res/drawable/b3.png b/project/res/drawable/b3.png index cb1cacbdb..565347d27 100644 Binary files a/project/res/drawable/b3.png and b/project/res/drawable/b3.png differ diff --git a/project/res/drawable/b4.png b/project/res/drawable/b4.png index cc202ae13..a93acbcda 100644 Binary files a/project/res/drawable/b4.png and b/project/res/drawable/b4.png differ diff --git a/project/res/drawable/b5.png b/project/res/drawable/b5.png index 1c6802113..9f6e2a512 100644 Binary files a/project/res/drawable/b5.png and b/project/res/drawable/b5.png differ diff --git a/project/res/drawable/b6.png b/project/res/drawable/b6.png index 83902c210..e2aad8770 100644 Binary files a/project/res/drawable/b6.png and b/project/res/drawable/b6.png differ diff --git a/project/res/drawable/dpad.png b/project/res/drawable/dpad.png index 38f369f55..ca2d7e5b5 100644 Binary files a/project/res/drawable/dpad.png and b/project/res/drawable/dpad.png differ diff --git a/project/res/drawable/keyboard.png b/project/res/drawable/keyboard.png index 62d2358c3..260f10980 100644 Binary files a/project/res/drawable/keyboard.png and b/project/res/drawable/keyboard.png differ diff --git a/project/res/drawable/sun_b1.png b/project/res/drawable/sun_b1.png deleted file mode 100644 index faa1f8b24..000000000 Binary files a/project/res/drawable/sun_b1.png and /dev/null differ diff --git a/project/res/drawable/sun_b2.png b/project/res/drawable/sun_b2.png deleted file mode 100644 index b9f58e5dd..000000000 Binary files a/project/res/drawable/sun_b2.png and /dev/null differ diff --git a/project/res/drawable/sun_b3.png b/project/res/drawable/sun_b3.png deleted file mode 100644 index 6e5fbe515..000000000 Binary files a/project/res/drawable/sun_b3.png and /dev/null differ diff --git a/project/res/drawable/sun_b4.png b/project/res/drawable/sun_b4.png deleted file mode 100644 index a92dd6af6..000000000 Binary files a/project/res/drawable/sun_b4.png and /dev/null differ diff --git a/project/res/drawable/sun_b5.png b/project/res/drawable/sun_b5.png deleted file mode 100644 index d40c10820..000000000 Binary files a/project/res/drawable/sun_b5.png and /dev/null differ diff --git a/project/res/drawable/sun_b6.png b/project/res/drawable/sun_b6.png deleted file mode 100644 index 9b644d122..000000000 Binary files a/project/res/drawable/sun_b6.png and /dev/null differ diff --git a/project/res/drawable/sun_dpad.png b/project/res/drawable/sun_dpad.png deleted file mode 100644 index f653f2550..000000000 Binary files a/project/res/drawable/sun_dpad.png and /dev/null differ diff --git a/project/res/drawable/sun_keyboard.png b/project/res/drawable/sun_keyboard.png deleted file mode 100644 index 10b740e92..000000000 Binary files a/project/res/drawable/sun_keyboard.png and /dev/null differ