App Inventor - logic - android

This very simple code does not behave the way it should and I don't quite understand why.
App Inventor code:
When Button1.Click
#1 set Label1.Text to "Wait"
#2 call ProcedureXYZ
#3 set Label1.Text to "Done"
Here's the problem. ProcedureXYZ takes 5 seconds to complete. So Label1 should have displayed "Wait", but it does not. Instead, line #1, #2, #3 get executed simultaneously. In other word, it disappears for 5 second, and then "Done" is shown (that's because it immediately override "Wait").
So for 5 seconds, my app appears to be frozen until ProcedureXYZ completes its calculations. My question is, how do I display "Wait" when ProcedureXYZ takes 5 seconds to complete?
I try using clock to fire up the "Wait" message, but that does not work either. The only thing that work is to display an alert message, but I don't want popup message.

Why this in App Inventor does not work like that, is explained here:The model of event processing in App Inventor by Lyn
You will have to use a Clock component to do this, see pseudo code below. In the Designer, set a very small TimerInterval (for example 10 milliseconds) and set property TimerEnabled to false.
Button1.Click event
set Label1.Text to "Wait"
set Clock.TimerEnabled to true
Clock.Timer event
set Clock.TimerEnabled to false
call ProcedureXYZ
set Label1.Text to "Done"

Related

update textview from couchdb using changelistener android

I am trying to get real time changes on a document using the changelistener, however i have to refresh tha mobile app to see the change. Here is my gist https://gist.github.com/mikekaraa/89416ea8b074c71d7153
Please help me out if you have a solution
Would you tie your ChangeListener() event to a time interval such that e.g after every 3 or 5 seconds it is fired and triggers the next sequence of events if at all the document changed within that time span.
I hope that helps.

Problems with Listpicker App Inventor

I'm a beginner at App Inventor and I don't know what I'm doing wrong with the listpicker.
I am trying to create and app to reproduce the music I have stored in my server but when i display the listpicker I can't click any of the options and also I can't go back to the first screen. Here I put my code:
Image 1
Image 2
I tried to remove the line that says call listpicker.open but it only made appear a totally black screen.
The result of the code I just posted is exactly what I spect a list with the name and the link of the 2 songs I already upload to my server but when I click them it didn't do anything.
Thanks for your help.
The Web component works asynchronously, which means, it takes a little bit, until the result is available. The result you will get in the Web.GotText event.
Therefore it does not make sense to call the updateListpicker procedure in the Listpicker.BeforePicking event, because the result still is not available and you get displayed an empty listpicker. The listpicker will be opened, before you have received the result!
Set the listpicker to visible=false and use a button.click event to call the updateListpicker procedure. Then as you already do it in the Web.GotText event, assign the received list to the listpicker and open it.

Calabash - My device won't rotate

I'm discovering Calabash, using it with cucumber and I'm having an issue.
I started some code to test my basic app :
Scenario: I can see a button Test Button
When I enter "Something" into input field number 1
Then I wait
Then I press the "Test Button" button
Then I wait
Then I should see text containing "Something"
Then I go back
Then I rotate landscape
Then I wait for 5 seconds
Everything works fine and everything is passed until I arrive on the device rotation step. It just doesn't work (doesn't rotate) and is treated as an "undefined" instead of passed and the very last line gets "skipped"
The test ends like this.
I checked everywhere and just can't figure out why it doesn't work.
Could anyone help me please ?
As mentioned in comment - disable rotation lock.

Define number of handled key events per second Android

I need to limit number of key events handled per second.
The idea is, because in my app users can use keyboard.
When user hold down on right navigation button, for example.
I don't want to handle every event, because my app can get stucked in calculation loop.
And then force close, wait dialog appears.
I want to handle 2,3 events per second and other just to ignore.
So I can add little cool down time for the app and calculation thread.
Is is possible?
I think I must use some timers or simple sleep function in my key listener, but I can't figure out right way to do this.
Any idea?
A simple solution would be doing some time comparison when you receive a key event:
// a variable in your class:
private long mPreviousKeyEventTime = 0;
// in the key event handling function:
if(System.currentTimeMillis() - mPreviousKeyEventTime < 300) return;
mPreviousKeyEventTime = System.currentTimeMillis();
300 is the time in milliseconds - change it to suite your needs.
Edit: if the keyboard is also used for typing, then make these restrictions only when navigating.

Android text to speech cuts off another text to speech

so I have a 3 CountDownTimers. 2 of the timers have the same time set. 1 has a different time set. After all timers reach 0, they restart again.
Well after about 3 restarts, the timers catch up with each other.. which is fine... however, I have it set so that at the 20 second mark, Timers 1 & 2 say something in text to speech. And Timer 3 also says something at the 20 second mark. The problem is that the whole phrase is not spoken because they are cutting each other off.
Currently, in all 3 of the countdowns i'm using:
tts.speak("20 seconds remaining.", TextToSpeech.QUEUE_FLUSH, null);
is this problem occuring because i'm using the same TextToSpeech (tts) ?
or maybe it has something to do with QUEUE_FLUSH and null?
And also if I change QUEUE_FLUSH to QUEUE_ADD the text just keeps repeating so that won't work
I resolved this problem by using an onUtteranceCompleted callback that sets a boolean value to true when it's done speaking. This way, the voice doesn't get cut off.

Categories

Resources