List of usage examples for android.view MotionEvent ACTION_MOVE
int ACTION_MOVE
To view the source code for android.view MotionEvent ACTION_MOVE.
Click Source Link
From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java
@Override public boolean onTouchEvent(MotionEvent e) { // MotionEvent reports input details from the touch screen // and other input controls. In this case, you are only // interested in events where the touch position changed. switch (e.getAction()) { case MotionEvent.ACTION_DOWN: if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else {/* w w w . j a v a 2s .c o m*/ mVelocityTracker.clear(); } queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasStarted(); } }); // No break is intentional case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(e); // Compute velocity in pixels per second mVelocityTracker.computeCurrentVelocity(1); final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1); Vector2 viewportPosition; Vector2 viewportVelocity = new Vector2( VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()), VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex())); // Add previous touch coordinates for (int i = 0; i < e.getHistorySize(); i++) { viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i)); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getHistoricalSize(i), e.getHistoricalPressure(i))); } // Add current touch coordinates viewportPosition = new Vector2(e.getX(), e.getY()); touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity, e.getSize(), e.getPressure())); // Ensure we call switchMode() on the OpenGL thread. // queueEvent() is a method of GLSurfaceView that will do this for us. queueEvent(new Runnable() { @Override public void run() { mRenderer.addTouchData(touchDataList); } }); requestRender(); break; case MotionEvent.ACTION_UP: queueEvent(new Runnable() { @Override public void run() { mRenderer.touchHasEnded(); } }); requestRender(); break; } return true; }
From source file:com.beyondar.example.CameraWithTouchEventsActivity.java
@Override public void onTouchBeyondarView(MotionEvent event, BeyondarGLSurfaceView beyondarView) { float x = event.getX(); float y = event.getY(); ArrayList<BeyondarObject> geoObjects = new ArrayList<BeyondarObject>(); // This method call is better to don't do it in the UI thread! beyondarView.getBeyondarObjectsOnScreenCoordinates(x, y, geoObjects); String textEvent = ""; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: textEvent = "Event type ACTION_DOWN: "; break;//from ww w. j a va 2s. c om case MotionEvent.ACTION_UP: textEvent = "Event type ACTION_UP: "; break; case MotionEvent.ACTION_MOVE: textEvent = "Event type ACTION_MOVE: "; break; default: break; } Iterator<BeyondarObject> iterator = geoObjects.iterator(); while (iterator.hasNext()) { BeyondarObject geoObject = iterator.next(); textEvent = textEvent + " " + geoObject.getName(); } mLabelText.setText("Event: " + textEvent); }
From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java
private float[] handleMotionEvent(MotionEvent event) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: last = new PointF(event.getX(0), event.getY(0)); ///* w w w . j a v a 2s . c o m*/ if (GalleryFileActivity.ll_dibumenu != null && GalleryFileActivity.ll_dibumenu.getVisibility() == View.GONE) { GalleryFileActivity.ll_dibumenu.setVisibility(View.VISIBLE); } if (Show_bigpic2.ll_dibumenu != null && Show_bigpic2.ll_dibumenu.getVisibility() == View.GONE) { Show_bigpic2.ll_dibumenu.setVisibility(View.VISIBLE); } // if (GalleryFileActivity.timeCount != null) { GalleryFileActivity.timeCount.cancel(); } GalleryFileActivity.timeCount = new TimeCount_pic_dibu(Millis.pic_dibus, 1000); GalleryFileActivity.timeCount.start(); System.out.println("pic "); if (Show_bigpic2.timeCount != null) { Show_bigpic2.timeCount.cancel(); } Show_bigpic2.timeCount = new TimeCount_pic_dibu_showbigpic2(Millis.pic_dibus, 1000); Show_bigpic2.timeCount.start(); break; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: PointF curr = new PointF(event.getX(0), event.getY(0)); return new float[] { curr.x - last.x, curr.y - last.y }; } return null; }
From source file:com.android.deskclock.VerticalViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { try {/* w w w.j a v a2s .co m*/ initializeParent(); final float x = ev.getX(); final float y = ev.getY(); switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mLastMotionX = x; mLastMotionY = y; if (!mParentViewPager.onTouchEvent(ev)) return false; return verticalDrag(ev); } case MotionEvent.ACTION_MOVE: { final float xDiff = Math.abs(x - mLastMotionX); final float yDiff = Math.abs(y - mLastMotionY); if (!mHorizontalDrag && !mVerticalDrag) { if (xDiff > mTouchSlop && xDiff > yDiff) { // Swiping left and right mHorizontalDrag = true; } else if (yDiff > mTouchSlop && yDiff > xDiff) { //Swiping up and down mVerticalDrag = true; } } if (mHorizontalDrag) { return mParentViewPager.onTouchEvent(ev); } else if (mVerticalDrag) { return verticalDrag(ev); } } case MotionEvent.ACTION_UP: { if (mHorizontalDrag) { mHorizontalDrag = false; return mParentViewPager.onTouchEvent(ev); } if (mVerticalDrag) { mVerticalDrag = false; return verticalDrag(ev); } } } // Set both flags to false in case user lifted finger in the parent view pager mHorizontalDrag = false; mVerticalDrag = false; } catch (Exception e) { // The mParentViewPager shouldn't be null, but just in case. If this happens, // app should not crash, instead just ignore the user swipe input // TODO: handle the exception gracefully } return false; }
From source file:com.vladstirbu.cordova.Gamepad.java
/** * @param cordova The context of the main Activity. * @param webView The associated CordovaWebView. *//*from w w w .j a va 2s .c o m*/ @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.map.put("KEYCODE_BUTTON_A", 0); this.map.put("KEYCODE_BUTTON_B", 1); this.map.put("KEYCODE_BUTTON_Y", 3); this.map.put("KEYCODE_BUTTON_X", 2); this.map.put("KEYCODE_BUTTON_L1", 4); this.map.put("KEYCODE_BUTTON_R1", 5); this.map.put("KEYCODE_BUTTON_L2", 6); this.map.put("KEYCODE_BUTTON_R2", 7); this.map.put("KEYCODE_SPACE", 8); this.map.put("KEYCODE_SELECT", 8); this.map.put("KEYCODE_ENTER", 9); this.map.put("KEYCODE_START", 9); this.map.put("KEYCODE_BUTTON_THUMBL", 10); this.map.put("KEYCODE_BUTTON_THUMBR", 11); this.map.put("KEYCODE_DPAD_UP", 12); this.map.put("KEYCODE_DPAD_DOWN", 13); this.map.put("KEYCODE_DPAD_LEFT", 14); this.map.put("KEYCODE_DPAD_RIGHT", 15); this.map.put("KEYCODE_BACK", 16); this.map.put("KEYCODE_BUTTON_MODE", 16); this.webView.setFocusable(true); this.webView.setFocusableInTouchMode(true); this.webView.requestFocus(); this.webView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { //Log.v("Keyboards", String.valueOf(InputDevice.getDeviceIds().length)); //Log.v("Input", InputDevice.getDevice(1).getName()); //Log.v("Input", String.valueOf(InputDevice.getDevice(1).getSources())); //Log.v("Device id", String.valueOf(event.getDeviceId())); //Log.v("Source id", String.valueOf(event.getSource())); //Log.v("Input device", String.valueOf(InputDevice.getDevice(event.getDeviceId()).getName())); Log.v("KEY", String.valueOf(event.getScanCode())); Log.v("KEY", KeyEvent.keyCodeToString(keyCode)); //Log.v("GamePad", String.valueOf(KeyEvent.isGamepadButton(keyCode))); String jsStr = jsString(keyCode, event); if (!jsStr.isEmpty()) { self.webView.sendJavascript(jsStr); } return true; } }); this.webView.setOnGenericMotionListener(new OnGenericMotionListener() { public boolean onGenericMotion(View v, MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... JSONObject data = new JSONObject(); JSONArray axes = new JSONArray(); try { axes.put(event.getAxisValue(MotionEvent.AXIS_X)); axes.put(event.getAxisValue(MotionEvent.AXIS_Y)); axes.put(event.getAxisValue(MotionEvent.AXIS_Z)); axes.put(event.getAxisValue(MotionEvent.AXIS_RZ)); data.put("deviceId", event.getDeviceId()); data.put("axes", axes); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); try { data.put("deviceId", event.getDeviceId()); data.put("button", 6); data.put("value", event.getAxisValue(MotionEvent.AXIS_LTRIGGER)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); try { data.put("deviceId", event.getDeviceId()); data.put("button", 7); data.put("value", event.getAxisValue(MotionEvent.AXIS_RTRIGGER)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X); float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y); try { data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 14); data.put("value", hatX < 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 15); data.put("value", hatX > 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); } catch (JSONException e) { } try { data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 12); data.put("value", hatY < 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 13); data.put("value", hatY > 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); } catch (JSONException e) { } } Log.v("MOTION", event.toString()); return true; } return false; } }); Log.v("GamepadButtons", "initialized"); }
From source file:com.alex.vmandroid.display.main.fragments.fragments.LoopAdvertisementFragment.java
@Override public void setViewPagerData(List<Integer> pictureList) { LoopAdvertisementAdapter mBannerPagerAdapter = new LoopAdvertisementAdapter(getActivity(), pictureList); mViewPager.setAdapter(mBannerPagerAdapter); mViewPager.setOnTouchListener(new View.OnTouchListener() { int flage = 0; @Override/*from w ww .ja va2 s .co m*/ public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: flage = 0; mIsUserTouched = true; break; case MotionEvent.ACTION_MOVE: mIsUserTouched = true; flage = 1; break; case MotionEvent.ACTION_UP: mIsUserTouched = false; if (flage == 0) { int item = mViewPager.getCurrentItem(); mPresenter.onViewPagerItemClick(item); } break; } return false; } }); startBannerTimer(); }
From source file:ch.jeda.platform.android.CanvasFragment.java
@Override public boolean onTouch(final View view, final MotionEvent event) { int index;//from w w w . j a va 2s . 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:com.brotherpowers.audiojournal.View.SwipeBackLayout.java
private void chkDragable() { setOnTouchListener(new OnTouchListener() { @Override/*from www.j a v a 2 s.c o m*/ public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { lastY = motionEvent.getRawY(); lastX = motionEvent.getRawX(); } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) { newY = motionEvent.getRawY(); lastX = motionEvent.getRawX(); offsetY = Math.abs(newY - lastY); lastY = newY; offsetX = Math.abs(newX - lastX); lastX = newX; switch (dragEdge) { case TOP: case BOTTOM: setEnablePullToBack(offsetY > offsetX); case LEFT: case RIGHT: setEnablePullToBack(offsetY < offsetX); break; } } return false; } }); }
From source file:android.support.v7.widget.DropDownListView.java
/** * Handles forwarded events.// w ww. ja v a 2 s. com * * @param activePointerId id of the pointer that activated forwarding * @return whether the event was handled */ public boolean onForwardedEvent(MotionEvent event, int activePointerId) { boolean handledEvent = true; boolean clearPressedItem = false; final int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_CANCEL: handledEvent = false; break; case MotionEvent.ACTION_UP: handledEvent = false; // $FALL-THROUGH$ case MotionEvent.ACTION_MOVE: final int activeIndex = event.findPointerIndex(activePointerId); if (activeIndex < 0) { handledEvent = false; break; } final int x = (int) event.getX(activeIndex); final int y = (int) event.getY(activeIndex); final int position = pointToPosition(x, y); if (position == INVALID_POSITION) { clearPressedItem = true; break; } final View child = getChildAt(position - getFirstVisiblePosition()); setPressedItem(child, position, x, y); handledEvent = true; if (actionMasked == MotionEvent.ACTION_UP) { clickPressedItem(child, position); } break; } // Failure to handle the event cancels forwarding. if (!handledEvent || clearPressedItem) { clearPressedItem(); } // Manage automatic scrolling. if (handledEvent) { if (mScrollHelper == null) { mScrollHelper = new ListViewAutoScrollHelper(this); } mScrollHelper.setEnabled(true); mScrollHelper.onTouch(this, event); } else if (mScrollHelper != null) { mScrollHelper.setEnabled(false); } return handledEvent; }
From source file:com.project.merauke.CustomItemizedOverlay.java
@Override public boolean onTouchEvent(MotionEvent event, MapView map) { if (event.getAction() == MotionEvent.ACTION_MOVE) { isMove = true;/*from w w w . j av a 2s . com*/ } if ((event.getAction() == MotionEvent.ACTION_UP) && isMove) { Log.d("ACTION", "UP after MOVE"); // Toast.makeText(c, "geser-geser detected", Toast.LENGTH_SHORT).show(); Projection projection = maps.getProjection(); GeoPoint geoPointMin = (GeoPoint) projection.fromPixels(0, 0); GeoPoint geoPointMax = (GeoPoint) projection.fromPixels(maps.getWidth(), maps.getHeight()); minLat = geoPointMin.getLatitudeE6() / 1E6; minLng = geoPointMin.getLongitudeE6() / 1E6; // Log.d("drikvy-min", minLat+"---"+minLng);// 2-3 maxLat = geoPointMax.getLatitudeE6() / 1E6; maxLng = geoPointMax.getLongitudeE6() / 1E6; // Log.d("drikvy-max", maxLat+"---"+maxLng);// 1-4 new FetchDataTask() { protected void onPreExecute() { whellProgress.show(); } protected void onPostExecute(ArrayList<CustomOverlayItem> result) { if (result != null) { storeAll(result); whellProgress.dismiss(); maps.invalidate(); } } }.execute(); isMove = false; } return false; }