modules/graphics/src/main/java/com/sun/glass/ui/TouchInputSupport.java

Print this page

        

*** 22,44 **** * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.glass.ui; - import com.sun.glass.events.GestureEvent; import com.sun.glass.events.TouchEvent; import java.util.HashMap; import java.util.Map; public class TouchInputSupport { private int touchCount = 0; private boolean filterTouchCoordinates; ! private Map<Long, Integer> touchX; ! private Map<Long, Integer> touchY; private TouchCountListener listener; private int curTouchCount; private View curView; --- 22,52 ---- * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.glass.ui; import com.sun.glass.events.TouchEvent; import java.util.HashMap; import java.util.Map; public class TouchInputSupport { private int touchCount = 0; private boolean filterTouchCoordinates; ! private static class TouchCoord { ! private final int x, y, xAbs, yAbs; ! ! private TouchCoord(int x, int y, int xAbs, int yAbs) { ! this.x = x; ! this.y = y; ! this.xAbs = xAbs; ! this.yAbs = yAbs; ! } ! } ! private Map<Long, TouchCoord> touch; private TouchCountListener listener; private int curTouchCount; private View curView;
*** 54,75 **** boolean filterTouchCoordinates) { Application.checkEventThread(); this.listener = listener; this.filterTouchCoordinates = filterTouchCoordinates; if (filterTouchCoordinates) { ! touchX = new HashMap<Long, Integer>(); ! touchY = new HashMap<Long, Integer>(); } } public int getTouchCount() { Application.checkEventThread(); return touchCount; } public void notifyBeginTouchEvent(View view, int modifiers, boolean isDirect, int touchEventCount) { curTouchCount = touchCount; curView = view; curModifiers = modifiers; curIsDirect = isDirect; if (view != null) { --- 62,97 ---- boolean filterTouchCoordinates) { Application.checkEventThread(); this.listener = listener; this.filterTouchCoordinates = filterTouchCoordinates; if (filterTouchCoordinates) { ! touch = new HashMap<>(); } } public int getTouchCount() { Application.checkEventThread(); return touchCount; } public void notifyBeginTouchEvent(View view, int modifiers, boolean isDirect, int touchEventCount) { + + if (view != curView && touchCount != 0) { + // Release the currently pressed touch points + curView.notifyBeginTouchEvent(0, true, touchCount); + for (Map.Entry<Long, TouchCoord> e : touch.entrySet()) { + TouchCoord coord = e.getValue(); + curView.notifyNextTouchEvent(TouchEvent.TOUCH_RELEASED, e.getKey(), coord.x, coord.y, coord.xAbs, coord.yAbs); + } + curView.notifyEndTouchEvent(); + touchCount = 0; + if (listener != null ) { + listener.touchCountChanged(this, curView, 0, true); + } + } + curTouchCount = touchCount; curView = view; curModifiers = modifiers; curIsDirect = isDirect; if (view != null) {
*** 108,140 **** System.err.println("Unknown touch state: " + state); return; } if (filterTouchCoordinates) { ! state = filterTouchInputState(state, id, x, y); } if (view != null) { view.notifyNextTouchEvent(state, id, x, y, xAbs, yAbs); } } ! private int filterTouchInputState(int state, long id, int x, int y) { switch (state) { case TouchEvent.TOUCH_RELEASED: ! touchX.remove(id); ! touchY.remove(id); break; case TouchEvent.TOUCH_MOVED: ! if (x == touchX.get(id) && y == touchY.get(id)) { state = TouchEvent.TOUCH_STILL; break; } // fall through; case TouchEvent.TOUCH_PRESSED: ! touchX.put(id, x); ! touchY.put(id, y); break; case TouchEvent.TOUCH_STILL: break; default: System.err.println("Unknown touch state: " + state); --- 130,161 ---- System.err.println("Unknown touch state: " + state); return; } if (filterTouchCoordinates) { ! state = filterTouchInputState(state, id, x, y, xAbs, yAbs); } if (view != null) { view.notifyNextTouchEvent(state, id, x, y, xAbs, yAbs); } } ! private int filterTouchInputState(int state, long id, int x, int y, int xAbs, int yAbs) { switch (state) { case TouchEvent.TOUCH_RELEASED: ! touch.remove(id); break; case TouchEvent.TOUCH_MOVED: ! TouchCoord c = touch.get(id); ! if (x == c.x && y == c.y) { state = TouchEvent.TOUCH_STILL; break; } // fall through; case TouchEvent.TOUCH_PRESSED: ! touch.put(id, new TouchCoord(x, y, xAbs, yAbs)); break; case TouchEvent.TOUCH_STILL: break; default: System.err.println("Unknown touch state: " + state);