Option to customize on-screen keyboard layout

This commit is contained in:
pelya
2010-12-30 15:23:46 +00:00
parent c4c16ec1d8
commit 66f7928078
18 changed files with 189 additions and 21 deletions

View File

@@ -104,6 +104,10 @@ class Settings
out.writeInt(Globals.CommandLine.length());
for( int i = 0; i < Globals.CommandLine.length(); i++ )
out.writeChar(Globals.CommandLine.charAt(i));
out.writeInt(Globals.ScreenKbControlsLayout.length);
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
out.writeInt(Globals.ScreenKbControlsLayout[i][ii]);
out.close();
settingsLoaded = true;
@@ -220,6 +224,12 @@ class Settings
for( int i = 0; i < len; i++ )
b.append( settingsFile.readChar() );
Globals.CommandLine = b.toString();
if( settingsFile.readInt() != Globals.ScreenKbControlsLayout.length )
throw new IOException();
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
Globals.ScreenKbControlsLayout[i][ii] = settingsFile.readInt();
settingsLoaded = true;
@@ -470,6 +480,8 @@ class Settings
items.add(p.getResources().getString(R.string.remap_screenkb));
items.add(p.getResources().getString(R.string.screenkb_custom_layout));
items.add(p.getResources().getString(R.string.ok));
AlertDialog.Builder builder = new AlertDialog.Builder(p);
@@ -497,6 +509,10 @@ class Settings
if( item == selected )
showRemapScreenKbConfig(p);
selected++;
if( item == selected )
showCustomizeScreenKbLayout(p);
selected++;
if( item == selected )
showConfigMainMenu(p);
@@ -753,6 +769,10 @@ class Settings
p.getResources().getString(R.string.controls_screenkb_small),
p.getResources().getString(R.string.controls_screenkb_tiny) };
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
Globals.ScreenKbControlsLayout[i][ii] = 0;
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(p.getResources().getString(R.string.controls_screenkb_size));
builder.setSingleChoiceItems(items, Globals.TouchscreenKeyboardSize, new DialogInterface.OnClickListener()
@@ -1390,7 +1410,7 @@ class Settings
p.keyListener = tool;
}
public static class ScreenEdgesCalibrationTool implements TouchEventsListener, KeyEventsListener
static class ScreenEdgesCalibrationTool implements TouchEventsListener, KeyEventsListener
{
MainActivity p;
ImageView img;
@@ -1449,6 +1469,119 @@ class Settings
}
}
static void showCustomizeScreenKbLayout(final MainActivity p)
{
p.setText(p.getResources().getString(R.string.screenkb_custom_layout_help));
CustomizeScreenKbLayoutTool tool = new CustomizeScreenKbLayoutTool(p);
p.touchListener = tool;
p.keyListener = tool;
};
static class CustomizeScreenKbLayoutTool implements TouchEventsListener, KeyEventsListener
{
MainActivity p;
FrameLayout layout = null;
ImageView imgs[] = new ImageView[Globals.ScreenKbControlsLayout.length];
Bitmap bmps[] = new Bitmap[Globals.ScreenKbControlsLayout.length];
int currentButton = 0;
int buttons[] = {
R.drawable.dpad,
R.drawable.keyboard,
R.drawable.b1,
R.drawable.b2,
R.drawable.b3,
R.drawable.b4,
R.drawable.b5,
R.drawable.b6
};
public CustomizeScreenKbLayoutTool(MainActivity _p)
{
p = _p;
layout = new FrameLayout(p);
p.getVideoLayout().addView(layout);
currentButton = 0;
setupButton(true);
}
void setupButton(boolean undo)
{
do {
currentButton += undo ? -1 : 1;
if(currentButton >= Globals.ScreenKbControlsLayout.length)
{
p.getVideoLayout().removeView(layout);
layout = null;
p.touchListener = null;
p.keyListener = null;
showScreenKeyboardConfigMainMenu(p);
return;
}
if(currentButton < 0)
{
currentButton = 0;
undo = false;
}
} while( ! Globals.ScreenKbControlsShown[currentButton] );
if( imgs[currentButton] == null )
{
imgs[currentButton] = new ImageView(p);
imgs[currentButton].setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
imgs[currentButton].setScaleType(ImageView.ScaleType.MATRIX);
bmps[currentButton] = BitmapFactory.decodeResource( p.getResources(), buttons[currentButton] );
imgs[currentButton].setImageBitmap(bmps[currentButton]);
layout.addView(imgs[currentButton]);
}
Matrix m = new Matrix();
RectF src = new RectF(0, 0, bmps[currentButton].getWidth(), bmps[currentButton].getHeight());
RectF dst = new RectF(Globals.ScreenKbControlsLayout[currentButton][0], Globals.ScreenKbControlsLayout[currentButton][1],
Globals.ScreenKbControlsLayout[currentButton][2], Globals.ScreenKbControlsLayout[currentButton][3]);
m.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
imgs[currentButton].setImageMatrix(m);
}
public void onTouchEvent(final MotionEvent ev)
{
if( ev.getAction() == MotionEvent.ACTION_DOWN )
{
Globals.ScreenKbControlsLayout[currentButton][0] = (int)ev.getX();
Globals.ScreenKbControlsLayout[currentButton][1] = (int)ev.getY();
Globals.ScreenKbControlsLayout[currentButton][2] = (int)ev.getX();
Globals.ScreenKbControlsLayout[currentButton][3] = (int)ev.getY();
}
if( ev.getAction() == MotionEvent.ACTION_MOVE )
{
if( Globals.ScreenKbControlsLayout[currentButton][0] > (int)ev.getX() )
Globals.ScreenKbControlsLayout[currentButton][0] = (int)ev.getX();
if( Globals.ScreenKbControlsLayout[currentButton][1] > (int)ev.getY() )
Globals.ScreenKbControlsLayout[currentButton][1] = (int)ev.getY();
if( Globals.ScreenKbControlsLayout[currentButton][2] < (int)ev.getX() )
Globals.ScreenKbControlsLayout[currentButton][2] = (int)ev.getX();
if( Globals.ScreenKbControlsLayout[currentButton][3] < (int)ev.getY() )
Globals.ScreenKbControlsLayout[currentButton][3] = (int)ev.getY();
}
Matrix m = new Matrix();
RectF src = new RectF(0, 0, bmps[currentButton].getWidth(), bmps[currentButton].getHeight());
RectF dst = new RectF(Globals.ScreenKbControlsLayout[currentButton][0], Globals.ScreenKbControlsLayout[currentButton][1],
Globals.ScreenKbControlsLayout[currentButton][2], Globals.ScreenKbControlsLayout[currentButton][3]);
m.setRectToRect(src, dst, Matrix.ScaleToFit.FILL);
imgs[currentButton].setImageMatrix(m);
if( ev.getAction() == MotionEvent.ACTION_UP )
setupButton(false);
}
public void onKeyEvent(final int keyCode)
{
if( layout != null && imgs[currentButton] != null )
layout.removeView(imgs[currentButton]);
imgs[currentButton] = null;
setupButton(true);
}
}
// ===============================================================================================
static void Apply(Activity p)
@@ -1487,11 +1620,16 @@ class Settings
nativeSetScreenKbKeyUsed(i, Globals.ScreenKbControlsShown[i] ? 1 : 0);
for( int i = 0; i < Globals.RemapScreenKbKeycode.length; i++ )
nativeSetKeymapKeyScreenKb(i, SDL_Keys.values[Globals.RemapScreenKbKeycode[i]]);
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
if( Globals.ScreenKbControlsLayout[i][0] < Globals.ScreenKbControlsLayout[i][2] )
nativeSetScreenKbKeyLayout( i, Globals.ScreenKbControlsLayout[i][0], Globals.ScreenKbControlsLayout[i][1],
Globals.ScreenKbControlsLayout[i][2], Globals.ScreenKbControlsLayout[i][3]);
for( int i = 0; i < Globals.RemapMultitouchGestureKeycode.length; i++ )
nativeSetKeymapKeyMultitouchGesture(i, Globals.MultitouchGesturesUsed[i] ? SDL_Keys.values[Globals.RemapMultitouchGestureKeycode[i]] : 0);
nativeSetMultitouchGestureSensitivity(Globals.MultitouchGestureSensitivity);
if( Globals.TouchscreenCalibration[2] > Globals.TouchscreenCalibration[0] )
nativeSetTouchscreenCalibration(Globals.TouchscreenCalibration[0], Globals.TouchscreenCalibration[1], Globals.TouchscreenCalibration[2], Globals.TouchscreenCalibration[3]);
nativeSetTouchscreenCalibration(Globals.TouchscreenCalibration[0], Globals.TouchscreenCalibration[1],
Globals.TouchscreenCalibration[2], Globals.TouchscreenCalibration[3]);
String lang = new String(Locale.getDefault().getLanguage());
if( Locale.getDefault().getCountry().length() > 0 )
@@ -1552,6 +1690,7 @@ class Settings
private static native int nativeGetKeymapKeyScreenKb(int keynum);
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);
private static native int nativeGetKeymapKeyMultitouchGesture(int keynum);
private static native void nativeSetKeymapKeyMultitouchGesture(int keynum, int key);
private static native void nativeSetMultitouchGestureSensitivity(int sensitivity);

View File

@@ -104,5 +104,5 @@
<string name="storage_custom">Geben Sie direkt</string>
<string name="storage_commandline">Geben Kommandozeilenparameter</string>
<string name="calibrate_touchscreen">Kalibrieren Touchscreen</string>
<string name="calibrate_touchscreen_touch">Touch allen vier Rändern des Bildschirms, wenn Sie fertig sind, drücken Sie Zurück</string>
<string name="calibrate_touchscreen_touch">Touch allen vier Rändern des Bildschirms, drücken Sie Menü, wenn Sie fertig</string>
</resources>

View File

@@ -104,5 +104,5 @@
<string name="storage_custom">Määritä hakemisto</string>
<string name="storage_commandline">Määritä komentoriviparametrit</string>
<string name="calibrate_touchscreen">Kalibroi kosketusnäyttö</string>
<string name="calibrate_touchscreen_touch">Touch kaikki neljä reunaa näytön, paina Takaisin, kun olet valmis</string>
<string name="calibrate_touchscreen_touch">Touch kaikki neljä reunaa näytön, paina Valikko, kun olet valmis</string>
</resources>

View File

@@ -107,5 +107,5 @@
<string name="storage_custom">Spécifiez le répertoire</string>
<string name="storage_commandline">Spécifier les paramètres de ligne de commande</string>
<string name="calibrate_touchscreen">Calibrer écran tactile</string>
<string name="calibrate_touchscreen_touch">Touchez les quatre bords de l\u0026#39;écran, appuyez sur Retour lorsque vous avez terminé</string>
<string name="calibrate_touchscreen_touch">Touchez les quatre bords de l\u0026#39;écran, appuyez sur MENU lorsque vous avez terminé</string>
</resources>

View File

@@ -97,5 +97,5 @@
<string name="storage_custom">Укажите каталог</string>
<string name="storage_commandline">Укажите параметры командной строки</string>
<string name="calibrate_touchscreen">Калибровка сенсорного экрана</string>
<string name="calibrate_touchscreen_touch">Дотроньтесь до всех четырех краев экрана, потом нажмите Назад</string>
<string name="calibrate_touchscreen_touch">Дотроньтесь до всех четырех краев экрана, потом нажмите MENU</string>
</resources>

View File

@@ -97,5 +97,5 @@
<string name="storage_custom">Вкажіть каталог</string>
<string name="storage_commandline">Вкажіть параметри командного рядка</string>
<string name="calibrate_touchscreen">Калібрування сенсорного екрану</string>
<string name="calibrate_touchscreen_touch">Доторкнiться до всіх чотирьох країв екрану, потiм натисніть Назад</string>
<string name="calibrate_touchscreen_touch">Доторкнiться до всіх чотирьох країв екрану, потiм натисніть MENU</string>
</resources>

View File

@@ -116,7 +116,10 @@
<string name="remap_screenkb_button_rotateleft">Rotate left two-finger gesture</string>
<string name="remap_screenkb_button_rotateright">Rotate right two-finger gesture</string>
<string name="screenkb_custom_layout">Customize on-screen keyboard layout</string>
<string name="screenkb_custom_layout_help">Slide screen to add button, press Menu to undo last button</string>
<string name="calibrate_touchscreen">Calibrate touchscreen</string>
<string name="calibrate_touchscreen_touch">Touch all four edges of the screen, press Back when done</string>
<string name="calibrate_touchscreen_touch">Touch all four edges of the screen, press Menu when done</string>
</resources>

View File

@@ -1 +1 @@
alienblaster
ballfield

View File

@@ -1416,7 +1416,7 @@ void ANDROID_InitOSKeymap()
}
JNIEXPORT jint JNICALL
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKey) ( JNIEnv* env, jobject thiz, jint code)
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKey) (JNIEnv* env, jobject thiz, jint code)
{
if( code < 0 || code > KEYCODE_LAST )
return SDL_KEY(UNKNOWN);
@@ -1424,7 +1424,7 @@ JAVA_EXPORT_NAME(Settings_nativeGetKeymapKey) ( JNIEnv* env, jobject thiz, jint
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKey) ( JNIEnv* env, jobject thiz, jint javakey, jint key)
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKey) (JNIEnv* env, jobject thiz, jint javakey, jint key)
{
if( javakey < 0 || javakey > KEYCODE_LAST )
return;
@@ -1432,7 +1432,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetKeymapKey) ( JNIEnv* env, jobject thiz, jint
}
JNIEXPORT jint JNICALL
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyScreenKb) ( JNIEnv* env, jobject thiz, jint keynum)
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyScreenKb) (JNIEnv* env, jobject thiz, jint keynum)
{
if( keynum < 0 || keynum > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 + 4 )
return SDL_KEY(UNKNOWN);
@@ -1444,7 +1444,7 @@ JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyScreenKb) ( JNIEnv* env, jobject th
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKeyScreenKb) ( JNIEnv* env, jobject thiz, jint keynum, jint key)
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKeyScreenKb) (JNIEnv* env, jobject thiz, jint keynum, jint key)
{
if( keynum < 0 || keynum > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 + 4 )
return;
@@ -1454,7 +1454,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetKeymapKeyScreenKb) ( JNIEnv* env, jobject th
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyUsed) ( JNIEnv* env, jobject thiz, jint keynum, jint used)
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyUsed) (JNIEnv* env, jobject thiz, jint keynum, jint used)
{
SDL_Rect rect = {0, 0, 0, 0};
int key = -1;
@@ -1470,7 +1470,7 @@ JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyUsed) ( JNIEnv* env, jobject thiz
}
JNIEXPORT jint JNICALL
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyMultitouchGesture) ( JNIEnv* env, jobject thiz, jint keynum)
JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyMultitouchGesture) (JNIEnv* env, jobject thiz, jint keynum)
{
if( keynum < 0 || keynum >= MAX_MULTITOUCH_GESTURES )
return SDL_KEY(UNKNOWN);
@@ -1478,21 +1478,21 @@ JAVA_EXPORT_NAME(Settings_nativeGetKeymapKeyMultitouchGesture) ( JNIEnv* env, j
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKeyMultitouchGesture) ( JNIEnv* env, jobject thiz, jint keynum, jint keycode)
JAVA_EXPORT_NAME(Settings_nativeSetKeymapKeyMultitouchGesture) (JNIEnv* env, jobject thiz, jint keynum, jint keycode)
{
if( keynum < 0 || keynum >= MAX_MULTITOUCH_GESTURES )
return SDL_KEY(UNKNOWN);
return;
multitouchGestureKeycode[keynum] = keycode;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetMultitouchGestureSensitivity) ( JNIEnv* env, jobject thiz, jint sensitivity)
JAVA_EXPORT_NAME(Settings_nativeSetMultitouchGestureSensitivity) (JNIEnv* env, jobject thiz, jint sensitivity)
{
multitouchGestureSensitivity = sensitivity;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenCalibration) (JNIEnv* env, jobject thiz, jint x1, jint y1, jint x2, jint y2)
JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenCalibration) (JNIEnv* env, jobject thiz, jint x1, jint y1, jint x2, jint y2)
{
SDL_ANDROID_TouchscreenCalibrationX = x1;
SDL_ANDROID_TouchscreenCalibrationY = y1;
@@ -1500,6 +1500,25 @@ JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenCalibration) (JNIEnv* env, jobjec
SDL_ANDROID_TouchscreenCalibrationHeight = y2 - y1;
}
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 = -1;
__android_log_print(ANDROID_LOG_INFO, "libSDL", "nativeSetScreenKbKeyLayout: %d %d %d %d", (int)rect.x, (int)rect.y, (int)rect.w, (int)rect.h);
if( keynum == 0 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD;
if( keynum == 1 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT;
if( keynum - 2 >= 0 && keynum - 2 <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
key = keynum - 2 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
if( key >= 0 )
SDL_ANDROID_SetScreenKeyboardButtonPos(key, &rect);
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeInitKeymap) ( JNIEnv* env, jobject thiz )
{

View File

@@ -860,12 +860,19 @@ int SDL_ANDROID_SetScreenKeyboardButtonPos(int buttonId, SDL_Rect * pos)
}
else
{
buttons[buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0] = *pos;
int i = buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
buttons[i] = *pos;
if(touchscreenKeyboardTheme == 0)
{
int i = buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
prepareFontCharWireframe(FONT_BTN1 + i, MIN(buttons[i].h, buttons[i].w), MIN(buttons[i].h, buttons[i].w));
}
if( i < AutoFireButtonsNum )
{
buttonsAutoFireRect[i].w = buttons[i].w * 2;
buttonsAutoFireRect[i].h = buttons[i].h * 2;
buttonsAutoFireRect[i].x = buttons[i].x - buttons[i].w / 2;
buttonsAutoFireRect[i].y = buttons[i].y - buttons[i].h / 2;
}
}
return 1;
};

BIN
project/res/drawable/b1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
project/res/drawable/b2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
project/res/drawable/b3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
project/res/drawable/b4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
project/res/drawable/b5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
project/res/drawable/b6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB