-
Notifications
You must be signed in to change notification settings - Fork 99
Added basic double-tap, based off view click by cleverchuk. Addresses #1642 and #1576 #1681
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
Open
DavidGrath
wants to merge
8
commits into
open-telemetry:main
Choose a base branch
from
DavidGrath:issue-1642-double-tap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3b43281
Added basic double-tap, based off view click
DavidGrath a051d4a
Made fixes to correct failures to checks
DavidGrath ae74e2a
Ran apiDump
DavidGrath 838d198
Merge branch 'main' into issue-1642-double-tap
DavidGrath fc26fa0
New hardware attributes: pointer, clicks, and button. Single tap and …
DavidGrath 7c58c18
Make detekt and apiDump happy
DavidGrath 75c1407
Removed primary button exclusivity from double-tap
DavidGrath 7c2d59c
Apply suggestions from code review
DavidGrath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
instrumentation/view-click/src/test/kotlin/TestUtils.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import android.os.SystemClock | ||
| import android.view.MotionEvent | ||
| import android.view.View | ||
| import android.view.ViewConfiguration | ||
| import androidx.test.core.view.PointerCoordsBuilder | ||
| import io.mockk.every | ||
| import io.mockk.mockkClass | ||
| import io.mockk.slot | ||
| import org.robolectric.shadows.ShadowLooper | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
|
|
||
| inline fun <reified T : View> mockView( | ||
| id: Int, | ||
| motionEvent: MotionEvent, | ||
| hitOffset: IntArray = intArrayOf(0, 0), | ||
| clickable: Boolean = true, | ||
| visibility: Int = View.VISIBLE, | ||
| applyOthers: (T) -> Unit = {}, | ||
| ): T { | ||
| val mockView = mockkClass(T::class) | ||
| every { mockView.visibility } returns visibility | ||
| every { mockView.isClickable } returns clickable | ||
|
|
||
| every { mockView.id } returns id | ||
| val location = IntArray(2) | ||
|
|
||
| location[0] = (motionEvent.x + hitOffset[0]).toInt() | ||
| location[1] = (motionEvent.y + hitOffset[1]).toInt() | ||
|
|
||
| val arrayCapturingSlot = slot<IntArray>() | ||
| every { mockView.getLocationInWindow(capture(arrayCapturingSlot)) } answers { | ||
| arrayCapturingSlot.captured[0] = location[0] | ||
| arrayCapturingSlot.captured[1] = location[1] | ||
| } | ||
|
|
||
| every { mockView.x } returns location[0].toFloat() | ||
| every { mockView.y } returns location[1].toFloat() | ||
|
|
||
| every { mockView.width } returns (location[0] + hitOffset[0]) | ||
| every { mockView.height } returns (location[1] + hitOffset[1]) | ||
| applyOthers.invoke(mockView) | ||
|
|
||
| return mockView | ||
| } | ||
|
|
||
| private val allowedToolTypes = arrayOf(MotionEvent.TOOL_TYPE_FINGER, MotionEvent.TOOL_TYPE_MOUSE, | ||
| MotionEvent.TOOL_TYPE_STYLUS, MotionEvent.TOOL_TYPE_ERASER, MotionEvent.TOOL_TYPE_UNKNOWN) | ||
|
|
||
| private val allowedButtonStates = arrayOf( | ||
| MotionEvent.BUTTON_PRIMARY, MotionEvent.BUTTON_STYLUS_PRIMARY, | ||
| MotionEvent.BUTTON_SECONDARY, MotionEvent.BUTTON_STYLUS_SECONDARY, | ||
| MotionEvent.BUTTON_TERTIARY, | ||
| MotionEvent.BUTTON_BACK, | ||
| MotionEvent.BUTTON_FORWARD | ||
| ) | ||
|
|
||
| fun getDoubleTapSequence(x: Float, y: Float, toolType: Int = MotionEvent.TOOL_TYPE_FINGER, buttonState: Int = 0, | ||
| exceedTimeOut: Boolean = false): Array<MotionEvent> { | ||
|
|
||
| require(toolType in allowedToolTypes) { "Invalid tool type" } | ||
|
|
||
| if(buttonState != 0) { | ||
| require(toolType == MotionEvent.TOOL_TYPE_MOUSE || toolType == MotionEvent.TOOL_TYPE_STYLUS) { | ||
| "Invalid tool type for button state" | ||
| } | ||
| require(buttonState in allowedButtonStates) { "Invalid button state" } | ||
| } | ||
|
|
||
| val initialTime = SystemClock.uptimeMillis() | ||
|
|
||
| val pointerProperties = MotionEvent.PointerProperties() | ||
| pointerProperties.id = 0 | ||
| pointerProperties.toolType = toolType | ||
|
|
||
| val pointerCoords = PointerCoordsBuilder.newBuilder().setCoords(x, y).build() | ||
|
|
||
| if(exceedTimeOut) { | ||
| val doubleTapTimeout = ViewConfiguration.getDoubleTapTimeout() | ||
|
|
||
| return arrayOf( | ||
| MotionEvent.obtain(initialTime, initialTime, | ||
| MotionEvent.ACTION_DOWN, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
| MotionEvent.obtain(initialTime, initialTime + 300L, | ||
| MotionEvent.ACTION_UP, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
|
|
||
| MotionEvent.obtain( | ||
| initialTime + 400L + doubleTapTimeout, initialTime + 500L + doubleTapTimeout, | ||
| MotionEvent.ACTION_DOWN, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
|
|
||
| MotionEvent.obtain( | ||
| initialTime + 600L + doubleTapTimeout, initialTime + 700L + doubleTapTimeout, | ||
| MotionEvent.ACTION_UP, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0) | ||
| ) | ||
| } else { | ||
|
|
||
| return arrayOf( | ||
| MotionEvent.obtain(initialTime, initialTime, | ||
| MotionEvent.ACTION_DOWN, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
| MotionEvent.obtain(initialTime, initialTime + 300L, | ||
| MotionEvent.ACTION_UP, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
|
|
||
| MotionEvent.obtain( | ||
| initialTime + 400L, initialTime + 500L, | ||
| MotionEvent.ACTION_DOWN, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
|
|
||
| MotionEvent.obtain( | ||
| initialTime + 600L, initialTime + 700L, | ||
| MotionEvent.ACTION_UP, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| fun getSingleTapSequence(x: Float, y: Float, toolType: Int = MotionEvent.TOOL_TYPE_FINGER, buttonState: Int = 0) | ||
| : Array<MotionEvent> { | ||
| require(toolType in allowedToolTypes) { | ||
| "Invalid tool type" | ||
| } | ||
|
|
||
| if(buttonState != 0) { | ||
| require(toolType == MotionEvent.TOOL_TYPE_MOUSE || toolType == MotionEvent.TOOL_TYPE_STYLUS) { | ||
| "Invalid tool type for button state" | ||
| } | ||
| require(buttonState in allowedButtonStates) { "Invalid button state" } | ||
| } | ||
|
|
||
| val initialTime = SystemClock.uptimeMillis() | ||
|
|
||
| val pointerProperties = MotionEvent.PointerProperties() | ||
| pointerProperties.id = 0 | ||
| pointerProperties.toolType = toolType | ||
|
|
||
| val pointerCoords = PointerCoordsBuilder.newBuilder().setCoords(x, y).build() | ||
| return arrayOf( | ||
| MotionEvent.obtain(initialTime, initialTime, | ||
| MotionEvent.ACTION_DOWN, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0), | ||
|
|
||
| MotionEvent.obtain(initialTime, initialTime + 100L, | ||
| MotionEvent.ACTION_UP, 1, arrayOf(pointerProperties), | ||
| arrayOf(pointerCoords), 0, buttonState, 1f, 1f, | ||
| 0, 0, 0, 0) | ||
| ) | ||
| } | ||
|
|
||
| fun fastForwardDoubleTapTimeout() { | ||
| ShadowLooper.idleMainLooper(ViewConfiguration.getDoubleTapTimeout().toLong(), TimeUnit.MILLISECONDS) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider driving this and other information via an enum in
ViewUtilsas that will reduce the amount of logic in this class. Here's a non-exhaustive example of what I mean:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I've applied the other suggestions. I'll look into this and give my feedback by Wednesday or Thursday