From a15aa70c32b7d5c0c40e717af86ef13770ebac1c Mon Sep 17 00:00:00 2001 From: shagr4th Date: Sun, 18 Dec 2016 15:21:19 +0100 Subject: [PATCH] No need to block input if there is delay between actual typing and event consuming by the native thread --- app/src/main/java/org/ab/x48/HPView.java | 48 +++++++++++------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/ab/x48/HPView.java b/app/src/main/java/org/ab/x48/HPView.java index 5767e1b..8c9da39 100644 --- a/app/src/main/java/org/ab/x48/HPView.java +++ b/app/src/main/java/org/ab/x48/HPView.java @@ -112,7 +112,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna mSurfaceHolder = getHolder(); mSurfaceHolder.addCallback(this); mainScreen = Bitmap.createBitmap(262, 14+128, Bitmap.Config.RGB_565); - queuedCodes = new Vector(); + queuedCodes = new ArrayList(); ann = new boolean [6]; buf = new short [(14+128)*262]; audiobuf = new short [44100]; // 1s worth @@ -993,6 +993,7 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna } if (code > -1) { + systemOptionDisplayed = false; key(code, actionCode == MotionEvent.ACTION_DOWN || actionCode == MotionEvent.ACTION_POINTER_DOWN, pointerID); return true; } @@ -1026,31 +1027,23 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna key(code, down, 255); // Use pointerID 255 for keyboard } - public synchronized void key(int code, boolean down, int pointerID) { - //Log.i("x48", "code: " + code + " / " + down); - if (code < MAX_TOUCHES) { - if (down) { - Integer cI = code+1; - if (!queuedCodes.contains(cI)) { + public void key(int code, boolean down, int pointerID) { + synchronized(this) { + if (code < MAX_TOUCHES) { + if (down) { + Integer cI = code + 1; queuedCodes.add(cI); - touches [code] = pointerID; + touches[code] = pointerID; performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, - HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING ); + HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); } else { - Log.i("x48", "rejected down"); - } - } - else { - Integer cI = code+100; - if (!queuedCodes.contains(cI) && touches [code] != 0) { + Integer cI = code + 100; queuedCodes.add(cI); - touches [code] = 0; - } else { - Log.i("x48", "rejected up"); + touches[code] = 0; } + x48.flipScreen(); + unpauseEvent(); } - x48.flipScreen(); - unpauseEvent(); } } @@ -1058,13 +1051,14 @@ public class HPView extends SurfaceView implements SurfaceHolder.Callback, Runna x48.openConditionVariable(); } - public synchronized int waitEvent() { - if (queuedCodes.size() == 0) { - return 0; - } - else { - int c = queuedCodes.remove(0); - return c; + public int waitEvent() { + synchronized(this) { + if (queuedCodes.size() == 0) { + return 0; + } else { + int c = queuedCodes.remove(0); + return c; + } } }