Search in sources :

Example 1 with Style

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));
}
Also used : Sprite(com.github.ybq.android.spinkit.sprite.Sprite) ViewGroup(android.view.ViewGroup) ViewPager(android.support.v4.view.ViewPager) SpinKitView(com.github.ybq.android.spinkit.SpinKitView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) SuppressLint(android.annotation.SuppressLint) Style(com.github.ybq.android.spinkit.Style) TextView(android.widget.TextView) SpinKitView(com.github.ybq.android.spinkit.SpinKitView)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 PagerAdapter (android.support.v4.view.PagerAdapter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 SpinKitView (com.github.ybq.android.spinkit.SpinKitView)1 Style (com.github.ybq.android.spinkit.Style)1 Sprite (com.github.ybq.android.spinkit.sprite.Sprite)1