Skip to content

Commit 7ece584

Browse files
committed
use RequiresApi on method and change coordinate type to long
1 parent 5503e0d commit 7ece584

6 files changed

Lines changed: 30 additions & 22 deletions

File tree

instrumentation/view-click/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ description = "OpenTelemetry Android View click library instrumentation"
77

88
android {
99
namespace = "io.opentelemetry.android.instrumentation.view.click"
10-
11-
defaultConfig {
12-
minSdk = 23
13-
}
1410
}
1511

1612
dependencies {

instrumentation/view-click/src/main/kotlin/io/opentelemetry/android/instrumentation/view/click/ViewClickEventGenerator.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class ViewClickEventGenerator(
3838
windowRef?.get()?.let { window ->
3939
if (motionEvent != null && motionEvent.actionMasked == MotionEvent.ACTION_UP) {
4040
createEvent(APP_SCREEN_CLICK_EVENT_NAME)
41-
.setAttribute(yCoordinateAttr, motionEvent.y.toDouble())
42-
.setAttribute(xCoordinateAttr, motionEvent.x.toDouble())
41+
.setAttribute(yCoordinateAttr, motionEvent.y.toLong())
42+
.setAttribute(xCoordinateAttr, motionEvent.x.toLong())
4343
.emit()
4444

4545
findTargetForTap(window.decorView, motionEvent.x, motionEvent.y)?.let { view ->
@@ -70,8 +70,8 @@ class ViewClickEventGenerator(
7070
builder.put(viewNameAttr, viewToName(view))
7171
builder.put(viewIdAttr, view.id.toLong())
7272

73-
builder.put(xCoordinateAttr, view.x.toDouble())
74-
builder.put(yCoordinateAttr, view.y.toDouble())
73+
builder.put(xCoordinateAttr, view.x.toLong())
74+
builder.put(yCoordinateAttr, view.y.toLong())
7575
return builder.build()
7676
}
7777

instrumentation/view-click/src/main/kotlin/io/opentelemetry/android/instrumentation/view/click/ViewClickInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ViewClickInstrumentation : AndroidInstrumentation {
2020
ViewClickEventGenerator(
2121
ctx.openTelemetry
2222
.logsBridge
23-
.loggerBuilder("io.opentelemetry.android.view.click")
23+
.loggerBuilder("io.opentelemetry.android.instrumentation.view.click")
2424
.build() as ExtendedLogger,
2525
),
2626
),

instrumentation/view-click/src/main/kotlin/io/opentelemetry/android/instrumentation/view/click/WindowCallbackWrapper.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
package io.opentelemetry.android.instrumentation.view.click
77

8+
import android.os.Build.VERSION_CODES
9+
import android.view.ActionMode
810
import android.view.MotionEvent
11+
import android.view.SearchEvent
912
import android.view.Window.Callback
13+
import androidx.annotation.RequiresApi
1014

1115
class WindowCallbackWrapper(
1216
private val callback: Callback,
@@ -17,5 +21,14 @@ class WindowCallbackWrapper(
1721
return callback.dispatchTouchEvent(event)
1822
}
1923

24+
@RequiresApi(api = VERSION_CODES.M)
25+
override fun onSearchRequested(searchEvent: SearchEvent?): Boolean = callback.onSearchRequested(searchEvent)
26+
27+
@RequiresApi(api = VERSION_CODES.M)
28+
override fun onWindowStartingActionMode(
29+
callback: ActionMode.Callback?,
30+
type: Int,
31+
): ActionMode? = this.callback.onWindowStartingActionMode(callback, type)
32+
2033
fun unwrap(): Callback = callback
2134
}

instrumentation/view-click/src/main/kotlin/io/opentelemetry/android/instrumentation/view/click/internal/ViewUtils.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
package io.opentelemetry.android.instrumentation.view.click.internal
77

88
import io.opentelemetry.api.common.AttributeKey
9-
import io.opentelemetry.api.common.AttributeKey.doubleKey
109
import io.opentelemetry.api.common.AttributeKey.longKey
1110
import io.opentelemetry.api.common.AttributeKey.stringKey
1211

1312
const val APP_SCREEN_CLICK_EVENT_NAME = "app.screen.click"
1413
const val VIEW_CLICK_EVENT_NAME = "event.app.widget.click"
1514
val viewNameAttr: AttributeKey<String> = stringKey("app.widget.name")
1615

17-
val xCoordinateAttr: AttributeKey<Double> = doubleKey("app.screen.coordinate.x")
18-
val yCoordinateAttr: AttributeKey<Double> = doubleKey("app.screen.coordinate.y")
16+
val xCoordinateAttr: AttributeKey<Long> = longKey("app.screen.coordinate.x")
17+
val yCoordinateAttr: AttributeKey<Long> = longKey("app.screen.coordinate.y")
1918
val viewIdAttr: AttributeKey<Long> = longKey("app.widget.id")

instrumentation/view-click/src/test/kotlin/io/opentelemetry/android/instrumentation/view/click/ViewClickInstrumentationTest.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ class ViewClickInstrumentationTest {
110110
assertThat(event)
111111
.hasEventName(APP_SCREEN_CLICK_EVENT_NAME)
112112
.hasAttributesSatisfyingExactly(
113-
equalTo(xCoordinateAttr, motionEvent.x.toDouble()),
114-
equalTo(yCoordinateAttr, motionEvent.y.toDouble()),
113+
equalTo(xCoordinateAttr, motionEvent.x.toLong()),
114+
equalTo(yCoordinateAttr, motionEvent.y.toLong()),
115115
)
116116

117117
event = events[1] as ExtendedLogRecordData
118118
assertThat(event)
119119
.hasEventName(VIEW_CLICK_EVENT_NAME)
120120
.hasAttributesSatisfyingExactly(
121-
equalTo(xCoordinateAttr, mockView.x.toDouble()),
122-
equalTo(yCoordinateAttr, mockView.y.toDouble()),
121+
equalTo(xCoordinateAttr, mockView.x.toLong()),
122+
equalTo(yCoordinateAttr, mockView.y.toLong()),
123123
equalTo(viewIdAttr, mockView.id),
124124
equalTo(viewNameAttr, "10012"),
125125
)
@@ -177,16 +177,16 @@ class ViewClickInstrumentationTest {
177177
assertThat(event)
178178
.hasEventName(APP_SCREEN_CLICK_EVENT_NAME)
179179
.hasAttributesSatisfyingExactly(
180-
equalTo(xCoordinateAttr, motionEvent.x.toDouble()),
181-
equalTo(yCoordinateAttr, motionEvent.y.toDouble()),
180+
equalTo(xCoordinateAttr, motionEvent.x.toLong()),
181+
equalTo(yCoordinateAttr, motionEvent.y.toLong()),
182182
)
183183

184184
event = events[1] as ExtendedLogRecordData
185185
assertThat(event)
186186
.hasEventName(VIEW_CLICK_EVENT_NAME)
187187
.hasAttributesSatisfyingExactly(
188-
equalTo(xCoordinateAttr, mockView.x.toDouble()),
189-
equalTo(yCoordinateAttr, mockView.y.toDouble()),
188+
equalTo(xCoordinateAttr, mockView.x.toLong()),
189+
equalTo(yCoordinateAttr, mockView.y.toLong()),
190190
equalTo(viewIdAttr, mockView.id),
191191
equalTo(viewNameAttr, "10012"),
192192
)
@@ -244,8 +244,8 @@ class ViewClickInstrumentationTest {
244244
assertThat(event)
245245
.hasEventName(APP_SCREEN_CLICK_EVENT_NAME)
246246
.hasAttributesSatisfyingExactly(
247-
equalTo(xCoordinateAttr, motionEvent.x.toDouble()),
248-
equalTo(yCoordinateAttr, motionEvent.y.toDouble()),
247+
equalTo(xCoordinateAttr, motionEvent.x.toLong()),
248+
equalTo(yCoordinateAttr, motionEvent.y.toLong()),
249249
)
250250
}
251251

0 commit comments

Comments
 (0)