((View) appBarLayout.getParent()).setFitsSystemWindows(false); appBarLayout.setFitsSystemWindows(false); CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior(); if (behavior != null && behavior instanceof AppBarLayout.Behavior) { int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset(); if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { window.setStatusBarColor(statusColor); } else { appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
@Override public void invalidate() { super.invalidate(); invalidateParentIfNeeded(); }
@Override public void setBackgroundDrawable(Drawable background) { if (background instanceof RippleDrawable) { setRippleDrawable((RippleDrawable) background); return; } if (rippleDrawable != null && rippleDrawable.getStyle() == RippleDrawable.Style.Background) { rippleDrawable.setCallback(null); rippleDrawable = null; } super.setBackgroundDrawable(background); }
private void shortPress(@Direction int direction) { if (mScrollable == null) { return; } switch (direction) { case DIRECTION_UP: if (!mScrollable.scrollToPrevious() && mAppBarEnabled && mAppBarLayout != null) { mAppBarLayout.setExpanded(true, true); } break; case DIRECTION_DOWN: if (mAppBarEnabled && mAppBarLayout != null && mAppBarLayout.getHeight() == mAppBarLayout.getBottom()) { mAppBarLayout.setExpanded(false, true); } else { mScrollable.scrollToNext(); } break; case DIRECTION_NONE: default: break; } }
private void changeUiMode(boolean isReachMode) { CoordinatorLayout.LayoutParams appBarParams = (CoordinatorLayout.LayoutParams) mAppBar.getLayoutParams(); CoordinatorLayout.LayoutParams containerParams = (CoordinatorLayout.LayoutParams) mWebViewContainer.getLayoutParams(); mAppBar.setLayoutParams(appBarParams); mAppBar.invalidate(); mWebViewContainer.setLayoutParams(containerParams); mWebViewContainer.invalidate();
@Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); if (mAppBarLayout == null || newState != 0 || mAppBarLayoutDistance == 0 || (mAppBarLayoutDistance == mAppBarLayout.getHeight() && mScrollDistance != 0)) { return; } boolean show = mAppBarLayoutDistance < mAppBarLayout.getHeight() * 0.5f || mScrollDistance <= mViewPagerParent.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(mAppBarLayoutDistance, show ? 0 : mAppBarLayout.getHeight()); animator.addUpdateListener(animation -> { mAppBarLayoutDistance = (int) animation.getAnimatedValue(); mAppBarLayout.setTranslationY(-mAppBarLayoutDistance); }); animator.start(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (mCustomContentViewId != 0) setContentView(mCustomContentViewId); else setContentView(R.layout.activity_setup_big_header); AppBarLayout appBar = findViewById(R.id.appbar); CollapsingToolbarLayout toolbarLayout = findViewById(R.id.toolbar_layout); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); mLayout = findViewById(R.id.layout); mLayout.getViewTreeObserver().addOnGlobalLayoutListener(() -> { int height = mLayout.getHeight(); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams(); params.height = height / 3; appBar.setLayoutParams(params); int childHeight = (mContentView != null ? mContentView.getHeight() : 0); if (mContentView instanceof NestedScrollView) childHeight = ((NestedScrollView) mContentView).getChildAt(0).getHeight(); boolean needsScroll = (mContentView != null && childHeight > height - params.height); AppBarLayout.LayoutParams paramsToolbar = (AppBarLayout.LayoutParams) toolbarLayout.getLayoutParams(); paramsToolbar.setScrollFlags(needsScroll ? (AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) : 0); toolbarLayout.setLayoutParams(paramsToolbar); }); }
mAppBarLayout.addOnOffsetChangedListener(mAppBarStateListener); mAppBarLayout.setExpanded( savedInstanceState.getBoolean(ADS_STATE_APP_BAR_COLLAPSED));
private void longPress(@Direction int direction) { switch (direction) { case DIRECTION_DOWN: case DIRECTION_NONE: default: break; case DIRECTION_UP: if (mAppBarEnabled && mAppBarLayout != null) { mAppBarLayout.setExpanded(true, true); } if (mScrollable != null) { mScrollable.scrollToTop(); } break; } }
private void setupToolbar() { activity.setSupportActionBar(toolbar); if (activity.getSupportActionBar() != null) { activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); activity.getSupportActionBar().setHomeAsUpIndicator(R.drawable.dragdismiss_ic_close); activity.getSupportActionBar().setTitle(toolbarTitle); } if (!shouldShowToolbar) { toolbar.setVisibility(View.GONE); } int statusBarHeight = StatusBarHelper.getStatusBarHeight(activity); statusBar.getLayoutParams().height = statusBarHeight; if (appBarLayout == null) { ((CoordinatorLayout.LayoutParams) toolbar.getLayoutParams()).topMargin = statusBarHeight; } else { ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).topMargin = statusBarHeight; } }
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { if (statusView.getAlpha() == 0) { statusView.animate().cancel(); statusView.animate().alpha(1f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start(); } } else { if (statusView.getAlpha() == 1) { statusView.animate().cancel(); statusView.animate().alpha(0f).setDuration(collapsingToolbarLayout.getScrimAnimationDuration()).start(); } } } });
/** * sets the title on the toolbar only if the toolbar is collapsed */ private void handleCollapsedToolbarTitle() { mBinding.appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { boolean isShow = true; int scrollRange = -1; @Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (scrollRange == -1) { scrollRange = appBarLayout.getTotalScrollRange(); } // verify if the toolbar is completely collapsed and set the movie name as the title if (scrollRange + verticalOffset == 0) { mBinding.collapsingToolbar.setTitle( mViewModel.getResult().getValue().data.movie.getTitle()); isShow = true; } else if (isShow) { // display an empty string when toolbar is expanded mBinding.collapsingToolbar.setTitle(" "); isShow = false; } } }); } }
int oldLeft, int oldTop, int oldRight, int oldBottom) -> { int height = bottom - top; mAppBar.post(() -> { if (!isAdded()) return; if (height < getResources().getDimensionPixelSize(R.dimen.collapse_toolbar_activate_height)) { mAppBar.setVisibility(View.GONE); } else { updateToolbarCompactLayoutStatus(height); mAppBar.setVisibility(View.VISIBLE);
@Override public void setTranslationY(float translationY) { super.setTranslationY(translationY); invalidateParentIfNeeded(); fireOnTransformationChangedListener(); }
@Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); }
@Override public void onHideCustomView() { if (mCustomView == null) { return; } getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setImmersiveMode(false); mAppBar.setVisibility(View.VISIBLE); mWebViewContainer.setVisibility(View.VISIBLE); ViewGroup viewGroup = (ViewGroup) mCustomView.getParent(); viewGroup.removeView(mCustomView); mFullScreenCallback.onCustomViewHidden(); mFullScreenCallback = null; mCustomView = null; }
appBarHeight = mAppBarLayout.getHeight(); if (mAppBarLayoutDistance > mAppBarLayout.getHeight()) { mAppBarLayoutDistance = mAppBarLayout.getHeight(); } else if (mAppBarLayoutDistance < 0) { mAppBarLayoutDistance = 0; mAppBarLayout.setTranslationY(-mAppBarLayoutDistance);
@Override public void setupToolbarImage(Bitmap bm) { ImageView collapsingImage = findViewById(R.id.collapsing_image); if (collapsingImage != null) { collapsingImage.setImageBitmap(bm); // FIXME DIRTY HACK: Manually fix the toolbar size to the screen width CollapsingToolbarLayout toolbar = findViewById(R.id.collapsing_toolbar); AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); params.height = getWindow().getDecorView().getMeasuredWidth(); // Always expand the toolbar to show the complete image AppBarLayout appbar = findViewById(R.id.appbar); appbar.setExpanded(true, false); } }
@Override public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) { if (window.getStatusBarColor() != statusColor) { startColorAnimation(window.getStatusBarColor(), statusColor, collapsingToolbarLayout.getScrimAnimationDuration(), window); } } else { if (window.getStatusBarColor() != Color.TRANSPARENT) { startColorAnimation(window.getStatusBarColor(), Color.TRANSPARENT, collapsingToolbarLayout.getScrimAnimationDuration(), window); } } } });
@Override public void onDestroy() { super.onDestroy(); mItems.clear(); mRecyclerViewAdapter = null; setAppBarLayoutAlpha(255); if (mAppBarLayout != null && !isForeground()) { mAppBarLayout.setTranslationY(0); ViewCompat.setElevation(mAppBarLayout, 0); } if (mLoader != null) { mLoader.cancel(true); mLoader = null; } if (mReloader != null) { mReloader.cancel(true); mReloader = null; } if (mDialogLoader != null) { mDialogLoader.cancel(true); mDialogLoader = null; } for (RecyclerViewItem item : mItems) { item.onDestroy(); } }