Example usage for android.view ViewGroup getWindowVisibleDisplayFrame

List of usage examples for android.view ViewGroup getWindowVisibleDisplayFrame

Introduction

In this page you can find the example usage for android.view ViewGroup getWindowVisibleDisplayFrame.

Prototype

public void getWindowVisibleDisplayFrame(Rect outRect) 

Source Link

Document

Retrieve the overall visible display size in which the window this view is attached to has been positioned in.

Usage

From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.ItemSlidingAnimator.java

private boolean slideToOutsideOfWindowInternal(RecyclerView.ViewHolder holder, boolean toLeft,
        boolean shouldAnimate, long duration) {
    if (!(holder instanceof SwipeableItemViewHolder)) {
        return false;
    }/*w w  w . j  a  va  2s  . co m*/

    final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView();
    final ViewGroup parent = (ViewGroup) containerView.getParent();

    if (parent == null) {
        return false;
    }

    final int left = containerView.getLeft();
    final int right = containerView.getRight();
    final int width = right - left;
    final boolean parentIsShown = parent.isShown();

    parent.getWindowVisibleDisplayFrame(mTmpRect);

    final int translateX;
    if ((width == 0) || !parentIsShown) {
        // not measured yet or not shown
        translateX = (toLeft) ? (-mTmpRect.width()) : (mTmpRect.width());
        shouldAnimate = false;
    } else {
        parent.getLocationInWindow(mTmpLocation);

        if (toLeft) {
            translateX = -(mTmpLocation[0] + width);
        } else {
            translateX = mTmpRect.width() - (mTmpLocation[0] - left);
        }
    }

    if (shouldAnimate) {
        shouldAnimate = containerView.isShown();
    }

    duration = (shouldAnimate) ? duration : 0;

    return animateSlideInternalCompat(holder, translateX, duration,
            mSlideToOutsideOfWindowAnimationInterpolator);
}

From source file:com.example.carlitos.swipeitemrecycler.view.animation.swipe_item.swipeable.ItemSlidingAnimator.java

private boolean slideToOutsideOfWindowInternal(RecyclerView.ViewHolder holder, int dir, boolean shouldAnimate,
        long duration, SwipeFinishInfo swipeFinish) {

    if (!(holder instanceof SwipeableItemViewHolder)) {
        return false;
    }//from w  w  w.  j a v  a  2  s  .  c  o m

    final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView();
    final ViewGroup parent = (ViewGroup) containerView.getParent();

    if (parent == null) {
        return false;
    }

    final int left = containerView.getLeft();
    final int right = containerView.getRight();
    final int top = containerView.getTop();
    final int bottom = containerView.getBottom();
    final int width = right - left;
    final int height = bottom - top;
    final boolean parentIsShown = parent.isShown();

    parent.getWindowVisibleDisplayFrame(mTmpRect);
    final int windowWidth = mTmpRect.width();
    final int windowHeight = mTmpRect.height();

    int translateX = 0;
    int translateY = 0;

    if ((width == 0) || (height == 0) || !parentIsShown) {
        // not measured yet or not shown
        switch (dir) {
        case DIR_LEFT:
            translateX = -windowWidth;
            break;
        case DIR_UP:
            translateY = -windowHeight;
            break;
        case DIR_RIGHT:
            translateX = windowWidth;
            break;
        case DIR_DOWN:
            translateY = windowHeight;
            break;
        default:
            break;
        }
        shouldAnimate = false;
    } else {
        parent.getLocationInWindow(mTmpLocation);
        final int x = mTmpLocation[0];
        final int y = mTmpLocation[1];

        switch (dir) {
        case DIR_LEFT:
            translateX = -(x + width);
            break;
        case DIR_UP:
            translateY = -(y + height);
            break;
        case DIR_RIGHT:
            translateX = windowWidth - (x - left);
            break;
        case DIR_DOWN:
            translateY = windowHeight - (y - top);
            break;
        default:
            break;
        }
    }

    if (shouldAnimate) {
        shouldAnimate = containerView.isShown();
    }

    duration = (shouldAnimate) ? duration : 0;

    boolean horizontal = (dir == DIR_LEFT || dir == DIR_RIGHT);
    return animateSlideInternalCompat(holder, horizontal, translateX, translateY, duration,
            mSlideToOutsideOfWindowAnimationInterpolator, swipeFinish);
}