Hey I have a problem with toast messages which does not show up. I'm creating an app which displays user‘s message into Morse code and I want toast message show up to inform which character is diplayed now. But when I put it like below, toast messages do not show up. It's probably because next function which is called are somehow killing the previous one, cause when I removed other commands and left only showStatus()
the messages appeared.
How can I deal with this situation?
public void dispDot()
{
final Parameters pM = cameraMorse.getParameters();
pM.setFlashMode(Parameters.FLASH_MODE_TORCH);
cameraMorse.setParameters(pM);
MorseActivity.backgroundMorse.setBackgroundResource(R.drawable.background1on);
waitFor(1);
pM.setFlashMode(Parameters.FLASH_MODE_OFF);
cameraMorse.setParameters(pM);
MorseActivity.backgroundMorse.setBackgroundResource(R.drawable.background1a);
}
//function that displays the line in Morse code
public void dispLine()
{
final Parameters pM = cameraMorse.getParameters();
pM.setFlashMode(Parameters.FLASH_MODE_TORCH);
cameraMorse.setParameters(pM);
MorseActivity.backgroundMorse.setBackgroundResource(R.drawable.background1on);
waitFor(3);
pM.setFlashMode(Parameters.FLASH_MODE_OFF);
cameraMorse.setParameters(pM);
MorseActivity.backgroundMorse.setBackgroundResource(R.drawable.background1a);
}
public void showStatus(char character)
{
//status1.setTextColor(Color.WHITE);
//status1.setText("Status: Now displaying "+character);
toast = Toast.makeText(MorseActivity.this, "Displaying "+character,Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 0, 30);
toast.show();
}
public void morseMessageTranslator()
{
morseMessage = textBox.getText().toString();
morseMessage = morseMessage.toUpperCase();
if(morseMessage.length()>0)
{
char character;
for(int a=0;a<morseMessage.length();a++)
{
character=morseMessage.charAt(a);
switch (character)
{
case 'A': //.-
showStatus('A');
dispDot();waitFor(1);dispLine();waitFor(1);
break;
case 'B': //-...
showStatus('B');
dispLine();waitFor(1);dispDot();waitFor(1);dispDot();waitFor(1);dispDot();waitFor(1);
break;
UPDATE: Ok it turns out that waitFor() function is the cause.
public void waitFor (final int time)
{
Thread waitthread = new Thread(new Runnable() {
// After call for background.start this run method call
public void run() {
try {
Thread.sleep(time*500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
waitthread.start();
try {
waitthread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
But still don't know how to show toast before the wait is launched.