Created
February 4, 2019 19:02
-
-
Save ssindher11/2931d037b82d86012c3ba77b18b4d85d to your computer and use it in GitHub Desktop.
MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.lottieplayground; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Toast; | |
import com.airbnb.lottie.LottieAnimationView; | |
public class MainActivity extends Activity { | |
LottieAnimationView thumb_up; | |
LottieAnimationView thumb_down; | |
LottieAnimationView toggle; | |
int flag = 0; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
thumb_up = findViewById(R.id.lav_thumbUp); | |
thumb_up.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
thumb_down.setProgress(0); | |
thumb_down.pauseAnimation(); | |
thumb_up.playAnimation(); | |
Toast.makeText(MainActivity.this, "Cheers!!", Toast.LENGTH_SHORT).show(); | |
//---- Your code here------ | |
} | |
}); | |
thumb_down = findViewById(R.id.lav_thumbDown); | |
thumb_down.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
thumb_up.setProgress(0); | |
thumb_up.pauseAnimation(); | |
thumb_down.playAnimation(); | |
Toast.makeText(MainActivity.this, "Boo!!", Toast.LENGTH_SHORT).show(); | |
//---- Your code here------ | |
} | |
}); | |
toggle = findViewById(R.id.lav_toggle); | |
toggle.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
changeState(); | |
} | |
}); | |
} | |
private void changeState() { | |
if (flag == 0) { | |
toggle.setMinAndMaxProgress(0f, 0.43f); //Here, calculation is done on the basis of start and stop frame divided by the total number of frames | |
toggle.playAnimation(); | |
flag = 1; | |
//---- Your code here------ | |
} else { | |
toggle.setMinAndMaxProgress(0.5f, 1f); | |
toggle.playAnimation(); | |
flag = 0; | |
//---- Your code here------ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment