Added advanced point-and-click features: right mouse click via several methods, left click configurable, and showing part of screen under finger in small window
This commit is contained in:
@@ -57,9 +57,10 @@ class Globals {
|
||||
public static int TrackballDampening = 0;
|
||||
public static int AudioBufferConfig = 0;
|
||||
public static boolean OptionalDataDownload[] = null;
|
||||
public static final int RIGHT_CLICK_WITH_MENU_BUTTON = 0;
|
||||
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
|
||||
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
|
||||
public static final int RIGHT_CLICK_NONE = 0;
|
||||
public static final int RIGHT_CLICK_WITH_MENU_BUTTON = 1;
|
||||
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 2;
|
||||
public static final int RIGHT_CLICK_WITH_PRESSURE = 3;
|
||||
public static int RightClickMethod = RIGHT_CLICK_WITH_MENU_BUTTON;
|
||||
public static boolean LeftClickUsesPressure = false;
|
||||
public static boolean ShowScreenUnderFinger = false;
|
||||
|
||||
@@ -55,6 +55,7 @@ public class MainActivity extends Activity {
|
||||
onClickListener( MainActivity _p ) { p = _p; }
|
||||
public void onClick(View v)
|
||||
{
|
||||
setUpStatusLabel();
|
||||
System.out.println("libSDL: User clicked change phone config button");
|
||||
Settings.showConfig(p);
|
||||
}
|
||||
@@ -106,6 +107,23 @@ public class MainActivity extends Activity {
|
||||
changeConfigAlertThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpStatusLabel()
|
||||
{
|
||||
MainActivity Parent = this; // Too lazy to rename
|
||||
if( Parent._btn != null )
|
||||
{
|
||||
Parent._layout2.removeView(Parent._btn);
|
||||
Parent._btn = null;
|
||||
}
|
||||
if( Parent._tv == null )
|
||||
{
|
||||
Parent._tv = new TextView(Parent);
|
||||
Parent._tv.setMaxLines(1);
|
||||
Parent._tv.setText(R.string.init);
|
||||
Parent._layout2.addView(Parent._tv);
|
||||
}
|
||||
}
|
||||
|
||||
public void startDownloader()
|
||||
{
|
||||
@@ -115,20 +133,7 @@ public class MainActivity extends Activity {
|
||||
public MainActivity Parent;
|
||||
public void run()
|
||||
{
|
||||
System.out.println("libSDL: Removing button from startup screen and adding status text");
|
||||
if( Parent._btn != null )
|
||||
{
|
||||
Parent._layout2.removeView(Parent._btn);
|
||||
Parent._btn = null;
|
||||
}
|
||||
if( Parent._tv == null )
|
||||
{
|
||||
Parent._tv = new TextView(Parent);
|
||||
Parent._tv.setMaxLines(1);
|
||||
Parent._tv.setText(R.string.init);
|
||||
Parent._layout2.addView(Parent._tv);
|
||||
}
|
||||
|
||||
setUpStatusLabel();
|
||||
System.out.println("libSDL: Starting downloader");
|
||||
if( Parent.downloader == null )
|
||||
Parent.downloader = new DataDownloader(Parent, Parent._tv);
|
||||
@@ -284,6 +289,9 @@ public class MainActivity extends Activity {
|
||||
else
|
||||
if( _btn != null )
|
||||
return _btn.dispatchTouchEvent(ev);
|
||||
else
|
||||
if( _touchMeasurementTool != null )
|
||||
_touchMeasurementTool.onTouchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -297,17 +305,18 @@ public class MainActivity extends Activity {
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public TextView Status;
|
||||
MainActivity Parent;
|
||||
public String text;
|
||||
public void run()
|
||||
{
|
||||
if(Status != null)
|
||||
Status.setText(text);
|
||||
Parent.setUpStatusLabel();
|
||||
if(Parent._tv != null)
|
||||
Parent._tv.setText(text);
|
||||
}
|
||||
}
|
||||
Callback cb = new Callback();
|
||||
cb.text = new String(t);
|
||||
cb.Status = _tv;
|
||||
cb.Parent = this;
|
||||
this.runOnUiThread(cb);
|
||||
}
|
||||
|
||||
@@ -348,5 +357,6 @@ public class MainActivity extends Activity {
|
||||
private FrameLayout _videoLayout = null;
|
||||
private EditText _screenKeyboard = null;
|
||||
private boolean sdlInited = false;
|
||||
public Settings.TouchMeasurementTool _touchMeasurementTool = null;
|
||||
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ class Settings
|
||||
*/
|
||||
|
||||
System.out.println("libSDL: Settings.Load(): loading settings failed, running config dialog");
|
||||
p.setUpStatusLabel();
|
||||
showConfig(p);
|
||||
}
|
||||
|
||||
@@ -208,6 +209,8 @@ class Settings
|
||||
|
||||
static void showKeyboardConfig(final MainActivity p)
|
||||
{
|
||||
Globals.PhoneHasArrowKeys = false;
|
||||
Globals.PhoneHasTrackball = false;
|
||||
if( ! Globals.AppNeedsArrowKeys )
|
||||
{
|
||||
showTrackballConfig(p);
|
||||
@@ -270,6 +273,9 @@ class Settings
|
||||
|
||||
static void showAdditionalInputConfig(final MainActivity p)
|
||||
{
|
||||
Globals.UseTouchscreenKeyboard = false;
|
||||
Globals.UseAccelerometerAsArrowKeys = false;
|
||||
|
||||
if( ! ( Globals.AppNeedsArrowKeys || Globals.AppNeedsTextInput || Globals.AppTouchscreenKeyboardKeysAmount > 0 ) && ! Globals.AppUsesJoystick )
|
||||
{
|
||||
showAccelerometerConfig(p);
|
||||
@@ -280,9 +286,6 @@ class Settings
|
||||
p.getResources().getString(R.string.controls_accelnav),
|
||||
};
|
||||
|
||||
Globals.UseTouchscreenKeyboard = false;
|
||||
Globals.UseAccelerometerAsArrowKeys = false;
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle(p.getResources().getString(R.string.controls_additional));
|
||||
builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener()
|
||||
@@ -406,7 +409,7 @@ class Settings
|
||||
Globals.TouchscreenKeyboardTheme = 0;
|
||||
if( ! Globals.UseTouchscreenKeyboard )
|
||||
{
|
||||
showRightClickConfigConfig(p);
|
||||
showAudioConfig(p);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -426,6 +429,29 @@ class Settings
|
||||
if( item == 1 )
|
||||
Globals.TouchscreenKeyboardTheme = 0;
|
||||
|
||||
dialog.dismiss();
|
||||
showAudioConfig(p);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.setOwnerActivity(p);
|
||||
alert.show();
|
||||
}
|
||||
|
||||
static void showAudioConfig(final MainActivity p)
|
||||
{
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.audiobuf_verysmall),
|
||||
p.getResources().getString(R.string.audiobuf_small),
|
||||
p.getResources().getString(R.string.audiobuf_medium),
|
||||
p.getResources().getString(R.string.audiobuf_large) };
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle(R.string.audiobuf_question);
|
||||
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
Globals.AudioBufferConfig = item;
|
||||
dialog.dismiss();
|
||||
showRightClickConfigConfig(p);
|
||||
}
|
||||
@@ -437,7 +463,7 @@ class Settings
|
||||
|
||||
static void showRightClickConfigConfig(final MainActivity p)
|
||||
{
|
||||
Globals.RightClickMethod = RIGHT_CLICK_WITH_MENU_BUTTON;
|
||||
Globals.RightClickMethod = Globals.RIGHT_CLICK_NONE;
|
||||
if( ! Globals.AppNeedsTwoButtonMouse )
|
||||
{
|
||||
showAdvancedPointAndClickConfigConfig(p);
|
||||
@@ -453,7 +479,7 @@ class Settings
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
Globals.RightClickMethod = item;
|
||||
Globals.RightClickMethod = item + 1;
|
||||
dialog.dismiss();
|
||||
showAdvancedPointAndClickConfigConfig(p);
|
||||
}
|
||||
@@ -470,13 +496,16 @@ class Settings
|
||||
|
||||
if( ! Globals.AppNeedsTwoButtonMouse )
|
||||
{
|
||||
showAudioConfig(p);
|
||||
showTouchPressureMeasurementTool(p);
|
||||
return;
|
||||
}
|
||||
final CharSequence[] items = (Globals.RightClickMethod == RIGHT_CLICK_WITH_PRESSURE) ?
|
||||
{ p.getResources().getString(R.string.pointandclick_showcreenunderfinger) } :
|
||||
{ p.getResources().getString(R.string.pointandclick_showcreenunderfinger),
|
||||
p.getResources().getString(R.string.pointandclick_usepressure) };
|
||||
CharSequence[] items = { p.getResources().getString(R.string.pointandclick_showcreenunderfinger),
|
||||
p.getResources().getString(R.string.pointandclick_usepressure) };
|
||||
if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE )
|
||||
{
|
||||
CharSequence[] items2 = { p.getResources().getString(R.string.pointandclick_showcreenunderfinger) };
|
||||
items = items2;
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle(p.getResources().getString(R.string.pointandclick_question));
|
||||
@@ -495,7 +524,7 @@ class Settings
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
dialog.dismiss();
|
||||
showAudioConfig(p);
|
||||
showTouchPressureMeasurementTool(p);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -504,29 +533,72 @@ class Settings
|
||||
alert.show();
|
||||
}
|
||||
|
||||
static void showAudioConfig(final MainActivity p)
|
||||
public static class TouchMeasurementTool
|
||||
{
|
||||
final CharSequence[] items = { p.getResources().getString(R.string.audiobuf_verysmall),
|
||||
p.getResources().getString(R.string.audiobuf_small),
|
||||
p.getResources().getString(R.string.audiobuf_medium),
|
||||
p.getResources().getString(R.string.audiobuf_large) };
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle(R.string.audiobuf_question);
|
||||
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
|
||||
MainActivity p;
|
||||
ArrayList<Integer> force = new ArrayList<Integer>();
|
||||
ArrayList<Integer> radius = new ArrayList<Integer>();
|
||||
static final int maxEventAmount = 100;
|
||||
|
||||
public TouchMeasurementTool(MainActivity _p)
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
p = _p;
|
||||
}
|
||||
|
||||
public void onTouchEvent(final MotionEvent ev)
|
||||
{
|
||||
force.add(new Integer((int)(ev.getPressure() * 1000.0)));
|
||||
radius.add(new Integer((int)(ev.getSize() * 1000.0)));
|
||||
p.setText(p.getResources().getString(R.string.measurepressure_response, force.get(force.size()-1), radius.get(radius.size()-1)));
|
||||
try {
|
||||
Thread.sleep(10L);
|
||||
} catch (InterruptedException e) { }
|
||||
|
||||
if( force.size() >= maxEventAmount )
|
||||
{
|
||||
Globals.AudioBufferConfig = item;
|
||||
dialog.dismiss();
|
||||
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();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.setOwnerActivity(p);
|
||||
alert.show();
|
||||
}
|
||||
|
||||
int getAverageForce()
|
||||
{
|
||||
int avg = 0;
|
||||
for(Integer f: force)
|
||||
{
|
||||
avg += f;
|
||||
}
|
||||
return avg / force.size();
|
||||
}
|
||||
int getAverageRadius()
|
||||
{
|
||||
int avg = 0;
|
||||
for(Integer r: radius)
|
||||
{
|
||||
avg += r;
|
||||
}
|
||||
return avg / radius.size();
|
||||
}
|
||||
}
|
||||
|
||||
static void showTouchPressureMeasurementTool(final MainActivity p)
|
||||
{
|
||||
if( Globals.RightClickMethod == Globals.RIGHT_CLICK_WITH_PRESSURE || Globals.LeftClickUsesPressure )
|
||||
{
|
||||
p.setText(p.getResources().getString(R.string.measurepressure_touchplease));
|
||||
p._touchMeasurementTool = new TouchMeasurementTool(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
Save(p);
|
||||
p.startDownloader();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void Apply(Activity p)
|
||||
{
|
||||
|
||||
@@ -61,10 +61,15 @@
|
||||
|
||||
<string name="rightclick_question">Right mouse click triggered by:</string>
|
||||
<string name="rightclick_menu">Menu key</string>
|
||||
<string name="rightclick_multitouch">Touching screen with second finger (device should support that)</string>
|
||||
<string name="rightclick_pressure">Pressing screen with force (device should support that)</string>
|
||||
<string name="rightclick_multitouch">Touch screen with second finger</string>
|
||||
<string name="rightclick_pressure">Touch screen with force</string>
|
||||
|
||||
<string name="rightclick_question">Right mouse click triggered by:</string>
|
||||
<string name="pointandclick_question">Advanced point-and-click features</string>
|
||||
<string name="pointandclick_showcreenunderfinger">Show screen under finger in separate window</string>
|
||||
<string name="pointandclick_usepressure">Left click triggered by touch force</string>
|
||||
|
||||
<string name="measurepressure_touchplease">Please slide finger across the screen for two seconds</string>
|
||||
<string name="measurepressure_response">Pressure %03d radius %03d</string>
|
||||
|
||||
<string name="audiobuf_verysmall">Very small (fast devices, less lag)</string>
|
||||
<string name="audiobuf_small">Small</string>
|
||||
|
||||
Reference in New Issue
Block a user