Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: allow showing near touch position #10

Closed
AndroidDeveloperLB opened this issue Aug 1, 2019 · 5 comments
Closed

Request: allow showing near touch position #10

AndroidDeveloperLB opened this issue Aug 1, 2019 · 5 comments

Comments

@AndroidDeveloperLB
Copy link

Similar to this:

https://stackoverflow.com/q/57290574/878126

@kakajika
Copy link
Owner

kakajika commented Aug 5, 2019

This library supports showing popup with offset.
Here is example:

fun View.setOnClickPositionListener(listener: (v: View, x: Float, y: Float) -> Unit) {
    var tapPosition = PointF()
    setOnTouchListener { _, event ->
        if (event.actionMasked == MotionEvent.ACTION_DOWN) {
            tapPosition = PointF(event.x, event.y)
        }
        false
    }
    setOnClickListener { v ->
        listener(v, tapPosition.x, tapPosition.y)
    }
}

anchorView.setOnClickPositionListener { v, x, y ->
    val popup = RelativePopupWindow(v.context).apply {
        width = ViewGroup.LayoutParams.WRAP_CONTENT
        height = ViewGroup.LayoutParams.WRAP_CONTENT
        ...
    }
    val vertPos = RelativePopupWindow.VerticalPosition.ALIGN_TOP
    val horizPos = RelativePopupWindow.HorizontalPosition.ALIGN_LEFT
    popup.showOnAnchor(v, vertPos, horizPos, x.toInt(), y.toInt(), true)
}

@AndroidDeveloperLB
Copy link
Author

setOnClickPositionListener is not a standard function.
The ContextMenu somehow gets the position of the touch, without me setting onTouchListener. Just OnClickListener or OnLongClickListener is enough.

@kakajika
Copy link
Owner

kakajika commented Aug 5, 2019

Then use the ContextMenu.
This library will not support any action about anchor view's touch event.

@AndroidDeveloperLB
Copy link
Author

ContextMenu doesn't support customized view to be set to it.

@kakajika kakajika closed this as completed Dec 8, 2019
@AndroidDeveloperLB
Copy link
Author

Too bad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants