예제 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    ButterKnife.inject(this);

    postponeEnterTransition();
    mPager
        .getViewTreeObserver()
        .addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
              public boolean onPreDraw() {
                mPager.getViewTreeObserver().removeOnPreDrawListener(this);
                startPostponedEnterTransition();
                return true;
              }
            });

    List<String> list = new ArrayList<String>();
    list.add("http://a1.zassets.com/images/z/3/0/2/7/2/8/3027286-p-MULTIVIEW.jpg");
    list.add("http://a1.zassets.com/images/z/2/7/2/7/3/3/2727332-p-MULTIVIEW.jpg");
    list.add("http://a3.zassets.com/images/z/2/7/3/4/1/0/2734106-p-MULTIVIEW.jpg");
    list.add("http://a3.zassets.com/images/z/2/8/1/4/5/4/2814541-p-MULTIVIEW.jpg");

    PhotoAdapter adapter = new PhotoAdapter(this, list);
    mPager.setAdapter(adapter);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tool_list);

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

    mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE);
    if (mToolType == null) {
      throw new IllegalStateException("ToolType not available as extra; use startActivity");
    }
    setTitle(mToolType.getToolNameResourceId());

    // Set up tabs
    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    final ToolPagerAdapter toolPagerAdapter =
        new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType);
    tabLayout.setTabsFromPagerAdapter(toolPagerAdapter);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    mViewPager.setAdapter(toolPagerAdapter);
    tabLayout.setOnTabSelectedListener(this);

    // Handle animation from previous activity
    postponeEnterTransition();
    mViewPager
        .getViewTreeObserver()
        .addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
              @Override
              public boolean onPreDraw() {
                mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
                startPostponedEnterTransition();
                return true;
              }
            });

    setEnterSharedElementCallback(
        new SharedElementCallback() {
          @Override
          public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (mViewPager.getCurrentItem() != 0) {
              // Not displaying the about page, which has the hero image
              names.clear();
              sharedElements.clear();
            }
          }
        });
  }