@Override public boolean handleMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) { int actionPointerIndex = event.getActionIndex(); int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_MOVE: SDLJoystick joystick = getJoystick(event.getDeviceId()); if (joystick != null) { for (int i = 0; i < joystick.axes.size(); i++) { InputDevice.MotionRange range = joystick.axes.get(i); /* Normalize the value to -1...1 */ float value = (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin()) / range.getRange() * 2.0f - 1.0f; SDLActivity.onNativeJoy(joystick.device_id, i, value); } } break; default: break; } } return true; }
@Override public boolean onTouch(View v, MotionEvent event) { builder.setLength(0); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: builder.append("down, "); break; case MotionEvent.ACTION_MOVE: builder.append("move, "); break; case MotionEvent.ACTION_CANCEL: builder.append("cancel, "); break; case MotionEvent.ACTION_UP: builder.append("up, "); break; } builder.append(event.getX()); builder.append(", "); builder.append(event.getY()); String text = builder.toString(); Log.d("TouchTest", text); textView.setText(text); return true; }
public boolean onTouchEvent(MotionEvent e) { x = e.getX(); y = e.getY(); // 更新を有効にする this.invalidate(); return true; }
// 새로운 볼 생성 public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { Ball NewBall = Ball.Create((int) event.getX(), (int) event.getY(), RAD); arBall.add(NewBall); invalidate(); return true; } return false; }
// Touch events public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); float x = event.getX(); float y = event.getY(); float p = event.getPressure(); // TODO: Anything else we need to pass? SDLActivity.onNativeTouch(action, x, y, p); return true; }
@Override public void screenTouched(MotionEvent aEvent) { super.screenTouched(aEvent); if (!onScreenInput) { if (!touchedOverActionBar(aEvent.getY())) { uiFullscreen = true; setupDisplay(); } } else if (toggleFullscreenOverActionBar(aEvent.getY())) { setupDisplay(); } }
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { final float xDistance = Math.abs(e1.getX() - e2.getX()); final float yDistance = Math.abs(e1.getY() - e2.getY()); if (xDistance > this.swipe_Max_Distance || yDistance > this.swipe_Max_Distance) return false; velocityX = Math.abs(velocityX); velocityY = Math.abs(velocityY); boolean result = false; if (velocityX > this.swipe_Min_Velocity && xDistance > this.swipe_Min_Distance) { if (e1.getX() > e2.getX()) // right to left this.listener.onSwipe(SWIPE_LEFT); else this.listener.onSwipe(SWIPE_RIGHT); result = true; } else if (velocityY > this.swipe_Min_Velocity && yDistance > this.swipe_Min_Distance) { if (e1.getY() > e2.getY()) // bottom to up this.listener.onSwipe(SWIPE_UP); else this.listener.onSwipe(SWIPE_DOWN); result = true; } return result; }
public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { Toast.makeText(HandleEvent.this, "Touch Event Received", Toast.LENGTH_SHORT).show(); return true; } return false; }
@Override public void screenTouched(MotionEvent aEvent) { super.screenTouched(aEvent); if (toggleFullscreenOverActionBar(aEvent.getY())) { setupDisplay(); } }
public void onTouchEvent(MotionEvent event) { if (!this.running) return; boolean result = this.detector.onTouchEvent(event); if (this.mode == MODE_SOLID) event.setAction(MotionEvent.ACTION_CANCEL); else if (this.mode == MODE_DYNAMIC) { if (event.getAction() == ACTION_FAKE) event.setAction(MotionEvent.ACTION_UP); else if (result) event.setAction(MotionEvent.ACTION_CANCEL); else if (this.tapIndicator) { event.setAction(MotionEvent.ACTION_DOWN); this.tapIndicator = false; } } // else just do nothing, it's Transparent }
public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int sel; sel = FindShapeIdx((int) event.getX(), (int) event.getY()); // 빈 바닥을 찍었으면 무시한다. if (sel == -1) { return true; } // 마지막 추가된 도형을 제대로 찍었으면 다음 단계로 진행. // 빈 화면 잠시 보여준 후 새 도형 추가 if (sel == arShape.size() - 1) { status = BLANK; invalidate(); mHandler.sendEmptyMessageDelayed(0, DELAY); // 엉뚱한 도형을 찍었으면 질문 후 게임 종료 또는 재시작 } else { new AlertDialog.Builder(getContext()) .setMessage("재미있지! 또 할래?") .setTitle("게임 끝") .setPositiveButton( "함더", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { arShape.clear(); status = BLANK; invalidate(); mHandler.sendEmptyMessageDelayed(0, DELAY); } }) .setNegativeButton( "안해", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mParent.finish(); } }) .show(); } return true; } return false; }
public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); if (event.getAction() == MotionEvent.ACTION_DOWN) { x += 15; y += 15; invalidate(); return true; } return false; }
@Override public boolean onSingleTapConfirmed(MotionEvent me) { if (this.mode == MODE_DYNAMIC) { // we owe an ACTION_UP, so we fake an me.setAction(ACTION_FAKE); // action which will be converted to an // ACTION_UP later. this.context.dispatchTouchEvent(me); } return false; }
// Generic Motion (mouse hover, joystick...) events go here @Override public boolean onGenericMotion(View v, MotionEvent event) { float x, y; int mouseButton; int action; switch (event.getSource()) { case InputDevice.SOURCE_JOYSTICK: case InputDevice.SOURCE_GAMEPAD: case InputDevice.SOURCE_DPAD: SDLActivity.handleJoystickMotionEvent(event); return true; case InputDevice.SOURCE_MOUSE: action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_SCROLL: x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0); y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0); SDLActivity.onNativeMouse(0, action, x, y); return true; case MotionEvent.ACTION_HOVER_MOVE: x = event.getX(0); y = event.getY(0); SDLActivity.onNativeMouse(0, action, x, y); return true; default: break; } default: break; } // Event was not managed return false; }
// Touch events @Override public boolean onTouch(View v, MotionEvent event) { /* Ref: http://developer.android.com/training/gestures/multi.html */ final int touchDevId = event.getDeviceId(); final int pointerCount = event.getPointerCount(); int action = event.getActionMasked(); int pointerFingerId; int mouseButton; int i = -1; float x, y, p; // !!! FIXME: dump this SDK check after 2.0.4 ships and require API14. if (event.getSource() == InputDevice.SOURCE_MOUSE && SDLActivity.mSeparateMouseAndTouch) { if (Build.VERSION.SDK_INT < 14) { mouseButton = 1; // For Android==12 all mouse buttons are the left button } else { try { mouseButton = (Integer) event.getClass().getMethod("getButtonState").invoke(event); } catch (Exception e) { mouseButton = 1; // oh well. } } SDLActivity.onNativeMouse(mouseButton, action, event.getX(0), event.getY(0)); } else { switch (action) { case MotionEvent.ACTION_MOVE: for (i = 0; i < pointerCount; i++) { pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_DOWN: // Primary pointer up/down, the index is always zero i = 0; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_DOWN: // Non primary pointer up/down if (i == -1) { i = event.getActionIndex(); } pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); break; case MotionEvent.ACTION_CANCEL: for (i = 0; i < pointerCount; i++) { pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, MotionEvent.ACTION_UP, x, y, p); } break; default: break; } } return true; }
// Touch events @Override public boolean onTouch(View v, MotionEvent event) { final int touchDevId = event.getDeviceId(); final int pointerCount = event.getPointerCount(); // touchId, pointerId, action, x, y, pressure int actionPointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; /* API 8: event.getActionIndex(); */ int pointerFingerId = event.getPointerId(actionPointerIndex); int action = (event.getAction() & MotionEvent.ACTION_MASK); /* API 8: event.getActionMasked(); */ float x = event.getX(actionPointerIndex) / mWidth; float y = event.getY(actionPointerIndex) / mHeight; float p = event.getPressure(actionPointerIndex); if (action == MotionEvent.ACTION_MOVE && pointerCount > 1) { // TODO send motion to every pointer if its position has // changed since prev event. for (int i = 0; i < pointerCount; i++) { pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); } } else { SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); } return true; }
// Touch events @Override public boolean onTouch(View v, MotionEvent event) { /* Ref: http://developer.android.com/training/gestures/multi.html */ final int touchDevId = event.getDeviceId(); final int pointerCount = event.getPointerCount(); int action = event.getActionMasked(); int pointerFingerId; int i = -1; float x, y, p; switch (action) { case MotionEvent.ACTION_MOVE: for (i = 0; i < pointerCount; i++) { pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_DOWN: // Primary pointer up/down, the index is always zero i = 0; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_POINTER_DOWN: // Non primary pointer up/down if (i == -1) { i = event.getActionIndex(); } pointerFingerId = event.getPointerId(i); x = event.getX(i) / mWidth; y = event.getY(i) / mHeight; p = event.getPressure(i); SDLActivity.onNativeTouch(touchDevId, pointerFingerId, action, x, y, p); break; default: break; } return true; }