You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is some sample code which would be much easier to understand
/**
* PhotoSorterView.java
*
* (c) Luke Hutchison ([email protected])
*
* TODO: Add OpenGL acceleration.
*
* Released under the Apache License v2.
*/
package eksempler.multitouch;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
import eksempler.multitouch.MultiTouchController;
import eksempler.multitouch.MultiTouchController.MultiTouchObjectCanvas;
import eksempler.multitouch.MultiTouchController.PointInfo;
import eksempler.multitouch.MultiTouchController.PositionAndScale;
import org.simpla.R;
public class Multitouch0View extends View implements MultiTouchObjectCanvas {
private MultiTouchController multiTouchController = new MultiTouchController(this);
private PointInfo currTouchPoints = new PointInfo();
private Paint mLinePaintTouchPointCircle = new Paint();
private Bitmap img;
private float x = 100;
private float y = 100;;
private float scale = 1;
private float angle = 0;
// ---------------------------------------------------------------------------------------------------
public Multitouch0View(Context context) {
super(context);
img = BitmapFactory.decodeResource(getResources(), R.drawable.car);
mLinePaintTouchPointCircle.setColor(Color.YELLOW);
mLinePaintTouchPointCircle.setStrokeWidth(5);
mLinePaintTouchPointCircle.setStyle(Style.STROKE);
mLinePaintTouchPointCircle.setAntiAlias(true);
setBackgroundColor(Color.BLACK);
}
// ---------------------------------------------------------------------------------------------------
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.scale(scale, scale, x, y);
canvas.rotate(angle * 180.0f / (float) Math.PI, x, y);
canvas.drawBitmap(img, x, y, null);
canvas.restore();
drawMultitouchDebugMarks(canvas);
}
// ---------------------------------------------------------------------------------------------------
private void drawMultitouchDebugMarks(Canvas canvas) {
if (currTouchPoints.isDown()) {
float[] xs = currTouchPoints.getXs();
float[] ys = currTouchPoints.getYs();
float[] pressures = currTouchPoints.getPressures();
int numPoints = currTouchPoints.getNumTouchPoints();
for (int i = 0; i < numPoints; i++)
canvas.drawCircle(xs[i], ys[i], 50 + pressures[i] * 80, mLinePaintTouchPointCircle);
if (numPoints == 2)
canvas.drawLine(xs[0], ys[0], xs[1], ys[1], mLinePaintTouchPointCircle);
}
}
// ---------------------------------------------------------------------------------------------------
/** Pass touch events to the MT controller */
@Override
public boolean onTouchEvent(MotionEvent event) {
return multiTouchController.onTouchEvent(event);
}
/** Get the image that is under the single-touch point, or return null (canceling the drag op) if none */
public Object getDraggableObjectAtPoint(PointInfo pt) {
return this;
}
/**
* Select an object for dragging. Called whenever an object is found to be under the point (non-null is returned by getDraggableObjectAtPoint())
* and a drag operation is starting. Called with null when drag op ends.
*/
public void selectObject(Object obj, PointInfo touchPoint) {
currTouchPoints.set(touchPoint);
invalidate();
}
/** Get the current position and scale of the selected image. Called whenever a drag starts or is reset. */
public void getPositionAndScale(Object obj, PositionAndScale objPosAndScaleOut) {
objPosAndScaleOut.set(x, y, true, scale, false, scale, scale, true, angle);
}
/** Set the position and scale of the dragged/stretched image. */
public boolean setPositionAndScale(Object obj, PositionAndScale newPosAndScale, PointInfo touchPoint) {
currTouchPoints.set(touchPoint);
x = newPosAndScale.getXOff();
y = newPosAndScale.getYOff();
scale = newPosAndScale.getScale();
angle = newPosAndScale.getAngle();
invalidate();
return true;
}
}
Original issue reported on code.google.com by jacob.nordfalk on 13 Dec 2010 at 12:35
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
jacob.nordfalk
on 13 Dec 2010 at 12:35The text was updated successfully, but these errors were encountered: