List of usage examples for android.graphics Matrix mapPoints
public void mapPoints(float[] pts)
From source file:Main.java
/** Convert coordination of face point to screen rect that will be draw on canvas<br> */ public static List<Point> convertFacePoint(boolean frontCamera, float displayOrientation, float viewWidth, float viewHeight, Point... points) { Matrix matrix = createConvertMatrix(frontCamera, displayOrientation, viewWidth, viewHeight); float[] pts = new float[points.length * 2]; for (int i = 0; i < points.length; ++i) { pts[i * 2] = points[i].x;//from w w w.j a va 2 s . c om pts[i * 2 + 1] = points[i].y; } matrix.mapPoints(pts); List<Point> result = new LinkedList<>(); for (int j = 0; j < pts.length; j += 2) { result.add(new Point((int) pts[j], (int) pts[j + 1])); } return result; }
From source file:Main.java
/** * Inverse of {@link #getDescendantCoordRelativeToSelf(View, int[])}. *///w ww .j a va 2s. c o m public static float mapCoordInSelfToDescendent(View descendant, View root, int[] coord) { ArrayList<View> ancestorChain = new ArrayList<View>(); float[] pt = { coord[0], coord[1] }; View v = descendant; while (v != root) { ancestorChain.add(v); v = (View) v.getParent(); } ancestorChain.add(root); float scale = 1.0f; Matrix inverse = new Matrix(); int count = ancestorChain.size(); for (int i = count - 1; i >= 0; i--) { View ancestor = ancestorChain.get(i); View next = i > 0 ? ancestorChain.get(i - 1) : null; pt[0] += ancestor.getScrollX(); pt[1] += ancestor.getScrollY(); if (next != null) { pt[0] -= next.getLeft(); pt[1] -= next.getTop(); next.getMatrix().invert(inverse); inverse.mapPoints(pt); scale *= next.getScaleX(); } } coord[0] = (int) Math.round(pt[0]); coord[1] = (int) Math.round(pt[1]); return scale; }
From source file:com.abct.tljr.news.widget.ZoomableImageView.java
static private void translatePoint(Matrix matrix, float[] xy) { matrix.mapPoints(xy); }
From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java
static protected void translatePoint(Matrix matrix, float[] xy) { matrix.mapPoints(xy); }
From source file:Main.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount; i++) { xy[2 * i] = pointerCoords[i].x;/*from w ww. ja v a 2 s . co m*/ xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount; i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
From source file:Main.java
private static MotionEvent transformEventOld(MotionEvent e, Matrix m) { long downTime = e.getDownTime(); long eventTime = e.getEventTime(); int action = e.getAction(); int pointerCount = e.getPointerCount(); int[] pointerIds = getPointerIds(e); PointerCoords[] pointerCoords = getPointerCoords(e); int metaState = e.getMetaState(); float xPrecision = e.getXPrecision(); float yPrecision = e.getYPrecision(); int deviceId = e.getDeviceId(); int edgeFlags = e.getEdgeFlags(); int source = e.getSource(); int flags = e.getFlags(); // Copy the x and y coordinates into an array, map them, and copy back. float[] xy = new float[pointerCoords.length * 2]; for (int i = 0; i < pointerCount; i++) { xy[2 * i] = pointerCoords[i].x;/* w ww . j a v a 2 s .com*/ xy[2 * i + 1] = pointerCoords[i].y; } m.mapPoints(xy); for (int i = 0; i < pointerCount; i++) { pointerCoords[i].x = xy[2 * i]; pointerCoords[i].y = xy[2 * i + 1]; pointerCoords[i].orientation = transformAngle(m, pointerCoords[i].orientation); } MotionEvent n = MotionEvent.obtain(downTime, eventTime, action, pointerCount, pointerIds, pointerCoords, metaState, xPrecision, yPrecision, deviceId, edgeFlags, source, flags); return n; }
From source file:Main.java
/** * Maps a coordinate in the root to a descendent. *//*from w w w . ja va 2s . c om*/ public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord, Matrix tmpInverseMatrix) { ArrayList<View> ancestorChain = new ArrayList<View>(); float[] pt = { coord[0], coord[1] }; View v = descendant; while (v != root) { ancestorChain.add(v); v = (View) v.getParent(); } ancestorChain.add(root); float scale = 1.0f; int count = ancestorChain.size(); tmpInverseMatrix.set(IDENTITY_MATRIX); for (int i = count - 1; i >= 0; i--) { View ancestor = ancestorChain.get(i); View next = i > 0 ? ancestorChain.get(i - 1) : null; pt[0] += ancestor.getScrollX(); pt[1] += ancestor.getScrollY(); if (next != null) { pt[0] -= next.getLeft(); pt[1] -= next.getTop(); next.getMatrix().invert(tmpInverseMatrix); tmpInverseMatrix.mapPoints(pt); scale *= next.getScaleX(); } } coord[0] = pt[0]; coord[1] = pt[1]; return scale; }
From source file:Main.java
/** * Maps a coordinate in the root to a descendent. *///from w w w . ja v a 2 s. co m public static float mapCoordInSelfToDescendent(View descendant, View root, float[] coord, Matrix tmpInverseMatrix) { ArrayList<View> ancestorChain = new ArrayList<>(); float[] pt = { coord[0], coord[1] }; View v = descendant; while (v != root) { ancestorChain.add(v); v = (View) v.getParent(); } ancestorChain.add(root); float scale = 1.0f; int count = ancestorChain.size(); tmpInverseMatrix.set(IDENTITY_MATRIX); for (int i = count - 1; i >= 0; i--) { View ancestor = ancestorChain.get(i); View next = i > 0 ? ancestorChain.get(i - 1) : null; pt[0] += ancestor.getScrollX(); pt[1] += ancestor.getScrollY(); if (next != null) { pt[0] -= next.getLeft(); pt[1] -= next.getTop(); next.getMatrix().invert(tmpInverseMatrix); tmpInverseMatrix.mapPoints(pt); scale *= next.getScaleX(); } } coord[0] = pt[0]; coord[1] = pt[1]; return scale; }
From source file:osm.custommaps.create.PreviewMapActivity.java
private IGeoPoint imageToGeoPoint(Matrix converter, Point imagePoint) { float[] coords = new float[] { imagePoint.x, imagePoint.y }; converter.mapPoints(coords); return new GeoPoint(Math.round(coords[1] * 1E6f), Math.round(coords[0] * 1E6f)); }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
public float[][] getSceneBounds(Matrix viewportTransformation) { float[] point = { 0.0f, 0.0f }; // map reference point to screen coordinate system viewportTransformation.mapPoints(point); // set min/max to reference position float[][] minMaxXY = { { point[0], point[1] }, { point[0], point[1] } }; // two points: minXY and maxXY synchronized (GlobalData.audioScene) { int numSources = GlobalData.audioScene.getNumSoundSources(); SoundSource s = null;/* www . j a v a2 s . c om*/ for (int i = 0; i < numSources; i++) { s = GlobalData.audioScene.getSoundSource(i); point[0] = s.getX(); point[1] = s.getY(); // map to reference coordinate system GlobalData.audioScene.mapPoint(point); viewportTransformation.mapPoints(point); // check if point lies outwards current bounds if (point[0] < minMaxXY[0][0]) minMaxXY[0][0] = point[0]; if (point[0] > minMaxXY[1][0]) minMaxXY[1][0] = point[0]; if (point[1] < minMaxXY[0][1]) minMaxXY[0][1] = point[1]; if (point[1] > minMaxXY[1][1]) minMaxXY[1][1] = point[1]; } } return minMaxXY; }