mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
different actions for long/short key pressings
This commit is contained in:
parent
db42d8afca
commit
caea03435a
1 changed files with 32 additions and 5 deletions
|
@ -472,7 +472,12 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
return view.onFingerLongPress(myPressedX, myPressedY);
|
return view.onFingerLongPress(myPressedX, myPressedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String myKeyUnderTracking;
|
||||||
|
private long myTrackingStartTime;
|
||||||
|
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
final ZLApplication application = ZLApplication.Instance();
|
||||||
|
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
case KeyEvent.KEYCODE_VOLUME_DOWN:
|
||||||
case KeyEvent.KEYCODE_VOLUME_UP:
|
case KeyEvent.KEYCODE_VOLUME_UP:
|
||||||
|
@ -481,19 +486,32 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||||
{
|
{
|
||||||
final String keyName = ZLAndroidKeyUtil.getKeyNameByCode(keyCode);
|
final String keyName = ZLAndroidKeyUtil.getKeyNameByCode(keyCode);
|
||||||
return ZLApplication.Instance().doActionByKey(keyName, false);
|
if (myKeyUnderTracking != null) {
|
||||||
|
if (myKeyUnderTracking.equals(keyName)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
myKeyUnderTracking = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (application.hasActionForKey(keyName, true)) {
|
||||||
|
myKeyUnderTracking = keyName;
|
||||||
|
myTrackingStartTime = System.currentTimeMillis();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return application.doActionByKey(keyName, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||||
ZLApplication.Instance().getCurrentView().onTrackballRotated(-1, 0);
|
application.getCurrentView().onTrackballRotated(-1, 0);
|
||||||
return true;
|
return true;
|
||||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||||
ZLApplication.Instance().getCurrentView().onTrackballRotated(1, 0);
|
application.getCurrentView().onTrackballRotated(1, 0);
|
||||||
return true;
|
return true;
|
||||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||||
ZLApplication.Instance().getCurrentView().onTrackballRotated(0, 1);
|
application.getCurrentView().onTrackballRotated(0, 1);
|
||||||
return true;
|
return true;
|
||||||
case KeyEvent.KEYCODE_DPAD_UP:
|
case KeyEvent.KEYCODE_DPAD_UP:
|
||||||
ZLApplication.Instance().getCurrentView().onTrackballRotated(0, -1);
|
application.getCurrentView().onTrackballRotated(0, -1);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -507,6 +525,15 @@ public class ZLAndroidWidget extends View implements View.OnLongClickListener {
|
||||||
case KeyEvent.KEYCODE_BACK:
|
case KeyEvent.KEYCODE_BACK:
|
||||||
case KeyEvent.KEYCODE_ENTER:
|
case KeyEvent.KEYCODE_ENTER:
|
||||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||||
|
if (myKeyUnderTracking != null) {
|
||||||
|
final String keyName = ZLAndroidKeyUtil.getKeyNameByCode(keyCode);
|
||||||
|
if (myKeyUnderTracking.equals(keyName)) {
|
||||||
|
final boolean longPress = System.currentTimeMillis() >
|
||||||
|
myTrackingStartTime + ViewConfiguration.getLongPressTimeout();
|
||||||
|
ZLApplication.Instance().doActionByKey(keyName, longPress);
|
||||||
|
}
|
||||||
|
myKeyUnderTracking = null;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue