コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    ActivityCompat.postponeEnterTransition(this);
    setContentView(R.layout.rect_prism_new);

    Toolbar toolbar = (Toolbar) findViewById(R.id.cyl_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    ViewPager viewPager = (ViewPager) findViewById(R.id.cyl_viewpager);
    setupViewPager(viewPager);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.cyl_tablayout);
    tabLayout.setupWithViewPager(viewPager);
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);
    ActivityCompat.postponeEnterTransition(this);
    mStartingPosition = getIntent().getIntExtra(Extras.STARTING_DETAIL_POSITION, 0);
    if (savedInstanceState == null) {
      mCurrentPosition = mStartingPosition;
    } else {
      mCurrentPosition = savedInstanceState.getInt(Extras.CURRENT_DETAIL_POSITION);
    }

    getLoaderManager().initLoader(0, null, this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      mCallback =
          new SharedElementCallback() {
            @Override
            public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
              if (mIsReturning) {
                ImageView sharedElement = mCurrentDetailsFragment.getHeaderImage();
                if (sharedElement == null) {
                  // If shared element is null, then it has been scrolled off screen and
                  // no longer visible. In this case we cancel the shared element transition by
                  // removing the shared element from the shared elements map.
                  names.clear();
                  sharedElements.clear();
                } else if (mStartingPosition != mCurrentPosition) {
                  // If the user has swiped to a different ViewPager page, then we need to
                  // remove the old shared element and replace it with the new shared element
                  // that should be transitioned instead.
                  names.clear();
                  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    names.add(sharedElement.getTransitionName());
                    sharedElements.clear();
                  }
                }
                sharedElements.put(sharedElement.getTransitionName(), sharedElement);
              }
            }
          };
      setEnterSharedElementCallback(mCallback);
    }

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);

    mPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageScrollStateChanged(int state) {
            super.onPageScrollStateChanged(state);
          }

          @Override
          public void onPageSelected(int position) {
            if (mCursor != null) {
              mCursor.moveToPosition(position);
            }
            mCurrentPosition = position;
            mSelectedItemId = mCursor.getLong(ArticleLoader.Query._ID);
          }
        });

    if (savedInstanceState == null) {
      if (getIntent() != null && getIntent().getData() != null) {
        mStartId = ItemsContract.Items.getItemId(getIntent().getData());
        mSelectedItemId = mStartId;
      }
    }
  }