Edit box for my game? - android

I am creating an Android game. Currently I'm using a "normal" View and draw, the onDraw() and have a Handler to process timed events and such. However Soon (tm) I will convert it to a SurfaceView with a Thread and a constant loop.
Anyway, when the player presses a certain button, I want to have a kind of edit box for the player to enter a value (a price). But I'm kind of lost on how to achieve this. First I thought, ok let's just make an EditText, position it on the screen, and done. But apparently I can't just put an EditText on an X,Y location and remove it afterwards.
I looked at the LunarLander example, which uses a TextView for displaying text. It is already defined in the layout XML and is turned visible and invisible by sending messages between the game thread and the UI thread. This seems awefully complicated and the edit box would exist all the time.
Furthermore I was thinking on making my own "edit box" by simply drawing a box on the screen, enabling the keyboard, and then capturing input from the keyboard. But I wouldn't even know where to begin with "custom" keyboard input (on screen vs physical, how to capture keyboard text input, how to hide the keyboard again when done, etc).
So I was wondering, what's the best way to do this?
Edit: maybe useful to know, but my game is fixed in landscape mode.

How about popping up a dialog box with some fancy graphics with the EditText in it?
If you want to stick to using only the SurfaceView, then you may have to implement your own simple GUI system. I'd look around, maybe there're some GUI libs out there for android games.

Related

button that simulates android keyboard input

I have created a Love application but the game requires an on screen keyboard that has arrow keys, is it possible to create buttons on screen like a game pad that simulate keyboard input of keys like the arrow keys or letters?
tl;dr: Use a more common touch input pattern like four touch-input quadrants of the screen.
It is possible but you would need to write an app to somehow pass the key-presses along with the android native keyboard which is a completely different question that is the beyond the scope of this answer.
Refer to the Android Input method documentation for help with that if you decide to go that route.
You could use something like:
if love.system.getOS() == "Android" then
doVirtualKeyboadThings()
end
To detect that your game is running on android, Assuming that you want it to be multi-arch and then use something like Thranduil (Gui Libary) to create your own virtual keyboard.
However I can't encourage such a complicated workaround for something
that could be accomplished with love.mouse (which uses touch events on android) and simple buttons or screen sections.
Example Image

Appcelerator: Proper Way Automatically Dismiss Keyboard

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.

Android + Sencha Touch text input duplicated and difficult to un-focus

I have an Android app using PhoneGap 1.6 and Sencha Touch 1.1.1. One view has a text input field which behaves oddly in Android: it duplicates itself and it is very difficult to remove focus.
I have determined that it is a WebTextView coming up over top of the "real" input field. The problem I am having with this is that blurring the text field with screen taps is extremely difficult, and if you scroll the parent container, the WebTextView does not scroll with it, so you can see both at the same time.
The only way to remove focus on the element is to tap furiously all over parts of the screen, much like triggering the frustration detector from Mavis Beacon.
My actual question is: how can I turn off this functionality completely, or at least work around it? It is not reasonable to expect the user to do anything other than single-tap outside of the box, or press the Back button on the device to stop input in the text field. As it is, pressing Back simply stows the soft keyboard and does not give up focus.
These are browser bugs, triggered by some CSS-flags.
To explain the bug:
The device creates some kind of "screenshot" from the web-sites content. All transformations and transitions are made on top of the "screenshots" from the actual page.
If you have input elements, there will be some kind of proxy elements rendered on top of the "screenshot". Sometimes the are these proxy-elements at the wrong position.
This happens, if you trigger the website to be hardware-accelerted. You have to drop some CSS-definitions:
transform(), translate(), transform3d(), translate3d().
The Bad news are:
You cannot solve this problem, because it a bug within the browser.
I have some different android devices, all have different problems, one fix will break another device.
I think the bug will never be solved, because noone cares about the embedded browser since android 4.1 and the chrome.
If you can disble hardware accelertion, this may help.
The good news are:
There are rumors about an embeddable chrome-webview.
I started to write some blogposts about "the new IE":
http://christian-kuetbach.de/blog/post/14

Dialog Box to get user text input on SurfaceView

I am wondering how I can get user input at the end of a game I am programming. Basically, when you lose three lives, I want to stop the game (stop all threads) and then display some sort of dialog box that allows the user to give their name so it can be saved with the high score. This is all being done in a SurfaceView, however. Does anybody have any good references to something like this? Thank you!!
I think you can simply use FrameLayout and put your SurfaceView there along with other layout which has your text entry forms plus any labels for it...
FrameLayout is capable of stacking several views on top of eachother so that would do what you need I guess.

How to create an on-screen android keyboard that isnt a rectangle at the bottom portion of the screen?

I want to develop a replacement keyboard, but I am afraid that Android assumes the general keyboard 'area' will be a single rectangular shape that sits at the bottom of the screen.
What if I want my keyboard to consist of multiple shapes that don't just sit at the bottom of the screen? Am I doomed from the start, or is it possible to do what I want to do?
On a related note, what if I only want my keyboard to appear when the phone is in a certain orientation but when the phone is held at a different orientation, the normal soft keyboard is used? Again, out of luck or possible?
cheers!
The IME is just a window. It is positioned relative to the bottom of the screen, so you can't really control that. But you can draw whatever you want in it, or not for places you want to be transparent. You can control how much applications move up away from your IME with this: http://developer.android.com/reference/android/inputmethodservice/InputMethodService.html#onComputeInsets(android.inputmethodservice.InputMethodService.Insets)
Android doesn't let windows decide one at a time whether events will be handled by them or dispatched to the window behind them; the only control you have to keep events from being consumed by your entire window is the Insets.touchableInsets constants to tell the window manager to allow events outside of the given insets to go through to what is behind it.
Presumably you could create a rectangle where ever you want and make bits of it transparent. Not sure how to pass UI events to the activity below your keyboard though.
Anyway, there's a softkeyboard sample that will probably be Quite Helpful.
As I see it there are two ways you might handle the UI Thing.
- Pass events off to the underlying activity when they "should go through"... As your softkeyboard may have its own process, this could get a bit thorny.
- Make your keyboard up of more than one rectangular region, such that the UI events pass through Naturally. I'm not sure if that's even possible. I'm still fairly new to Android development myself.

Categories

Resources