本文整理匯總了Java中android.graphics.PointF.length方法的典型用法代碼示例。如果您正苦於以下問題:Java PointF.length方法的具體用法?Java PointF.length怎麽用?Java PointF.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.PointF
的用法示例。
在下文中一共展示了PointF.length方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleTouchEvent
import android.graphics.PointF; //導入方法依賴的package包/類
/**
* 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;
}
示例2: createPath
import android.graphics.PointF; //導入方法依賴的package包/類
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;
}
示例3: distance
import android.graphics.PointF; //導入方法依賴的package包/類
/** 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));
}
示例4: normalizeVector
import android.graphics.PointF; //導入方法依賴的package包/類
private void normalizeVector(PointF point) {
final float abs = point.length();
point.set(point.x / abs, point.y / abs);
}
示例5: normalizePoint
import android.graphics.PointF; //導入方法依賴的package包/類
public static PointF normalizePoint(PointF p) {
PointF c = new PointF();
c.x = p.x / p.length();
c.y = p.y / p.length();
return c;
}
示例6: normalizeVector
import android.graphics.PointF; //導入方法依賴的package包/類
private void normalizeVector(PointF point) {
float abs = point.length();
point.set(point.x / abs, point.y / abs);
}
示例7: isClick
import android.graphics.PointF; //導入方法依賴的package包/類
/**
* 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;
}
示例8: euclideanDistance
import android.graphics.PointF; //導入方法依賴的package包/類
/**
* 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);
}