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:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user