Java Code Examples for android.support.design.widget.AppBarLayout#getTotalScrollRange()

The following examples show how to use android.support.design.widget.AppBarLayout#getTotalScrollRange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppBarStateChangeListener.java    From AmazingAvatar with MIT License 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
	if (i == 0) {
		if (mCurrentState != State.EXPANDED) {
			onStateChanged(appBarLayout, State.EXPANDED);
		}
		mCurrentState = State.EXPANDED;
	} else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
		if (mCurrentState != State.COLLAPSED) {
			onStateChanged(appBarLayout, State.COLLAPSED);
		}
		mCurrentState = State.COLLAPSED;
	} else {
		if (mCurrentState != State.IDLE) {
			onStateChanged(appBarLayout, State.IDLE);
		}
		mCurrentState = State.IDLE;
	}
	float offset = Math.abs(i / (float) appBarLayout.getTotalScrollRange());
	if (offset != mCurrentOffset) {
		mCurrentOffset = offset;
		onOffsetChanged(mCurrentState, offset);
	}
}
 
Example 2
Source File: AppBarStateChangeListener.java    From LazyRecyclerAdapter with MIT License 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 3
Source File: AppBarStateChangeEvent.java    From LQRBiliBlili with MIT License 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    if (verticalOffset == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED, verticalOffset);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED, verticalOffset);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE, verticalOffset);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 4
Source File: AppBarStateChangeListener.java    From Capstone-Project with MIT License 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 5
Source File: SixStickyViewActivity.java    From YCRefreshView with Apache License 2.0 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    int totalScrollRange = appBarLayout.getTotalScrollRange();
    if (verticalOffset == 0) {
        if (state != STATES.EXPANDED) {
            //修改状态标记为展开
            state = STATES.EXPANDED;
            RefreshLogUtils.e("OnOffsetChangedListener"+ "修改状态标记为展开");
        }
    } else if (Math.abs(verticalOffset) >= totalScrollRange) {
        if (state != STATES.COLLAPSED) {
            //修改状态标记为折叠
            state = STATES.COLLAPSED;
            RefreshLogUtils.e("OnOffsetChangedListener"+ "修改状态标记为折叠");
        }
    } else {
        if (state != STATES.INTERMEDIATE) {
            //修改状态标记为中间
            state = STATES.INTERMEDIATE;
            //代码设置是否拦截事件
            RefreshLogUtils.e("OnOffsetChangedListener"+ "修改状态标记为中间");
        }
        
    }
}
 
Example 6
Source File: AppBarStateChangeListener.java    From LRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 7
Source File: AppBarStateChangeListener.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 8
Source File: MyCollapsingToolbarLayout.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout layout, int verticalOffset) {
    final int scrollRange = layout.getTotalScrollRange();

    //if (Math.abs(verticalOffset) == scrollRange) {
    //    // If we have some pinned children, and we're offset to only show those views,
    //    // we want to be elevate
    //
    //
      ViewCompat.setElevation(layout, layout.getTargetElevation());
    //} else {
    //    // Otherwise, we're inline with the content
    //    ViewCompat.setElevation(layout, 0f);
    //}

    if(Math.abs(verticalOffset)>=getHeight()-56*getResources().getDisplayMetrics().density){
        if(listener!=null){
            listener.collapsed();
        }
    }else {
        if(listener!=null){
            listener.expand();
        }
    }
}
 
Example 9
Source File: AppBarStateChangeListener.java    From Cook-It-Android-XML-Template with MIT License 6 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
    if (i == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED);
        }
        mCurrentState = State.EXPANDED;
    } else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED);
        }
        mCurrentState = State.COLLAPSED;
    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 10
Source File: UserCenterActivity.java    From MaoWanAndoidClient with Apache License 2.0 6 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    //获取最大偏移值
    int scrollRangle = appBarLayout.getTotalScrollRange();
    ivParallax.setTranslationY(verticalOffset);
    /**
     * 这个数值可以自己定义 显示 toolbar 用户名称
     */
    if (verticalOffset < -250) {
        tvTbNickName.setVisibility(View.VISIBLE);
    } else {
        tvTbNickName.setVisibility(View.GONE);
    }
    int mAlpha = (int) Math.abs(255f / scrollRangle * verticalOffset);
    int color = ContextCompat.getColor(appBarLayout.getContext(), R.color.colorPrimary)&0x00ffffff;
    StatusBarUtil.setColorNoTranslucentLightMode(this,((mAlpha) << 24) | color);
    //顶部title渐变效果
    mToolBar.setBackgroundColor(((mAlpha) << 24) | color);
}
 
Example 11
Source File: ScrollController.java    From GpCollapsingToolbar with Apache License 2.0 6 votes vote down vote up
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    if (appBarLayout != null) {
        int scrollRange = appBarLayout.getTotalScrollRange();
        if (mAppBarScrollRange == null || mAppBarScrollRange != scrollRange) {
            mAppBarScrollRange = scrollRange;
        }
    }

    int absOffset = Math.abs(verticalOffset);
    StringBuilder sb = new StringBuilder();
    if (mPreviousVerticalOffset == null) {
        mPreviousVerticalOffset = absOffset;
        sb.append("Starting offset change detection\r\n");
    } else if (absOffset < mPreviousVerticalOffset) {
        sb.append("Scroll UP!");
    } else if (absOffset > mPreviousVerticalOffset) {
        sb.append("Scroll DOWN!");
    }
    calculateDistance(appBarLayout, absOffset, mPreviousVerticalOffset);
    mPreviousVerticalOffset = absOffset;
}
 
Example 12
Source File: FixAppBarLayoutBehavior.java    From px-android with MIT License 5 votes vote down vote up
private void stopNestedScrollIfNeeded(final int dy,
    @NonNull final AppBarLayout child,
    @NonNull final View target, final int type) {

    if (type == ViewCompat.TYPE_NON_TOUCH) {
        final int currOffset = getTopAndBottomOffset();
        if ((dy < 0 && currOffset == 0)
            || (dy > 0 && currOffset == -child.getTotalScrollRange())) {
            ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH);
        }
    }
}
 
Example 13
Source File: ThreadListFragment.java    From TLint with Apache License 2.0 5 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    if (verticalOffset == 0 || verticalOffset == -appBarLayout.getTotalScrollRange()) {
        refreshLayout.setEnabled(true);
    } else {
        refreshLayout.setEnabled(false);
    }
}
 
Example 14
Source File: AlipayHomeActivity.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    Log.d("lzx", "verticalOffset=" + verticalOffset);
    //720*1080手机 verticalOffset取值范围[0-200]px
    int absVerticalOffset = Math.abs(verticalOffset);//AppBarLayout竖直方向偏移距离px
    int totalScrollRange = appBarLayout.getTotalScrollRange();//AppBarLayout总的距离px
    //背景颜色转化成RGB的渐变色
    int argb = Color.argb(absVerticalOffset, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor));
    int argbDouble = Color.argb(absVerticalOffset * 2, Color.red(mMaskColor), Color.green(mMaskColor), Color.blue(mMaskColor));
    //appBarLayout上滑一半距离后小图标应该由渐变到全透明
    int title_small_offset = (200 - absVerticalOffset) < 0 ? 0 : 200 - absVerticalOffset;
    int title_small_argb = Color.argb(title_small_offset * 2, Color.red(mMaskColor),
            Color.green(mMaskColor), Color.blue(mMaskColor));
    //appBarLayout上滑不到一半距离
    if (absVerticalOffset <= totalScrollRange / 2) {
        include_toolbar_search.setVisibility(View.VISIBLE);
        include_toolbar_small.setVisibility(View.GONE);
        //为了和下面的大图标渐变区分,乘以2倍渐变
        v_toolbar_search_mask.setBackgroundColor(argbDouble);
    } else {
        include_toolbar_search.setVisibility(View.GONE);
        include_toolbar_small.setVisibility(View.VISIBLE);
        //appBarLayout上滑一半距离后小图标应该由渐变到全透明
        v_toolbar_small_mask.setBackgroundColor(title_small_argb);

    }
    //上滑时遮罩由全透明到半透明
    v_title_big_mask.setBackgroundColor(argb);
}
 
Example 15
Source File: AppBarStateChangeListener.java    From RetrofitGO with Apache License 2.0 5 votes vote down vote up
@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    //当前滚动了多少高度
    int mVerticalOffset = Math.abs(verticalOffset);
    //AppBarLayout总共高度
    int totalScrollRange = appBarLayout.getTotalScrollRange();

    if (verticalOffset == 0) {
        if (mCurrentState != State.EXPANDED) {
            onStateChanged(appBarLayout, State.EXPANDED, verticalOffset);
        }
        mCurrentState = State.EXPANDED;

    } else if (mVerticalOffset >= totalScrollRange) {
        if (mCurrentState != State.COLLAPSED) {
            onStateChanged(appBarLayout, State.COLLAPSED, verticalOffset);
        }
        mCurrentState = State.COLLAPSED;

    } else if (mVerticalOffset > (totalScrollRange/2 - middleRangeValue)
            && mVerticalOffset < (totalScrollRange/2 + middleRangeValue)){
        if (mCurrentState != State.MIDDLE) {
            onStateChanged(appBarLayout, State.MIDDLE, verticalOffset);
        }
        mCurrentState = State.MIDDLE;

    } else {
        if (mCurrentState != State.IDLE) {
            onStateChanged(appBarLayout, State.IDLE, verticalOffset);
        }
        mCurrentState = State.IDLE;
    }
}
 
Example 16
Source File: UserActivity.java    From materialup with Apache License 2.0 5 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    int maxScroll = appBarLayout.getTotalScrollRange();
    float percentage = (float) Math.abs(verticalOffset) / (float) maxScroll;

    handleAlphaOnTitle(percentage);
    handleToolbarTitleVisibility(percentage);
}
 
Example 17
Source File: ScrollingActivity.java    From XPlayer2 with Apache License 2.0 4 votes vote down vote up
@Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
//        MLog.i("verticalOffset = " + verticalOffset);
        if (verticalOffset == 0) {
            if (mAppBarLayoutCurrentState != APP_BAR_LAYOUT_EXPANDED) {
                mCollapsingToolbarLayout.setTitle("");

                if (mVideoView.getSurface() != null) {
                    mMediaPlayer.setSurface(mVideoView.getSurface());
                }

                if (mSmallVideoView.getVisibility() == View.VISIBLE) {
                    mSmallVideoView.setVisibility(View.GONE);
                }

                mAppBarLayoutCurrentState = APP_BAR_LAYOUT_EXPANDED;
            }
        } else if (Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()) {
            if (mAppBarLayoutCurrentState != APP_BAR_LAYOUT_COLLAPSED) {
                mCollapsingToolbarLayout.setTitle("大小视频显示组件互动");

                if (mSmallVideoView.getVisibility() == View.GONE) {
                    mSmallVideoView.setVisibility(View.VISIBLE);
                    // 重置到初始化所在位置
                    mSmallVideoView.restorePosition();

                    if (mSmallVideoView.getSurface() != null) {
                        mMediaPlayer.setSurface(mSmallVideoView.getSurface());
                    }
                }

                mAppBarLayoutCurrentState = APP_BAR_LAYOUT_COLLAPSED;
            }
        } else {
            if (mAppBarLayoutCurrentState != APP_BAR_LAYOUT_IDLE) {
                if (mAppBarLayoutCurrentState == APP_BAR_LAYOUT_COLLAPSED) {
                    // 中间状态
                    mSmallVideoView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            if (mVideoView.getSurface() != null) {
                                mMediaPlayer.setSurface(mVideoView.getSurface());
                            }

                            if (mSmallVideoView.getVisibility() == View.VISIBLE) {
                                mSmallVideoView.setVisibility(View.GONE);
                            }
                        }
                    }, 50);
                }
                mAppBarLayoutCurrentState = APP_BAR_LAYOUT_IDLE;
            }
        }
    }
 
Example 18
Source File: ProfileActivity.java    From AndroidPlusJava with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    int maxScroll = appBarLayout.getTotalScrollRange();
    float percentage = (float) Math.abs(verticalOffset) / (float) maxScroll;
    mProfileInfo.setAlpha(1 - percentage);
}
 
Example 19
Source File: FixScrollingFooterBehavior.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
private int calculateBottomPadding(@NonNull AppBarLayout dependency) {
    final int totalScrollRange = dependency.getTotalScrollRange();
    return totalScrollRange + dependency.getTop();
}
 
Example 20
Source File: FlexibleToolbarLayout.java    From AppCompat-Extension-Library with Apache License 2.0 4 votes vote down vote up
@Override
public void onOffsetChanged(AppBarLayout layout, int verticalOffset) {
    mCurrentOffset = verticalOffset;

    final int insetTop = mLastInsets != null ? mLastInsets.getSystemWindowInsetTop() : 0;
    final int scrollRange = layout.getTotalScrollRange();

    for (int i = 0, z = getChildCount(); i < z; i++) {
        final View child = getChildAt(i);
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        final ViewOffsetHelper offsetHelper = getViewOffsetHelper(child);

        switch (lp.mCollapseMode) {
            case LayoutParams.COLLAPSE_MODE_PIN:
                if (getHeight() - insetTop + verticalOffset >= child.getHeight()) {
                    offsetHelper.setTopAndBottomOffset(-verticalOffset);
                }
                break;
            case LayoutParams.COLLAPSE_MODE_PARALLAX:
                offsetHelper.setTopAndBottomOffset(
                        Math.round(-verticalOffset * lp.mParallaxMult));
                break;
        }
    }

    // Show or hide the scrims if needed
    if (mContentScrim != null || mStatusBarScrim != null) {
        setScrimsShown(getHeight() + verticalOffset < getScrimTriggerOffset() + insetTop);
    }

    if (mStatusBarScrim != null && insetTop > 0) {
        ViewCompat.postInvalidateOnAnimation(FlexibleToolbarLayout.this);
    }

    // Update the collapsing text's fraction
    final int expandRange = getHeight() - ViewCompat.getMinimumHeight(
            FlexibleToolbarLayout.this) - insetTop;
    float fraction = Math.abs(verticalOffset) / (float) expandRange;
    mTitleCollapsingTextHelper.setExpansionFraction(fraction);
    mSubtitleCollapsingTextHelper.setExpansionFraction(fraction);
    mIconCollapsingHelper.setExpansionFraction(fraction);
}