Dialog Box to get user text input on SurfaceView - android

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.

Related

Android Development: How to realize this? Moving Buttons and Gravity

I am developing an app and I would appreciate to get some input and your 2cents about this scenario:
I want to have 5 buttons in a circle and 1 button in the middle.
The buttons in the circle shall be able to be moved to the middle button and there are two scenarios:
if the button touches the middle button --> switch screen
if the button does not touch the middle button and you stop moving --> it should be moved back to the original place (gravity)
Is it optimal to solve this scenario with buttons or would you prefer any other item?
Thanks a lot!
Developing this will take a lot of time and effort. I don't know if this can be done using simple buttons or you need custom elements but I can help you get started. Try looking into the Facebook chat heads behaviour. I think the behavior of chat heads when removing them (with the X circle in middle bottom where you drag chat heads to remove) is similar to what you are trying to achieve.
Here is some useful information you can go through and maybe you find what you're looking for.
What APIs in Android is Facebook using to create Chat Heads?
https://github.com/henrychuangtw/Android-ChatHead
https://github.com/marshallino16/Demo-FloatingView
Note: I am still going through all the information in these links because it looks like it might be helpful for you. You also go through the links and we can further discuss in the comments and later edit the answer when we have a solution

how to determine where a user clicked at on an ImageButton via Android?

this is my ImageButton. my confusion is that i do not know how to determine whether the user clicked on the Login half, or the Sign up half, so i can take them to the respective Activity. i would be incredibly grateful if somebody can 1) name a resource i can use to learn on my own, or 2) explain the process of finding view locations and any possible algorithms used to determine if a click was in bounds of a specific portion of a View or not.
You should divide your button into 2 different ones, and process clicks separately.
Have 2 image buttons and try to achieve the same look and feel you want.
In your case, even though this kind of thing is doable. It is expensive and complicated and unnecessary. And you will have problems with styling of the buttons (eg: focus)
Edit:
Yes I understand, But I suggest you not to over complicate things. Because, your device has limited resources (eg: battery),
But you can still get the experience on how to create a circle like button with two sides on it, using 2 buttons which is still exciting :D.

draw multiple texts on button for android,inner-shadow

I need a way to draw multiple texts for a button in android..
I would like to simply just extend the default android button with the possibility to have an aditional text that should be overlapped by another text to create sort of a very "intense" inner-shadow effect.
The idea as mentioned is to simply extend the default button and override the onDraw-function and then draw a new text at the same position as the "default-text" for the button.. the problem is that I have no idea about how Im supposed to get the location of the "default-text" for the button..
Any ideas?
You don't have to use multiple views to create this effect. I wrote a blog post awhile back about using EmbossMaskFilter to apply this effect to a TextView. Button is just a glorified TextView, so you can use the same approach to modify its display text through a simple subclass:
http://wiresareobsolete.com/wordpress/2012/04/textview-inner-shadows/
One thing to keep in mind is that this filter is not yet supported by hardware acceleration, so you may need to draw this view on a software layer if the rest of your app takes advantage of acceleration on newer devices (if you don't know whether or not it is, by default it probably is).

need guidance on how to create a questionaire for android

I have a task to create 10 questions where a user should be able to input the answer by using a touch keypad. The user should be able to cycle through questions by pressing a button called "N" Once the the user answers all of the questions a total score out of 10 would be displayed.
Im not asking for an answer but how to approach such a task.
So far ive created a keypad consisting of numbers and i can get 1 question to work and display whether the user entered correct or incorrect information but trying to get more then 1 question to work is messing up.
I had a thought and know that i can create 10 seperate activities for 10 questions but thats slightly crazy.
Can someone give me guidance on how to approach such as task
note im pretty new to android.
Thank You
All views have a visibility attribute (android:visibility); what would look nice is every time the user presses next is to simply hide the old view and make the next one show up (Can even add a fading transition to make it look fun as well)
In XML you can set them all to android:visibility="gone" to begin with, and then in your code, set it to objectName.setVisibility(0) to make it visible, and objectName.setVisibility(8) to hide it completely again.
Here is one approach (not necessarily the best):
*Wherever your question is (hopefully a TextView), get a reference of it in your activity.
*When the user answers a question, output if it was correct or not (A toast?)
*Change the TextView to the next question
You can programmatically add and remove views. You could create an empty view with just a linear layout then add and modify the existing views as you need them.
Are you writing it as a native Android app? A web-app (HTML, Javascript) could do what you're asking, and could be turned into an native app with embedded webkit view.

Edit box for my game?

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.

Categories

Resources