Java Code Examples for com.nineoldandroids.view.ViewHelper#getTranslationY()

The following examples show how to use com.nineoldandroids.view.ViewHelper#getTranslationY() . 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: ParentAppCompatActivity.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void moveToolbar(float toTranslationY) {
    if (ViewHelper.getTranslationY(mToolbar) == toTranslationY) {
        return;
    }
    ValueAnimator animator = ValueAnimator
            .ofFloat(ViewHelper.getTranslationY(mToolbar), toTranslationY)
            .setDuration(200);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float translationY = (float) animation.getAnimatedValue();
            ViewHelper.setTranslationY(mToolbar, translationY);
        }
    });
    animator.start();
}
 
Example 2
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
private void animateToolbar(final float toY) {
    float layoutTranslationY = ViewHelper.getTranslationY(mInterceptionLayout);
    if (layoutTranslationY != toY) {
        ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mInterceptionLayout), toY).setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float translationY = (float) animation.getAnimatedValue();
                ViewHelper.setTranslationY(mInterceptionLayout, translationY);
                if (translationY < 0) {
                    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
                    lp.height = (int) (-translationY + getScreenHeight());
                    mInterceptionLayout.requestLayout();
                }
            }
        });
        animator.start();
    }
}
 
Example 3
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
private void animateToolbar(final float toY) {
    float layoutTranslationY = ViewHelper.getTranslationY(mInterceptionLayout);
    if (layoutTranslationY != toY) {
        ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mInterceptionLayout), toY).setDuration(200);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float translationY = (float) animation.getAnimatedValue();
                ViewHelper.setTranslationY(mInterceptionLayout, translationY);
                if (translationY < 0) {
                    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInterceptionLayout.getLayoutParams();
                    lp.height = (int) (-translationY + getScreenHeight());
                    mInterceptionLayout.requestLayout();
                }
            }
        });
        animator.start();
    }
}
 
Example 4
Source File: ToolbarControlScrollViewActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    mBaseTranslationY = 0;

    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (scrollState == ScrollState.UP) {
        if (toolbarHeight < mScrollView.getCurrentScrollY()) {
            if (headerTranslationY != -toolbarHeight) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
            }
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (toolbarHeight < mScrollView.getCurrentScrollY()) {
            if (headerTranslationY != 0) {
                ViewPropertyAnimator.animate(mHeaderView).cancel();
                ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
            }
        }
    }
}
 
Example 5
Source File: SlidingUpBaseActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void changeToolbarTitleVisibility() {
    if (ViewHelper.getTranslationY(mInterceptionLayout) <= mIntersectionHeight) {
        if (ViewHelper.getAlpha(mToolbarTitle) != 1) {
            ViewPropertyAnimator.animate(mToolbarTitle).cancel();
            ViewPropertyAnimator.animate(mToolbarTitle).alpha(1).setDuration(200).start();
        }
    } else if (ViewHelper.getAlpha(mToolbarTitle) != 0) {
        ViewPropertyAnimator.animate(mToolbarTitle).cancel();
        ViewPropertyAnimator.animate(mToolbarTitle).alpha(0).setDuration(200).start();
    } else {
        ViewHelper.setAlpha(mToolbarTitle, 0);
    }
}
 
Example 6
Source File: SlidingUpBaseActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void changeHeaderOverlay() {
    final float translationY = ViewHelper.getTranslationY(mInterceptionLayout);
    if (translationY <= mToolbar.getHeight() - mSlidingHeaderBlueSize) {
        mHeaderOverlay.setVisibility(View.VISIBLE);
        mHeaderFlexibleSpace.getLayoutParams().height = (int) (mToolbar.getHeight() - mSlidingHeaderBlueSize - translationY);
        mHeaderFlexibleSpace.requestLayout();
        mHeaderOverlay.requestLayout();
    } else {
        mHeaderOverlay.setVisibility(View.INVISIBLE);
    }
}
 
Example 7
Source File: StickyHeaderScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void hideToolbar() {
    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    int toolbarHeight = mToolbarView.getHeight();
    if (headerTranslationY != -toolbarHeight) {
        ViewPropertyAnimator.animate(mHeaderView).cancel();
        ViewPropertyAnimator.animate(mHeaderView).translationY(-toolbarHeight).setDuration(200).start();
    }
}
 
Example 8
Source File: ViewPagerTabActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void showToolbar() {
    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    if (headerTranslationY != 0) {
        ViewPropertyAnimator.animate(mHeaderView).cancel();
        ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
    }
    propagateToolbarState(true);
}
 
Example 9
Source File: ViewPagerTabScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: MainActivity.java    From ExpressHelper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
	if (dragging) {
		int toolbarHeight = mToolbar.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 11
Source File: TouchInterceptionRecyclerViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public void onMoveMotionEvent(MotionEvent ev, float diffX, float diffY) {
    float translationY = ViewHelper.getTranslationY(mInterceptionLayout) - mScrollYOnDownMotion + diffY;
    if (translationY < -mIntersectionHeight) {
        translationY = -mIntersectionHeight;
    } else if (getScreenHeight() - mHeaderBarHeight < translationY) {
        translationY = getScreenHeight() - mHeaderBarHeight;
    }

    slideTo(translationY, true);
}
 
Example 12
Source File: RecyclerViewFragment.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
    super.onScrollStateChanged(recyclerView, newState);

    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        int height = applyOnBootLayout.getHeight();
        if (offset > 0 && offset < height && ViewHelper.getTranslationY(applyOnBootLayout) != 0)
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        float density = getResources().getDisplayMetrics().density * 2;
                        for (; offset >= 0; offset -= density) {
                            getActivity().runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    move(offset);
                                }
                            });
                            Thread.sleep(16);
                        }
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (offset != 0) move(offset = 0);
                            }
                        });
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
    }
}
 
Example 13
Source File: MainActivity.java    From AppManager-for-Android with Apache License 2.0 5 votes vote down vote up
private void showInfo(boolean animated) {
    View infoView = findViewById(R.id.info);
    if (ViewHelper.getTranslationY(infoView) == 0) {
        return;
    }
    if (animated) {
        ViewPropertyAnimator.animate(infoView).translationY(0).setDuration(1000).start();
    } else {
        ViewHelper.setTranslationY(infoView, 0);
    }
}
 
Example 14
Source File: StickyHeaderScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void showToolbar() {
    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    if (headerTranslationY != 0) {
        ViewPropertyAnimator.animate(mHeaderView).cancel();
        ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
    }
}
 
Example 15
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    if (!mScrolled && mSlop < Math.abs(diffX) && Math.abs(diffY) < Math.abs(diffX)) {
        // Horizontal scroll is maybe handled by ViewPager
        return false;
    }

    Scrollable scrollable = getCurrentScrollable();
    if (scrollable == null) {
        mScrolled = false;
        return false;
    }

    // If interceptionLayout can move, it should intercept.
    // And once it begins to move, horizontal scroll shouldn't work any longer.
    int toolbarHeight = mToolbarView.getHeight();
    int translationY = (int) ViewHelper.getTranslationY(mInterceptionLayout);
    boolean scrollingUp = 0 < diffY;
    boolean scrollingDown = diffY < 0;
    if (scrollingUp) {
        if (translationY < 0) {
            mScrolled = true;
            mLastScrollState = ScrollState.UP;
            return true;
        }
    } else if (scrollingDown) {
        if (-toolbarHeight < translationY) {
            mScrolled = true;
            mLastScrollState = ScrollState.DOWN;
            return true;
        }
    }
    mScrolled = false;
    return false;
}
 
Example 16
Source File: MainActivity.java    From ExpressHelper with GNU General Public License v3.0 4 votes vote down vote up
private boolean toolbarIsHidden() {
	return ViewHelper.getTranslationY(mHeaderView) == - mToolbar.getHeight();
}
 
Example 17
Source File: StickyHeaderScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
private boolean toolbarIsShown() {
    return ViewHelper.getTranslationY(mHeaderView) == 0;
}
 
Example 18
Source File: ViewPagerTab2Activity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
private boolean toolbarIsHidden() {
    return ViewHelper.getTranslationY(mInterceptionLayout) == -mToolbarView.getHeight();
}
 
Example 19
Source File: ViewPagerTabFragmentParentFragment.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
private boolean toolbarIsShown() {
    return ViewHelper.getTranslationY(mInterceptionLayout) == 0;
}
 
Example 20
Source File: ViewPagerTabActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
private boolean toolbarIsHidden() {
    return ViewHelper.getTranslationY(mHeaderView) == -mToolbarView.getHeight();
}