2017-05-06 2 views
2

EDIT: Pour être clair, il est lent à charger, pas à animer.Pourquoi mon animation Lottie est-elle lente?

Je l'utilise sur un AsyncTask comme suit:

public class GetCurrentLocation extends AsyncTask<String, Void, String>{ 

private Context mContext; 
private View view; 

public GetCurrentLocation (View view, Context mContext) { 
this.view = view; 
this.mContext = mContext; 
} 


protected void onPreExecute() { 
super.onPreExecute(); 
    //Custom Dialog 
    customDialog = new Dialog(mContext); 
    customDialog.setContentView(R.layout.dialog_custom); 
    customDialog.setTitle("Looking for address"); 

    //Custom Dialog Animation 
    LottieAnimationView animationView = (LottieAnimationView) customDialog.findViewById(R.id.animation_view); 
    animationView.setAnimation("PinJump.json"); //Lottie's premade animation 
    animationView.loop(true); 
    animationView.playAnimation(); 

    //Custom Dialog Text 
    TextView text = (TextView) customDialog.findViewById(R.id.textView); 
    text.setText(R.string.dialog_looking_for_address); 
    customDialog.show(); 
} 

protected String doInBackground(String... params) { 
//Code removed to shorten codeblock, it calls gps location here 
return null; 
} 

protected void onPostExecute(String result) { 
super.onPostExecute(result); 
customDialog.dismiss(); 
mPostSolicitationFragment.setLocalText(); //This is the method it transfer the GPS address to the view 
} 
} 

Tout fonctionne bien ici.

Mon problème avec ce code est qu'une fois la boîte de dialogue affichée, l'animation de Lottie prend une seconde avant d'apparaître à l'écran. Si c'est sur le réseau 4G, je peux voir l'animation. Si c'est sur WIFI, la seule chose que je peux voir est le texte.

Ma question est, comment puis-je faire apparaître l'animation dès que la boîte de dialogue apparaît?

Répondre

1

Enfin résolu, grâce à Gabriel Peal

Assez simple en fait. Afin d'éviter de rendre la composition lorsque la boîte de dialogue apparaît, nous rendions avant la main dans LottieComposition, comme indiqué ci-dessous:

 LottieComposition.Factory.fromAssetFileName(mContext, "PinJump.json", new OnCompositionLoadedListener() { 
      @Override 
      public void onCompositionLoaded(LottieComposition composition) { 
       mAnimationView.loop(true); 
       mAnimationView.playAnimation(); 
       TextView text = (TextView) customDialog.findViewById(R.id.textView); 
       text.setText(R.string.dialog_looking_for_address); 
       customDialog.show(); 
      } 
     }); 

De cette façon, l'animation avec apparaitre la boîte de dialogue.