Try putting a short sleep into your onTouchEvent handler, about 16ms
is good.  If I remember correctly (from previous posts in this forum)
your app is getting hammered by all the Touch events, they are coming
much more frequently than the maximum possible screen refresh/redraw
rate.

--
RichardC

On Oct 18, 4:56 am, Dianne Hackborn <[email protected]> wrote:
> The move event you receive contains as close as possible to the most recent
> location (it is retrieved immediately before dispatching to the app).
> You don't say how much lag you are seeing, so it is hard to offer advice --
> is it more laggy than in other standard parts of the UI like list views?  Is
> it the same?  If it is the same, this is probably just a lower-level
> characteristic of the device -- there can be a lot of filtering/processing
> going on in the touch firmware to generate clean points, for example.
>
> If the lag you are seeing is worse than the rest of the UI, it most likely
> is an issue in your app, unrelated to the simple dispatching code here.
>  Perhaps some part of the drawing is very slow, etc.  You could try
> profiling it to see what is going on.
>
>
>
> On Sat, Oct 17, 2009 at 8:04 PM, Matt Hall <[email protected]> wrote:
>
> > Hi everyone,
>
> > I noticed when developing on an HTC Magic (G2) that when moving your
> > finger on the screen the location of the touch events trail your
> > finger pretty significantly. To test this I wrote a very simple app
> > that just draws a rectangle where you're touching. Even in this simple
> > case the rectangle can trail the finger on screen by a fair amount.
> > Here's the View that handles the touches and draws the rectangle:
>
> > public class TouchTestView extends View {
> >    private float x;
> >    private float y;
> >    private Paint paint = new Paint();
> >    public static final int SIZE = 40;
>
> >    public TouchTestView(Context context) {
> >        super(context);
> >        paint.setColor(Color.RED);
> >    }
>
> >   �...@override
> >    public boolean onTouchEvent(MotionEvent event) {
> >        switch (event.getAction()) {
> >            case MotionEvent.ACTION_DOWN:
> >                x = event.getX();
> >                y = event.getY();
> >                invalidate();
> >                return true;
> >            case MotionEvent.ACTION_MOVE:
> >                x = event.getX();
> >                y = event.getY();
> >                invalidate();
> >                return true;
> >            case MotionEvent.ACTION_UP:
> >                x = -1;
> >                y = -1;
> >                invalidate();
> >                return true;
> >        }
> >        return super.onTouchEvent(event);
> >    }
>
> >   �...@override
> >    protected void onDraw(Canvas canvas) {
> >        canvas.drawRect(x - SIZE, y - SIZE, x + SIZE, y + SIZE,
> > paint);
> >    }
> > }
>
> > So my question is: Is there a significant built in time delay between
> > the generation of the touch event and it's reception in the running
> > activity? If so, is there any tricks or methods to get those events in
> > a faster or more direct way? In our application the delay is causing
> > some pretty unfortunate performance results.
>
> > Thanks for any advice or help,
> > Matt
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to