Saturday, 14 September 2013

How can I show a value on the screen without blocking the UI and make it fade out with style in android activity?

How can I show a value on the screen without blocking the UI and make it
fade out with style in android activity?

I'm making a word game for android, and basically whenever a user enters
something right I'm updating the score in the application, and I want to
show the score on the screen to make it show in big then fade out slowly
and get smaller, how can I do that? and is it possible to implement it in
an AsyncTask class? This is the method I'm using to check if the word
entered is right.
public class checkWord extends AsyncTask<String, String, Void> {
private String c;
@Override
protected Void doInBackground(String... arg0) {
int size = correctWords.size();
String word = arg0[0];
for (int i = 0; i < size; i++) {
if (word.equalsIgnoreCase(correctWords.get(i))) {
publishProgress("bad");
}
}
try {
c = bufferedReader.readLine();
while (c != null && !c.equalsIgnoreCase(word)) {
c = bufferedReader.readLine();
}
if (c != null) {
correctWords.add(0, word);
score += word.length();
publishProgress("good");
} else {
incorrectWords.add(0, word);
publishProgress("bad");
}
} catch (IOException e) {
e.printStackTrace();
}
closeWordFile();
openWordFile();
return null;
}
So is there anyway I could pass a param to the publishProgress so that in
onProgressUpdate I draw the score they got, for example +3 then make it
fade out? This is my onProgressUpdate where I add seconds to the timer and
play a sound if it's a valid word or not
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
if (values[0].matches("bad"))
failureSound.start();
if (values[0].matches("good")) {
successSound.start();
if (countDownTimer != null) {
countDownTimer.cancel();
startTimer(countDownTime + c.length() / 2);
}
}
}

No comments:

Post a Comment