Problem is not yet resolved :( I'm able to draw my bitmaps in a continuous path, but the rendering is very slow.
I am taking history points of a motion event into account but these also do not give me all the points. I'm introducing more points if the distance between 2 history points is greater than say 10. Number of points depend on the distance between two history points and the radius of the bitmap to be drawn. Radius of bitmap can vary between 2x2 and 30x30. There are considerable lags if these many bitmaps are drawn and if I reduce the number of points, the curve is not smooth. There is bug reported in the android bug base: http://code.google.com/p/android/issues/detail?id=1740 Could it be because of the same reason? Is there a better way of doing it? Is it possible to improve performance using a canvas? On Sep 19, 11:14 am, "[email protected]" <[email protected]> wrote: > Historical data for motion events helped! Thank you Blake! > > On Sep 19, 9:05 am, "[email protected]" <[email protected]> wrote: > > > Will it not just move the element as I move my finger on the screen. I > > want to draw the element at all positions where my finger has touched > > so that I can see a continuous drawing. > > > Let me know if I have misunderstood. > > > On Sep 19, 3:03 am, Dianne Hackborn <[email protected]> wrote: > > > > You don't need the history to do smooth tracking. The history gives you > > > all > > > of the points between this in the last motion event... but when tracking > > > you always want to show your object at the most recent reported position, > > > so > > > the history is irrelevant. > > > > The problem with the code is that it is trying to draw in to mCanvas > > > directly. The view hierarchy is update-based; you need to update the > > > state > > > and then invalidate the view drawing it to show the new state. Even if > > > you > > > could draw to the Canvas outside of an update, the code here would be > > > broken > > > because it would just leave a trail of bitmaps drawn at various positions > > > without erasing the previous one. (Though I guess it is doing an > > > invalidate() after drawing the bitmap, so you'd end up with the bitmap > > > being > > > briefly drawn and then erased as the invalidate is executed.) > > > > Anyway, just store the new position of the bitmap, call invalidate(), and > > > then in your onDraw() draw the bitmap at the current position. > > > > On Sun, Sep 18, 2011 at 7:20 AM, blake <[email protected]> wrote: > > > > If you look at the sample code in the Google documents you'll see that > > > > motion events have history. You'll need to use it to get a smooth > > > > trace > > > > -Blake > > > > Programming Android, FTW > > > > > On Sep 18, 5:20 am, "[email protected]" <[email protected]> wrote: > > > > > I want to let a user smoothly draw elements with his finger and avoid > > > > > any lags as follows: > > > > > > public boolean onTouchEvent(MotionEvent event) { > > > > > float x = event.getX(); > > > > > float y = event.getY(); > > > > > > switch (event.getAction()) { > > > > > case MotionEvent.ACTION_DOWN: > > > > > mCanvas.drawBitmap(primitive, x, y, > > > > mPaint); > > > > > > invalidate(); > > > > > break; > > > > > case MotionEvent.ACTION_MOVE: > > > > > mCanvas.drawBitmap(primitive, x, y, > > > > mPaint); > > > > > > invalidate(); > > > > > break; > > > > > case MotionEvent.ACTION_UP: > > > > > mCanvas.drawBitmap(primitive, x, y, > > > > mPaint); > > > > > > invalidate(); > > > > > break; > > > > > } > > > > > return true; > > > > > } > > > > > } > > > > > > Using android SDK I find onTouchEvent is not called for every motion > > > > > event. This results in drawing of a bitmap only at the points when the > > > > > motion event is detected. > > > > > > I can do this very easily using iPhone SDK . Can anyone confirm if > > > > > this is a limitation in Android or if there is a way we can increase > > > > > the rate of motion events? > > > > > -- > > > > 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 > > > > -- > > > Dianne Hackborn > > > Android framework engineer > > > [email protected] > > > > Note: please don't send private questions to me, as I don't have time to > > > provide private support, and so won't reply to such e-mails. All such > > > questions should be posted on public forums, where I and others can see > > > and > > > answer them. > > -- 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

