Is it possible to allow the user to touch the screen only once?
Meaning: A user touches the screen and if he tries to touch the screen again nothing will happen. I am implementing the approach using canvas to draw the objects on the screen.
Thank you in advance!
From what you have in mind, setClickable() or onTouchEvent would be the best way to go.
Have a look on this reference:
Responding to Touch Events
Disable All Touch Screen Interactions While Animation
setEnabled() vs setClickable(), what is the difference?
As commented above - use a boolean variable as a flag and toggle it between true and false according to how the user interacts!
Related
I have a floating app which works perfectly.
I am using OnTouchListener to catch events since I need to use the GestureDetector for swipes etc.
My only problem is that sometimes I wish to ignore certain events on the view.
In this case the view is invisible but not "gone" because I need it to accept certain gestures but not others.
I can't seem to be able to do that.
Returning false from "onTouch" simply doesn't work.
I checked that by experiment by disabling the GestureDetector and simply always returning false just to see what would happen. Result was nothing going through.
Is it even possible to pass a click through to a covered app?
Due to security reasons it's not possible to record and pass a click below (essentially allows building a keylogger).
Best you can do is have your floating window small enough to start the touch but not cover too much of the screen below.
I am working on a background service that runs to give sound feedback device-wide whenever the user is touching the screen. I tried to create an overlay with a custom view to listen to touches and pass them down to the views below in a similar direction to what was attempted in this question but my overlay seemed to be either consuming all the touch events or if I returned false only the down touch was detected.
I was wondering if there was perhaps an accessibility route I could take? Basically I need a way to get the information of any current touches on the screen (preferably multitouch) I don't need to alter the touch event or anything, just need the information.
Please tell me why is the following XML attribute used ?
I looked up the documentation on developer.android.com but could not understand anything.
android:focusableInTouchMode
This blog post can help you to understand the meaning of touch mode.
The most relevant part :
The touch mode is a state of the view hierarchy that depends solely on the user interaction with the phone. By itself, the touch mode is something very easy to understand as it simply indicates whether the last user interaction was performed with the touch screen. For example, if you are using a G1 phone, selecting a widget with the trackball will take you out of touch mode; however, if you touch a button on the screen with your finger, you will enter touch mode. When the user is not in touch mode, we talk about the trackball mode, navigation mode or keyboard navigation, so do not be surprised if you encounter these terms. Finally, there is only one API directly related to touch mode, View.isInTouchMode().
So android:focusableInTouchMode="true" means that the view can get the focus when the phone is in touch mode.
Typically an EditText is generally focusable in touch mode and on the other hand a Button is generally not focusable in touch mode.
Happened to me when I didn't have the correct number of items in getItemCount().
Double check that you have the right number of items!
I'm looking for a way to lock the user interface, for example when I select "Lock" from the options menu, the UI will be block from touches. It's sort of adding an overlay with some kind of lock icon over the UI.
Do you guys have any suggestions? Thanks!
To make the entire window of the activity untouchable, call this:
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
to make it touchable again, call
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
Though this may cause an ANR...if you can get around that then this is the easiest method, otherwise what bitbox said may be the apropriate solution
Do you need to do that on multiple activities or just one ?
If it's just one, then add a transparent ViewGroup(MatchParent,Parent) to the top of your view hierarchy. Make it Gone by default.
Then in OnCreate(), add a OnTouchListener that always returns true (meaning that it took into account the touch);
Then when you need it, just make it "Visible".
Explanation : adding it to the top will make it the top-most "layer" in the view hierarchy. So it will be first to receive touch events which you then veto by returning true to the listener's caller.
Good day to all!
I'm trying to implement a voice over for Android (like iPhone), but a specific application (not the entire operating system)
Imagine a screen with six buttons, so they occupy the entire activity, distributed equally in size.
When I "walk" with my finger on the screen, I want to give focus to the button and capture the event when the button has focus and let the focus as well.
Conclusion: As I flick on the screen and if it is over a button, the focus button. if I continue to drag the finger, give the focus to another button without taking your finger off the screen.
Can anyone help me? Sorry for bad English.
I don't think you can use the Android Button class for this, but instead do a custom view, draw six rectangles, and write an onTouchEvent method that determines what sound to play based on where the user's finger is. See the Sudokuv4 example at http://pragprog.com/book/eband3/hello-android for some code you can use.
Well you have to know positions of buttons. You can use basic view functions to get positions (getLeft(), and so on...)
After that you have to implment onTouchListner for Activity. Within you have to check where Event.x and Event.y pointers are and set foucs to specified view. After pointers move from specified view you set focus to false.