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

The following examples show how to use android.view.View#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: PreferenceFragment.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (getDivider() == null) {
        return;
    }
    final int childCount = parent.getChildCount();
    final int width = parent.getWidth();
    for (int childViewIndex = 0; childViewIndex < childCount; childViewIndex++) {
        final View view = parent.getChildAt(childViewIndex);
        if (shouldDrawDividerBelow(view, parent)) {
            int top = (int) view.getY() + view.getHeight() + mPadding;
            getDivider().setBounds(0, top, width, top + getDividerHeight());
            getDivider().draw(c);
        }
    }
}
 
Example 2
Source File: PenService.java    From Android-Lib-Pen with Apache License 2.0 6 votes vote down vote up
private void onPenSettingClick() {
    if (this.penSettingEnabled) {
        if (this.penSetting.isShown()) {
            this.penSetting.setVisibility(View.GONE);
        } else {
            this.penSetting.setViewMode(SpenSettingPenLayout.VIEW_MODE_EXTENSION);

            final View                     toolsLayout = (View)this.rootLayout.findViewById(R.id.pen_buttons).getParent();
            final FrameLayout.LayoutParams params      = (FrameLayout.LayoutParams)this.penSetting.getLayoutParams();
            params.leftMargin = (int)toolsLayout.getX() + this.penButton.getLeft();
            params.topMargin  = (int)toolsLayout.getY() + this.penButton.getTop() + this.penButton.getHeight();

            this.penSetting.setLayoutParams(params);
            this.penSetting.setVisibility(View.VISIBLE);
        }
    }
}
 
Example 3
Source File: ScrollAwareFABBehavior.java    From CustomBottomSheetBehavior with Apache License 2.0 6 votes vote down vote up
/**
     * Define one of the point in where the FAB should be hide when it reaches that point.
     * @param coordinatorLayout container of BottomSheet and AppBarLayout
     */
    private void setOffsetValue(CoordinatorLayout coordinatorLayout) {

        for (int i = 0; i < coordinatorLayout.getChildCount(); i++) {
            View child = coordinatorLayout.getChildAt(i);

            if (child instanceof MergedAppBarLayout) {
                offset = child.getY()+child.getHeight();
                break;
            }

//            if (child instanceof AppBarLayout) {
//
//                if (child.getTag() != null &&
//                        child.getTag().toString().contentEquals("modal-appbar") ) {
//                    offset = child.getY()+child.getHeight();
//                    break;
//                }
//            }
        }
    }
 
Example 4
Source File: WaterFlake.java    From CustomWaterView with Apache License 2.0 6 votes vote down vote up
/**
 * 设置小球数据,根据数据集合创建小球数量
 *
 * @param modelList 数据集合
 */
public void setModelList(final List<WaterModel> modelList, View view) {
    if (modelList == null || modelList.isEmpty()) {
        return;
    }
    this.treeCenterX = view.getX();
    this.treeCenterY = view.getY();
    removeAllViews();
    post(new Runnable() {
        @Override
        public void run() {
            addWaterView(modelList);
        }
    });

}
 
Example 5
Source File: ExpandableStickyDecoration.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
private int getGroupHeaderTop(final RecyclerView parent, boolean isReverseLayout, View child, int adapterPos, int layoutPosition) {
    if (mExpandableAdapter == null) return 0;

    if (child.getY() > mDrawingInfo.sticky.bottom) {
        return OFFSET_NOT_FOUND;
    }

    int top = mDrawingInfo.sticky.bottom == 0 ? (int) child.getY() : mDrawingInfo.sticky.bottom;
    int childCount = parent.getChildCount();
    final long currentHeaderId = mExpandableAdapter.getGroupUniqueId(adapterPos);

    return calculateTop(isReverseLayout, layoutPosition, childCount, top, new Function<Integer, Integer>() {
        @Override
        public Integer apply(Integer integer) {
            return calculateGroupOffset(parent, currentHeaderId, integer);
        }
    });
}
 
Example 6
Source File: InstaTag.java    From InstaTag with Apache License 2.0 6 votes vote down vote up
public ArrayList<Tag> getTags() {
    ArrayList<Tag> tags = new ArrayList<>();
    if (!mTagList.isEmpty()) {
        for (int i = 0; i < mTagList.size(); i++) {
            View view = mTagList.get(i);
            float x = view.getX();
            x = (x / mRootWidth) * 100;
            float y = view.getY();
            y = (y / mRootHeight) * 100;
            tags.
                    add(new Tag(((TextView) view.
                            findViewById(R.id.tag_text_view)).getText().toString(), x, y));
        }
    }
    return tags;
}
 
Example 7
Source File: ExpandableStickyDecoration.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
private int calculateStickyOffset(RecyclerView parent, int headerHeight, long currentHeaderId, int nextPosition) {
    if (mStickyAdapter == null) return 0;
    int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(nextPosition));
    if (adapterPosHere != RecyclerView.NO_POSITION) {
        long nextId = mStickyAdapter.getStickyId(adapterPosHere);
        if (nextId != currentHeaderId && nextId != NO_STICKY_ID) {
            View next = parent.getChildAt(nextPosition);
            RecyclerView.ViewHolder viewHolder = getStickyHeader(parent, adapterPosHere);
            if (viewHolder == null) return 0;
            return ((int) next.getY()) - (headerHeight + viewHolder.itemView.getHeight());
        }
    }
    return 0;
}
 
Example 8
Source File: ViewPropertyAnimatorHC.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets the value of the named property from the View object.
 *
 * @param propertyConstant The property whose value should be returned
 * @return float The value of the named property
 */
private float getValue(int propertyConstant) {
    //final View.TransformationInfo info = mView.mTransformationInfo;
    View v = mView.get();
    if (v != null) {
        switch (propertyConstant) {
            case TRANSLATION_X:
                //return info.mTranslationX;
                return v.getTranslationX();
            case TRANSLATION_Y:
                //return info.mTranslationY;
                return v.getTranslationY();
            case ROTATION:
                //return info.mRotation;
                return v.getRotation();
            case ROTATION_X:
                //return info.mRotationX;
                return v.getRotationX();
            case ROTATION_Y:
                //return info.mRotationY;
                return v.getRotationY();
            case SCALE_X:
                //return info.mScaleX;
                return v.getScaleX();
            case SCALE_Y:
                //return info.mScaleY;
                return v.getScaleY();
            case X:
                //return v.mLeft + info.mTranslationX;
                return v.getX();
            case Y:
                //return v.mTop + info.mTranslationY;
                return v.getY();
            case ALPHA:
                //return info.mAlpha;
                return v.getAlpha();
        }
    }
    return 0;
}
 
Example 9
Source File: SwitchThemeAnimView.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
/**
 * 获取view在屏幕中的绝对y坐标
 */
private static float getAbsoluteY(View view) {
    float y = view.getY();
    ViewParent parent = view.getParent();
    if (parent instanceof View) {
        y += getAbsoluteY((View) parent);
    }
    return y;
}
 
Example 10
Source File: AvatarImageBehavior.java    From Android-skin-support with MIT License 5 votes vote down vote up
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, CircleImageView child, View dependency) {

    // 初始化属性
    shouldInitProperties(child, dependency);

    // 最大滑动距离: 起始位置-状态栏高度
    final int maxScrollDistance = (int) (mStartToolbarPosition - getStatusBarHeight());

    // 滑动的百分比
    float expandedPercentageFactor = dependency.getY() / maxScrollDistance;

    // Y轴距离
    float distanceYToSubtract = ((mStartYPosition - mFinalYPosition)
            * (1f - expandedPercentageFactor)) + (child.getHeight() / 2);

    // X轴距离
    float distanceXToSubtract = ((mStartXPosition - mFinalXPosition)
            * (1f - expandedPercentageFactor)) + (child.getWidth() / 2);

    // 高度减小
    float heightToSubtract = ((mStartHeight - mFinalHeight) * (1f - expandedPercentageFactor));

    // 图片位置
    child.setY(mStartYPosition - distanceYToSubtract);
    child.setX(mStartXPosition - distanceXToSubtract);

    // 图片大小
    CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams();
    lp.width = (int) (mStartHeight - heightToSubtract);
    lp.height = (int) (mStartHeight - heightToSubtract);
    child.setLayoutParams(lp);

    return true;
}
 
Example 11
Source File: AvatarImageBehavior.java    From Android-skin-support with MIT License 5 votes vote down vote up
/**
 * 初始化动画值
 *
 * @param child      图片控件
 * @param dependency ToolBar
 */
private void shouldInitProperties(CircleImageView child, View dependency) {

    // 图片控件中心
    if (mStartYPosition == 0)
        mStartYPosition = (int) (child.getY() + (child.getHeight() / 2));

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

    // 图片高度
    if (mStartHeight == 0)
        mStartHeight = child.getHeight();

    // Toolbar缩略图高度
    if (mFinalHeight == 0)
        mFinalHeight = mContext.getResources().getDimensionPixelOffset(R.dimen.image_final_width);

    // 图片控件水平中心
    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) + (mFinalHeight / 2);

    // Toolbar的起始位置
    if (mStartToolbarPosition == 0)
        mStartToolbarPosition = dependency.getY() + (dependency.getHeight() / 2);
}
 
Example 12
Source File: CallFragment.java    From owt-client-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (v.getId() == R.id.small_renderer) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                dX = v.getX() - event.getRawX();
                dY = v.getY() - event.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                v.animate()
                        .x(event.getRawX() + dX)
                        .y(event.getRawY() + dY)
                        .setDuration(0)
                        .start();
                break;
            case MotionEvent.ACTION_UP:
                v.animate()
                        .x(event.getRawX() + dX >= event.getRawY() + dY ? event.getRawX()
                                + dX : 0)
                        .y(event.getRawX() + dX >= event.getRawY() + dY ? 0
                                : event.getRawY() + dY)
                        .setDuration(10)
                        .start();
                break;
        }
    }
    return true;
}
 
Example 13
Source File: CustomTabActivity.java    From V2EX with GNU General Public License v3.0 5 votes vote down vote up
private void swipe(MotionEvent motionEvent){
    int firstVisibleItem = mLayoutManager.findFirstCompletelyVisibleItemPosition();

    View firstItem = mLayoutManager.findViewByPosition(firstVisibleItem);
    float span = 0;
    if (firstItem != null){
        span = firstItem.getY() <= 0 ? firstItem.getY() : 0;
    }

    float y = (motionEvent.getY()) + span;
    int itemInScreen = (int) y / mDragView.getHeight();
    int moveTo = itemInScreen + firstVisibleItem;
    if (mFrom != moveTo) {
        if (mFrom > moveTo){
            int temp = mFrom;
            mFrom = moveTo;
            moveTo = temp;
        }
        if (mFrom < 0 || moveTo >= mTabs.size()){
            return;
        }

        mTabs.add(mFrom, mTabs.get(moveTo));
        mTabs.add(moveTo + 1, mTabs.get(mFrom + 1));
        mTabs.remove(mFrom + 1);
        mTabs.remove(moveTo + 1);

        mTabSelectAdapter.notifyItemMoved(mFrom, moveTo);
        mTabSelectAdapter.notifyItemRangeChanged(mFrom, moveTo - mFrom + 1);
    }
}
 
Example 14
Source File: FlingCardListener.java    From Swipecards with Apache License 2.0 5 votes vote down vote up
public FlingCardListener(View frame, Object itemAtPosition, float rotation_degrees, FlingListener flingListener) {
    super();
    this.frame = frame;
    this.objectX = frame.getX();
    this.objectY = frame.getY();
    this.objectH = frame.getHeight();
    this.objectW = frame.getWidth();
    this.halfWidth = objectW / 2f;
    this.dataObject = itemAtPosition;
    this.parentWidth = ((ViewGroup) frame.getParent()).getWidth();
    this.BASE_ROTATION_DEGREES = rotation_degrees;
    this.mFlingListener = flingListener;

}
 
Example 15
Source File: FewChipsRowTest.java    From ChipsLayoutManager with Apache License 2.0 5 votes vote down vote up
@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
Source File: VerticalFabBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {

    if(child.getVisibility() == View.VISIBLE&&viewY==0){
        //获取控件距离父布局(coordinatorLayout)底部距离
        viewY=coordinatorLayout.getHeight()-child.getY();
    }

    return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;//判断是否竖直滚动
}
 
Example 17
Source File: AVStreamingActivity.java    From PLDroidMediaStreaming with Apache License 2.0 4 votes vote down vote up
@Override
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }

            int action = event.getAction();
            float touchRawX = event.getRawX();
            float touchRawY = event.getRawY();
            float touchX = event.getX();
            float touchY = event.getY();

            if (action == MotionEvent.ACTION_DOWN) {
                boolean xOK = touchX >= v.getWidth() * 3 / 4 && touchX <= v.getWidth();
                boolean yOK = touchY >= v.getHeight() * 2 / 4 && touchY <= v.getHeight();
                scale = xOK && yOK;
            }

            if (action == MotionEvent.ACTION_MOVE) {
                float deltaRawX = touchRawX - lastTouchRawX;
                float deltaRawY = touchRawY - lastTouchRawY;

                if (scale) {
                    // rotate
                    float centerX = v.getX() + (float) v.getWidth() / 2;
                    float centerY = v.getY() + (float) v.getHeight() / 2;
                    double angle = Math.atan2(touchRawY - centerY, touchRawX - centerX) * 180 / Math.PI;
                    v.setRotation((float) angle - 45);

                    // scale
                    float xx = (touchRawX >= centerX ? deltaRawX : -deltaRawX);
                    float yy = (touchRawY >= centerY ? deltaRawY : -deltaRawY);
                    float sf = (v.getScaleX() + xx / v.getWidth() + v.getScaleY() + yy / v.getHeight()) / 2;
                    v.setScaleX(sf);
                    v.setScaleY(sf);
                } else {
                    // translate
                    v.setTranslationX(v.getTranslationX() + deltaRawX);
                    v.setTranslationY(v.getTranslationY() + deltaRawY);
                }
            }

            if (action == MotionEvent.ACTION_UP) {
//                当 mMediaStreamingManager.setAutoRefreshOverlay(false) 时自动刷新关闭,建议在 UP 事件里进行手动刷新。
//                mMediaStreamingManager.refreshOverlay(v, false);
            }

            lastTouchRawX = touchRawX;
            lastTouchRawY = touchRawY;
            return true;
        }
 
Example 18
Source File: ViewHelper.java    From imsdk-android with MIT License 4 votes vote down vote up
static float getY(View view) {
    return view.getY();
}
 
Example 19
Source File: ViewHelper.java    From Mover with Apache License 2.0 4 votes vote down vote up
static float getY(View view) {
    return view.getY();
}
 
Example 20
Source File: ViewCompatHC.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static float getY(View view) {
    return view.getY();
}