package com.cky.learnandroiddetails.ViewPagerTest;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.cky.learnandroiddetails.Camera.DisplayUtil;
import com.cky.learnandroiddetails.R;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.adapter.LoopPagerAdapter;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class ViewPagerMainActivity extends AppCompatActivity {

    public MyViewPagerAdapter.MyHandler mMyHandler;
    public RollPagerView mRollViewPager;
    private TestLoopAdapter mAdapter;

    private List<Integer> imgs = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager_main);


        mRollViewPager = (RollPagerView) findViewById(R.id.view_pager);
        mRollViewPager.setHintView(null);
        mAdapter = new TestLoopAdapter(mRollViewPager, imgs);
        mRollViewPager.setAdapter(mAdapter);

        imgs.add(R.mipmap.vp_1);
        imgs.add(R.mipmap.vp_2);
        imgs.add(R.mipmap.vp_3);
        imgs.add(R.mipmap.vp_4);

        mAdapter.notifyDataSetChanged();
        int width = DisplayUtil.getScreenMetrics(this).x - DisplayUtil.dip2px(this, 15) * 2;
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT);
        mRollViewPager.setGravity(Gravity.CENTER);
        mRollViewPager.getViewPager().setClipChildren(false);
        mRollViewPager.getViewPager().setOffscreenPageLimit(imgs.size());
        //mRollViewPager.getViewPager().setPageMargin(DisplayUtil.dip2px(this, 15));
        mRollViewPager.getViewPager().setLayoutParams(layoutParams);
        mRollViewPager.getViewPager().setPageTransformer(true, new ZoomOutPageTransformer());
        mRollViewPager.getViewPager().setOverScrollMode(ViewPager.OVER_SCROLL_NEVER);

        int mScrollSpeed = 450;
        try {
            Field mScroller =ViewPager.class.getDeclaredField("mScroller");
            mScroller.setAccessible(true);
            AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
            FixedSpeedScroller myScroller = new FixedSpeedScroller(this, interpolator, mScrollSpeed);
            mScroller.set(mRollViewPager.getViewPager(), myScroller);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    private class TestLoopAdapter extends LoopPagerAdapter {
        private List<Integer> imgs = new ArrayList<>();

        public TestLoopAdapter(RollPagerView viewPager) {
            super(viewPager);
        }

        public TestLoopAdapter(RollPagerView viewPager, List<Integer> imgs) {
            super(viewPager);
            this.imgs = imgs;
        }

        @Override
        public View getView(ViewGroup container, int position) {
            ImageView view = new ImageView(container.getContext());
            view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            view.setImageResource(imgs.get(position));

            return view;
        }

        @Override
        public int getRealCount() {
            return imgs.size();
        }
    }
}

@@ -1760,70 +1760,8 @@
 R);%0A
-        mRollViewPager.getViewPager().setClipChildren(false);%0A
     
@@ -1826,24 +1826,54 @@
 gs.size());%0A
+        //%E8%AE%BE%E7%BD%AE%E4%B8%8B%E9%9D%A2%E5%B1%9E%E6%80%A7%E5%AF%BC%E8%87%B4%E5%B7%A6%E5%8F%B3%E4%B8%A4%E4%BE%A7%E9%98%B4%E5%BD%B1%E9%83%A8%E5%88%86%E4%B8%8D%E6%98%BE%E7%A4%BA%0A
         //mR

modify view pager