lukehutch / android-multitouch-controller Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/android-multitouch-controller
Automatically exported from code.google.com/p/android-multitouch-controller
pbourke discovered that if you have pt 1 & 2 down and bring them close
together, they merge into one point, and then MTVisualizer thinks there are 0
points down (you can keep moving pts 1 & 2 and the screen looks like no points
are down).
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:47
import
org.metalev.multitouch.controller.MultiTouchController.MultiTouchObjectCanvas;
import org.metalev.multitouch.controller.MultiTouchController.PointInfo;
import org.metalev.multitouch.controller.MultiTouchController.PositionAndScale;
??? Where ???
Original issue reported on code.google.com by [email protected]
on 26 Sep 2011 at 11:00
Hi there, first of all sorry for double post..., second, thank you for the app :)
I wonder how can I change your code to support multi touch simultaneously for several users, in other words users can zoom, rotate and drag several image simultaneously.
you are using the history of every touch event in your app, how can we use the specific history for every image object in multi touch canvas? is this a good idea??
Hi. By analogy with this:
private MultiTouchController<PinchWidgetType> multiTouchController = new MultiTouchController<PinchWidgetType>(this);
, I'm trying to declare a variable in the activity:
View view = findViewById(R.id.view);
multiTouchController = new MultiTouchController<View>(view);
But I get the error : incompatible types: The view cannot be converted to MultiTouchObjectCanvas.
What am I doing wrong?
Are there any examples of manipulating text using this library? Instead of creating a drawable, could you not generate a TextView programmatically and then manipulate it with the available multi-touch controller? Just wondering if there are any existing examples or if anyone knows of anything specifically so that I know it's worth working on this... Thanks!
Hi,
thanks for project.I want to use it in my project.
I should be change images in canvas. To do this I set IMG object in my array and then load again. But I realize that when I do that the code dont undestand which image is where if I drag photo before.
If I dont drag any photo it is work properly. I change photo in canvas.(make category of photo and change photo in same category)
But if I drag photo and then change my array and load it mix the position of photos?
How can solve this issue?
thanks in advance
MultiTouchController.java:
public class MultiTouchController<T> {
...
float mStartAbsoluteAng; // <----------
...
private void anchorAtThisPositionAndScale() {
...
/* add at the end of the function */
mStartAbsoluteAng = mCurrXform.angle; // <----------
}
...
private void performDragOrPinch() {
/* Don't do anything if we're not dragging anything*/
if (selectedObject == null)
return;
/* Calc new position of dragged object*/
float currScale = !mCurrXform.updateScale ? 1.0f : mCurrXform.scale == 0.0f ? 1.0f : mCurrXform.scale;
extractCurrPtInfo();
float newPosX = mCurrPtX - startPosX * currScale;
float newPosY = mCurrPtY - startPosY * currScale;
float newScale = startScaleOverPinchDiam * mCurrPtDiam;
float newScaleX = startScaleXOverPinchWidth * mCurrPtWidth;
float newScaleY = startScaleYOverPinchHeight * mCurrPtHeight;
float newAngle = startAngleMinusPinchAngle + mCurrPtAng;
/*
* Fix: Rotation relative to the midpoint start
*/
float[] deltaPosition = new float[2];
deltaPosition[0] = newPosX - mCurrPtX;
deltaPosition[1] = newPosY - mCurrPtY;
float deltaAngle = newAngle - mStartAbsoluteAng;
float[] deltaRotate = new float[2];
deltaRotate[0] = (float)( deltaPosition[0] * Math.cos(deltaAngle)) -
(float) ( deltaPosition[1] * Math.sin(deltaAngle));
deltaRotate[1] = (float)( deltaPosition[0] * Math.sin(deltaAngle)) +
(float) ( deltaPosition[1] * Math.cos(deltaAngle));
newPosX = mCurrPtX + deltaRotate[0];
newPosY = mCurrPtY + deltaRotate[1];
/*
* Fix: Rotation relative to the midpoint end
*/
// Set the new obj coords, scale, and angle as appropriate (notifying the subclass of the change).
mCurrXform.set(newPosX, newPosY, newScale, newScaleX, newScaleY, newAngle);
boolean success = objectCanvas.setPositionAndScale(selectedObject, mCurrXform, mCurrPt);
if (!success)
; // If we could't set those params, do nothing currently
}
...
}
Hi,
This code works fine, but i have load image from server instead of resource.
Is it possible? if yes plz provide some hint or guideline.
Thanks.
Original issue reported on code.google.com by [email protected]
on 22 Apr 2013 at 5:10
When pinch-rotating images in MTPhotoSortrDemo, they rotate around the center
of the image, not around the center of the pinch. Reported by Ralf (mr_roots).
The short-term solution is to figure out where the pinch center is within the
image when a pinch operation starts, then "pin" the center of the pinch to this
location, and rotate the image center position about this point.
The best long-term / general-purpose solution is to implement full affine
homogeneous matrices for all operations. However, this is slower, and it then
gets more complicated to extract transform parameters in simpler use cases,
such as when just the pinch distance and center is needed.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:34
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
If the touch up/down state changes and the remaining/new points don't move, the
screen appears to have lost one or more points: if pt 1 is down, and pt 2 is
added precisely without moving either point, the visualizer won't display pt 2
until you actually move pt 2.
Alternatively, with pt 1 & 2 down, lift pt 2 without moving pt 1. It will look
like there are no points down until pt 1 is moved.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:47
Paul Bourke extended the MTController code to handle single-finger drags, as
well creating a couple of new generic canvas object classes:
git://github.com/brk3/android-multitouch-controller.git
I think a couple of changes need to be made before merging (see my comments in
the current MultiTouchController.java hosted here), but this is a useful
capability.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:57
(Bug originally filed by [email protected] when MTVisualizer was in a
separate project.)
What steps will reproduce the problem?
1. sync source
2. insert <uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="15" /> above the <application>
3. compile
4. install & ran on galaxy nexus
What is the expected output? What do you see instead?
I expect it to run just as the version you released runs, but using the Holo
theme. The outcome is an extremely laggy experience, along with trouble
detecting multiple moving points, the the beautiful holo theme.
What version of the product are you using? On what operating system?
android 4.0.2, verizon galaxy nexus LTE (stock firmware)
Please provide any additional information below.
The only change to the app was the target sdk version, and minimum sdk version.
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.metalev.multitouch.visualizer2" android:versionName="2.2.2"
android:versionCode="13">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="false">
<activity android:name=".MultiTouchVisualizerActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
I would like to add, the same code works fine on a stock nexus s 4.0.3
While android:targetSdkVersion 14 & 15 produce the lag, anything below 13 does
not.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 3:00
onResume();
The images to be in the same position. Instead they move to a new position.
The latest version. Windows 8.
My app does not need to rotate the screen orientation. It is always portrait. I
am using your PhotoSortrView class and modifying it for my app. Can I locate
and disable your rotation method so that within PhotoSortrView.load(), it will
successfully keep the images in the same position? Thanks.
Original issue reported on code.google.com by [email protected]
on 12 Jan 2014 at 11:48
Request from Yuan Chin: provide individual setters in PointInfo class so that
you don't have to set all fields on every frame. Some apps only want to update
some params on some operations (e.g. to deal with translation but not scale).
My reply: Yes, I actually had about six set() methods before I committed the
new version with more params, I thought it was cleaner but I guess that's not
true on a per-app basis. The problem is that if you have a separate set() for
position, angle and scale, the controller doesn't know if you're no longer
updating one of those -- e.g. if you switch from rotation mode to scale mode.
What really needs to happen is that the PointInfo object needs to be notified
when there's a new MotionEvent, and it needs to reset its updatingAngle etc.
fields. But I don't know a clean way to do that, so I have the user specify it
every time. I'll keep thinking about it.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:52
What steps will reproduce the problem?
1.
2.
3.
pls change
package="org.metalev.multitouch.photosorter">
to
package="org.metalev.multitouch.photosortr">
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue reported on code.google.com by jacob.nordfalk
on 14 Sep 2010 at 1:36
How can i apply flip animation on single photo?
i tried to apply animation, but it apply on whole canvas(photoSortrView).
Plz help to apply animation on single photo.
Thanks.
Original issue reported on code.google.com by [email protected]
on 5 Jun 2013 at 7:21
If the user pinch-zooms or drags outside of an individual image in the photo
sorter demo, the whole canvas should be zoomed/panned, not just individual
photos.
This will require another coordinate system transform, and separate
restrictions on what sorts of operations are valid on the canvas and on objects
on the canvas (e.g. maybe the canvas can't be rotated, but objects can).
Original issue reported on code.google.com by luke.hutch
on 30 Apr 2013 at 4:30
TODO: Figure out if it makes sense refactoring this code to extend Android's
own multitouch gesture detector class.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:50
Zac Livesay's suggestion: implement fullscreen mode where there is no app
titlebar, so that whole screen can be tested.
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:52
Hey i modified the code a little bit by including an xml file and including
the custom view and a button inside the
xml file and set this xml file in secontent view of the photosotr activity file
and the on click method of the button i have called the
photoSorter.loadImages(this); , in the on draw method i have set a flag that
will make sure that images get drawn after button is clicked and not when the
activity goes to its on resume state
i have included the modified code and the xml
.THE ISSUE
1)once the button is clicked the images are not loaded automatically but instead shown when i touch the screen once or twice
2) when i come i get an error
at org.metalev.multitouch.photosortr.ImageEntity.draw(ImageEntity.java:59)
at org.metalev.multitouch.photosortr.PhotoSortrView.onDraw(PhotoSortrView.java:129)
Original issue reported on code.google.com by [email protected]
on 21 Nov 2013 at 7:35
Attachments:
Mickael Despesse's suggestion:
I had another idea to improve MultitouchControler yesterday, I don't know if
you think the right place to implement it is in your controler or in user's
code, but as this controler is a helper, it could make sense. Now that there is
rotation management, if user wants to use it, there is one drawack : as soon as
there are 2 fingers down, scale and rotation are enabled at the same time.
Let's say the user just wants to resize an object, it's very difficult
(/impossible) without rotating it a little bit. What could be done is to set a
minimum angle offset before we start applying rotation to PositionAndScale
object (the same could also be done for moving/rezing, as in the android home :
it starts moving from one desktop screen to another only if finger moved more
than ViewConfiguration.getTouchSlop() pixels).
Original issue reported on code.google.com by luke.hutch
on 22 Apr 2012 at 4:49
What steps will reproduce the problem?
1. Tried to change the canvas drawing, storing, and modifying it
2. Tried to change the Bitmap
3. Tried to remake the multiController object.
What is the expected output? What do you see instead?
To change the initial image
Please provide any additional information below.
Is there a way to do this_
Original issue reported on code.google.com by [email protected]
on 16 Nov 2011 at 6:51
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.