List of usage examples for android.view MotionEvent getHistorySize
public final int getHistorySize()
From source file:Main.java
public static float getPressure(MotionEvent event, int index) { final int historySize = event.getHistorySize(); return historySize == 0 ? event.getPressure(index) : event.getHistoricalPressure(index, historySize - 1); }
From source file:Main.java
public static float getSize(MotionEvent event, int index) { final int historySize = event.getHistorySize(); return historySize == 0 ? event.getSize(index) : event.getHistoricalSize(index, historySize - 1); }
From source file:tv.piratemedia.flightcontroller.ControlActivity.java
@Override public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) { final int historySize = event.getHistorySize(); // Process the movements starting from the // earliest historical position in the batch for (int i = 0; i < historySize; i++) { // Process the event at historical position i processJoystickInput(event, i); }/*from w w w . ja v a2 s . c o m*/ // Process the current movement sample in the batch (position -1) processJoystickInput(event, -1); return true; } return super.onGenericMotionEvent(event); }
From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java
public boolean onTouch(View view, MotionEvent event) { if (event.getAction() != MotionEvent.ACTION_UP) { for (int i = 0; i < event.getHistorySize(); i++) { Point point = new Point(); point.x = event.getHistoricalX(i); point.y = event.getHistoricalY(i); // points.add(point); }/* www. j a v a 2 s .c om*/ invalidate(); return true; } return super.onTouchEvent(event); }
From source file:com.ichi2.anki.Whiteboard.java
/** * Handle touch screen motion events.//from www . ja v a 2 s . c o m * * @param event The motion event. * @return True if the event was handled, false otherwise. */ public boolean handleTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touchStart(x, y); invalidate(); return true; case MotionEvent.ACTION_MOVE: for (int i = 0; i < event.getHistorySize(); i++) { touchMove(event.getHistoricalX(i), event.getHistoricalY(i)); } touchMove(x, y); invalidate(); return true; case MotionEvent.ACTION_UP: touchUp(); invalidate(); return true; default: return false; } }
From source file:com.p3authentication.preferences.Prefs.java
@SuppressWarnings("static-access") @Override/*from w w w .j a v a2 s . c o m*/ public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub int action = event.getAction(); int N = event.getHistorySize(); if (action == event.ACTION_DOWN) { calibrator.setColorFilter(Color.BLACK); for (int i = 0; i < N; i++) { calibrate(event.getHistoricalX(i), event.getHistoricalY(i), event.getHistoricalPressure(i), event.getHistoricalSize(i)); } calibrate(event.getX(), event.getY(), event.getPressure(), event.getSize()); } else if (action == event.ACTION_UP) { Float temp = Collections.max(CalList); temp = (float) Math.ceil((Double.parseDouble(Float.valueOf(temp).toString())) / 10); LargeValue = temp * 10; calibrator.setColorFilter(Color.GREEN); // Largest.setText(String.valueOf(LargeValue)); } return true; }
From source file:com.ylw.split.splitview.view.SplitView3.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { initDragView(vTop, event);/*from w w w. j a v a2 s. c o m*/ initDragView(vCenter, event); initDragView(vBottom, event); } if (event.getHistorySize() > 0) { //Touch if (dragView == vTop) { //vTop if (event.getY() > event.getHistoricalY(0)) { //? if (vTop.getScrollY() == 0) { return mDragger.shouldInterceptTouchEvent(event); } else { return false; } } else if (event.getY() < event.getHistoricalY(0)) { //? if (vTop.getTop() > 0) { return mDragger.shouldInterceptTouchEvent(event); } else { return false; } } else if (event.getY() == event.getHistoricalY(0)) { Log.d(TAG, "onInterceptTouchEvent - " + "event.getY() == event.getHistoricalY(0)"); return false; } } else if (dragView == vBottom) { //vBottom if (event.getY() > event.getHistoricalY(0)) { //? // ?webView? int ci = vBottom.getCurrentItem(); WebView webView = (WebView) vBottom.findViewById(ci); if (webView.getScrollY() == 0) { return mDragger.shouldInterceptTouchEvent(event); } else { return false; } } else { return false; } } else if (dragView == vCenter) { return mDragger.shouldInterceptTouchEvent(event); } } return mDragger.shouldInterceptTouchEvent(event); }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
public boolean onGenericMotionEvent(MotionEvent event) { // Check that the event came from a game controller if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK && event.getAction() == MotionEvent.ACTION_MOVE) { // Process all historical movement samples in the batch final int historySize = event.getHistorySize(); // Process the movements starting from the // earliest historical position in the batch for (int i = 0; i < historySize; i++) { // Process the event at historical position i processJoystickInput(event, i); }//from w w w .j a v a2s . com // Process the current movement sample in the batch (position -1) processJoystickInput(event, -1); return true; } return super.onGenericMotionEvent(event); }
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. java 2 s . 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.hippo.widget.lockpattern.LockPatternView.java
private void handleActionMove(MotionEvent event) { // Handle all recent motion events so we don't skip any cells even when the device // is busy... final float radius = mPathWidth; final int historySize = event.getHistorySize(); mTmpInvalidateRect.setEmpty();/* ww w .j a va2 s . c om*/ boolean invalidateNow = false; for (int i = 0; i < historySize + 1; i++) { final float x = i < historySize ? event.getHistoricalX(i) : event.getX(); final float y = i < historySize ? event.getHistoricalY(i) : event.getY(); Cell hitCell = detectAndAddHit(x, y); final int patternSize = mPattern.size(); if (hitCell != null && patternSize == 1) { mPatternInProgress = true; notifyPatternStarted(); } // note current x and y for rubber banding of in progress patterns final float dx = Math.abs(x - mInProgressX); final float dy = Math.abs(y - mInProgressY); if (dx > DRAG_THRESHHOLD || dy > DRAG_THRESHHOLD) { invalidateNow = true; } if (mPatternInProgress && patternSize > 0) { final ArrayList<Cell> pattern = mPattern; final Cell lastCell = pattern.get(patternSize - 1); float lastCellCenterX = getCenterXForColumn(lastCell.column); float lastCellCenterY = getCenterYForRow(lastCell.row); // Adjust for drawn segment from last cell to (x,y). Radius accounts for line width. float left = Math.min(lastCellCenterX, x) - radius; float right = Math.max(lastCellCenterX, x) + radius; float top = Math.min(lastCellCenterY, y) - radius; float bottom = Math.max(lastCellCenterY, y) + radius; // Invalidate between the pattern's new cell and the pattern's previous cell if (hitCell != null) { final float width = mSquareWidth * 0.5f; final float height = mSquareHeight * 0.5f; final float hitCellCenterX = getCenterXForColumn(hitCell.column); final float hitCellCenterY = getCenterYForRow(hitCell.row); left = Math.min(hitCellCenterX - width, left); right = Math.max(hitCellCenterX + width, right); top = Math.min(hitCellCenterY - height, top); bottom = Math.max(hitCellCenterY + height, bottom); } // Invalidate between the pattern's last cell and the previous location mTmpInvalidateRect.union(Math.round(left), Math.round(top), Math.round(right), Math.round(bottom)); } } mInProgressX = event.getX(); mInProgressY = event.getY(); // To save updates, we only invalidate if the user moved beyond a certain amount. if (invalidateNow) { mInvalidate.union(mTmpInvalidateRect); invalidate(mInvalidate); mInvalidate.set(mTmpInvalidateRect); } }