When the user clicks on a button (assuming the device is not in silent/vibration mode) a confirmation sound is played, along with vibration.
From what I can tell we can have this happen on a custom View by setting the onClickListener and invoking performClick(); I have noticed that no feedback is given if the listener is not set.
Is there a way to just get the audio/vibration feedback without invoking the onClick() method?
I will need to implement onClick() for other reasons, so leaving the body empty does not work for me. Notice that the contrary is possible: with callOnClick() we can invoke the method without getting the feedback.
In addition, long clicks have no default feedback (at least on my devices). Any way to add it, again without resorting to performClick()?
EDIT:
A workaround could be using a dummy View to perform an empty click on. But I would like to know if there is a more elegant solution without this overhead.
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 want to add custom audible feedback to a button press (various click sounds encoded as *.ogg) I've done this by using the RingtoneManager to create Ringtones for each of the clicks and then .play() them in the onClick() method. This works but seems a little sluggish. This leaves me wondering if there is a better way to attach a custom sound effect to a button press. I've scanned the Button reference page and all I found was playSoundEffect() which seems to handle only system defined sounds.
thanks,
hank
Use a SoundPool- they work it preloads the data into memory (so no file reads which cause sluggishness). Ringtones are definitely not what you want to be using here- those are typically much longer and not time critical (delaying a ringtone by a second or so isn't a problem, whereas delaying a button sound effect by that long is).
I'm writing an app using Titanium. I want to be able to automatically dismiss the keyboard anytime something outside of the text field is clicked. I have yet to find an elegant solution for this issue.
Couple things that I've thought about, but am still looking for a better solution:
Assign event listeners to basically everything else present in the view, and dismiss the keyboard (using textField.blur()). I want to avoid this since it results in a LOT of code just to dismiss the keyboard. Also, if I end up adding anything else to the view, I'll have to add a click listener to that object as well, so it's not very maintainable.
Create a large transparent view, and have it take up the entire screen. Place it directly beneath the text field and add to it one click listener on that which will dismiss the keyboard. This is a better solution than #1, but still isn't great because I've had a lot of trouble getting zIndexes to work properly. It's also inefficient for my purposes because I've got views with a specific width and height that encapsulate text fields. I've used these for the sake of code simplicity and I re-use them throughout my application.
I've tried adding a listener for the "blur" event for the text field but that doesn't seem to get fired appropriately.
That's about it. I'm sort of at a loss. The zIndexing also behaves strangely on the iPhone, and I haven't tried on Android yet. Also, as I mentioned above, many of the text fields I use are encapsulated within small views with set widths/heights-- so I think that will affect the functionality of Z-indexes.
So the root question is: What's the best way to dismiss a keyboard whenever anything outside the text field that's in focus is clicked?
If I'm correct the click event propagates through all views and windows therefore your #1 option could be modified to check for clicks on the bottom most layer (view or window), check for its source then decide what to do.
In android, is it possible for me to register a long click listener on a seekbar?
I have done this:
mySeekBar.setLongClickable(true);
mySeekBar.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick (View v) {
Log.d("TEST", "Get a long click event!!!!!!!!!!!!");
}
});
But I don't see my debug print statement at all. Any idea about how can I achieve it?
Thank you.
While not mentioned in the documentation, I've experimentally determined that both click and long-click listeners are unsupported on SeekBars. They are supported in ProgressBars.
Digging through the source code shows why: SeekBar.onTouchEvent() does not call super.onTouchEvent(). It is in View.onTouchEvent() that performClick() and performLongClick() are called, as appropriate. So the only way to handle long-clicks on a SeekBar is to manually detect them.
My own thinking is that having a long-click handler for a SeekBar doesn't actually make sense. If the user is dragging the "thumb" for longer than the long-click threshold/delay, suddenly you have a long-press that probably was not meant as one. You can cancel and reset the delay every time the thumb is moved, requiring a long-press to be several seconds in exactly one position. But it's rare to be perfectly still; it's in fact difficult to hold the thumb yet not move it for several seconds. So you could then have a minimum change in thumb position that resets the delay. That's what I would do if I had to, but I must say it's a very strange user experience. There are many places in Android where a user expects a long-press to be significant, but a SeekBar isn't one of them.
AFAICT this is not possible to do with the OnLongClickListener. The documentation doesn't say it won't work, but I've never seen any example of this (and I never got it to work myself either).
A possible workaround (depending on what you want to achieve) could be to use the OnSeekBarChangeListener handling the long click through onStartTrackingTouch / onStopTrackingTouch callbacks.
Alternately, you could sub-class SeekBar and implement your own onLongClick listener. This is not for the faint of heart, but Terry Long seems to have done it in a round-about way. (At least I think he has, my Mandarin is pretty rusty.) He lays out four steps:
Sub-class SeekBar, overriding setOnLongClickListener to kill it
Create a thread that terminates after the desired "long click" time
Create a "long click" event that gets fired when the thread terminates
Override the SeekBar OnSeekBarChangeListener event handler to handle the event
I haven't tried his code, but the basic idea looks sound. I would have thought he would have tried to do this in AbsSeekBar to avoid overriding SeekBar's OnSeekBarChangeListener, but he doesn't say why he didn't do it that way (again, AFAICT).
Sounds like overkill to me, though. ProgressBar does support long clicks; could you use that somehow?
I'd like to hook to an event that fires when android's on screen keyboard appears. For example when user taps EditText to bring up the keyboard. Anyone know which event (or listener) to use?
Timo
According to following discussion thread in Android Developers Google Group the only way to solve this is to listen to size changed events of the main view. The thread is pretty old though. I wonder if any of the newer APIs have provided better way.
http://groups.google.com/group/android-developers/browse_thread/thread/9d1681a01f05e782
The last post explains a logic behind a working solution.
There won't be a way to determine when the keyboard comes up, but if you want to check when the user taps on an edittext you can register a click listener or an onfocuschangedlistener to that view.