Java Code Examples for android.graphics.PointF#length()
The following examples show how to use
android.graphics.PointF#length() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomPagerView.java From timecat with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent evt) { switch (evt.getAction()) { case MotionEvent.ACTION_DOWN: // 记录按下时候的坐标 downPoint.x = evt.getX(); downPoint.y = evt.getY(); if (this.getChildCount() > 1) { //有内容,多于1个时 // 通知其父控件,现在进行的是本控件的操作,不允许拦截 getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_MOVE: if (this.getChildCount() > 1) { //有内容,多于1个时 // 通知其父控件,现在进行的是本控件的操作,不允许拦截 getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_UP: // 在up时判断是否按下和松手的坐标为一个点 if (PointF.length(evt.getX() - downPoint.x, evt.getY() - downPoint.y) < (float) 5.0) { onSingleTouch(this); return true; } break; default: break; } return super.onTouchEvent(evt); }
Example 2
Source File: BaseContainerView.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
/** * Handles the touch events that shows the workspace when clicking outside the bounds of the * touch delegate target view. */ private boolean handleTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: // Check if the touch is outside touch delegate target view View touchDelegateTargetView = getTouchDelegateTargetView(); float leftBoundPx = touchDelegateTargetView.getLeft(); if (ev.getX() < leftBoundPx || ev.getX() > (touchDelegateTargetView.getWidth() + leftBoundPx)) { mLastTouchDownPosPx.set((int) ev.getX(), (int) ev.getY()); } break; case MotionEvent.ACTION_UP: if (mLastTouchDownPosPx.x > -1) { ViewConfiguration viewConfig = ViewConfiguration.get(getContext()); float dx = ev.getX() - mLastTouchDownPosPx.x; float dy = ev.getY() - mLastTouchDownPosPx.y; float distance = PointF.length(dx, dy); if (distance < viewConfig.getScaledTouchSlop()) { // The background was clicked, so just go home Launcher.getLauncher(getContext()).showWorkspace(true); return true; } } // Fall through case MotionEvent.ACTION_CANCEL: mLastTouchDownPosPx.set(-1, -1); break; } return false; }
Example 3
Source File: Utils.java From atlas with Apache License 2.0 | 5 votes |
static Path createPath(PointF startPoint, PointF endPoint, PointF cp1, PointF cp2) { Path path = new Path(); path.moveTo(startPoint.x, startPoint.y); if (cp1 != null && cp1.length() != 0 && cp2 != null && cp2.length() != 0) { path.cubicTo( startPoint.x + cp1.x, startPoint.y + cp1.y, endPoint.x + cp2.x, endPoint.y + cp2.y, endPoint.x, endPoint.y); } else { path.lineTo(endPoint.x, endPoint.y); } return path; }
Example 4
Source File: Utils.java From lottie-android with Apache License 2.0 | 5 votes |
public static Path createPath(PointF startPoint, PointF endPoint, PointF cp1, PointF cp2) { Path path = new Path(); path.moveTo(startPoint.x, startPoint.y); if (cp1 != null && cp2 != null && (cp1.length() != 0 || cp2.length() != 0)) { path.cubicTo( startPoint.x + cp1.x, startPoint.y + cp1.y, endPoint.x + cp2.x, endPoint.y + cp2.y, endPoint.x, endPoint.y); } else { path.lineTo(endPoint.x, endPoint.y); } return path; }
Example 5
Source File: DragPinchListener.java From AndroidPDF with Apache License 2.0 | 5 votes |
/** Calculates the distance between the 2 current pointers */ private float distance(MotionEvent event) { if (event.getPointerCount() < 2) { return 0; } return PointF.length(event.getX(POINTER1) - event.getX(POINTER2), // event.getY(POINTER1) - event.getY(POINTER2)); }
Example 6
Source File: WheelView.java From Prodigal with Apache License 2.0 | 5 votes |
private float xyToDegrees(float x, float y) { float distanceFromCenter = PointF.length((x - 0.5f), (y - 0.5f)); if (distanceFromCenter < 0.15f || distanceFromCenter > 0.5f) { // ignore center and out of bounds events return Float.NaN; } else { return (float) Math.toDegrees(Math.atan2(x - 0.5f, y - 0.5f)); } }
Example 7
Source File: PieChartRenderer.java From SmartChart with Apache License 2.0 | 4 votes |
private void normalizeVector(PointF point) { final float abs = point.length(); point.set(point.x / abs, point.y / abs); }
Example 8
Source File: BadgeViewHelper.java From Lay-s with MIT License | 4 votes |
public boolean satisfyMoveDismissCondition(MotionEvent event) { return PointF.length(event.getRawX() - mDownPointF.x, event.getRawY() - mDownPointF.y) > mMoveHiddenThreshold; }
Example 9
Source File: PieChartRenderer.java From hellocharts-android with Apache License 2.0 | 4 votes |
private void normalizeVector(PointF point) { final float abs = point.length(); point.set(point.x / abs, point.y / abs); }
Example 10
Source File: DragPinchListener.java From AndroidPDF with Apache License 2.0 | 3 votes |
/** * Test if a MotionEvent with the given start and end offsets * can be considered as a "click". * @param upEvent The final finger-up event. * @param xDown The x-offset of the down event. * @param yDown The y-offset of the down event. * @param xUp The x-offset of the up event. * @param yUp The y-offset of the up event. * @return true if it's a click, false otherwise */ private boolean isClick(MotionEvent upEvent, float xDown, float yDown, float xUp, float yUp) { if (upEvent == null) return false; long time = upEvent.getEventTime() - upEvent.getDownTime(); float distance = PointF.length( // xDown - xUp, // yDown - yUp); return time < MAX_CLICK_TIME && distance < MAX_CLICK_DISTANCE; }
Example 11
Source File: Utils.java From spruce-android with MIT License | 2 votes |
/** * Get the euclidean distance between two points * * @param firstPoint PointF object * @param secondPoint PointF object * @return float value representing the distance in a straight line between two points */ public static float euclideanDistance(PointF firstPoint, PointF secondPoint) { return PointF.length(secondPoint.x - firstPoint.x, secondPoint.y - firstPoint.y); }