Libgdx InputProcessor - Determine if you swiped off of a keyDown - android

Working on a mobile game at the moment and was having difficulty getting the back button on android devices to function as I want it to.
Here's the scenario: You click down on the back button, realize you don't actually want to go back so you swipe up (while still pressed) onto the game screen, thus negating the back button being pushed.
I'm using InputProcessor and i have keyDown and keyUp. The problem is, i'm not sure how to use these two together so that when i swipe off the back button it doesn't go back.
I have been able to get the back button to do the other functionality i want (such as not exiting the app and going between screens and such), just stuck on this one scenario.
Any help is much appreciated.
Edit: This functionality can be seen in the facebook mobile app. If you click on the back button swipe off of it to the mainscreen, the app doesn't exit.

I don't know exactly the Syntax for Mobile development but I figure your best course of action is to create a Boolean willExit, and instantiate it as true, and in the KeyUp() function put and if (willExit) statement. Now you can have it run through the block KeyUp() without doing anything if willExit = false. From there you just set willExit to false whenever the condition is met, such as in your case when Swiping.

Simply in the KeyDown use the switch statement to see if the it is the back button or not.
If it is the back button, check if the screen is touched.
As simple as that.
BTW sorry for not providing code snippets.

Related

Touch events happen befor an activity is displayed

In my program I have 2 activities. First one contains a keyboard for Pin and a second one which is displayed right after.
When an user enters 4 pin numbers second activity starts. But the problem is if the user clicks too many times on keyboard (more than 5 click), some touch events are propagated to next activity, while the first activity is still displayed.
This behavior is also somewhat device depended, to me it occurs on Asus Memo 10 tablet with Android 4.3, but it doesn't appear on nexus 7 with android 4.4.
Is there anyway to prevent click events being propagated to another while the first is still active?
And if that is not possible is there a way to detect when is activity is fully displayed so that I can disable click events until it is displayed.
Because I would really prefer not to have any arbitrary delay after pin input.
Thanks in advance.
onStart() method is what you're looking for to disable click events, but your aproach is not a good thing, maybe you should consider to have something like "Done" button, which user will click after he finishes his input? It can also be useful because you can write code to check pin for lenght or validate

libgGdx: Elegant way to use back key for going to previous screen

I'm using libGdx with multiple screens. I want to use the back key on my android device to back to the previous screen similar to how android goes back to the prevvious activity by default.
My current way of doing this is to have every screen get the screen it was called from. Then I'd implement the InputProcessor in every Screen and use it to receive back key presses and then change the screen to the one that was shown before.
While this works, it sucks when working with multiple screens because essentially one has to rewrite the code over and over again.
Does anyone know a more elegant way of achieving this? Does libGdx maybe even have this function by default and I just don't find it? Or do I need to do it this way.
Thanky you for answering,
Cheers,
Tony
My current way of doing this is to have every screen get the screen it was called from. Then I'd implement the InputProcessor in every Screen and use it to receive back key presses and then change the screen to the one that was shown before.
This is how I do it. I dont see any other more elegant solution for this. And the code you must rewrite in every screen is minimal:
switch(keycode){
...
case Keys.BACK:
game.setScreen(previousScreen);
return true;
}
(game is your ApplicationListener, previousScreen is the screen that called the current one, and keycode is the int given in the keydown/up methods of the InputListener)

Custom view like lock/unlock screen of android

I would like to create effects like lock/unlock screen of android. I have attached the screenshot here as well. In lock screen we have 2 buttons but in my case I am having 3 buttons and the middle button must be draggable.
The middle button can be drag to left/right.
I know I have to create custom view for this to work but I don't have any idea about how to drag button left/right with nice effect(animations) which normally any android phone have.
I need guidance on this, so can anyone suggest me how to approach for this.
Basically i wish to move/slide button left and right and based on that want to take some action.
I have tried making a lockscreen application myself and i almost made it, but here are the facts you will have to face at the end
You will not be able to disable home or menu button.
you will need user permission (not the one you get while installing the application, the menu pops up every time you press the home button unless the user decides to make your application default home screen, if that does happen you have successfully made a lock screen) if you decide to make a home screen application too.
the lock screen doesn't go very well with passwords
But if it helps, here's what i did:
You need to create a service that keeps a check on the screen being off and on.
if the screen is off, you do nothing. when the screen if ON you start the activity and wait for the user to do the thing you want the user to make him unlock the screen. and when he does that you finish() the activity.
While doing that you need to setup a method that can listen to check the incoming calls you can do that by extending PhoneStateListener and also disable the back button.
Good Luck and if you are able to make any further progress do let me know.
Maybe this project could help you GlowPadView. I've used it succesfully in one project. Hope it's what you're looking for.

return back to previous activity

i am doing a search results and once I click on the results, it will display the details. After I click on the back button, it should display the searched results I have done.
E.g.
When I click "back" on image 3, it returned to image 1 instead of image 2. Is there a way to solve it? I simply just did finish(); on image 3
You need to intercept the back button and control the flow of your application. DO NOT use state variables, avoid this approach as this can lead to more unstable problem UNLESS you design your states very carefully and have your states defined WELL. Try to learn the control that is available in the android framework.

Back button Wont work

I have created an app using appinvintor. The problem is when i hit the back button on my android it closes the whole application i just want it to go to the previous step or page, how would i code that
Currently you can't do that because right now we are given only one screen. But you can manipulate like this.
since beginning of 2012 there is the multiple screen feature in AI and now it is possible to catch the back button, see this example http://puravidaapps.com/backbutton.php
Taifun

Categories

Resources