Android App Design - Synchronizing the GUI with a sequence of Sounds - android

I need some advice. I’m building an app that has a sequence of 4 actions that will occur when the user presses a button. As soon as the user presses GO, that button must become un-enabled, and some visual cues in the interface must show which of the 4 actions is taking place. (Changing the visibility of ImageView, for example) The GUI must change immediately to keep in sync with sounds that are playing.
After each of the 4 actions, the GUI must change to reflect which of the actions is currently happening.
Current attempts – I can’t get the GUI to change before the first action starts (sound is playing), and at the appropriate times in between the actions. The actions are to play 4 different sounds. Currently, I’m using the MediaPlayer.
I haven’t had any luck trying to force the GUI to update when I want to. I have used AsyncTask, and tried all combinations of setEnabled(), invalidate(), forceLayout(), refreshDrawableState() to try to force things to happen in the gui when I want them to – corresponding to the 4 sounds playing in sequence.
My problem seems to be that I’m trying to do 4 things in one onClick handler. I have been really struggling with validate() calling reDraw at "sometime in the future."
I don’t know what design pattern would be best suited to providing a visual cue to the 4 things that are happening in sequence.
I’m just starting to look at Handlers. Is this the way to go? I thought it would be easy. Any advice?

If I remember correctly the onPreExecute and onPostExecute methods of the AsyncTask execute on the GUI thread. Doesn't updating the GUI from these methods work?

Related

Starting a function in the onCreate (without a button click)?

I know this might be a basic question, but I am a beginner and I haven't been able to find an answer.
I would like to know, if it is possible to trigger some function/action while creating an activity. eg. trigger a void without user intervention, start an animation automatically after an Activity is created etc.(at the moment I am trying to trigger an animation without a button click, but this question is general and not specific code related).
I know how to bind an action to a button click and every resource I have found is doing that, I haven't, however, been able to start an animation or a void without it and I am not sure if it is possible. (I have tried using Handler, it worked but prevented the rest of the code being executed - I might have done it wrong, though as I really am a beginner)
so my question(s): Is it possible to trigger a function/animation without user intervention(click)?
If so, where can I find some resources to read about it? (I tried reading Android documentation already)
Thank you very much and I apologize if the question is too simple, I know it might be.
Please have a look at this photo.
It clearly explains the lifecycle of Android activity.
To answer your question, yes, it is possible to trigger a function/animation without user intervention(click). You have to call the function from onStart() activity.

Android App with Fragments/Actionbar: How to run code when startup is totally finished?

I am writing an android app that uses Fragments and an ActionBar.
Is there a simple way to know when the entire app has finished starting up? Each fragment has it's own layout, and my startup code needs to touch them all. Is there an event I could use to accomplish this?
Thanks!!
onCreateView is called after the view is "all there", so its a good place for code that needs to run late in the game. You could set a flag here or send an event to notify other views that you're ready, but it is per fragment.
However, fragments are kind of based on the idea that they will be created as needed. In a normal app they come and go dynamically so there isnt ever a time when the "whole app is loaded". So, there isnt going to be a single place you can check for whether all fragments are ready unless you make your own. Before doing that you might want to consider other ways to accomplish the task at hand. Your design may not be a good one if you are having to fight against the underlying system.

Order of UI operations on Android?

I've been building for Android for six months now, and I'm still confused about how things happen in the UI. When I learned iOS programming, the books and docs were very clear about what happened when: for instance, that view changes and animations didn't take effect until the next iteration through the run loop. This understanding is critical to debugging UI glitches, and without it I'm having trouble tracking stuff down in our Android app (http://emu.is/download/).
For instance:
We had a situation where pressing a button brought up a fragment, and also displayed an animation as feedback for the button click. I started the animation before pulling in the fragment, yet it didn't actually run until after the fragment appeared. Why?
Often, opening a new Activity will take a long time, during which the user doesn't have great feedback that anything is happening. I'd love to pull up a minimal container for the Activity, then load its content, so the user knows what's happening. How do I do that?
Sometimes our chat bubbles (which are drawn programmatically via a custom Drawable) flash a bit, and it looks like they're being rendered halfway through their drawing process. Why? How do I avoid that?
And so forth. Basically I'd like to understand as much as possible about what happens when in the Android UI -- not just the lifecycle stuff that's well-documented, but the relationship between various UI calls and when/how things actually happen onscreen. Thanks.

IME and catching (touch) events

Im currently trying to get my diploma in psychology and i want to write about different types of keyboards for smartphones. To research this area i need a tool that measures times. As Im new to Android programming, my friend is helping me, but we got stuck.
Here is what we need, and what we tried. Id really appreciate any help =)
We need a way to call a function before user input in IME begins and after user input in IME ends. (We need this only for timelogging, we dont need the actual input.)
We also need to call a function before user input for chosing autocorrection starts/ends.
We need to do this for all kinds of IMEs especially keyboards
like Swype, Swiftkey etc (though one of them working is enough)
We tried:
TextWatcher via addTextChangedListener
- seems to be unreliable to get the times beforeTextChanged/afterTextChanged is randomly called, even within a gesture
or multiple times within a gesture
subclassing EditText implementing OnTouchListener,
using onTouch()
- didnt seem to get called at all when using swype, so either we did it wrong or ime/swpye consumes those events,
also tried it with onKeyPreIme, wasnt called either
Ideal would be:
a way of catching the "touch" events before they are passed to the IME to log the current time via System.currentTimeMillis()
the same "after" the gesture ends i.e. when the finger is released from display
we dont need actual code, a link to the right command/documentation/widget would be sweet.
You get bonus cookies if you are ever in berlin and need a place to ... get cookies :)
Not sure if this is much of an answer, but...
Is your plan to write this in an Android application that you can distribute and run on anybody's device?
Sounds like whatever you do on the EditText or your application may not be enough because the IME is a separate module in Android, so you would not be able to get any information about auto correct or prediction or things like that (different IME have different of such features). You would only be able to get the text entered (or removed) from the text entry.
The best I can think of is for you to develop your own IME, then you can log anything you like in there.
To go about that, I would suggest, you first checkout this article from Android Developer:
http://developer.android.com/guide/topics/text/creating-input-method.html
And then you can check out the source code for the default Latin IME there:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/android/inputmethod/latin/LatinIME.java
Although this one has probably much more than you need and has (I think) some links into the Android framework itself, so you cannot really build it as a separate module the way it is now.
Hope that helps

How do I get my Android game's graphics to update?

I'm struggling right now to figure out the best way to get the graphics to free up in my Android game. Right now, I've tried the following.
Just start everything in onCreate() -> No graphics appear, because I never leave onCreate().
Set up a thread - Has problems with dialogs and such, but without dialogs, I can make it work.
So, what should I be doing? I would like to start this when I enter the activity, and require no input to start (There are several inputs during the game, of course), at least, ideally. So, what can I do?
If you're having problems with dialogs, you might need to look into runOnUiThread.

Categories

Resources