Generic physical phone key to SDL key remapper, only dialog is implemented - it's not saved and not working yet

This commit is contained in:
pelya
2010-12-07 20:05:52 +02:00
parent dfb09282c8
commit 3dd4da9b0b
7 changed files with 114 additions and 15 deletions

View File

@@ -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;/" | \

View File

@@ -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<Integer> RemapHwKeycodeJava = new Vector<Integer>();
public static Vector<Integer> RemapHwKeycodeSdl = new Vector<Integer>();
}
class LoadLibrary {

View File

@@ -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;
}

View File

@@ -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<Integer> force = new ArrayList<Integer>();
@@ -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 );

View File

@@ -81,6 +81,7 @@
<string name="pointandclick_joystickmouseaccel">Move mouse with joystick acceleration</string>
<string name="none">None</string>
<string name="measurepressure">Calibrate touchscreen pressure</string>
<string name="measurepressure_touchplease">Please slide finger across the screen for two seconds</string>
<string name="measurepressure_response">Pressure %03d radius %03d</string>
@@ -90,4 +91,8 @@
<string name="audiobuf_large">Large (older devices, if sound is choppy)</string>
<string name="audiobuf_question">Size of audio buffer</string>
<string name="remap_hwkeys">Remap physical keys</string>
<string name="remap_hwkeys_press">Press any key except HOME and POWER, you may use volume keys</string>
<string name="remap_hwkeys_select">Select SDL keycode</string>
</resources>

View File

@@ -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'

View File

@@ -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