Is there a way to speed up touch/click detection? - android

I have been working on a game where speed is required to score well, in the game the user is clicking on objects and using them with other objects which are held in a gridView that's being controlled by an imageAdapter. I have noticed that when I click quite fast some clicks don't register, I have cleaned up the code running when the user clicks but that doesn't seem to be the problem since I tested it just highlighting objects and not running code when clicked and it was just as slow. So is there a way to speed up the click detection, or would this be limited by the speed of the device its self, I have been testing on an htc one m8.

Return as soon as possible from the handler and run the UI update code in background with 'runOnUiThread()'.
Notice that changing view status MUST be done in the UI thread or the Android runtime will throw an exception. You can work complex calculations in background 'AsyncTask' and call 'runOnUiThread()' from within them whenever you want to update UI components.

As far as I know, there is no way to do such think. It depends on the speed of your hardware. But what you can do is to use the onTouch listener. In this way you listen only after one action(when it is pressed). for onClick it is registered 2 actions(when u press the button and when u release the button). In this way maybe you could do it faster.
You can also try this:
http://developer.android.com/guide/topics/graphics/hardware-accel.html

Related

Android touch data logs

For the research I am doing, I need to some way to track user touches when they are using the phone in general daily basis. The user will be fully aware about what they are recording. Any method to do would be great.
What have I tried so far?
Method 1.
Create an service with overlay transparent view.
Problem Due to obvious security flaws this is prevented starting with ICS. The input touches on the transparent view is not transferred to background and hence user is not able to interact with phone normally. I tried various methods with overlay view defining as type phone or type system alert or switching between them during program execution.
Method 2.
View with 1% screen size make with touch outside model
Problem As problem as previous. Touch outside only returns the if touch event happened outside without even initial x, y coordinates.
There are other methods I tried but those are highlighted. Currently, I am thinking about other options:
Option 1 - The pointer location option in developer options: In settings there is this pointer location option that I can utilize. When that option is on, all the info about touch are shown in the top panel. If I can have access to those data afterwards that would be fine too, despite the fact that there will be drawings on the screen when user is using the phone. I have traced the source code of ICS and found the core class that is making that tracking possible. I recreated that class into an service. The logcat shows all the info about touch when I am running it from app. Only problem is the same as problem 1. I cannot track it outside current app. So, if it logs the tracking info even when pointer option is turned on, how will be able to get the information later to use?
This option seems the easiest.
Option 2 - Android NDK If above method is not possible is it possible to do so using NDK? Right direction to this route is also great.
Option 3 - Custom ROM Do I really need to go for Custom ROM while doing this? I am pretty sure this is 100% sure way to do it. But it is seeming very impractical in this particular research.
I would appreciate any suggestion to the path that I can follow.
Thank you all in advance.
You can use rooted phones and RepetiTouch for your research. https://play.google.com/store/apps/details?id=com.cygery.repetitouch.free

Android changing imageview locks up app

I have an Android app that uses the LocationListener to determine the speed the car is going. Currently I show the speed by updating a TextView to show when the speed changes. I am now trying to use images of digital looking numbers to show the speed to make it look more like the dash of a car. I show 3 different ImageViews next to each other and when the speed changes I change the image to the correct number using the setImageResource like this:
speedImg.setImageResource(R.drawable.dig_1);
When I try the app it works fine for a few minutes but then eventually the phone becomes non-responsive and none of the phone buttons work and eventually Android gives me the option to force close. I can only test it in the car so I am not able to debug.
Is there another way I should be changing the image to make it more efficient? I have also thought about reducing how often the listener gets called but didn't know how many meters to set it to still get an accurate speed of the car.
Most probably you're doing some long-running operation in main UI thread. You could give StrictMode a try to detect such things.

Actionscript 3 for Android - should I attach mouse event listeners to the stage or to individual sprites?

In AS3 on Android is it bad from a performance perspective to attach mouse event listeners to individual sprites rather than to the stage?
I am writing an app for an Android phone using AS3 in Flash Builder. The app has multiple screens that respond to user touch. The screens are arranged in a hierarchy and show list data so that when you click on an item in a list you are presented with a new screen with a new sub list on it.
I have been using an event listener to detect mouse / touch input and based on something I read that indicated that performance is much better if you keep the number of objects you are listening to to a minimum I have attached the mouse listeners from each screen to the stage object.
This all works fine but I am finding that as I move between screens (and they get popped or pushed onto the dislay stack) I have to keep track of alot of adding and removing listeners to the stage object. If I don't then windows higher up the hierarchy than the current screen keep receiving mouse events.
If I used listeners attached to sprites in each window then when the window was removed from the display even though it is kept in memory (ready to be popped back when a child window is closed) it won't receive any mouse events....
Performance doesn't seem to be impacted using listeners directly on sprites when using my HTC phone to test with, however I obviously don't know what it will be like on other phones. Does anyone have any experience either way or a view on the best approach?
I would recommend to use Listeners on specific sprites, as it will be easier to code and maintain, also coordinates conversion might get cumbersome to manage with different screen/sprites sizes, and removing/adding listeners might not be so easy to maintain as you add more screens...
As for performance, I don't believe Listeners will have any impact, it is just a function that get called when the sprite is clicked, if you don't set a Listener, the OS registers the click anyway and sends it down to the lower level View until it eventually finds a Listener to the event, or drops it.

Approach for Android game with timers and touch event (move) handling

I'm doing a game with game loop and active rendering (using SurfaceView and SurfaceHolder.Callback).
I'm wondering how to make that work together with timed events and touch event management.
The timed events are like each xx ms something happens, each yy ms something different happens.
Touch management is update game and screen when down, up, and move.
I have made a few tries, but it looks somehow awkward and the game isnt performing very well..
On one side I have a classic game loop (in separate thread):
while running update, render, draw, sleep a bit
Now I didn't know well how to make this work with timer loops. I used handler approach - make classes which extend handler, do what they have to do in handleMessage, and call then themselves with sendMessageDelayed.
They just update game state. The rendering of the resulting changes would be done in the gameLoop.
This approach needs synchronization for update of gameloop not intefering with update of the timers.
And - besides of this I need to handle touch events - down, up, and move!
My approach here was, like in the timers, just update game state, and leave it to the loop to handle and display correctly.
I don't know if I'm maybe on the completly wrong path, noob to Androd, and made it just like i thought "could work".
For example I'm not sure if its necessary to make a game loop in a separate thread. I thought it was, to show the results of touch handling (move) according to certain framerate.
On the other side I could leave the loop and just tell to draw after each timer update, and after each touch handling, but this doesnt work well either.
The question is what's the general approach for this kind of game? (timed loops / touch event (move) which has to render to screen continuosly).
Thanks in advance.
Have you read Using Input Pipelines In Your Android Game? It presents a solution to your problem for handling input.

Android Prepressed State of View

I am working on an app that will let the user trigger a sound by touching multiple views. Unfortunately, the android goes into a prepressed state (of 120 millisec I think) before recognizing a real press and play the sound. This is a significant problem for my application as I need the sounds to be triggered without that lag. Is there any known way to avoid the prepressed state of android? can you suggest another approach to solving this problem?
Thank you
If you are using the OnTouchListener and not a button, I would think that it would be fairly responsive.

Categories

Resources