content: package com.angcyo.sample.viewpager;
  
  import android.content.Intent;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.design.widget.FloatingActionButton;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentPagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.util.Log;
  import android.view.Gravity;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import com.angcyo.sample.R;
  import com.rsen.exception.RCrashHandler;
  import com.rsen.view.CircleIndicator;
  
  public class ViewPagerActivity extends AppCompatActivity {
  
      ViewPager viewPager;
      CircleIndicator circleIndicator;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_view_pager);
          Toolbar toolbar = (Toolbar) findViewById(R.id.base_toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.base_fab);
  //        fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  //                .setAction("Action", null).show());
  //        fab.setOnClickListener(v ->
  //                Snackbar.make(v, "Replace with your own action", Snackbar.LENGTH_LONG)
  //                        .setAction("Action", null).show()
  //        );
  
          RCrashHandler.init(this);
          initView();
  
  //        Intent intent = new Intent(Intent.ACTION_VIEW);
  //        startActivity(intent);
      }
  
      private void initView() {
          viewPager = (ViewPager) findViewById(R.id.view_pager);
          viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
  //        viewPager.setPageTransformer(true, new ZoomOutPageTransformer());
          viewPager.setPageTransformer(true, new DepthPageTransformer());
          viewPager.setOffscreenPageLimit(0);
  
          circleIndicator = (CircleIndicator) findViewById(R.id.indicator);
          circleIndicator.setViewPager(viewPager);
      }
  
      public static class RFragment extends Fragment {
  
          private int index;
  
          public static RFragment newInstance(int index) {
              RFragment fragment = new RFragment();
              Bundle bundle = new Bundle();
              bundle.putInt("index", index);
              fragment.setArguments(bundle);
              return fragment;
          }
  
          @Override
          public void onCreate(@Nullable Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              index = getArguments().getInt("index");
              e("-->onCreate ");
          }
  
          @Nullable
          @Override
          public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
              e("-->onCreateView ");
              TextView textView = new TextView(getActivity());
              textView.setText("Page index " + index);
              textView.setBackgroundColor(Color.parseColor("#30ff0092"));
              textView.setGravity(Gravity.CENTER);
              return textView;
          }
  
          @Override
          public void onStart() {
              super.onStart();
              e("-->onStart ");
          }
  
          @Override
          public void onResume() {
              super.onResume();
              e("-->onResume ");
          }
  
          @Override
          public void onPause() {
              super.onPause();
              e("-->onPause ");
          }
  
          @Override
          public void onStop() {
              super.onStop();
              e("-->onStop ");
          }
  
          @Override
          public void setUserVisibleHint(boolean isVisibleToUser) {
              super.setUserVisibleHint(isVisibleToUser);
              e("-->isVisibleToUser " + isVisibleToUser);
          }
  
          private void e(String log) {
              Log.e("angcyo-->" + index, this.getClass().getSimpleName() + log);
          }
      }
  
      class ViewPagerAdapter extends FragmentPagerAdapter {
  
          public ViewPagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public Fragment getItem(int position) {
              if (position == 1) {
                  Intent intent = new Intent("com.angcyo.test");
                  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                  ViewPagerActivity.this.startActivity(intent);
              }
              if (position == 3) {
                  throw new IllegalStateException("哎呀,,,什么情况?");
              }
              return RFragment.newInstance(position);
          }
  
          @Override
          public int getCount() {
              return 10;
          }
  
          @Override
          public CharSequence getPageTitle(int position) {
              return new String("title " + position);
          }
      }
  
      public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
          private static final float MIN_SCALE = 0.85f;
          private static final float MIN_ALPHA = 0.5f;
  
          public void transformPage(View view, float position) {
              int pageWidth = view.getWidth();
              int pageHeight = view.getHeight();
              if (position < -1) { // [-Infinity,-1)
                  // This page is way off-screen to the left. 将要从左边离开屏幕
                  view.setAlpha(0);
              } else if (position <= 1) { // [-1,1]
                  // Modify the default slide transition to shrink the page as well
                  float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
                  float vertMargin = pageHeight * (1 - scaleFactor) / 2;
                  float horzMargin = pageWidth * (1 - scaleFactor) / 2;
                  if (position < 0) {
                      view.setTranslationX(horzMargin - vertMargin / 2);
                  } else {
                      view.setTranslationX(-horzMargin + vertMargin / 2);
                  }
                  // Scale the page down (between MIN_SCALE and 1)
                  view.setScaleX(scaleFactor);
                  view.setScaleY(scaleFactor);
                  // Fade the page relative to its size.
                  view.setAlpha(MIN_ALPHA +
                          (scaleFactor - MIN_SCALE) /
                                  (1 - MIN_SCALE) * (1 - MIN_ALPHA));
              } else { // (1,+Infinity]
                  // This page is way off-screen to the right.  将要从右边离开屏幕
                  view.setAlpha(0);
              }
          }
      }
  
      // -1  0  1
      //-1 表示中心的 左边page
      // 0 表示中心
      // 1 表示中心的 右边page
  
      //向左滑
      //左边page -1 -2
      //中心      0 -1
      //右边page  1  0
  
      //向右滑
      //左边page -1 0
      //中心      0 1
      //右边page  1 2
  
      public class DepthPageTransformer implements ViewPager.PageTransformer {
          private static final float MIN_SCALE = 0.75f;
  
          public void transformPage(View view, float position) {
              int pageWidth = view.getWidth();
              if (position < -1) { // [-Infinity,-1)
                  // This page is way off-screen to the left.
                  view.setAlpha(0);
              } else if (position <= 0) { // [-1,0]
                  // Use the default slide transition when moving to the left page
                  view.setAlpha(1);
                  view.setTranslationX(0);
                  view.setScaleX(1);
                  view.setScaleY(1);
              } else if (position <= 1) { // (0,1]
                  // Fade the page out.
                  view.setAlpha(1 - position);
                  // Counteract the default slide transition
                  view.setTranslationX(pageWidth * -position);
                  // Scale the page down (between MIN_SCALE and 1)
                  float scaleFactor = MIN_SCALE
                          + (1 - MIN_SCALE) * (1 - Math.abs(position));
                  view.setScaleX(scaleFactor);
                  view.setScaleY(scaleFactor);
              } else { // (1,+Infinity]
                  // This page is way off-screen to the right.
                  view.setAlpha(0);
              }
          }
      }
  
  }
  