I'm working on animation and I want to organize my code in best way I'm new in android and not know too much about this. Here is my code that I'm using to animate views
TestClick
public class TestClick implements OnClickListener {
Context context;
ImageView iv1,iv2,iv3;
public static boolean bActive = false;
public TestClick(Context ctx, ImageView imageView1, ImageView imageView2, ImageView imageView3){
context = ctx;
iv1 = imageView1;
iv2 = imageView2;
iv3 = imageView3;
}
@Override
public void onClick(View v) {
if(bActive) {
active();
}else{
Animation animPictureDeactiveLeft = AnimationUtils.loadAnimation(context, R.anim.deactivate_picturebtn_onleft);
Animation animVideoMiniLeft = AnimationUtils.loadAnimation(context, R.anim.activate_videobtn_onleft);
Animation animGifMiniLeft = AnimationUtils.loadAnimation(context, R.anim.move_gifbtn_onleft);
iv1.startAnimation(animPictureDeactiveLeft);
iv2.startAnimation(animVideoMiniLeft);
iv3.startAnimation(animGifMiniLeft);
bActive = true;
}
}
public void active(){
}
}
MainActivity
button1.setOnClickListener(new TestClick(MainActivity.this, view1, view2, view3){
public void active(){
// do some work
}
});
button2.setOnClickListener(new TestClick(MainActivity.this, view1, view2, view3){
public void active(){
// do some work
}
});
This code is working fine there is no problem in this.
What I need Actually I need to manage my all animation in separate file. I don't want to write whole code in MainActivity
it's not look good.
As you can see in my code I'm passing
views
in constructor is it a good way passing two many views in constructor ?Animations load in
onClick
override method everytime whenonClick
called animation load again Right ?As you can see
button2
also need same animation I want whenbutton1
is clicked it load animations but whenbutton2
click don't load again animation just use the previous loaded animation is it possible if yes how ?Is there any heap memory problem by passing views in such manner.
I'm asking these questions because I'm new to Android. If there is another method to achieve this please let me know. I want efficient code.