I am a beginner in programming android.
Is there any way to combine two long press buttons with an Android service and react to that?
I want to combine two long press buttons (home & volume down ) for activate wifi even if the phone is locked.
thanks.
Rather than connecting to the long press listener..
Connect to the button press listener.
Check when the button is pressed down, and when it is lifted up.
Measure the time between these 2 events. Was it long enough to be classed as a long press?
Were both buttons pressed down long enough at the same time?..
If you want to trigger while they are down still, just ensure the up event hasnt fired yet after 2 seconds for example.
Related
A famous game pubg just implemented a new feature in android game app,
If we double tap on either overview button, home button or back button then only it responses,
As i know, generally double tap/click on back button stops the running app, but only single tap on home or overview button lands to home screen or minimises the app.
I need the same in my app, User will have to double tap on overview, home or exit button for the result, like if user wants to go on home screen then User have to double tap on home button.
first of all, using a double click is not recommended in android studio, you have the long click option which is much must better, here is how to implement it!.
if your long click is already take by some other feature or you just really want the double click you have few options:
1) add a Gesture Listener.
2) By using a boolean to detect the double click as follows:
Add a boolean du_click = false; and a Handler du_handler;
when the btn is click check the du_click if it false or true.
if it's true it means it is a double click
if it's false it means it's not a double click so set du_click to true.
use your handler postDelayed() method to set it back to false after some period of time(i.e 1 second).
if you're having a lot of trouble with the Handler you can also accomplish it by after the first click set a timer to count for a period of time(i.e 1 second) using a thread and after it to check if there was another click(via the boolean du_click) but I think the Handler is your best option(or using the Gesture Listener).
I was trying to develop a basic application, I wanted to add feature of how long a key is pressed.
Basically I am trying to make a small game.
I just want to know that how can I detect in application that how long the key is been pressed. However the key must not be pressed multiple times the input must not be given.
The key pressed once, the application should start calculating time from the beginning when the key got pressed to the point when it got released.
Any idea related to this and if code can be given it would be helpful.
Thank you:)
Use a key event listener for when the button is pressed and released, and for both use the System.currentTimeMillis() method. Subtract the first "time" with the later one, and you have how long the button has been pressed
There's a way to handle headphones button clicks in computer (not smartphone) with Java?
The usage is very similar to Android, which by pressing the button some event is fired.
There's not much info about this, then I thought a way to perform this could be interpret the bytes of the moment of the click, and based this, do something. This "could works" but I don't know if something changes by the button click in a computer, as happens in smartphones.
So is possible handle headphones clicks in computer?
Please, I guess how it is called: an on-screen floating message with small arrow, they used to show to user what button to push when he sees the program for first time. They are usually with text "press this button to..." or "here you can get this.."
How to implement it in android application?
edit: I implemented some buttons on screen, and they say that it is not clear what they are for. I want to show user, when he (she) run the program after update, that this is a button and it is for...
maybe u could make a a whole new UI over ride for floating display or make a
activity fully transparent with a limited window size
and over lap it over ur previous activity
I'm experiencing some strange behaviour when using a stylus with swing.
I am interpreting pressing the button on the side of the stylus(RIGHT) and pressing the stylus down(LEFT) as a "Grab" event, but occasionally (more often than 0), events are just being dropped.
The JavaDocs for MouseEvent are pretty explicit about how multibutton presses are handled if executed one at a time (left down, right down, right up, left up) but say nothing about simultaneous button presses.
I'm left to wonder, would they be emitted as two mousePressed events, or as one with the button mask set for both buttons, or something else entirely?
Thanks.
I'd interpret the API doc as simultaneous button presses being simply not possible:
When multiple mouse buttons are pressed, each press, release, and click results in a separate event.
So there should be separate events. The problems you observe could be due to errors in your code, the stylus' driver, the hardware, or Swing (this is in decreasing order of likelihood as I see it :)
I'd try to diagnose the problem by logging events at different levels, if possible.
Simultaneous button presses are processed as two separate mousePressed events. Run the Mouse Events Demo to see them processed separately.
As I recall, there's no way to handle simultaneous button presses. What I used to do to ensure that multiple buttons being pressed at once were treated as such was I would have a boolean variable for each button and when it was pressed, I would set it to true and when it was released, I would set the boolean to false. Then when it came time to perform an action, I would check for the boolean variables (sometimes I would have the actionlistener redirect to the method call for determining what action was to happen next after setting the booleans). This doesn't work if the only thing you want to do is them being pressed at the exact same time, but if you're just trying to get combinations to work, then that's how I did it. This was about 4 years ago, before Java 5, so I may be wrong about that.