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

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

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setPageMargin(
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));

    mPager.addOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {

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

    if (savedInstanceState == null) {
      if (getIntent() != null && getIntent().getData() != null) {
        mStartId = ItemsContract.Items.getItemId(getIntent().getData());
        mSelectedItemId = mStartId;
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow()
          .getDecorView()
          .setSystemUiVisibility(
              View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }
    setContentView(R.layout.activity_article_detail);

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

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setPageMargin(
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));

    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);
            }
            mSelectedItemId = mCursor.getLong(ArticleLoader.Query._ID);
          }
        });

    // Enable up button on toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if (savedInstanceState == null) {
      if (getIntent() != null && getIntent().getData() != null) {
        mStartId = ItemsContract.Items.getItemId(getIntent().getData());
        mSelectedItemId = mStartId;
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article_detail);

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

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setPageMargin(
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()));
    mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));

    mPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageScrollStateChanged(int state) {
            super.onPageScrollStateChanged(state);
            mUpButton
                .animate()
                .alpha((state == ViewPager.SCROLL_STATE_IDLE) ? 1f : 0f)
                .setDuration(300);
          }

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

    mUpButtonContainer = findViewById(R.id.up_container);

    mUpButton = findViewById(R.id.action_up);
    mUpButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            onSupportNavigateUp();
          }
        });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      mUpButtonContainer.setOnApplyWindowInsetsListener(
          new View.OnApplyWindowInsetsListener() {
            @Override
            public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
              view.onApplyWindowInsets(windowInsets);
              mTopInset = windowInsets.getSystemWindowInsetTop();
              mUpButtonContainer.setTranslationY(mTopInset);
              updateUpButtonPosition();
              return windowInsets;
            }
          });
    }

    if (savedInstanceState == null) {
      if (getIntent() != null && getIntent().getData() != null) {
        mStartId = ItemsContract.Items.getItemId(getIntent().getData());
        mSelectedItemId = mStartId;
      }
    }
  }
예제 #4
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;
      }
    }
  }