List of usage examples for android.view MotionEvent getEventTime
@Override public final long getEventTime()
From source file:com.google.blockly.android.ui.PendingDrag.java
/** * Compares if {@code event} on {@code touchedView} is a continuation of the event stream * tracked by this PendingDrag. This includes whether the event stream has had sufficient * regular updates, at least more often than {@link #MAX_MOTION_EVENT_MILLISECONDS_DELTA} * (in an effort to disregard it from dropped previous streams with dropped * {@link MotionEvent#ACTION_UP} and {@link MotionEvent#ACTION_CANCEL}). If that threshold * is exceeded (for matching view and pointer id), the PendingDrag will no longer be alive * ({@link #isAlive()}, and not match any future events. * <p/>//from w w w. j a v a 2s.com * If the event is a match and alive, it will pass the event through a {@link GestureDetector} * to determine if the event triggers a click (or other interesting gestures in the future). * Check {@link #isClick()} to determine whether a click was detected. * <p/> * This method should only be called from {@link Dragger#onTouchBlockImpl}. * * @param event The event to compare to. * @param touchedView The view that received the touch event. * @return Whether the event was a match and the drag is still alive. */ boolean isMatchAndProcessed(MotionEvent event, BlockView touchedView) { if (!mAlive) { return false; } final int pointerId = event.getPointerId(event.getActionIndex()); long curEventTime = event.getEventTime(); long deltaMs = curEventTime - mLatestEventTime; if (deltaMs < MAX_MOTION_EVENT_MILLISECONDS_DELTA) { if (pointerId == mPointerId && touchedView == mTouchedView) { mLatestEventTime = curEventTime; mGestureDetector.onTouchEvent(event); return true; } } else { mAlive = false; // Exceeded threshold and expired. } return false; // Not a pointer & view match or died. }
From source file:com.jwork.spycamera.MainFragment.java
@Override public boolean onTouch(View view, MotionEvent event) { log.v(this, "onTouch(action:" + event.getAction() + "|actionindex:" + event.getActionIndex() + "|downtime:" + event.getDownTime() + "|eventtime:" + event.getEventTime() + ")"); if (view == layoutBlack) { sgdBlack.onTouchEvent(event);/* w w w . ja v a 2s .c om*/ if (event.getAction() == MotionEvent.ACTION_DOWN) { controller.blackScreenClick(); } return true; } else if (view == svPreview) { sgdPreview.onTouchEvent(event); return true; } return false; }
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./* ww w . ja va2 s . c om*/ * * @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:org.solovyev.android.calculator.drag.SimpleDragListener.java
@Override public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) { boolean consumed = false; final MotionEvent motionEvent = event.getMotionEvent(); final Point2d start = event.getStartPoint(); final Point2d end = new Point2d(motionEvent.getX(), motionEvent.getY()); final float distance = Maths.getDistance(start, end); final MutableObject<Boolean> right = new MutableObject<>(); final double angle = Math.toDegrees(Maths.getAngle(start, Maths.sum(start, axis), end, right)); final long duration = motionEvent.getEventTime() - motionEvent.getDownTime(); final DragDirection direction = getDirection(distance, (float) angle, right.getObject()); if (direction != null && duration > 40 && duration < 2500) { consumed = processor.processDragEvent(direction, dragButton, start, motionEvent); }//from w w w . j av a 2s .c o m return consumed; }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (getMiniKeyboard() != null && mMiniKeyboardPopup.isShowing()) { final int miniKeyboardX = (int) me.getX(); final int miniKeyboardY = (int) me.getY(); final int action = MotionEventCompat.getActionMasked(me); MotionEvent translated = generateMiniKeyboardMotionEvent(action, miniKeyboardX, miniKeyboardY, me.getEventTime()); getMiniKeyboard().onTouchEvent(translated); translated.recycle();/*www . ja va 2s . co m*/ return true; } return super.onTouchEvent(me); }
From source file:com.smsc.usuario.ui.MapaActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mapa);/*from www . jav a2 s . co m*/ Button btnIncendio = (Button) findViewById(R.id.btnIncendio); OnTouchListener btnIncendioListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Incendio", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 2); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnIncendio.setOnTouchListener(btnIncendioListener); Button btnSecuestro = (Button) findViewById(R.id.btnSecuestro); OnTouchListener btnSecuestroListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Secuestro", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 3); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnSecuestro.setOnTouchListener(btnSecuestroListener); Button btnHomicidio = (Button) findViewById(R.id.btnHomicidio); OnTouchListener btnHomicidioListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Homicidio", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 4); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnHomicidio.setOnTouchListener(btnHomicidioListener); Button btnAccidente = (Button) findViewById(R.id.btnAccidente); OnTouchListener btnAccidenteListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Accidente", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 5); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnAccidente.setOnTouchListener(btnAccidenteListener); Button btnViolacion = (Button) findViewById(R.id.btnViolacion); OnTouchListener btnViolacionListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Violacion", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 6); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnViolacion.setOnTouchListener(btnViolacionListener); Button btnOtros = (Button) findViewById(R.id.btnOtros); OnTouchListener btnOtrosListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Otros", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 7); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnOtros.setOnTouchListener(btnOtrosListener); Button btnRobo = (Button) findViewById(R.id.btnRobo); OnTouchListener btnRoboListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP && event.getEventTime() - event.getDownTime() >= 1000) { Toast.makeText(MapaActivity.this, "Robo", Toast.LENGTH_SHORT).show(); Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class); i.putExtra("ID", "" + 1); i.putExtra("latitude", "" + latitude); i.putExtra("longitude", "" + longitude); startActivity(i); } return false; } }; btnRobo.setOnTouchListener(btnRoboListener); // Getting Google Play availability status int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); // Showing status if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available int requestCode = 10; Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); dialog.show(); } else { // Google Play Services are available // Getting reference to the SupportMapFragment of activity_main.xml SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); // Getting GoogleMap object from the fragment googleMap = fm.getMap(); // Enabling MyLocation Layer of Google Map googleMap.setMyLocationEnabled(true); googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { getDetalle(Integer.parseInt(marker.getSnippet())); } }); getLocation(); } }
From source file:com.github.pedrovgs.DraggableView.java
/** * Clone given motion event and set specified action. This method is useful, when we want to * cancel event propagation in child views by sending event with {@link MotionEvent#ACTION_CANCEL} action. * @param event event to clone/*from w w w .j a v a 2 s . c om*/ * @param action new action * @return cloned motion event */ private MotionEvent cloneMotionEventWithAction(MotionEvent event, int action) { return MotionEvent.obtain(event.getDownTime(), event.getEventTime(), action, event.getX(), event.getY(), event.getMetaState()); }
From source file:org.libreoffice.impressremote.fragment.slides.PointerFragment.java
@Override public boolean onTouch(View v, MotionEvent event) { float x = (event.getX() - xoffset) / displaywidth; float y = (event.getY() - yoffset) / displayheight; // get masked action int aMaskedAction = event.getActionMasked(); switch (aMaskedAction) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: // a pointer start mCommunicationService.getCommandsTransmitter().startPointer(x, y); break;/* w ww. j a v a 2s . c om*/ case MotionEvent.ACTION_MOVE: // a pointer was moved if (nextUpdate <= event.getEventTime()) { mCommunicationService.getCommandsTransmitter().movePointer(x, y); nextUpdate = event.getEventTime() + REFRESH_MILLIS; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_CANCEL: // a pointer was removed mCommunicationService.getCommandsTransmitter().stopPointer(); break; } return true; }
From source file:fr.tvbarthel.attempt.googlyzooapp.MainActivity.java
/** * process motion event to detect double touch * * @param event should be an ACTION_DOWN event * @return true if double touch motion/* w ww . ja v a 2 s. com*/ */ private boolean isDoubleTouch(MotionEvent event) { boolean isDoubleTouch = false; long newTimeStamp = event.getEventTime(); final long delay = newTimeStamp - mLastTouchTimeStamp; if (mLastTouchTimeStamp != 0 && delay < DOUBLE_TOUCH_DELAY_IN_MILLI) { newTimeStamp = 0; isDoubleTouch = true; } mLastTouchTimeStamp = newTimeStamp; return isDoubleTouch; }
From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaVRModeFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { mStorage = new ThetaObjectStorage(getContext()); setRetainInstance(true);/*from w w w. j a va2s.c o m*/ ThetaDeviceApplication app = (ThetaDeviceApplication) getActivity().getApplication(); mDataCache = app.getCache(); View rootView = inflater.inflate(R.layout.theta_vr_mode, null); mRightLayout = (RelativeLayout) rootView.findViewById(R.id.right_ui); mSphereView = (SphericalImageView) rootView.findViewById(R.id.vr_view); SphericalViewApi api = app.getSphericalViewApi(); mSphereView.setViewApi(api); mSphereView.setOnTouchListener(new View.OnTouchListener() { private boolean mIsEnabledLongTouch = true; @Override public boolean onTouch(final View view, final MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { mIsEnabledLongTouch = true; return true; } if (motionEvent.getPointerCount() == 1) { if (mIsEnabledLongTouch && motionEvent.getEventTime() - motionEvent.getDownTime() >= 300) { mSphereView.resetCameraDirection(); } } else { mIsEnabledLongTouch = false; mScaleDetector.onTouchEvent(motionEvent); } return true; } }); init3DButtons(rootView); enableView(); mScaleDetector = new ScaleGestureDetector(getActivity(), new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(final ScaleGestureDetector detector) { mScaleFactor /= detector.getScaleFactor(); double scale = mScaleFactor; if (scale > MAX_FOV) { scale = MAX_FOV; mScaleFactor = MAX_FOV; } if (scale < MIN_FOV) { scale = MIN_FOV; mScaleFactor = MIN_FOV; } mSphereView.setFOV(scale); return true; } }); return rootView; }