1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
private class CreatTransition extends AsyncTask<Void, Integer, Void>
{
TransitionDrawable transitionTemp=null;
//Valeur pour les temps de transition en ms
int transitionDuration = 500;
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
@Override
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
//Important que la durée soit la meme que ds le doInBackground()
doCreatTransition();
}
@Override
protected Void doInBackground(Void... arg0)
{
publishProgress(0);
//Temporisation du temps de la transition + 500 ms pour attendre le onProgressUpdate
//IMPORTANT pour ne pas lancer le reverse de l'animation avant meme quelle ne soit finie
doThreadWait(transitionDuration+500);
return null;
}
@Override
protected void onPostExecute(Void result)
{
//Fonction permettant de remettre l'état d'origine sur la view
doResetTransition();
// Application de la gravité dans la grille + Maj de la Grille IHM
gravityControlCol();
updateViewArea();
Log.d("RESET LISTEANIM", "0");
listeAnim.clear();
}
protected ErrorStatus doCreatTransition()
{
try
{
for (int cpt=0;cpt<listeAnim.size();cpt++)
{
//Stockage de la view en memoire temp dans un TextView
TextView temp = listeAnim.get(cpt);
//Recuperation du background de la vue dans un objet TransitionDrawable en vue de son changement d'état
transitionTemp = (TransitionDrawable) temp.getBackground();
//Debut de la transition avec le temps defini en var global
transitionTemp.startTransition(transitionDuration);
//Force le rafraichissement de notre view normalement pas obligatoire vue que nous sommes dans un thread séparé de notre appli
temp.refreshDrawableState();
}
return ErrorStatus.NO_ERROR;
}
catch (Exception e)
{return ErrorStatus.ERROR_1;}
}
protected ErrorStatus doThreadWait(int values) {
try
{
Thread.sleep(values);
return ErrorStatus.NO_ERROR;
}
catch (InterruptedException e)
{
return ErrorStatus.ERROR_3;
}
}
protected ErrorStatus doResetTransition()
{
try
{
for (int cpt=0;cpt<listeAnim.size();cpt++)
{
//retour au background d'origine idem que pour le doCreattransition
TextView temp = listeAnim.get(cpt);
transitionTemp = (TransitionDrawable) temp.getBackground();
//Permet d'init le background à son état d'origine toujours en fonction de temps définie en var global
transitionTemp.reverseTransition(transitionDuration);
temp.refreshDrawableState();
}
return ErrorStatus.NO_ERROR;
}
catch (Exception e)
{return ErrorStatus.ERROR_2;}
}
} |