package
com.android.gfgapp;
import
android.os.Bundle;
import
android.view.View;
import
android.view.animation.AnimationUtils;
import
android.view.animation.LayoutAnimationController;
import
android.widget.Button;
import
androidx.appcompat.app.AppCompatActivity;
import
androidx.recyclerview.widget.LinearLayoutManager;
import
androidx.recyclerview.widget.RecyclerView;
import
java.util.ArrayList;
import
java.util.List;
public
class
MainActivity
extends
AppCompatActivity
implements
View.OnClickListener {
private
RecyclerView recyclerView;
private
RecyclerViewAdapter recyclerViewAdapter;
private
List<String> dataStructure =
new
ArrayList<>();
private
Button fallDownButton, slideUpButton, rotateInButton, scaleInButton;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(
new
LinearLayoutManager(
this
));
dataStructure.add(
"Array"
);
dataStructure.add(
"Linked List"
);
dataStructure.add(
"Stack"
);
dataStructure.add(
"Queue"
);
dataStructure.add(
"Tree"
);
dataStructure.add(
"Graph"
);
dataStructure.add(
"Hash Table"
);
dataStructure.add(
"Heap"
);
dataStructure.add(
"Trie"
);
dataStructure.add(
"Segment Tree"
);
recyclerViewAdapter =
new
RecyclerViewAdapter(
this
, dataStructure);
recyclerView.setAdapter(recyclerViewAdapter);
int
resId = R.anim.layout_animation_fall_down;
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(
this
, resId);
recyclerView.setLayoutAnimation(animation);
recyclerViewAdapter.notifyDataSetChanged();
fallDownButton = findViewById(R.id.fall_down_button);
slideUpButton = findViewById(R.id.btn_slide_up);
rotateInButton = findViewById(R.id.btn_rotate_in);
scaleInButton = findViewById(R.id.btn_scale_in);
fallDownButton.setOnClickListener(
this
);
slideUpButton.setOnClickListener(
this
);
rotateInButton.setOnClickListener(
this
);
scaleInButton.setOnClickListener(
this
);
}
@Override
public
void
onClick(View v) {
int
resId =
0
;
switch
(v.getId()) {
case
R.id.fall_down_button:
resId = R.anim.layout_animation_fall_down;
break
;
case
R.id.btn_slide_up:
resId = R.anim.layout_animation_slide_up;
break
;
case
R.id.btn_rotate_in:
resId = R.anim.layout_animation_rotate_in;
break
;
case
R.id.btn_scale_in:
resId = R.anim.layout_animation_scale_in;
break
;
}
if
(resId !=
0
) {
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(
this
, resId);
recyclerView.setLayoutAnimation(animation);
recyclerViewAdapter.notifyDataSetChanged();
}
}
}