Java Code Examples for com.github.ksoichiro.android.observablescrollview.ScrollUtils#getFloat()
The following examples show how to use
com.github.ksoichiro.android.observablescrollview.ScrollUtils#getFloat() .
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: FlexibleSpaceToolbarWebViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
private void updateFlexibleSpaceText(final int scrollY) { ViewHelper.setTranslationY(mFlexibleSpaceView, -scrollY); int adjustedScrollY = (int) ScrollUtils.getFloat(scrollY, 0, mFlexibleSpaceHeight); // Special logic for WebView. adjustTopMargin(mWebViewContainer, adjustedScrollY <= mFlexibleSpaceHeight ? 0 : mFlexibleSpaceHeight + getActionBarSize()); float maxScale = (float) (mFlexibleSpaceHeight - mToolbarView.getHeight()) / mToolbarView.getHeight(); float scale = maxScale * ((float) mFlexibleSpaceHeight - adjustedScrollY) / mFlexibleSpaceHeight; ViewHelper.setPivotX(mTitleView, 0); ViewHelper.setPivotY(mTitleView, 0); ViewHelper.setScaleX(mTitleView, 1 + scale); ViewHelper.setScaleY(mTitleView, 1 + scale); int maxTitleTranslationY = mToolbarView.getHeight() + mFlexibleSpaceHeight - (int) (mTitleView.getHeight() * (1 + scale)); int titleTranslationY = (int) (maxTitleTranslationY * ((float) mFlexibleSpaceHeight - adjustedScrollY) / mFlexibleSpaceHeight); ViewHelper.setTranslationY(mTitleView, titleTranslationY); }
Example 2
Source File: FlexibleSpaceWithImageWithViewPagerTab2Activity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
private void updateFlexibleSpace(float translationY) { ViewHelper.setTranslationY(mInterceptionLayout, translationY); int minOverlayTransitionY = getActionBarSize() - mOverlayView.getHeight(); ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-translationY / 2, minOverlayTransitionY, 0)); // Change alpha of overlay float flexibleRange = mFlexibleSpaceHeight - getActionBarSize(); ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat(-translationY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat((flexibleRange + translationY - mTabHeight) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); setPivotXToTitle(); ViewHelper.setPivotY(mTitleView, 0); ViewHelper.setScaleX(mTitleView, scale); ViewHelper.setScaleY(mTitleView, scale); }
Example 3
Source File: FlexibleSpaceWithImageRecyclerViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { // Translate overlay and image float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize; int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight(); ViewHelper.setTranslationY(mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0)); ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0)); // Translate list background ViewHelper.setTranslationY(mRecyclerViewBackground, Math.max(0, -scrollY + mFlexibleSpaceImageHeight)); // Change alpha of overlay ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat((flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); setPivotXToTitle(); ViewHelper.setPivotY(mTitleView, 0); ViewHelper.setScaleX(mTitleView, scale); ViewHelper.setScaleY(mTitleView, scale); // Translate title text int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale); int titleTranslationY = maxTitleTranslationY - scrollY; ViewHelper.setTranslationY(mTitleView, titleTranslationY); }
Example 4
Source File: StickyHeaderWebViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 6 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (mDragging) { int toolbarHeight = mToolbarView.getHeight(); if (mFirstScroll) { mFirstScroll = false; float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 5
Source File: ScrollFromBottomListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { int toolbarHeight = mToolbarView.getHeight(); if (dragging || scrollY < toolbarHeight) { if (firstScroll) { float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (-toolbarHeight < currentHeaderTranslationY && toolbarHeight < scrollY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 6
Source File: ViewPagerTabFragmentParentFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) { View toolbarView = getActivity().findViewById(R.id.toolbar); float translationY = ScrollUtils.getFloat(ViewHelper.getTranslationY(mInterceptionLayout) + diffY, -toolbarView.getHeight(), 0); ViewHelper.setTranslationY(mInterceptionLayout, translationY); ViewHelper.setTranslationY(toolbarView, translationY); if (translationY < 0) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); lp.height = (int) (-translationY + getScreenHeight()); mInterceptionLayout.requestLayout(); } }
Example 7
Source File: StickyHeaderListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); if (firstScroll) { float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 8
Source File: ScrollFromBottomRecyclerViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { int toolbarHeight = mToolbarView.getHeight(); if (dragging || scrollY < toolbarHeight) { if (firstScroll) { float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (-toolbarHeight < currentHeaderTranslationY && toolbarHeight < scrollY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 9
Source File: ViewPagerTab2Activity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) { float translationY = ScrollUtils.getFloat(ViewHelper.getTranslationY(mInterceptionLayout) + diffY, -mToolbarView.getHeight(), 0); ViewHelper.setTranslationY(mInterceptionLayout, translationY); if (translationY < 0) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); lp.height = (int) (-translationY + getScreenHeight()); mInterceptionLayout.requestLayout(); } }
Example 10
Source File: StickyHeaderScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); if (firstScroll) { float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 11
Source File: ViewPagerTabActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (firstScroll) { if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 12
Source File: ViewPagerTab2Activity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) { float translationY = ScrollUtils.getFloat(ViewHelper.getTranslationY(mInterceptionLayout) + diffY, -mToolbarView.getHeight(), 0); ViewHelper.setTranslationY(mInterceptionLayout, translationY); if (translationY < 0) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams(); lp.height = (int) (-translationY + getScreenHeight()); mInterceptionLayout.requestLayout(); } }
Example 13
Source File: ViewPagerTabListViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (firstScroll) { if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 14
Source File: ViewPagerTabActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (firstScroll) { if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 15
Source File: StickyHeaderRecyclerViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); if (firstScroll) { float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 16
Source File: FlexibleSpaceWithImageWithViewPagerTab2Activity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) { int flexibleSpace = mFlexibleSpaceHeight - mTabHeight; float translationY = ScrollUtils.getFloat(ViewHelper.getTranslationY(mInterceptionLayout) + diffY, -flexibleSpace, 0); MotionEvent e = MotionEvent.obtainNoHistory(ev); e.offsetLocation(0, translationY - mBaseTranslationY); mVelocityTracker.addMovement(e); updateFlexibleSpace(translationY); }
Example 17
Source File: ViewPagerTabScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { if (dragging) { int toolbarHeight = mToolbarView.getHeight(); float currentHeaderTranslationY = ViewHelper.getTranslationY(mHeaderView); if (firstScroll) { if (-toolbarHeight < currentHeaderTranslationY) { mBaseTranslationY = scrollY; } } float headerTranslationY = ScrollUtils.getFloat(-(scrollY - mBaseTranslationY), -toolbarHeight, 0); ViewPropertyAnimator.animate(mHeaderView).cancel(); ViewHelper.setTranslationY(mHeaderView, headerTranslationY); } }
Example 18
Source File: FlexibleSpaceWithImageWithViewPagerTabActivity.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
private void translateTab(int scrollY, boolean animated) { int flexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height); int tabHeight = getResources().getDimensionPixelSize(R.dimen.tab_height); View imageView = findViewById(R.id.image); View overlayView = findViewById(R.id.overlay); TextView titleView = (TextView) findViewById(R.id.title); // Translate overlay and image float flexibleRange = flexibleSpaceImageHeight - getActionBarSize(); int minOverlayTransitionY = tabHeight - overlayView.getHeight(); ViewHelper.setTranslationY(overlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0)); ViewHelper.setTranslationY(imageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0)); // Change alpha of overlay ViewHelper.setAlpha(overlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat((flexibleRange - scrollY - tabHeight) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); setPivotXToTitle(titleView); ViewHelper.setPivotY(titleView, 0); ViewHelper.setScaleX(titleView, scale); ViewHelper.setScaleY(titleView, scale); // Translate title text int maxTitleTranslationY = flexibleSpaceImageHeight - tabHeight - getActionBarSize(); int titleTranslationY = maxTitleTranslationY - scrollY; ViewHelper.setTranslationY(titleView, titleTranslationY); // If tabs are moving, cancel it to start a new animation. ViewPropertyAnimator.animate(mSlidingTabLayout).cancel(); // Tabs will move between the top of the screen to the bottom of the image. float translationY = ScrollUtils.getFloat(-scrollY + mFlexibleSpaceHeight - mTabHeight, 0, mFlexibleSpaceHeight - mTabHeight); if (animated) { // Animation will be invoked only when the current tab is changed. ViewPropertyAnimator.animate(mSlidingTabLayout) .translationY(translationY) .setDuration(200) .start(); } else { // When Fragments' scroll, translate tabs immediately (without animation). ViewHelper.setTranslationY(mSlidingTabLayout, translationY); } }
Example 19
Source File: FlexibleSpaceWithImageGridViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { // Translate overlay and image float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize; int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight(); ViewHelper.setTranslationY(mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0)); ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0)); // Translate list background ViewHelper.setTranslationY(mListBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight)); // Change alpha of overlay ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat((flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); setPivotXToTitle(); ViewHelper.setPivotY(mTitleView, 0); ViewHelper.setScaleX(mTitleView, scale); ViewHelper.setScaleY(mTitleView, scale); // Translate title text int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale); int titleTranslationY = maxTitleTranslationY - scrollY; ViewHelper.setTranslationY(mTitleView, titleTranslationY); // Translate FAB int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2; float fabTranslationY = ScrollUtils.getFloat( -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2, mActionBarSize - mFab.getHeight() / 2, maxFabTranslationY); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin, // which causes FAB's OnClickListener not working. FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams(); lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth(); lp.topMargin = (int) fabTranslationY; mFab.requestLayout(); } else { ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth()); ViewHelper.setTranslationY(mFab, fabTranslationY); } // Show/hide FAB if (fabTranslationY < mFlexibleSpaceShowFabOffset) { hideFab(); } else { showFab(); } }
Example 20
Source File: FlexibleSpaceWithImageScrollViewActivity.java From Android-ObservableScrollView with Apache License 2.0 | 4 votes |
@Override public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) { // Translate overlay and image float flexibleRange = mFlexibleSpaceImageHeight - mActionBarSize; int minOverlayTransitionY = mActionBarSize - mOverlayView.getHeight(); ViewHelper.setTranslationY(mOverlayView, ScrollUtils.getFloat(-scrollY, minOverlayTransitionY, 0)); ViewHelper.setTranslationY(mImageView, ScrollUtils.getFloat(-scrollY / 2, minOverlayTransitionY, 0)); // Change alpha of overlay ViewHelper.setAlpha(mOverlayView, ScrollUtils.getFloat((float) scrollY / flexibleRange, 0, 1)); // Scale title text float scale = 1 + ScrollUtils.getFloat((flexibleRange - scrollY) / flexibleRange, 0, MAX_TEXT_SCALE_DELTA); ViewHelper.setPivotX(mTitleView, 0); ViewHelper.setPivotY(mTitleView, 0); ViewHelper.setScaleX(mTitleView, scale); ViewHelper.setScaleY(mTitleView, scale); // Translate title text int maxTitleTranslationY = (int) (mFlexibleSpaceImageHeight - mTitleView.getHeight() * scale); int titleTranslationY = maxTitleTranslationY - scrollY; ViewHelper.setTranslationY(mTitleView, titleTranslationY); // Translate FAB int maxFabTranslationY = mFlexibleSpaceImageHeight - mFab.getHeight() / 2; float fabTranslationY = ScrollUtils.getFloat( -scrollY + mFlexibleSpaceImageHeight - mFab.getHeight() / 2, mActionBarSize - mFab.getHeight() / 2, maxFabTranslationY); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // On pre-honeycomb, ViewHelper.setTranslationX/Y does not set margin, // which causes FAB's OnClickListener not working. FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mFab.getLayoutParams(); lp.leftMargin = mOverlayView.getWidth() - mFabMargin - mFab.getWidth(); lp.topMargin = (int) fabTranslationY; mFab.requestLayout(); } else { ViewHelper.setTranslationX(mFab, mOverlayView.getWidth() - mFabMargin - mFab.getWidth()); ViewHelper.setTranslationY(mFab, fabTranslationY); } // Show/hide FAB if (fabTranslationY < mFlexibleSpaceShowFabOffset) { hideFab(); } else { showFab(); } }