Java Code Examples for android.view.View.getY()

The following are Jave code examples for showing how to use getY() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: CoordinatorBehavior   File: ImageBehavior.java   Source Code and License Vote up 8 votes
@SuppressLint("PrivateResource")
private void maybeInitProperties(ImageView child, View dependency) {
    if (startYPosition == 0)
        startYPosition = (int) (dependency.getY());

    if (finalYPosition == 0)
        finalYPosition = (dependency.getHeight() / 2);

    if (startHeight == 0)
        startHeight = child.getHeight();

    if (finalHeight == 0)
        finalHeight = context.getResources().getDimensionPixelOffset(R.dimen.image_small_width);

    if (startXPosition == 0)
        startXPosition = (int) (child.getX() + (child.getWidth() / 2));

    if (finalXPosition == 0)
        finalXPosition = context.getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material) + (finalHeight / 2);

    if (startToolbarPosition == 0)
        startToolbarPosition = dependency.getY() + (dependency.getHeight() / 2);
}
 
Example 2
Project: ArcLayout-master   File: MainActivity.java   Source Code and License Vote up 8 votes
private Animator createShowItemAnimator(View item) {

        float dx = fab.getX() - item.getX();
        float dy = fab.getY() - item.getY();

        item.setRotation(0f);
        item.setTranslationX(dx);
        item.setTranslationY(dy);

        Animator anim = ObjectAnimator.ofPropertyValuesHolder(
                item,
//                AnimatorUtils.rotation(0f, 720f),
                AnimatorUtils.translationX(dx, 0f),
                AnimatorUtils.translationY(dy, 0f)
        );

        return anim;
    }
 
Example 3
Project: Nimbus   File: TeamLogoBehavior.java   Source Code and License Vote up 8 votes
private void maybeInitProperties(ImageView child, View dependency) {
    if (mStartYPosition == 0)
        mStartYPosition = (int) (dependency.getY());

    if (mFinalYPosition == 0)
        mFinalYPosition = (dependency.getHeight() /2);

    if (mStartHeight == 0)
        mStartHeight = child.getHeight();

    if (mStartXPosition == 0)
        mStartXPosition = (int) (child.getX() + (child.getWidth() / 2));

    if (mFinalXPosition == 0)
        mFinalXPosition = mContext.getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material) + ((int) mCustomFinalHeight / 2);

    if (mStartToolbarPosition == 0)
        mStartToolbarPosition = dependency.getY();

    if (mChangeBehaviorPoint == 0) {
        mChangeBehaviorPoint = (child.getHeight() - mCustomFinalHeight) / (2f * (mStartYPosition - mFinalYPosition));
    }
}
 
Example 4
Project: RNLearn_Project1   File: LayoutUpdateAnimation.java   Source Code and License Vote up 7 votes
@Override
@Nullable Animation createAnimationImpl(View view, int x, int y, int width, int height) {
  boolean animateLocation = view.getX() != x || view.getY() != y;
  boolean animateSize = view.getWidth() != width || view.getHeight() != height;
  if (!animateLocation && !animateSize) {
    return null;
  } else if (animateLocation && !animateSize && USE_TRANSLATE_ANIMATION) {
    // Use GPU-accelerated animation, however we loose the ability to resume interrupted
    // animation where it was left off. We may be able to listen to animation interruption
    // and set the layout manually in this case, so that next animation kicks off smoothly.
    return new TranslateAnimation(view.getX() - x, 0, view.getY() - y, 0);
  } else {
    // Animation is sub-optimal for perf, but scale transformation can't be use in this case.
    return new PositionAndSizeAnimation(view, x, y, width, height);
  }
}
 
Example 5
Project: StackCardsView   File: SwipeTouchHelper.java   Source Code and License Vote up 7 votes
private ScrollInfo calcScrollInfo(View movingView) {
    ScrollInfo result = new ScrollInfo();
    float dx = movingView.getX() - mChildInitX;
    float dy = movingView.getY() - mChildInitY;
    int direction;
    if (Float.compare(dx, 0) == 0 && Float.compare(dy, 0) == 0) {
        direction = StackCardsView.SWIPE_NONE;
    } else {
        if (Math.abs(dx) * SLOPE > Math.abs(dy)) {
            direction = dx > 0 ? StackCardsView.SWIPE_RIGHT : StackCardsView.SWIPE_LEFT;
        } else {
            direction = dy > 0 ? StackCardsView.SWIPE_DOWN : StackCardsView.SWIPE_UP;
        }
    }
    log(TAG, "calcScrollInfo,direction=" + direction + ",dx=" + dx + ",dy=" + dy);
    result.direction = direction;
    double distance = Math.sqrt(dx * dx + dy * dy);
    float dismiss_distance = mSwipeView.getDismissDistance();
    if (distance >= dismiss_distance) {
        result.progress = 1;
    } else {
        result.progress = (float) distance / dismiss_distance;
    }
    return result;
}
 
Example 6
Project: GitHub   File: StickyHeaderDecoration.java   Source Code and License Vote up 7 votes
private int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) {
    int headerHeight = getHeaderHeightForLayout(header);
    int top = ((int) child.getY()) - headerHeight;
    if (layoutPos == 0) {

        final int count = parent.getChildCount();
        for (int i = 1; (i < count); i++) {
            int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(i));
            if (adapterPosHere != RecyclerView.NO_POSITION && hasHeader(adapterPosHere)) {
                final View next = parent.getChildAt(i);
                final int offset = ((int) next.getY()) - (header.getHeight() + getHeaderHeightForLayout(getHeader(parent, adapterPosHere).itemView));
                if (offset < 0) {
                    return offset;
                }
                break;
            }
        }
    }
    top = Math.max(0, top);
    return top;
}
 
Example 7
Project: turn-layout-manager   File: TurnLayoutManager.java   Source Code and License Vote up 7 votes
/**
 * Given that the is {@link Orientation#VERTICAL}, apply rotation if rotation is enabled.
 */
private void setChildRotationVertical(@Gravity int gravity, View child, int radius, Point center) {
    if (!rotate) {
        child.setRotation(0);
        return;
    }
    boolean childPastCenter = (child.getY() + child.getHeight() / 2) > center.y;
    float directionMult;
    if (gravity == Gravity.END) {
        directionMult = childPastCenter ? -1 : 1;
    } else {
        directionMult = childPastCenter ? 1 : -1;
    }
    final float opposite = Math.abs(child.getY() + child.getHeight() / 2 - center.y);
    child.setRotation((float) (directionMult * Math.toDegrees(Math.asin(opposite / radius))));
}
 
Example 8
Project: android-WearAccessibilityApp   File: ScalingScrollLayoutCallback.java   Source Code and License Vote up 7 votes
@Override
public void onLayoutFinished(View child, RecyclerView parent) {

    // Figure out % progress from top to bottom.
    float centerOffset = (child.getHeight() / 2.0f) / parent.getHeight();
    float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;

    // Normalize for center.
    float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);

    // Adjust to the maximum scale.
    progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS);

    child.setScaleX(1 - progressToCenter);
    child.setScaleY(1 - progressToCenter);
}
 
Example 9
Project: RNLearn_Project1   File: LayoutUpdateAnimation.java   Source Code and License Vote up 7 votes
@Override
@Nullable Animation createAnimationImpl(View view, int x, int y, int width, int height) {
  boolean animateLocation = view.getX() != x || view.getY() != y;
  boolean animateSize = view.getWidth() != width || view.getHeight() != height;
  if (!animateLocation && !animateSize) {
    return null;
  } else if (animateLocation && !animateSize && USE_TRANSLATE_ANIMATION) {
    // Use GPU-accelerated animation, however we loose the ability to resume interrupted
    // animation where it was left off. We may be able to listen to animation interruption
    // and set the layout manually in this case, so that next animation kicks off smoothly.
    return new TranslateAnimation(view.getX() - x, 0, view.getY() - y, 0);
  } else {
    // Animation is sub-optimal for perf, but scale transformation can't be use in this case.
    return new PositionAndSizeAnimation(view, x, y, width, height);
  }
}
 
Example 10
Project: PlusGram   File: ViewProxy.java   Source Code and License Vote up 6 votes
public static float getY(View view) {
    if (View10.NEED_PROXY) {
        return View10.wrap(view).getY();
    } else {
        return view.getY();
    }
}
 
Example 11
Project: OpenWithX   File: ResolverDrawerLayout.java   Source Code and License Vote up 6 votes
private static boolean isChildUnder(View child, float x, float y) {
    final float left = child.getX();
    final float top = child.getY();
    final float right = left + child.getWidth();
    final float bottom = top + child.getHeight();
    return x >= left && y >= top && x < right && y < bottom;
}
 
Example 12
Project: UltimateRecyclerView   File: StickyHeaderDecoration.java   Source Code and License Vote up 6 votes
private int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) {
    int headerHeight = getHeaderHeightForLayout(header);
    int top = ((int) child.getY()) - headerHeight;
    if (layoutPos == 0) {
        final int count = parent.getChildCount();
        final long currentId = mListener.getHeaderId(adapterPos);
        // find next view with header and compute the offscreen push if needed
        for (int i = 1; i < count; i++) {
            int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(i));
            if (adapterPosHere != RecyclerView.NO_POSITION) {
                long nextId = mListener.getHeaderId(adapterPosHere);
                if (nextId != currentId) {
                    final View next = parent.getChildAt(i);
                    final int offset = ((int) next.getY()) - (headerHeight + getHeader(parent, adapterPosHere).itemView.getHeight());
                    if (offset < 0) {
                        return offset;
                    } else {
                        break;
                    }
                }
            }
        }

        top = Math.max(0, top);
    }

    return top;
}
 
Example 13
Project: SharePanel   File: SlideHideBehaviour.java   Source Code and License Vote up 6 votes
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, CardView child, View dependency) {
    initValues(child);
    child.setY(dependency.getY() - child.getHeight() / 2);
    if (notFirstRun) {
        currentPos = dependency.getY();
        if (currentPos > hidingPos)
            animateIn(child);
        else animateOut(child);
    } else {
        child.setX(shownPosX);
        notFirstRun = true;
    }
    return false;
}
 
Example 14
Project: WearVibrationCenter   File: TimedMuteActivity.java   Source Code and License Vote up 6 votes
@Override
public void updateChild(View child, WearableRecyclerView parent) {
    super.updateChild(child, parent);

    // Figure out % progress from top to bottom
    float centerOffset = ((float) child.getHeight() / 2.0f) /  (float) recycler.getHeight();
    float yRelativeToCenterOffset = (child.getY() / recycler.getHeight()) + centerOffset;

    // Normalize for center
    float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset) * 2;
    progressToCenter = Math.min(0.8f, progressToCenter);

    child.setAlpha(1 - progressToCenter);
}
 
Example 15
Project: ChipsLayoutManager   File: FewChipsRowTest.java   Source Code and License Vote up 6 votes
@Test
public void deleteItemInTheFirstLine_ItemHasMaximumHeight_SameStartPadding() throws Exception {
    //arrange
    //just adapt input items list to required start values
    items.remove(1);
    activity.runOnUiThread(() -> activity.initialize());

    ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));

    InstrumentalUtil.waitForIdle();

    View second = layoutManager.getChildAt(1);
    int startHeight = second.getHeight();
    double expectedY = second.getY();

    //act
    recyclerView.perform(
            actionDelegate(((uiController, view) -> items.remove(1))),
            notifyItemRemovedAction(1));

    InstrumentalUtil.waitForIdle();

    second = layoutManager.getChildAt(1);
    int endHeight = second.getHeight();
    double resultY = second.getY();

    //assert
    //check test behaviour
    assumeTrue(startHeight > endHeight);

    assertNotEquals(0, expectedY, 0.01);
    assertNotEquals(0, resultY, 0.01);
    assertEquals(resultY, expectedY, 0.01);
}
 
Example 16
Project: Bridge   File: ResolverDrawerLayout.java   Source Code and License Vote up 6 votes
private View findListChildUnder(float x, float y) {
    View v = findChildUnder(x, y);
    while (v != null) {
        x -= v.getX();
        y -= v.getY();
        if (v instanceof RecyclerView/*AbsListView*/) {
            // One more after this.
            return findChildUnder((ViewGroup) v, x, y);
        }
        v = v instanceof ViewGroup ? findChildUnder((ViewGroup) v, x, y) : null;
    }
    return null;
}
 
Example 17
Project: Rx2Animations   File: RxAnimations.java   Source Code and License Vote up 6 votes
public static Completable leave(final View view, final int xOffset, final int yOffset) {
    final float startingX = view.getX();
    final float startingY = view.getY();
    return animate(view, new AccelerateInterpolator())
            .fadeOut()
            .translateBy(xOffset, yOffset)
            .onAnimationCancel(aView -> set(aView, startingX, startingY, TRANSPARENT))
            .schedule(false);
}
 
Example 18
Project: boohee_v5.6   File: ViewHelper.java   Source Code and License Vote up 5 votes
static float getY(View view) {
    return view.getY();
}
 
Example 19
Project: InstaTag   File: TagOnTouchListener.java   Source Code and License Vote up 5 votes
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (isDragging) {
        float[] bounds = new float[4];
        // LEFT
        bounds[0] = event.getRawX() + dX;
        if (bounds[0] < maxLeft) {
            bounds[0] = maxLeft;
        }
        // RIGHT
        bounds[2] = bounds[0] + width;
        if (bounds[2] > maxRight) {
            bounds[2] = maxRight;
            bounds[0] = bounds[2] - width;
        }
        // TOP
        bounds[1] = event.getRawY() + dY;
        if (bounds[1] < maxTop) {
            bounds[1] = maxTop;
        }
        // BOTTOM
        bounds[3] = bounds[1] + height;
        if (bounds[3] > maxBottom) {
            bounds[3] = maxBottom;
            bounds[1] = bounds[3] - height;
        }

        switch (event.getAction()) {
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                onDragFinish();
                break;
            case MotionEvent.ACTION_MOVE:
                mView.animate().x(bounds[0]).y(bounds[1]).setDuration(0).start();
                break;
        }
        return true;
    } else {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                isDragging = true;
                if (!isInitialized) {
                    updateBounds();
                }
                dX = v.getX() - event.getRawX();
                dY = v.getY() - event.getRawY();
                if (mOnDragActionListener != null) {
                    mOnDragActionListener.onDragStart(mView);
                }
                return true;
        }
    }
    return false;
}
 
Example 20
Project: LuaViewPlayground   File: ViewHelper.java   Source Code and License Vote up 5 votes
static float getY(View view) {
    return view.getY();
}