tags:

views:

438

answers:

2

Hi

I want to move an image around the screen according to the trackball movement. I am able to capture the movements using the onTrackballEvent method. But this is being called for very small float values (I believe for each rotation?) of the trackball.

Now as X and Y positions of views should be integers when specifying with LayoutParams, it makes no sense to move the view with every rotation. Instead I want to move the view only after the user stops rotating the trackball.

Is there any method by which we can get whether the user stopped using the trackball or not?

Thanks.

+1  A: 

If there isn't (I don't know Android), the classic approach is to start a timer in each event, and keep track of the deltas reported in it (by adding them to a running sum, one for X and one for Y). On any subsequent event, before the timer has triggered, just re-start the same timer, pushing its triggering further into the future.

When the user stops generating events, the timer will eventually trigger, and then you can apply the sum of all the movements, and clear the sums.

A suitable timeout must be chosen so that the user interaction is not perceived as being too sluggish. Perhaps something on the order of 200-300 milliseconds, or more. This is easy to tweak until it feels "right".

unwind
+1  A: 

I've also gotten a lot of value out of setting a threshold. So if the total movement in a specific direction adds up to a given amount, then trigger a navigational event.

haseman
Thanks haseman. Thats what I did. Once the difference amounts to something significant, I change the view's position
lostInTransit