Rotation is not smooth ,can someone help me.
Drag left to right for clockwise rotation 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package R.com;



import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

public class RActivity extends Activity implements OnTouchListener {
	/** Called when the activity is first created. */
	Matrix matrix = new Matrix();
	ImageView imageView;
	double downx = 0, downy = 0, upx = 0, upy = 0;
	LinearLayout llLayout;
	float scaleHeight=0;
	float scaleWidth=0;
	  protected double dw;
	    protected double dh;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main);
		imageView = (ImageView) findViewById(R.id.imageView1);	
		View contentView = (View) findViewById(R.id.llayout);
		contentView.setOnTouchListener((View.OnTouchListener) this);
		Display currentDisplay = getWindowManager().getDefaultDisplay();		  
	    dw = currentDisplay.getWidth(); 
	    dh = currentDisplay.getHeight(); 
		
	}

	@Override
	public boolean onTouch(View arg0, MotionEvent event) {
		// TODO Auto-generated method stub
		
		double angle = 0;

		Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
				R.drawable.icon);
		int width = bitmapOrg.getWidth();
		int height = bitmapOrg.getHeight();
		Bitmap resizedBitmap;
		BitmapDrawable bmd;


		int action = event.getAction();

		
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			downx = event.getX();
			downy = event.getY();
			
			break;
		case MotionEvent.ACTION_MOVE:

			upx = event.getX();
			upy = event.getY();
			//Toast.makeText(this, ""+upx, Toast.LENGTH_SHORT).show();
			//Toast.makeText(this, ""+upy, Toast.LENGTH_SHORT).show();
			double diff=(upy-downy)+(upx-downx);					
			if(diff>0)
			angle = 3+Math.atan((downy - upy) / (downx - upx));
			else
				angle = Math.atan((downy - upy) / (downx - upx))-2;
			Toast.makeText(this, ""+angle, Toast.LENGTH_SHORT).show();
			
			matrix.postRotate((float) angle);
			resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);
			bmd = new BitmapDrawable(resizedBitmap);

			imageView.setImageDrawable(bmd);
				
			break;
		case MotionEvent.ACTION_UP:

			upx = event.getX();
			upy = event.getY();
					break;

		}
	

		return true;
	}
	
}

Reply via email to