I'm working on an app which presents users with four buttons and a timer. The users then tap as fast as they can, each user on his own button, and the one with the most taps at the end wins.
I can't use onClick here, because it locks up the UI thread until the button is released, effectively blocking other button presses. I have searched around for a bit and found that I could use onTouch, but it doesn't work the way I want it to. If a user has touched and is still holding a button, any subsequent touches on other buttons will behave as though this first button was pressed.
Someone suggested the use of an image, transparent and stretched across the entire visible UI. One could then read any touches on this imageview and assign a touch to a particular button based on the coordinates of the press. (I guess I would take a screenshot of my UI with the four buttons visible, open it in paint and write down the coordinates of the borders for each button, then use those coordinates in the code to figure out which button the user was trying to press.)
Can anyone help me with this method of work, give me a quick example, or link to where I can learn how to do it and implement it in my app? It would be much appreciated.
TL;DR: How to use an image, transparent and stretched across the entire visible UI and read the coordinates of each press (even if multiple at once)?
Related
I am experimenting with Transition animations following the Android Documentation here. I have a small POC where an ImageView and TextView are animated once the user clicks a button, as shown in the recording below.
This is working fine.
However, what I'm struggling to figure out next, is rather than triggering the animation with a click event, I would like the views to respond to continuous user input, such as dragging a Seekbar, and animate accordingly. So basically, if I drag the Seekbar let's say until mid point, then the views would perform only half of the animation and stop.
Any tips where should I look into, in order to achieve that?
There are some application that disables all the touch inputs, including the touch events that occur on the navigation bar.
Examples are Touch Lock or UnTouch. How one can do that?
By analyzing the second linked app seems that there is a hidden layout that capture the touch events (like an empty onClickListener).
Initially I tried to draw a transparent foreground using the SYSTEM_ALERT_WINDOW permission and by assigning an empty touch listener. However in this way I cannot draw on the navigation bar, so the user can touch the home button and the back button.
Another way that I tried is to launch an Activity with transparent background and in fullscreen mode. In this way I can capture all the events. This works, but obviously this causes other activities to go in pause state.
So my question is, how can one reach the goal? Alternatively is possible to use some root/system commands?
Thanks!
Try this link. If you want to do it on just 1 view then edit out the iteration in the methods given.
Hi there is thery any way to invoke a method that enables or disables the Touch Screen of Android?
I want this, because I have several buttons on my activity. When the user clicks on a button, it takes a few seconds to start the following activity, and because of that, while waiting that time, I don't want the user to be able to press anything.
I used a boolean that is True at start, then It changes to false when I click on the first button. And to every click on a button I check if the boolean is true...
But the problem is that Visually the user can click the button, it gets that look of being pressed..
So is there any good method that disables the entire touch screen ? And another that enables the entire touch screen ?
Thanks alot in advance ;)
But the problem is that Visually the user can click the button, it gets that look of being pressed
Disable the buttons, using setEnabled(false). This will not only prevent the user from clicking on them, but they will visually appear disabled, to let the user know that the user cannot click on them. It is important for the user to get the proper visual feedback about the buttons being disabled (and later enabled).
is thery any way to invoke a method that enables or disables the Touch Screen of Android?
Not really.
I am creating a news app which contains a 'share news' button. Currently this button is showing all the time when user reads the news, which makes news reading irritating. Now my question is how can I make that share button show up when user touch on the screen, and will disappear after 2-3 seconds if it is left without touching. It would be nice if I can make a little animation during the button appearing/disappearing (like, show up from bottom and disappear going down). Please help...
Thanks
add an on touch event on your view and change visibilty of your button visible when touched after that start an timer using handler for three seconds and set visibility gone there after three seconde for handler code check this answer
Running a thread for some seconds
on softkeyboard, which one is better to give user a visual feedback during keypress:
1.redraw portion of button that was pressed to background canvas of main View to give pressed effect
2.each button has its own "pressed" View, and that View is set to visible (flashing) during keypress event (so no redraw needed but need more memory)
I know its trade-off between speed and memory usage, but I just want to know what you will do under this situation.
You wont be able to see the key because your finger will be covering it! The character being added to the focused text field might be enough.