List of usage examples for android.view MotionEvent getPointerId
public final int getPointerId(int pointerIndex)
From source file:io.mariachi.allianzvision.camera.api14.Camera1.java
public void handleFocus(MotionEvent event, Camera.Parameters params) { int pointerId = event.getPointerId(0); int pointerIndex = event.findPointerIndex(pointerId); // Get the pointer's current position float x = event.getX(pointerIndex); float y = event.getY(pointerIndex); List<String> supportedFocusModes = params.getSupportedFocusModes(); if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { mCamera.autoFocus(new Camera.AutoFocusCallback() { @Override/*from ww w.ja va2s .co m*/ public void onAutoFocus(boolean b, Camera camera) { // currently set to auto-focus on single touch } }); } }
From source file:ch.jeda.platform.android.CanvasFragment.java
@Override public boolean onTouch(final View view, final MotionEvent event) { int index;//from w ww . ja va2 s . co m switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: index = event.getActionIndex(); this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_DOWN, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: index = event.getActionIndex(); this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_UP, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); break; case MotionEvent.ACTION_MOVE: for (index = 0; index < event.getPointerCount(); ++index) { this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_MOVED, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); } break; } return true; }
From source file:android.support.v7.widget.ForwardingListener.java
/** * Observes motion events and determines when to start forwarding. * * @param srcEvent motion event in source view coordinates * @return true to start forwarding motion events, false otherwise *///from ww w. j a v a2 s . c o m private boolean onTouchObserved(MotionEvent srcEvent) { final View src = mSrc; if (!src.isEnabled()) { return false; } final int actionMasked = MotionEventCompat.getActionMasked(srcEvent); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mActivePointerId = srcEvent.getPointerId(0); if (mDisallowIntercept == null) { mDisallowIntercept = new DisallowIntercept(); } src.postDelayed(mDisallowIntercept, mTapTimeout); if (mTriggerLongPress == null) { mTriggerLongPress = new TriggerLongPress(); } src.postDelayed(mTriggerLongPress, mLongPressTimeout); break; case MotionEvent.ACTION_MOVE: final int activePointerIndex = srcEvent.findPointerIndex(mActivePointerId); if (activePointerIndex >= 0) { final float x = srcEvent.getX(activePointerIndex); final float y = srcEvent.getY(activePointerIndex); // Has the pointer moved outside of the view? if (!pointInView(src, x, y, mScaledTouchSlop)) { clearCallbacks(); // Don't let the parent intercept our events. src.getParent().requestDisallowInterceptTouchEvent(true); return true; } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: clearCallbacks(); break; } return false; }
From source file:iSoron.HistoryChart.java
@Override public boolean onSingleTapUp(MotionEvent e) { if (!isEditable) return false; performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); if (controller == null) return false; int pointerId = e.getPointerId(0); float x = e.getX(pointerId); float y = e.getY(pointerId); final Long timestamp = positionToTimestamp(x, y); if (timestamp == null) return false; int offset = timestampToOffset(timestamp); /*//w w w .jav a 2 s. c om if (offset<checkmarks.length){ boolean isChecked = checkmarks[offset] == 0; checkmarks[offset] = (isChecked ? 1 : 2); }*/ controller.onToggleCheckmark(timestamp, offset); postInvalidate(); return true; }
From source file:org.deviceconnect.android.deviceplugin.host.activity.TouchProfileActivity.java
/** * Send event data./* w w w. j a v a 2s. c om*/ * * @param state MotionEvent state. * @param event MotionEvent. * @param events Event request list. */ private void sendEventData(final String state, final MotionEvent event, final List<Event> events) { List<Event> touchEvents = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null, ATTRIBUTE_ON_TOUCH_CHANGE); Bundle touchdata = new Bundle(); List<Bundle> touchlist = new ArrayList<Bundle>(); Bundle touches = new Bundle(); for (int n = 0; n < event.getPointerCount(); n++) { int pointerId = event.getPointerId(n); touchdata.putInt(TouchProfile.PARAM_ID, pointerId); touchdata.putFloat(TouchProfile.PARAM_X, event.getX(n)); touchdata.putFloat(TouchProfile.PARAM_Y, event.getY(n)); touchlist.add((Bundle) touchdata.clone()); } touches.putParcelableArray(TouchProfile.PARAM_TOUCHES, touchlist.toArray(new Bundle[touchlist.size()])); for (int i = 0; i < events.size(); i++) { Event eventdata = events.get(i); String attr = eventdata.getAttribute(); Intent intent = EventManager.createEventMessage(eventdata); intent.putExtra(TouchProfile.PARAM_TOUCH, touches); intent.setAction(HostTouchProfile.ACTION_TOUCH); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); mApp.setTouchCache(attr, touches); } for (int i = 0; i < touchEvents.size(); i++) { Event eventdata = touchEvents.get(i); String attr = eventdata.getAttribute(); touches.putString("state", state); Intent intent = EventManager.createEventMessage(eventdata); intent.putExtra(TouchProfile.PARAM_TOUCH, touches); intent.setAction(HostTouchProfile.ACTION_TOUCH); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); mApp.setTouchCache(attr, touches); } }
From source file:com.google.blockly.android.ui.PendingDrag.java
/** * Constructs a new PendingDrag that, if accepted by the DragHandler, begins with the * {@code actionDown} event.//from ww w . j a va2 s.c o m * * @param controller The activity's {@link BlocklyController}. * @param touchedView The initial touched {@link BlockView} of the drag. * @param actionDown The first {@link MotionEvent#ACTION_DOWN} event. */ PendingDrag(@NonNull BlocklyController controller, @NonNull BlockView touchedView, @NonNull MotionEvent actionDown) { if (actionDown.getAction() != MotionEvent.ACTION_DOWN) { throw new IllegalArgumentException(); } mController = controller; mHelper = controller.getWorkspaceHelper(); mLatestEventTime = actionDown.getEventTime(); mTouchedView = touchedView; mPointerId = actionDown.getPointerId(actionDown.getActionIndex()); int pointerIdx = actionDown.findPointerIndex(mPointerId); mTouchDownBlockX = (int) actionDown.getX(pointerIdx); mTouchDownBlockY = (int) actionDown.getY(pointerIdx); touchedView.getTouchLocationOnScreen(actionDown, mTouchDownScreen); mHelper.screenToWorkspaceCoordinates(mTouchDownScreen, mTouchDownWorkspace); mGestureDetector = new GestureDetectorCompat(mController.getContext(), new GestureListener()); mGestureDetector.onTouchEvent(actionDown); }
From source file:me.wizos.loread.view.webview.NestedScrollWebView.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int actionMasked = ev.getActionMasked(); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mIsBeingDragged = false;/*from ww w . j a v a 2 s .c o m*/ // Remember where the motion event started mLastMotionY = (int) ev.getY(); // downY = (int) ev.getY(); mActivePointerId = ev.getPointerId(0); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; case MotionEvent.ACTION_MOVE: // KLog.e(""); final int activePointerIndex = ev.findPointerIndex(mActivePointerId); if (activePointerIndex == -1) { break; } // if( !onlyVerticalMove(ev) ){ // break; // } final int y = (int) ev.getY(activePointerIndex); int deltaY = mLastMotionY - y; if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; } // Scroll to follow the motion event mLastMotionY = y - mScrollOffset[1]; final int oldY = getScrollY(); final int scrolledDeltaY = Math.max(0, oldY + deltaY) - oldY; final int unconsumedY = deltaY - scrolledDeltaY; if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) { mLastMotionY -= mScrollOffset[1]; } // KLog.e("?"); break; case MotionEvent.ACTION_UP: mActivePointerId = INVALID_POINTER; endDrag(); break; case MotionEvent.ACTION_CANCEL: mActivePointerId = INVALID_POINTER; endDrag(); break; case MotionEvent.ACTION_POINTER_DOWN: { final int index = ev.getActionIndex(); mLastMotionY = (int) ev.getY(index); mActivePointerId = ev.getPointerId(index); break; } case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionY = (int) ev.getY(ev.findPointerIndex(mActivePointerId)); break; default: break; } return super.onTouchEvent(ev); }
From source file:com.example.android.bluetoothchat.BluetoothFragment.java
private void setMainView(int mode) { switch (mode) { case MODE_SEND_PHONENUM: mainMode = MODE_SEND_PHONENUM;/*from w ww . j av a 2s .c om*/ cardGameLayout.setVisibility(View.GONE); gestureOverlayView.setVisibility(View.VISIBLE); gestureOverlayView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int pointerIndex = event.getActionIndex(); int pointerID = event.getPointerId(pointerIndex); float touchXValue = event.getX(pointerIndex); float touchYValue = event.getY(pointerIndex); touchX.setText(String.valueOf(touchXValue)); touchY.setText(String.valueOf(touchYValue)); if (touchYValue <= 0) { if (event.getAction() == MotionEvent.ACTION_UP) {//? ? ? ?? . signal = phoneNum; sendSignal(signal); } } return false; } }); break; case MODE_SEND_DRAW: mainMode = MODE_SEND_DRAW; cardGameLayout.setVisibility(View.INVISIBLE); gestureOverlayView.setVisibility(View.INVISIBLE); sendDrawLayout = (RelativeLayout) getActivity().findViewById(R.id.send_draw_layout); sendDrawLayout.setVisibility(View.VISIBLE); Log.d(TAG, sendDrawLayout.getWidth() + " isjsafdffs"); drawView = new DrawView(getActivity(), sendDrawLayout, getActivity(), mChatService); sendDrawLayout.addView(drawView); break; case MODE_CARD_GAME: mainMode = MODE_CARD_GAME; gestureOverlayView.setVisibility(View.GONE); cardGameLayout.setVisibility(View.VISIBLE); //ViewFlipper break; case MODE_BOMB_GAME: mainMode = MODE_BOMB_GAME; break; } }
From source file:de.lmu.ifi.medien.probui.system.ProbUIManager.java
public void manageHelper(MotionEvent ev) throws WrongObservationDelegationException { this.currentTouchObservations.clear(); int action = MotionEventCompat.getActionMasked(ev); int index = MotionEventCompat.getActionIndex(ev); int pointerID = ev.getPointerId(index); int type = -1; switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: type = ProbObservationTouch.TYPE_TOUCH_DOWN; break;// www. j av a2s.com case MotionEvent.ACTION_MOVE: type = ProbObservationTouch.TYPE_TOUCH_MOVE; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: type = ProbObservationTouch.TYPE_TOUCH_UP; break; default: type = -1; break; } long timestamp = ev.getEventTime(); ProbObservationTouch observation = ProbObservationFactory.createTouchObservation(ev.getX(index), ev.getY(index), ev.getX(index) * 1.0 / container.getWidth(), ev.getY(index) * 1.0 / container.getHeight(), ev.getOrientation(index), ev.getTouchMinor(index) * 1.0 / container.getWidth(), ev.getTouchMajor(index) * 1.0 / container.getHeight(), ev.getPressure(index), type, pointerID, timestamp); this.currentTouchObservations.add(observation); // Since move is always associated with the first pointer, // we need to manually duplicate it for the second one // (TODO: and for further pointers, if we change it to more than 2): if (ev.getPointerCount() == 2 && type == ProbObservationTouch.TYPE_TOUCH_MOVE) { ProbObservationTouch observation2 = ProbObservationFactory.createTouchObservation(ev.getX(index), ev.getY(index), ev.getX(1) * 1.0 / container.getWidth(), ev.getY(1) * 1.0 / container.getHeight(), ev.getOrientation(1), ev.getToolMinor(1) * 1.0 / container.getWidth(), ev.getToolMajor(1) * 1.0 / container.getHeight(), ev.getPressure(1), type, ev.getPointerId(1), timestamp); this.currentTouchObservations.add(observation2); } //Log.d("MULTITOUCH", "type: " + type + ", index: " + pointerID + ", size: " + ev.getTouchMajor(index) * 1.0 / container.getHeight()); // Distribute touch observation to the cores of all probInteractors // (for reasoning by these interactor cores!, not for visual feedback etc. - that comes below: interactor.onTouchDown etc.) boolean passedOn = false; for (ProbInteractor interactor : this.probInteractors) { for (int i = 0; i < this.currentTouchObservations.size(); i++) { ProbObservationTouch obs = this.currentTouchObservations.get(i); if (obs == null) continue; if (obs.getNominalFeatures()[0] != ProbObservationTouch.TYPE_TOUCH_MOVE || this.currentTouchObservations.size() != this.previousTouchObservations.size()) { interactor.getCore().onTouchObservation(obs); passedOn = true; } else { // This code filters out move events that moved very little (potentially improves performance): double[] obsXY = this.currentTouchObservations.get(i).getRealFeatures(); double[] obsPrevXY = this.previousTouchObservations.get(i).getRealFeatures(); double dx = obsXY[0] - obsPrevXY[0]; double dy = obsXY[1] - obsPrevXY[1]; double dist = Math.sqrt(dx * dx + dy * dy); if (dist > 0.0125) { // TODO: movement threshold currently hardcoded: 0.0125 interactor.getCore().onTouchObservation(obs); passedOn = true; } else { } } } } if (passedOn) { this.previousTouchObservations.clear(); this.previousTouchObservations.addAll(this.currentTouchObservations); } // Forward the touch observation for probInteractors // to react (e.g. visual feedback, triggering actions, nothing to do with the mediation): for (ProbInteractor interactor : this.probInteractors) { for (ProbObservationTouch obs : this.currentTouchObservations) { if (obs != null) { switch (obs.getNominalFeatures()[0]) { case ProbObservationTouch.TYPE_TOUCH_DOWN: interactor.onTouchDown(obs); break; case ProbObservationTouch.TYPE_TOUCH_MOVE: interactor.onTouchMove(obs); break; case ProbObservationTouch.TYPE_TOUCH_UP: interactor.onTouchUp(obs, ev.getPointerCount() - 1); break; default: break; } } } } // If no element is determined yet (i.e. no decision yet), update the reasoning process. if (!isOneDetermined() && passedOn) { this.mediator.mediate(false); } // Post mediation: Forward the touch observation again // to the post-mediation versions of the onTouch... methods for (ProbInteractor interactor : this.probInteractors) { for (ProbObservationTouch obs : this.currentTouchObservations) { if (obs != null) { switch (obs.getNominalFeatures()[0]) { case ProbObservationTouch.TYPE_TOUCH_DOWN: interactor.onTouchDownPost(obs); break; case ProbObservationTouch.TYPE_TOUCH_MOVE: interactor.onTouchMovePost(obs); break; case ProbObservationTouch.TYPE_TOUCH_UP: interactor.onTouchUpPost(obs, ev.getPointerCount() - 1); break; default: break; } } } } // Pass on to other GUI elements: if (!isOneDetermined()) { for (View view : this.nonProbInteractors) { if (view.isFocusable() && view.isEnabled()) view.onTouchEvent(ev); } } }
From source file:de.gobro.andreas.pa.pa_cleint_java.SendTouch.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: { Log.d("down", "action_down"); break;/*from ww w .j a v a 2s . c o m*/ } case MotionEvent.ACTION_MOVE: { for (Integer i = 0; (i < ev.getPointerCount()) && (i < maxPoints); i++) { //final Integer pointerIndex = MotionEventCompat.getActionIndex(ev); Integer id = ev.getPointerId(i); Log.d("ind", "pinterindex" + i.toString()); Log.d("ind", "ID" + id.toString()); Log.d("pos", "(" + String.valueOf(MotionEventCompat.getX(ev, i)) + ";" + String.valueOf(MotionEventCompat.getY(ev, i)) + ")"); Log.d("test", "action_move"); try { serializer.startTag("", "touch"); serializer.startTag("", "dx"); serializer.text(String.valueOf(MotionEventCompat.getX(ev, i) / size.x)); serializer.endTag("", "dx"); serializer.startTag("", "dy"); serializer.text(String.valueOf(MotionEventCompat.getY(ev, i) / size.y)); serializer.endTag("", "dy"); serializer.startTag("", "id"); serializer.text(id.toString()); serializer.endTag("", "id"); serializer.endTag("", "touch"); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (RuntimeException e) { e.printStackTrace(); } // try { // writer.writeStartElement("touch"); // writer.writeStartElement("dx"); // writer.writeCharacters(String.valueOf(MotionEventCompat.getX(ev, i)/size.x)); // writer.writeEndElement(); // writer.writeStartElement("dy"); // writer.writeCharacters(String.valueOf(MotionEventCompat.getY(ev, i)/size.y)); // writer.writeEndElement(); // writer.writeStartElement("id"); // writer.writeCharacters(id.toString()); // writer.writeEndElement(); // writer.writeEndElement(); // } catch (XMLStreamException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } //write the stuff to the network try { serializer.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show(); finish(); } break; } case MotionEvent.ACTION_UP: { Log.d("test", "action_up"); break; } case MotionEvent.ACTION_CANCEL: { Log.d("test", "action_cancel"); break; } case MotionEvent.ACTION_POINTER_DOWN: { Log.d("down", "action_p_down"); break; } case MotionEvent.ACTION_POINTER_UP: { Log.d("test", "action_p_up"); break; } } return true; }