Draw in Canvas by finger, Android

Start By going through the Fingerpaint demo in the sdk sample. Another Sample: public class MainActivity extends Activity { DrawingView dv ; private Paint mPaint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); dv = new DrawingView(this); setContentView(dv); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12); } public class DrawingView extends View { … Read more

How do I simulate a hover with a touch in touch enabled browsers?

OK, I’ve worked it out! It involves changing the CSS slightly and adding some JS. Using jQuery to make it easy: $(document).ready(function() { $(‘.hover’).on(‘touchstart touchend’, function(e) { e.preventDefault(); $(this).toggleClass(‘hover_effect’); }); }); In english: when you start or end a touch, turn the class hover_effect on or off. Then, in your HTML, add a class hover … Read more

android: move a view on touch move (ACTION_MOVE)

I’ve found an easy approach to do that with the ViewPropertyAnimator: float dX, dY; @Override public boolean onTouch(View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: dX = view.getX() – event.getRawX(); dY = view.getY() – event.getRawY(); break; case MotionEvent.ACTION_MOVE: view.animate() .x(event.getRawX() + dX) .y(event.getRawY() + dY) .setDuration(0) .start(); break; default: return false; } return … Read more

Android ImageView Scaling and translating issue

this is a working example of two fingers move/scale/rotate (note: the code is quite short due to smart detector used – see MatrixGestureDetector): class ViewPort extends View { List<Layer> layers = new LinkedList<Layer>(); int[] ids = {R.drawable.layer0, R.drawable.layer1, R.drawable.layer2}; public ViewPort(Context context) { super(context); Resources res = getResources(); for (int i = 0; i < … Read more