Rumors on the web that HTC's Hero-rom support for multi-touch are mostly rooted in the ability to control the size of a page by gestures, like the iphone, when browsing Web pages and images. The following example is the use of the existing API to achieve Hero Browsing pictures and Web page zoom function.
The main principle is the parameter Motionevent in the Ontouchevent event, which has a getsize () method. At one point, the method always returns 0, and when two is electrocuted, the method returns different values based on the relative position of two points. We only need to figure out the distance between two points, the size of the distance indicates the trend we want to change the target. The Getx () and Gety () methods are always located between the two contacts, so we have both the trend and the target. The rest is to enlarge or shrink the target according to the trend.
Copy Code code as follows:
/**
* ...
*
* @author Vlinux
*
*/
public class Multitouchtestactivity extends activity {
/** called the activity is a. */
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
View view = new Multitouchview (this);
Setcontentview (view);
}
Class Multitouchview extends View {
private float x1;
private float Y1;
private float x2;
private float y2;
Public Multitouchview {
Super (context);
TODO auto-generated Constructor stub
}
@Override
public boolean ontouchevent (Motionevent event) {
TODO auto-generated Method Stub
Float size = event.getsize ();
int szi = (int) size;
int dxi = Szi >> 12;
int dyit = ((1 << 12)-1);
int dyi = Szi & dyit;
Displaymetrics metrics = getresources (). Getdisplaymetrics ();
FLOAT dx = metrics.widthpixels * DXi/(float) dyit;
float dy = metrics.heightpixels * Dyi/(float) dyit;
X1 = Event.getx ();
Y1 = Event.gety ();
x2 = x1 + dx;
y2 = y1 + dy;
Invalidate ();
return true;
}
@Override
protected void OnDraw (Canvas Canvas) {
TODO auto-generated Method Stub
Super.ondraw (canvas);
float R = (float) math.sqrt ((x1-x2) * (X1-X2) + (Y1-Y2)
* (Y1-Y2))/2;
R = >= r? 50:r;
Paint Paint = new Paint ();
Paint.setcolor (Color.Blue);
Canvas.drawcircle (x1, y1, R, Paint);
}
}
}