use of android.graphics.PointF in project RxTools by vondear.
the class RxSwipeCaptcha method drawPartCircle.
/**
* 传入起点、终点 坐标、凹凸和Path。
* 会自动绘制凹凸的半圆弧
*
* @param start 起点坐标
* @param end 终点坐标
* @param path 半圆会绘制在这个path上
* @param outer 是否凸半圆
*/
private void drawPartCircle(PointF start, PointF end, Path path, boolean outer) {
float c = 0.551915024494f;
// 中点
PointF middle = new PointF(start.x + (end.x - start.x) / 2, start.y + (end.y - start.y) / 2);
// 半径
float r1 = (float) Math.sqrt(Math.pow((middle.x - start.x), 2) + Math.pow((middle.y - start.y), 2));
// gap值
float gap1 = r1 * c;
if (start.x == end.x) {
// 绘制竖直方向的
// 是否是从上到下
boolean topToBottom = end.y - start.y > 0 ? true : false;
// 以下是我写出了所有的计算公式后推的,不要问我过程,只可意会。
// 旋转系数
int flag;
if (topToBottom) {
flag = 1;
} else {
flag = -1;
}
if (outer) {
// 凸的 两个半圆
path.cubicTo(start.x + gap1 * flag, start.y, middle.x + r1 * flag, middle.y - gap1 * flag, middle.x + r1 * flag, middle.y);
path.cubicTo(middle.x + r1 * flag, middle.y + gap1 * flag, end.x + gap1 * flag, end.y, end.x, end.y);
} else {
// 凹的 两个半圆
path.cubicTo(start.x - gap1 * flag, start.y, middle.x - r1 * flag, middle.y - gap1 * flag, middle.x - r1 * flag, middle.y);
path.cubicTo(middle.x - r1 * flag, middle.y + gap1 * flag, end.x - gap1 * flag, end.y, end.x, end.y);
}
} else {
// 绘制水平方向的
// 是否是从左到右
boolean leftToRight = end.x - start.x > 0 ? true : false;
// 以下是我写出了所有的计算公式后推的,不要问我过程,只可意会。
// 旋转系数
int flag;
if (leftToRight) {
flag = 1;
} else {
flag = -1;
}
if (outer) {
// 凸 两个半圆
path.cubicTo(start.x, start.y - gap1 * flag, middle.x - gap1 * flag, middle.y - r1 * flag, middle.x, middle.y - r1 * flag);
path.cubicTo(middle.x + gap1 * flag, middle.y - r1 * flag, end.x, end.y - gap1 * flag, end.x, end.y);
} else {
// 凹 两个半圆
path.cubicTo(start.x, start.y + gap1 * flag, middle.x - gap1 * flag, middle.y + r1 * flag, middle.x, middle.y + r1 * flag);
path.cubicTo(middle.x + gap1 * flag, middle.y + r1 * flag, end.x, end.y + gap1 * flag, end.x, end.y);
}
}
}
use of android.graphics.PointF in project RxTools by vondear.
the class RxSwipeCaptcha method createCaptchaPath.
/**
*生成验证码Path
*/
private void createCaptchaPath() {
// 原本打算随机生成gap,后来发现 宽度/3 效果比较好,
int gap = mRandom.nextInt(mCaptchaWidth / 2);
gap = mCaptchaWidth / 3;
// 随机生成验证码阴影左上角 x y 点,
mCaptchaX = mRandom.nextInt(Math.abs(mWidth - mCaptchaWidth - gap));
mCaptchaY = mRandom.nextInt(Math.abs(mHeight - mCaptchaHeight - gap));
Log.d(TAG, "createCaptchaPath() called mWidth:" + mWidth + ", mHeight:" + mHeight + ", mCaptchaX:" + mCaptchaX + ", mCaptchaY:" + mCaptchaY);
mCaptchaPath.reset();
mCaptchaPath.lineTo(0, 0);
// 从左上角开始 绘制一个不规则的阴影
// 左上角
mCaptchaPath.moveTo(mCaptchaX, mCaptchaY);
/*mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
//画出凹凸 由于是多段Path 无法闭合,简直阿西吧
int r = mCaptchaWidth / 2 - gap;
RectF oval = new RectF(mCaptchaX + gap, mCaptchaY - (r), mCaptchaX + gap + r * 2, mCaptchaY + (r));
mCaptchaPath.arcTo(oval, 180, 180);*/
mCaptchaPath.lineTo(mCaptchaX + gap, mCaptchaY);
// draw一个随机凹凸的圆
drawPartCircle(new PointF(mCaptchaX + gap, mCaptchaY), new PointF(mCaptchaX + gap * 2, mCaptchaY), mCaptchaPath, mRandom.nextBoolean());
// 右上角
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY);
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap);
// draw一个随机凹凸的圆
drawPartCircle(new PointF(mCaptchaX + mCaptchaWidth, mCaptchaY + gap), new PointF(mCaptchaX + mCaptchaWidth, mCaptchaY + gap * 2), mCaptchaPath, mRandom.nextBoolean());
// 右下角
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + mCaptchaHeight);
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth - gap, mCaptchaY + mCaptchaHeight);
// draw一个随机凹凸的圆
drawPartCircle(new PointF(mCaptchaX + mCaptchaWidth - gap, mCaptchaY + mCaptchaHeight), new PointF(mCaptchaX + mCaptchaWidth - gap * 2, mCaptchaY + mCaptchaHeight), mCaptchaPath, mRandom.nextBoolean());
// 左下角
mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight);
mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight - gap);
// draw一个随机凹凸的圆
drawPartCircle(new PointF(mCaptchaX, mCaptchaY + mCaptchaHeight - gap), new PointF(mCaptchaX, mCaptchaY + mCaptchaHeight - gap * 2), mCaptchaPath, mRandom.nextBoolean());
mCaptchaPath.close();
/* RectF oval = new RectF(mCaptchaX + gap, mCaptchaY - (r), mCaptchaX + gap + r * 2, mCaptchaY + (r));
mCaptchaPath.addArc(oval, 180,180);
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY);
//凹的话,麻烦一点,要利用多次move
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap);
oval = new RectF(mCaptchaX + mCaptchaWidth - r, mCaptchaY + gap, mCaptchaX + mCaptchaWidth + r, mCaptchaY + gap + r * 2);
mCaptchaPath.addArc(oval, 90, 180);
mCaptchaPath.moveTo(mCaptchaX + mCaptchaWidth, mCaptchaY + gap + r * 2);*/
/*
mCaptchaPath.lineTo(mCaptchaX + mCaptchaWidth, mCaptchaY + mCaptchaHeight);
mCaptchaPath.lineTo(mCaptchaX, mCaptchaY + mCaptchaHeight);
mCaptchaPath.close();*/
}
use of android.graphics.PointF in project RxTools by vondear.
the class ActivityELMe method add.
@Override
public void add(View view, int position) {
int[] addLocation = new int[2];
int[] cartLocation = new int[2];
int[] recycleLocation = new int[2];
view.getLocationInWindow(addLocation);
mShoppingCart.getLocationInWindow(cartLocation);
mRightMenu.getLocationInWindow(recycleLocation);
PointF startP = new PointF();
PointF endP = new PointF();
PointF controlP = new PointF();
startP.x = addLocation[0];
startP.y = addLocation[1] - recycleLocation[1];
endP.x = cartLocation[0];
endP.y = cartLocation[1] - recycleLocation[1];
controlP.x = endP.x;
controlP.y = startP.y;
final RxFakeAddImageView rxFakeAddImageView = new RxFakeAddImageView(this);
mMainLayout.addView(rxFakeAddImageView);
rxFakeAddImageView.setImageResource(R.drawable.ic_add_circle_blue_700_36dp);
rxFakeAddImageView.getLayoutParams().width = getResources().getDimensionPixelSize(R.dimen.item_dish_circle_size);
rxFakeAddImageView.getLayoutParams().height = getResources().getDimensionPixelSize(R.dimen.item_dish_circle_size);
rxFakeAddImageView.setVisibility(View.VISIBLE);
ObjectAnimator addAnimator = ObjectAnimator.ofObject(rxFakeAddImageView, "mPointF", new RxPointFTypeEvaluator(controlP), startP, endP);
addAnimator.setInterpolator(new AccelerateInterpolator());
addAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
rxFakeAddImageView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animator) {
rxFakeAddImageView.setVisibility(View.GONE);
mMainLayout.removeView(rxFakeAddImageView);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
ObjectAnimator scaleAnimatorX = new ObjectAnimator().ofFloat(mShoppingCart, "scaleX", 0.6f, 1.0f);
ObjectAnimator scaleAnimatorY = new ObjectAnimator().ofFloat(mShoppingCart, "scaleY", 0.6f, 1.0f);
scaleAnimatorX.setInterpolator(new AccelerateInterpolator());
scaleAnimatorY.setInterpolator(new AccelerateInterpolator());
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(scaleAnimatorX).with(scaleAnimatorY).after(addAnimator);
animatorSet.setDuration(800);
animatorSet.start();
showTotalPrice();
}
use of android.graphics.PointF in project StreetComplete by westnordost.
the class MapFragment method onDoubleTap.
/* -------------------------------- Touch responders --------------------------------------- */
@Override
public boolean onDoubleTap(float x, float y) {
if (requestUnglueViewFromPosition()) {
LngLat zoomTo = controller.screenPositionToLngLat(new PointF(x, y));
controller.setPositionEased(zoomTo, 500);
}
controller.setZoomEased(controller.getZoom() + 1.5f, 500);
updateView();
return true;
}
use of android.graphics.PointF in project StreetComplete by westnordost.
the class QuestsMapFragment method getDisplayedArea.
public BoundingBox getDisplayedArea(Rect offset) {
if (controller == null)
return null;
if (getView() == null)
return null;
Point size = new Point(getView().getWidth() - offset.left - offset.right, getView().getHeight() - offset.top - offset.bottom);
if (size.equals(0, 0))
return null;
// 45°
if (controller.getTilt() > Math.PI / 4f)
return null;
LatLon[] positions = new LatLon[4];
positions[0] = getPositionAt(new PointF(offset.left, offset.top));
positions[1] = getPositionAt(new PointF(offset.left + size.x, offset.top));
positions[2] = getPositionAt(new PointF(offset.left, offset.top + size.y));
positions[3] = getPositionAt(new PointF(offset.left + size.x, offset.top + size.y));
// dealing with rotation: find each the largest latlon and the smallest latlon, that'll
// be our bounding box
Double latMin = null, lonMin = null, latMax = null, lonMax = null;
for (LatLon position : positions) {
double lat = position.getLatitude();
double lon = position.getLongitude();
if (latMin == null || latMin > lat)
latMin = lat;
if (latMax == null || latMax < lat)
latMax = lat;
if (lonMin == null || lonMin > lon)
lonMin = lon;
if (lonMax == null || lonMax < lon)
lonMax = lon;
}
return new BoundingBox(latMin, lonMin, latMax, lonMax);
}
Aggregations