use of com.github.ybq.android.spinkit.Style in project Android-SpinKit by ybq.
the class DetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setOffscreenPageLimit(0);
viewPager.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return Style.values().length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
@SuppressLint("InflateParams") View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_pager, null);
SpinKitView spinKitView = (SpinKitView) view.findViewById(R.id.spin_kit);
TextView name = (TextView) view.findViewById(R.id.name);
Style style = Style.values()[position];
name.setText(style.name());
Sprite drawable = SpriteFactory.create(style);
spinKitView.setIndeterminateDrawable(drawable);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int color = (int) ArgbEvaluator.getInstance().evaluate(positionOffset, colors[position % colors.length], colors[(position + 1) % colors.length]);
getWindow().getDecorView().setBackgroundColor(color);
}
@Override
public void onPageSelected(int position) {
getWindow().getDecorView().setBackgroundColor(colors[position % colors.length]);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
viewPager.setCurrentItem(getIntent().getIntExtra("position", 0));
}
Aggregations