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

The following examples show how to use com.nineoldandroids.view.ViewHelper#getTranslationY() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 2
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
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
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 5
@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 6
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 7
private void showToolbar() {
    float headerTranslationY = ViewHelper.getTranslationY(mHeaderView);
    if (headerTranslationY != 0) {
        ViewPropertyAnimator.animate(mHeaderView).cancel();
        ViewPropertyAnimator.animate(mHeaderView).translationY(0).setDuration(200).start();
    }
}
 
Example 8
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 9
@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 10
@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 11
@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 12
@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 13
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 14
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 15
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 16
private boolean toolbarIsHidden() {
    return ViewHelper.getTranslationY(mHeaderView) == -mToolbarView.getHeight();
}
 
Example 17
private boolean toolbarIsHidden() {
    return ViewHelper.getTranslationY(mInterceptionLayout) == -mToolbarView.getHeight();
}
 
Example 18
private boolean toolbarIsHidden() {
	return ViewHelper.getTranslationY(mHeaderView) == - mToolbar.getHeight();
}
 
Example 19
private boolean toolbarIsShown() {
    return ViewHelper.getTranslationY(mHeaderView) == 0;
}
 
Example 20
private boolean toolbarIsShown() {
    return ViewHelper.getTranslationY(mInterceptionLayout) == 0;
}