List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:com.cssweb.android.view.TrendView.java
public void touchesMoved(MotionEvent event) { currentPositionX = event.getX(); currentPositionY = event.getY();// ww w . j ava 2s . com float deltaX = startPositionX - currentPositionX; float deltaY = startPositionY - currentPositionY; if (Math.abs(deltaX) < 8 && Math.abs(deltaY) < 8) { isTouchMoved = false; } else { isTouchMoved = true; } if (isTrackStatus) {//?? int x = (int) event.getX(); int y = (int) event.getY(); float sep = SPACE; int idx = (int) ((x - LSpace) / sep); if (idx < actualDataLen && idx >= 0) { //if (x >= LSpace && x <= (width - LSpace)) if (x >= LSpace || x <= width) { trackLineV = (int) (LSpace + idx * SPACE); } if (y > axisLabelHeight && y < (height - axisLabelHeight)) trackLineH = y; isTrackNumber = idx; } else { if (idx < 0) { idx = 0; isTrackNumber = idx; trackLineV = LSpace; } if (idx >= actualDataLen) { isTrackNumber = actualDataLen - 1; trackLineV = (int) (LSpace + (actualDataLen - 1) * SPACE); } } } this.invalidate(); }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
@Override public boolean onScroll(MotionEvent firstEvent, MotionEvent thisEvent, float distanceX, float distanceY) { // transform sound source or surface? if (lastTouchSoundSource != null) { // transform sound source synchronized (GlobalData.audioScene) { // is lastTouchSoundSource selected? if (!lastTouchSoundSource.isSelected()) { // select only this source GlobalData.audioScene.deselectAllSoundSources(); GlobalData.audioScene.selectSoundSource(lastTouchSoundSource); }/*from www . j a v a2 s . co m*/ // save positions of sources if this is first scroll event if (!scrolling) { scrolling = true; firstScrollPoint[0] = firstEvent.getX(); firstScrollPoint[1] = firstEvent.getY(); ArrayList<SoundSource> selectedSources = GlobalData.audioScene.getSelectedSoundSources(); int numSources = selectedSources.size(); for (int i = 0; i < numSources; i++) { // loop through all currently selected sources selectedSources.get(i).getXY(point); GlobalData.audioScene.mapPoint(point); viewportTransformation.mapPoints(point); selectedSources.get(i).savePosition(point); } } // enough time elapsed to do next position update? long currentTime = SystemClock.uptimeMillis(); if (currentTime - lastSendTime < MAX_POSITION_UPDATE_FREQ) return true; lastSendTime = currentTime; // translate or rotate? if (transformationMode == TransformationMode.TRANSLATE) { // translate // generate server request string String strMsg = "<request>"; ArrayList<SoundSource> selectedSources = GlobalData.audioScene.getSelectedSoundSources(); int numSources = selectedSources.size(); SoundSource soundSource; for (int i = 0; i < numSources; i++) { // loop through all currently selected sources soundSource = selectedSources.get(i); // if source is fixed, skip it if (soundSource.isPositionFixed()) continue; strMsg += "<source id='" + soundSource.getId() + "'>"; // transform screen coords into object coords, consider offset point[0] = soundSource.getSavedX() + thisEvent.getX() - firstScrollPoint[0]; point[1] = soundSource.getSavedY() + thisEvent.getY() - firstScrollPoint[1]; inverseViewportTransformation.mapPoints(point); if (soundSource.getSourceModel() == SoundSource.SourceModel.PLANE) { // recalculate orientation for plane waves float norm = FloatMath.sqrt(point[0] * point[0] + point[1] * point[1]); // for plane waves, if source is movable if (norm != 0.0f) { float newAzimuth; if (point[1] >= 0.0f) newAzimuth = (float) (Math.acos(point[0] / norm) / Math.PI * 180.0f) - 180.0f + GlobalData.audioScene.getReference().getAzimuth(); else newAzimuth = (float) -(Math.acos(point[0] / norm) / Math.PI * 180.0f) - 180.0f + GlobalData.audioScene.getReference().getAzimuth(); strMsg += "<orientation azimuth='" + String.valueOf(newAzimuth) + "'/>"; } } GlobalData.audioScene.inverseMapPoint(point); strMsg += "<position x='" + String.valueOf(point[0]) + "' y='" + String.valueOf(point[1]) + "'/>"; strMsg += "</source>"; } strMsg += "</request>\0"; // send changes to server sendToServer(strMsg); } else { // rotate // not implemented } } } else { // transform surface if (!scrolling) { scrolling = true; firstScrollPoint[0] = thisEvent.getX(); firstScrollPoint[1] = thisEvent.getY(); currentSavedTranslation[0] = currentTranslation[0]; currentSavedTranslation[1] = currentTranslation[1]; } // translate or rotate? if (transformationMode == TransformationMode.TRANSLATE) { // translate if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { point[0] = thisEvent.getX() - firstScrollPoint[0]; point[1] = thisEvent.getY() - firstScrollPoint[1]; } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { point[0] = thisEvent.getY() - firstScrollPoint[1]; point[1] = -(thisEvent.getX() - firstScrollPoint[0]); } setCurrentTranslation(currentSavedTranslation[0] + point[0], currentSavedTranslation[1] + point[1]); } else { // rotate // not implemented } } return true; }
From source file:android.widget.Gallery.java
@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if (localLOGV) Log.v(TAG, String.valueOf(e2.getX() - e1.getX())); /*//from w w w . ja v a2 s . co m * Now's a good time to tell our parent to stop intercepting our events! * The user has moved more than the slop amount, since GestureDetector * ensures this before calling this method. Also, if a parent is more * interested in this touch's events than we are, it would have * intercepted them by now (for example, we can assume when a Gallery is * in the ListView, a vertical scroll would not end up in this method * since a ListView would have intercepted it by now). */ mParent.requestDisallowInterceptTouchEvent(true); // As the user scrolls, we want to callback selection changes so related- // info on the screen is up-to-date with the gallery's selection if (!mShouldCallbackDuringFling) { if (mIsFirstScroll) { /* * We're not notifying the client of selection changes during * the fling, and this scroll could possibly be a fling. Don't * do selection changes until we're sure it is not a fling. */ if (!mSuppressSelectionChanged) mSuppressSelectionChanged = true; postDelayed(mDisableSuppressSelectionChangedRunnable, SCROLL_TO_FLING_UNCERTAINTY_TIMEOUT); } } else { if (mSuppressSelectionChanged) mSuppressSelectionChanged = false; } // Track the motion trackMotionScroll(-1 * (int) distanceX); mIsFirstScroll = false; return true; }
From source file:com.example.SmartBoard.DrawingView.java
/***********************************REMOVE OBJECT************************************/ //removes an object touched from the canvas public void onRemoveObjectEvent(MotionEvent event) { int xRemove = (int) event.getX(); int yRemove = (int) event.getY(); JSONObject touchedObject = getTouchedObject(xRemove, yRemove); if (touchedObject != null) { removeObject(touchedObject.optString("id")); mqtt.removeObjectFromServer(touchedObject.optString("id")); }//from w w w . j a va 2 s.co m }
From source file:com.example.SmartBoard.DrawingView.java
/***********************************************************************************/ //handles color dropper mode touch events public void onTouchColorDropperMode(MotionEvent event) { int X = (int) event.getX(); int Y = (int) event.getY(); dropperX = X;// w w w.j a v a 2 s . c o m dropperY = Y; if (event.getAction() == MotionEvent.ACTION_DOWN) { JSONObject touchedObject = getTouchedObject(X, Y); if (touchedObject != null) { try { touchedObject.put("color", dropperColor); //for text if (touchedObject.optString("type").compareTo("Text") == 0) { Bitmap bm = textToBitmap(touchedObject.optString("text"), dropperColor, touchedObject.optInt("x"), touchedObject.optInt("y"), touchedObject.optInt("size")); touchedObject.put("textBitmap", mqtt.bitmapToString(bm)); } mqtt.publishObject(touchedObject); } catch (JSONException e) { } invalidate(); } } }
From source file:com.android.dialer.widget.OverlappingPaneLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide) { return super.onTouchEvent(ev); }// w w w. j a v a 2 s. co m mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } } return wantTouchEvents; }
From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); checkFirstLaunch();/*from www . j ava 2 s. co m*/ if (isFirstLaunch) { setDefaultPreferences(); } Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.capture); viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view); cameraButtonView = findViewById(R.id.camera_button_view); resultView = findViewById(R.id.result_view); statusViewBottom = (TextView) findViewById(R.id.status_view_bottom); registerForContextMenu(statusViewBottom); statusViewTop = (TextView) findViewById(R.id.status_view_top); registerForContextMenu(statusViewTop); handler = null; lastResult = null; hasSurface = false; beepManager = new BeepManager(this); // Camera shutter button if (DISPLAY_SHUTTER_BUTTON) { shutterButton = (ShutterButton) findViewById(R.id.shutter_button); shutterButton.setOnShutterButtonListener(this); } ocrResultView = (TextView) findViewById(R.id.ocr_result_text_view); registerForContextMenu(ocrResultView); translationView = (TextView) findViewById(R.id.translation_text_view); registerForContextMenu(translationView); progressView = (View) findViewById(R.id.indeterminate_progress_indicator_view); cameraManager = new CameraManager(getApplication()); viewfinderView.setCameraManager(cameraManager); // Set listener to change the size of the viewfinder rectangle. viewfinderView.setOnTouchListener(new View.OnTouchListener() { int lastX = -1; int lastY = -1; @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: lastX = -1; lastY = -1; return true; case MotionEvent.ACTION_MOVE: int currentX = (int) event.getX(); int currentY = (int) event.getY(); try { Rect rect = cameraManager.getFramingRect(); final int BUFFER = 50; final int BIG_BUFFER = 60; if (lastX >= 0) { // Adjust the size of the viewfinder rectangle. Check if the touch event occurs in the corner areas first, because the regions overlap. if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER) || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER)) && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER) || (lastY <= rect.top + BIG_BUFFER && lastY >= rect.top - BIG_BUFFER))) { // Top left corner: adjust both top and left sides cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (lastY - currentY)); viewfinderView.removeResultText(); } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER) || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER)) && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER) || (lastY <= rect.top + BIG_BUFFER && lastY >= rect.top - BIG_BUFFER))) { // Top right corner: adjust both top and right sides cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (lastY - currentY)); viewfinderView.removeResultText(); } else if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER) || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER)) && ((currentY <= rect.bottom + BIG_BUFFER && currentY >= rect.bottom - BIG_BUFFER) || (lastY <= rect.bottom + BIG_BUFFER && lastY >= rect.bottom - BIG_BUFFER))) { // Bottom left corner: adjust both bottom and left sides cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (currentY - lastY)); viewfinderView.removeResultText(); } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER) || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER)) && ((currentY <= rect.bottom + BIG_BUFFER && currentY >= rect.bottom - BIG_BUFFER) || (lastY <= rect.bottom + BIG_BUFFER && lastY >= rect.bottom - BIG_BUFFER))) { // Bottom right corner: adjust both bottom and right sides cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (currentY - lastY)); viewfinderView.removeResultText(); } else if (((currentX >= rect.left - BUFFER && currentX <= rect.left + BUFFER) || (lastX >= rect.left - BUFFER && lastX <= rect.left + BUFFER)) && ((currentY <= rect.bottom && currentY >= rect.top) || (lastY <= rect.bottom && lastY >= rect.top))) { // Adjusting left side: event falls within BUFFER pixels of left side, and between top and bottom side limits cameraManager.adjustFramingRect(2 * (lastX - currentX), 0); viewfinderView.removeResultText(); } else if (((currentX >= rect.right - BUFFER && currentX <= rect.right + BUFFER) || (lastX >= rect.right - BUFFER && lastX <= rect.right + BUFFER)) && ((currentY <= rect.bottom && currentY >= rect.top) || (lastY <= rect.bottom && lastY >= rect.top))) { // Adjusting right side: event falls within BUFFER pixels of right side, and between top and bottom side limits cameraManager.adjustFramingRect(2 * (currentX - lastX), 0); viewfinderView.removeResultText(); } else if (((currentY <= rect.top + BUFFER && currentY >= rect.top - BUFFER) || (lastY <= rect.top + BUFFER && lastY >= rect.top - BUFFER)) && ((currentX <= rect.right && currentX >= rect.left) || (lastX <= rect.right && lastX >= rect.left))) { // Adjusting top side: event falls within BUFFER pixels of top side, and between left and right side limits cameraManager.adjustFramingRect(0, 2 * (lastY - currentY)); viewfinderView.removeResultText(); } else if (((currentY <= rect.bottom + BUFFER && currentY >= rect.bottom - BUFFER) || (lastY <= rect.bottom + BUFFER && lastY >= rect.bottom - BUFFER)) && ((currentX <= rect.right && currentX >= rect.left) || (lastX <= rect.right && lastX >= rect.left))) { // Adjusting bottom side: event falls within BUFFER pixels of bottom side, and between left and right side limits cameraManager.adjustFramingRect(0, 2 * (currentY - lastY)); viewfinderView.removeResultText(); } } } catch (NullPointerException e) { Log.e(TAG, "Framing rect not available", e); } v.invalidate(); lastX = currentX; lastY = currentY; return true; case MotionEvent.ACTION_UP: lastX = -1; lastY = -1; return true; } return false; } }); isEngineReady = false; aq = new AQuery(this); beerQuery = new BeerQuery(); }
From source file:com.android.contacts.common.list.ContactListItemView.java
@Override public boolean onTouchEvent(MotionEvent event) { final float x = event.getX(); final float y = event.getY(); // If the touch event's coordinates are not within the view's header, then delegate // to super.onTouchEvent so that regular view behavior is preserved. Otherwise, consume // and ignore the touch event. if (mBoundsWithoutHeader.contains((int) x, (int) y) || !pointIsInView(x, y)) { return super.onTouchEvent(event); } else {/*ww w. ja v a 2 s . com*/ return true; } }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (!mCanSlide || !mIsSlidingEnabled || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel();/*from w w w. j a v a 2s .com*/ return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } final float x = ev.getX(); final float y = ev.getY(); boolean interceptTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; mInitialMotionX = x; mInitialMotionY = y; if (isDragViewUnder((int) x, (int) y) && !mIsUsingDragViewTouchEvents) { interceptTap = true; } break; } case MotionEvent.ACTION_MOVE: { final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int dragSlop = mDragHelper.getTouchSlop(); // Handle any horizontal scrolling on the drag view. if (mIsUsingDragViewTouchEvents) { if (adx > mScrollTouchSlop && ady < mScrollTouchSlop) { return super.onInterceptTouchEvent(ev); } // Intercept the touch if the drag view has any vertical scroll. // onTouchEvent will determine if the view should drag vertically. else if (ady > mScrollTouchSlop) { interceptTap = isDragViewUnder((int) x, (int) y); } } if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) x, (int) y)) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } break; } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag || interceptTap; }
From source file:com.aigo.kt03airdemo.ui.view.ResideLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // Preserve the open state based on the last view that was touched. if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) { // After the first things will be slideable. final View secondChild = getChildAt(1); if (secondChild != null) { mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY()); }/*ww w.j a va 2 s .c o m*/ } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } boolean interceptTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) { interceptTap = true; } break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); View view = findViewAtPosition(this, (int) x, (int) y); if (adx > slop && ady > adx || view != null) { if (view != null) { Log.d(TAG, "touch on unscrollable view"); } mDragHelper.cancel(); mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag || interceptTap; }