IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Cancel ObjectAnimator ?


Sujet :

Android

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    etudiant
    Inscrit en
    Janvier 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : etudiant

    Informations forums :
    Inscription : Janvier 2014
    Messages : 1
    Par défaut Cancel ObjectAnimator ?
    Salut,

    J'ai un bout de code où je voudrais que quand l'utilisateur clique une première fois sur un bouton, l'animation commence, et ensuite soit l'animation se termine et le jeu se termine, ou soit il clique sur le bouton avant que l'animation se termine et alors l'animation recommence. Mon animation est une progress bar qui diminue au fil du temps.

    Voici mon code. Concrètement, c'est le animation.cancel() qui ne marche pas.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    public class MainActivity extends Activity {
     
    Button b_bleu;
    PrgressBar bar1;
     
    Override
    public void onWindowFocusChanged(boolean hasFocus) {
     
     
     
        b_bleu.setOnClickListener(new View.OnClickListener() {
     
            @Override
            public void onClick(View v) {
     
     
                ObjectAnimator animation = ObjectAnimator.ofInt(bar1, "progress", 100,
                        0);
                animation.setDuration(5000);
                animation.addListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animator) {
     
                    }
     
                    @Override
                    public void onAnimationEnd(Animator animator) {
                        //application se termine
                    }
     
                    @Override
                    public void onAnimationCancel(Animator animator) {
     
     
     
     
                    }
     
                    @Override
                    public void onAnimationRepeat(Animator animator) {
                    }
                });
     
                animation.cancel();
                animation.start();
     
            }
        });
     
    }

  2. #2
    Expert confirmé

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Billets dans le blog
    3
    Par défaut
    Heu.... je vais peut-être dire une bêtise, mais là tu cancel une animation qui n'a pas encore démarrée, je ne vois pas trop à quoi il sert du coup....

    Si j'ai bien compris la logique:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    void onClick(View v)
    {
        if (this.animation != null)
            stopAnimation();
        else
            startAnimation();
    }
     
    void startAnimation()
    {
         this.animation = createAnimation();
         this.animation.start();
    }
     
    void stopAnimation()
    {
         if (this.animation != null) {
             this.animation.cancel();
             this.animation = null;
         }
    }
     
    Animation createAnimation()
    {
       Animation ret = ....;
     
       ret.addListener( ....
            onAnimationEnd() {
                MainActivity.this.animation = null;
            }
        }
    }
    Enfin un truc du genre....

Discussions similaires

  1. Réponses: 2
    Dernier message: 24/10/2005, 13h01
  2. diferrence en cancel et "" dans input box
    Par shirya dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 29/09/2005, 19h30
  3. [C#] Event Cancel de DataGrid
    Par bendj dans le forum ASP.NET
    Réponses: 2
    Dernier message: 12/08/2005, 14h42
  4. [JFrame] Boite de dialogue d'entrée de texte et bouton Cancel
    Par tooney dans le forum Agents de placement/Fenêtres
    Réponses: 4
    Dernier message: 29/05/2005, 16h42
  5. [VB6] Cancel et Commondialog
    Par ChrisFAPS dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 09/04/2003, 16h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo