List of usage examples for android.graphics PointF set
public final void set(float x, float y)
From source file:Main.java
public static PointF calculateMidPoint(PointF start, PointF end) { PointF middle = new PointF(); middle.set((start.x + end.x) / 2, (start.y + end.y) / 2); return middle; }
From source file:Main.java
/** * This method normalize specified vector. * * @param point {@link PointF}/*from w ww . j a va 2s. c o m*/ */ public static void normalizeVector(PointF point) { final float abs = point.length(); point.set(point.x / abs, point.y / abs); }
From source file:Main.java
public static PointF drawBitmapOffset(PointF center, Bitmap bitmap) { PointF offset = new PointF(); if (bitmap == null || bitmap.getWidth() < 0) { return center; }/*from w w w .j a v a 2 s . c o m*/ offset.set(center.x - bitmap.getWidth() / 2, center.y - bitmap.getHeight() / 2); return offset; }
From source file:Main.java
public static PointF calculateQuadPoint(PointF start, PointF end, int quadType) { PointF quadPoint = new PointF(); switch (quadType) { case QUAD_TYPE_LEFT_TOP: quadPoint.set((start.x + end.x) / 2 - QUAD_OFFSET, (start.y + end.y) / 2 - QUAD_OFFSET); break;/* w ww . j a v a 2 s .c o m*/ case QUAD_TYPE_LEFT_BOTTOM: quadPoint.set((start.x + end.x) / 2 - QUAD_OFFSET, (start.y + end.y) / 2 + QUAD_OFFSET); break; case QUAD_TYPE_RIGHT_TOP: quadPoint.set((start.x + end.x) / 2 + QUAD_OFFSET, (start.y + end.y) / 2 - QUAD_OFFSET); break; case QUAD_TYPE_RIGHT_TOP_LAST: quadPoint.set((start.x + end.x) / 2 + QUAD_OFFSET_RIGHT_TOP_LAST, (start.y + end.y) / 2 - QUAD_OFFSET_RIGHT_TOP_LAST); break; case QUAD_TYPE_RIGHT_BOTTOM: quadPoint.set((start.x + end.x) / 2 + QUAD_OFFSET_RIGHT_BOTTOM, (start.y + end.y) / 2 + QUAD_OFFSET_RIGHT_BOTTOM); break; } return quadPoint; }
From source file:Main.java
public static void resolveMiddlePoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); }
From source file:Main.java
/** * Calculate the mid point of two pointers *///from w ww . jav a2s.c o m public static void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1) + event.getX(2); float y = event.getY(0) + event.getY(1) + event.getY(2); point.set(x / 3, y / 3); }
From source file:Main.java
static void midPointOfEvent(PointF point, MotionEvent event) { if (event.getPointerCount() == 2) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); }//from w w w.j a va 2 s .c o m }
From source file:Main.java
public static void barrelDistortion(double paramA, double paramB, double paramC, PointF src) { double paramD = 1.0 - paramA - paramB - paramC; // describes the linear scaling of the image float d = 1.0f; // center of dst image double centerX = 0f; double centerY = 0f; if (src.x == centerX && src.y == centerY) { return;/*from ww w . j av a2 s . c om*/ } // cartesian coordinates of the destination point (relative to the centre of the image) double deltaX = (src.x - centerX) / d; double deltaY = (src.y - centerY) / d; // distance or radius of dst image double dstR = Math.sqrt(deltaX * deltaX + deltaY * deltaY); // distance or radius of src image (with formula) double srcR = (paramA * dstR * dstR * dstR + paramB * dstR * dstR + paramC * dstR + paramD) * dstR; // comparing old and new distance to get factor double factor = Math.abs(dstR / srcR); // coordinates in source image float xResult = (float) (centerX + (deltaX * factor * d)); float yResult = (float) (centerY + (deltaY * factor * d)); src.set(xResult, yResult); }
From source file:com.android.view.leg.ImageDetailFragmentLeg.java
private void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); }
From source file:com.windnow.StationPicActivity.java
@SuppressLint("NewApi") @Override/* ww w. j a va 2s . co m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_station_pic); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { getActionBar().setDisplayHomeAsUpEnabled(true); } TextView tv = (TextView) findViewById(R.id.textViewPicName); tv.setText(getIntent().getExtras().getString("name")); imageDetail = (ImageView) findViewById(R.id.imageView1); String filename = "pic" + getIntent().getExtras().getString("txt").hashCode(); Bitmap pic = null; try { FileInputStream is = this.openFileInput(filename); pic = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { LoadSaveOps.printErrorToLog(e); } imageDetail.setImageBitmap(pic); imageDetail.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: savedMatrix.set(matrix); startPoint.set(event.getX(), event.getY()); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(midPoint, event); mode = ZOOM; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { matrix.set(savedMatrix); matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); } else if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; matrix.postScale(scale, scale, midPoint.x, midPoint.y); matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); //new } } break; } view.setImageMatrix(matrix); return true; } @SuppressLint("FloatMath") private float spacing(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return FloatMath.sqrt(x * x + y * y); } private void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); } }); }