Package com. cardroid. layer;
Import Android. content. context;
Import Android. Graphics. Bitmap;
Import Android. Graphics. bitmapfactory;
Import Android. Graphics. camera;
Import Android. Graphics. Canvas;
Import Android. Graphics. matrix;
Import Android. View. motionevent;
Import Android. View. view;
Public class cameradraw extends view {
Private context;
Private bitmap showbmp;
Private matrix; // Action Matrix
Private camera;
Private int deltax, deltay; // flip angle difference
Private int centerx, centery; // image center point
Public cameradraw (context ){
Super (context );
This. Context = context;
Initdata ();
}
Private void initdata (){
Showbmp = bitmapfactory. decoderesource (context. getresources (), R. drawable. bg );
Centerx = showbmp. getwidth ()/2;
Centery = showbmp. getheight ()/2;
Matrix = new matrix ();
Camera = new camera ();
}
Int lastmousex;
Int lastmousey;
@ Override
Public Boolean dispatchtouchevent (motionevent event ){
Int x = (INT) event. getx ();
Int y = (INT) event. Gety ();
Switch (event. getaction ()){
Case motionevent. action_down:
Lastmousex = X;
Lastmousey = y;
Break;
Case motionevent. action_move:
Int dx = x-lastmousex;
Int DY = Y-lastmousey;
Deltax + = DX;
Deltay + = Dy;
Break;
}
Invalidate ();
Return true;
}
@ Override
Protected void ondraw (canvas ){
Camera. Save ();
// Flip around the X axis
Camera. rotatex (-deltay );
// Flip around the Y axis
Camera. rotatey (deltax );
// Sets the camera role matrix.
Camera. getmatrix (matrix );
Camera. Restore (); // mainly obtains the size of the flip matrix.
// Set the flip Center
Matrix. pretranslate (-This. centerx,-This. centery );
Matrix. posttranslate (this. centerx, this. centery );
Canvas. drawbitmap (showbmp, matrix, null );
}
}
Public class layerdraw extends activity {
/** Called when the activity is first created .*/
Private imageview mimageview;
Private textview tview;
Private cameradraw carmeracameradraw;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Carmeracameradraw = new cameradraw (this );
// Setcontentview (R. layout. Main );
Setcontentview (carmeracameradraw );
// Mimageview = (imageview) findviewbyid (R. Id. Image );
// Tview = (textview) findviewbyid (R. Id. TV );
// Setimage ();
}