Skip to content

Commit

Permalink
chore(android): docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaysood committed Dec 8, 2024
1 parent 3d5e8ab commit f5d7b35
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ internal class GestureCollector(
if (!(gesture != null && motionEvent.action == MotionEvent.ACTION_UP)) {
return@trace
}
val layoutSnapshot = getLayoutSnapshot(gesture, window, motionEvent)
val layoutSnapshot = try {
getLayoutSnapshot(gesture, window, motionEvent)
} catch (e: Exception) {
logger.log(LogLevel.Error, "Failed to parse layout, gesture will not be tracked", e)
return@trace
}

if (layoutSnapshot.isEmpty()) {
return@trace
Expand Down Expand Up @@ -213,8 +218,7 @@ internal class GestureCollector(
private fun getScreenWidthHeight(window: Window): Pair<Int, Int> {
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
val displayMetrics = DisplayMetrics()
@Suppress("DEPRECATION")
window.windowManager.defaultDisplay.getMetrics(displayMetrics)
@Suppress("DEPRECATION") window.windowManager.defaultDisplay.getMetrics(displayMetrics)
Pair(displayMetrics.widthPixels, displayMetrics.heightPixels)
} else {
val bounds = window.windowManager.currentWindowMetrics.bounds
Expand Down
1 change: 1 addition & 0 deletions docs/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ All the features supported by the Measure SDK are listed below.
* [Network monitoring](features/feature_network_monitoring.md)
* [Network changes](features/feature_network_changes.md)
* [Gesture tracking](features/feature_gesture_tracking.md)
* [Layout Snapshots](features/feature_layout_snapshots.md)
* [Navigation & Lifecycle](features/feature_navigation_and_lifecycle.md)
* [App launch](features/feature_app_launch.md)
* [App exit info](features/feature_app_exit_info.md)
Expand Down
19 changes: 19 additions & 0 deletions docs/android/features/feature_layout_snapshots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Feature — Layout Snapshots

Layout snapshots are collected for every click event (with throttling). These are lightweight snapshots of the layout
hierarchy which provide context on the UI which was visible to the user, without taking screenshots which are
expensive to take and store.

| Screenshot | Layout snapshot |
|--------------------------------------------------------|--------------------------------------------------|
| ![Screenshot](../images/layoutSnapshotScreenshot.png)) | ![Layout Snapshot](../images/layoutSnapshot.svg) |

## How it works

Once a [gesture is detected](feature_gesture_tracking.md), the layout is parsed by going over every element
(view or compose) and recording its dimensions and size information. The result is converted into an SVG and tracked
as an [attachment](../../api/sdk/README.md#attachments).

For view-based systems, it is simply done by traversing the entire layout once. While for Compose, this
is done by traversing the semantics tree
using [SemanticsOwner.getAllSemanticsNodes](https://developer.android.com/reference/kotlin/androidx/compose/ui/semantics/package-summary#(androidx.compose.ui.semantics.SemanticsOwner).getAllSemanticsNodes(kotlin.Boolean,kotlin.Boolean)).
1 change: 1 addition & 0 deletions docs/android/images/layoutSnapshot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/android/images/layoutSnapshotScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f5d7b35

Please sign in to comment.