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

The following examples show how to use com.nineoldandroids.view.ViewHelper#getY() . 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: MotionEventUtils.java    From ListViewAnimations with Apache License 2.0 6 votes vote down vote up
public static List<MotionEvent> createMotionEvents(final AbsListView absListView, final int position, final float fromX, final float toX) {
    int[] listViewCoords = new int[2];
    absListView.getLocationOnScreen(listViewCoords);

    View view = absListView.getChildAt(position - absListView.getFirstVisiblePosition());
    int y = (int) (ViewHelper.getY(view) + view.getHeight() / 2) + listViewCoords[1];

    List<MotionEvent> results = new ArrayList<>();
    results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, fromX, y, 0));

    float diff = fromX - toX;
    for (int i = 1; i < 10; i++) {
        float x = fromX + diff / 10 * i;
        results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0));
    }
    results.add(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, toX, y, 0));

    return results;
}
 
Example 2
Source File: FloatingActionButton.java    From Fabulous with MIT License 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    // Perform the default behavior
    super.onLayout(changed, left, top, right, bottom);
    if (mLeftDisplayed == -1) {
        mLeftDisplayed = left;
        mRightDisplayed = right;
        mTopDisplayed = top;
        mBottomDisplayed = bottom;
    }

    // Store the FAB button's displayed Y position if we are not already aware of it
    if (mYDisplayed == -1) {
        mYDisplayed = ViewHelper.getY(this);
    }
}
 
Example 3
Source File: DescriptionAnimation.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * When next item show in ViewPagerEx, let's make an animation to show the
 * description layout.
 * @param view
 */
@Override
public void onNextItemAppear(View view) {

    View descriptionLayout = view.findViewById(R.id.description_layout);
    if(descriptionLayout!=null){
        float layoutY = ViewHelper.getY(descriptionLayout);
        view.findViewById(R.id.description_layout).setVisibility(View.VISIBLE);
        ValueAnimator animator = ObjectAnimator.ofFloat(
                descriptionLayout,"y",layoutY + descriptionLayout.getHeight(),
                layoutY).setDuration(500);
        animator.start();
    }

}
 
Example 4
Source File: SlidingUpBaseActivity.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) {
    final int minInterceptionLayoutY = -mIntersectionHeight;

    // slight fix for untappable floating action button for larger screens
    Rect fabRect = new Rect();
    mFab.getHitRect(fabRect);
    // if the user's touch is within the floating action button's touch area, don't intercept
    if (fabRect.contains((int) ev.getX(), (int) ev.getY())) {
        return false;
    } else {
        return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout)
                || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
    }
}
 
Example 5
Source File: SlideBottomPanel.java    From pius1 with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void handleActionUp(MotionEvent event) {
    if (!isPanelOnTouch) {
        return;
    }
    long pressDuration = System.currentTimeMillis() - mPressStartTime;
    computeVelocity();
    if (!isPanelShowing && ((event.getY() - firstDownY) < 0 && (Math.abs(event.getY() - firstDownY) > mMoveDistanceToTrigger))
                || (yVelocity < 0 && Math.abs(yVelocity) > Math.abs(xVelocity) && Math.abs(yVelocity) > mMinVelocity)) {
        displayPanel();
    } else if (!isPanelShowing && pressDuration < MAX_CLICK_TIME &&
            distance(firstDownX, firstDownY, event.getX(), event.getY()) < MAX_CLICK_DISTANCE) {
        displayPanel();
    } else if (!isPanelShowing && isDragging && ((event.getY() - firstDownY > 0) ||
            Math.abs(event.getY() - firstDownY) < mMoveDistanceToTrigger)){
        hidePanel();
    }

    if (isPanelShowing) {
        View mPanel = findViewWithTag(TAG_PANEL);
        float currentY = ViewHelper.getY(mPanel);
        if (currentY < (mMeasureHeight - mPanelHeight) ||
                currentY < (mMeasureHeight - mPanelHeight + mMoveDistanceToTrigger)) {
            ObjectAnimator.ofFloat(mPanel, "y", currentY, mMeasureHeight - mPanelHeight)
                    .setDuration(mAnimationDuration).start();
        } else if (currentY > mMeasureHeight - mPanelHeight + mMoveDistanceToTrigger){
            hidePanel();
        }
    }

    isPanelOnTouch = false;
    isDragging = false;
    deltaY = 0;
}
 
Example 6
Source File: DescriptionAnimation.java    From AndroidImageSlider with MIT License 5 votes vote down vote up
/**
 * When next item show in ViewPagerEx, let's make an animation to show the
 * description layout.
 * @param view
 */
@Override
public void onNextItemAppear(View view) {

    View descriptionLayout = view.findViewById(R.id.description_layout);
    if(descriptionLayout!=null){
        float layoutY = ViewHelper.getY(descriptionLayout);
        view.findViewById(R.id.description_layout).setVisibility(View.VISIBLE);
        ValueAnimator animator = ObjectAnimator.ofFloat(
                descriptionLayout,"y",layoutY + descriptionLayout.getHeight(),
                layoutY).setDuration(500);
        animator.start();
    }

}
 
Example 7
Source File: MemoFragment.java    From MaterialCalendar with Apache License 2.0 5 votes vote down vote up
void upRed() {
    startRedX = ViewHelper.getX(mRed);
    startRedY = ViewHelper.getY(mRed);
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mRed, "y", ViewHelper.getY(mRed),
            mBluePair.getBottom() - mRed.getHeight() / 2);
    objectAnimator.addListener(new SimpleListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            disappearRed();
        }
    });
    objectAnimator.setDuration(650);
    objectAnimator.setInterpolator(ACCELERATE_DECELERATE);
    objectAnimator.start();
}
 
Example 8
Source File: FloatingView.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    // Perform the default behavior
    super.onLayout(changed, left, top, right, bottom);

    // Store the FAB button's displayed Y position if we are not already aware of it
    if (mYDisplayed == -1) {

        mYDisplayed = ViewHelper.getY(this);
    }
}
 
Example 9
Source File: FloatingActionButton.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    // Perform the default behavior
    super.onLayout(changed, left, top, right, bottom);

    // Store the FAB button's displayed Y position if we are not already aware of it
    if (mYDisplayed == -1) {

        mYDisplayed = ViewHelper.getY(this);
    }
}
 
Example 10
Source File: DescriptionAnimation.java    From ImageSliderWithSwipes with Apache License 2.0 5 votes vote down vote up
/**
 * When next item show in ViewPagerEx, let's make an animation to show the
 * description layout.
 * @param view
 */
@Override
public void onNextItemAppear(View view) {

    View descriptionLayout = view.findViewById(R.id.description_layout);
    if(descriptionLayout!=null){
        float layoutY = ViewHelper.getY(descriptionLayout);
        view.findViewById(R.id.description_layout).setVisibility(View.VISIBLE);
        ValueAnimator animator = ObjectAnimator.ofFloat(
                descriptionLayout,"y",layoutY + descriptionLayout.getHeight(),
                layoutY).setDuration(500);
        animator.start();
    }

}
 
Example 11
Source File: Utils.java    From MousePaint with MIT License 4 votes vote down vote up
public static float centerY(View view){
    return ViewHelper.getY(view) + view.getHeight()/2;
}
 
Example 12
Source File: MemoFragment.java    From MaterialCalendar with Apache License 2.0 4 votes vote down vote up
public static float centerY(View view) {
    return ViewHelper.getY(view) + view.getHeight() / 2;
}
 
Example 13
Source File: FillGap3BaseActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    return getMinInterceptionLayoutY() < (int) ViewHelper.getY(mInterceptionLayout)
            || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
}
 
Example 14
Source File: TouchInterceptionListViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    final int minInterceptionLayoutY = -mIntersectionHeight;
    return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout)
            || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
}
 
Example 15
Source File: TouchInterceptionScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    final int minInterceptionLayoutY = -mIntersectionHeight;
    return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout)
            || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
}
 
Example 16
Source File: TouchInterceptionGridViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    final int minInterceptionLayoutY = -mIntersectionHeight;
    return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout)
            || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
}
 
Example 17
Source File: TouchInterceptionWebViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    final int minInterceptionLayoutY = -mIntersectionHeight;
    return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout)
            || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
}
 
Example 18
Source File: TouchInterceptionRecyclerViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean shouldInterceptTouchEvent(MotionEvent ev, boolean moving, float diffX, float diffY) {
    final int minInterceptionLayoutY = -mIntersectionHeight;
    return minInterceptionLayoutY < (int) ViewHelper.getY(mInterceptionLayout)
            || (moving && mScrollable.getCurrentScrollY() - diffY < 0);
}
 
Example 19
Source File: SlideBottomPanel.java    From pius1 with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void handleActionMove(MotionEvent event) {
    if (!isPanelOnTouch) {
        return;
    }
    if (isPanelShowing && supportScrollInView((int) (firstDownY - event.getY()))) {
        return;
    }
    computeVelocity();
    if (Math.abs(xVelocity) > Math.abs(yVelocity)) {
        return;
    }
    if (!isDragging && Math.abs(event.getY() - firstDownY) > mTouchSlop
            && Math.abs(event.getX() - firstDownX) < mTouchSlop) {
        isDragging = true;
        downY = event.getY();
    }
    if (isDragging) {
        deltaY = event.getY() - downY;
        downY = event.getY();

        View touchingView = findViewWithTag(TAG_PANEL);

        if (mHidePanelTitle && isPanelShowing) {
            hidePanelTitle(touchingView);
        }

        if (mDarkFrameLayout != null && mIsFade) {
            float currentY = ViewHelper.getY(touchingView);
            if (currentY > mMeasureHeight - mPanelHeight &&
                    currentY < mMeasureHeight - mTitleHeightNoDisplay) {
                mDarkFrameLayout.fade(
                        (int) ((1 - currentY / (mMeasureHeight - mTitleHeightNoDisplay)) * DarkFrameLayout.MAX_ALPHA));
            }
        }
        if (!mBoundary) {
            touchingView.offsetTopAndBottom((int) deltaY);
        } else {
            float touchingViewY = ViewHelper.getY(touchingView);
            if (touchingViewY + deltaY <= mMeasureHeight - mPanelHeight) {
                touchingView.offsetTopAndBottom((int) (mMeasureHeight - mPanelHeight - touchingViewY));
            } else if (touchingViewY + deltaY >= mMeasureHeight - mTitleHeightNoDisplay) {
                touchingView.offsetTopAndBottom((int) (mMeasureHeight - mTitleHeightNoDisplay - touchingViewY));
            } else {
                touchingView.offsetTopAndBottom((int) deltaY);
            }
        }
    }
}