Commit dfa18d2
authored
feat: migrate onClick out of the layout files, add testing (#2328)
* feat(test): Add tests and refactor demos to use ViewBinding
This commit introduces a suite of Espresso tests for several demo activities and refactors numerous activities to use ViewBinding, eliminating `findViewById` and `onClick` XML attributes.
- **Testing Infrastructure:**
- Adds `MapIdlingResource` for both Java and Kotlin test sources to synchronize Espresso tests with map camera movements, preventing flaky tests.
- Introduces custom Truth subjects (`LatLngSubject`, `LatLngBoundsSubject`) for more readable and precise assertions on map-related objects, with built-in tolerance for floating-point comparisons.
- Adds new dependencies for testing: `espresso-idling-resource`, `truth`, and `uiautomator`.
- Increases Gradle daemon heap size to support test execution.
- **New Espresso Tests:**
- Adds comprehensive tests for `GroundOverlayDemoActivity`, `CameraClampingDemoActivity`, `IndoorDemoActivity`, `CameraDemoActivity`, and `VisibleRegionDemoActivity` in both Java and Kotlin modules.
- Tests verify UI interactions, camera behavior, and state changes within the demo activities.
- **Code Refactoring:**
- Enables ViewBinding in the `java-app`, `kotlin-app`, and `common-ui` modules.
- Refactors all major demo activities (e.g., `GroundOverlayDemoActivity`, `MarkerDemoActivity`, `CircleDemoActivity`, `UiSettingsDemoActivity`) to use ViewBinding.
- Replaces `android:onClick` XML attributes with programmatic `setOnClickListener` calls, improving code organization and maintainability.
- Enhances Javadoc and KDoc in `GroundOverlayDemoActivity` to better explain the concepts and implementation details, improving its educational value.
* feat(androidTest): Refactor GroundOverlayDemoActivityTest and add MapProvider
Refactors the GroundOverlayDemoActivityTest to improve reliability and readability. This commit introduces a `MapProvider` interface and a base `MapDemoActivityTest` class to abstract away common map initialization logic.
Key changes include:
- Add a `MapProvider` interface to ensure activities provide a `GoogleMap` object.
- Create an abstract `MapDemoActivityTest` to handle common test setup, including map initialization and idling resources (WIP).
- Update `GroundOverlayDemoActivityTest` to extend `MapDemoActivityTest`, simplifying its setup logic.
- Replace `Thread.sleep()` calls with `idlingResource.waitForIdle()`.
- Update `GroundOverlayDemoActivity` to use `lateinit` for overlays, preventing nullable types.
- Add `maps-utils-ktx` dependency for idiomatic spherical offset calculations.
* fix(test): Improve CircleDemoActivityTest readability and precision
Enhances the `testLongClickAddsNewCircle` in `CircleDemoActivityTest` by adding
detailed comments that explain the test's flow and the critical reason for
camera movements: to minimize precision loss during LatLng to screen coordinate
conversion for accurate click event simulation.
This commit also includes the necessary `LatLngSubject` extension, introducing
a `isWith(tolerance).of(target)` assertion. This new assertion allows for
more precise and readable verification of spherical distances between `LatLng`
objects, directly supporting the improved test logic in `CircleDemoActivityTest`.
* feat(java): Align CircleDemoActivity and tests with Kotlin version
* refactor(test): Extend MapDemoActivityTest and improve synchronization
Refactors the java version of `GroundOverlayDemoActivityTest` to extend the common `MapDemoActivityTest` base class. This change centralizes test setup, teardown, and map interaction logic, removing redundant code and improving maintainability.
- `GroundOverlayDemoActivity` now implements the `MapProvider` interface to correctly expose the map instance and its ready state to the test framework.
- Replaces `Thread.sleep()` calls in `CircleDemoActivityTest` and `GroundOverlayDemoActivityTest` with `idlingResource.waitForIdle()`. This creates more reliable tests by waiting for map events to complete rather than using fixed delays.
- Adds a `waitForIdle(long)` overload to `MapIdlingResource` to handle cases requiring a brief, controlled pause after the map has settled.
* chore: fix missing copyright headers
* refactor(kotlin): Address lint warnings
This commit applies several small refactorings to the Kotlin demo activities, focusing on code modernization and resolving lint issues.
- In `MarkerDemoActivity`, replaces `Math.max()` with the more idiomatic Kotlin function `coerceAtLeast()`.
- Simplifies trigonometric function calls by using top-level `sin` and `cos` from the Kotlin standard library instead of `Math`.
- Removes unused imports from `MarkerDemoActivity`.
- In `LayersDemoActivity`, adds `@SuppressLint("MissingPermission")` to the `onMyLocationToggled` method to address a lint warning.
* refactor(ui): Use android:name for FragmentContainerView
This commit updates the layout files to use the `android:name` attribute instead of the `class` attribute for `FragmentContainerView` to declare the fragment class. This is the modern, recommended practice.
It also removes minor whitespace and `onClick` attributes that are no longer necessary.
- Replaces the `class` attribute with `android:name` for all instances of `SupportMapFragment` and `SupportStreetViewPanoramaFragment` within `FragmentContainerView` tags across multiple demo layouts.
- Removes unnecessary `onClick` attributes from checkboxes in `layers_demo.xml`.
- Cleans up minor whitespace in `camera_clamping_demo.xml`, `street_view_panorama_navigation_demo.xml`, `indoor_demo.xml`, and `ground_overlay_demo.xml`.1 parent c624297 commit dfa18d2
File tree
90 files changed
+3305
-1165
lines changed- ApiDemos/project
- common-ui
- src/main/res
- layout-land
- layout
- values
- gradle
- java-app
- src
- androidTest/java/com/example/mapdemo
- truth
- utils
- main/java/com/example/mapdemo
- utils
- v3/java/com/example/mapdemo
- kotlin-app
- src
- androidTest/java/com/example/kotlindemos
- truth
- utils
- main/java/com/example/kotlindemos
- utils
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
90 files changed
+3305
-1165
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
Lines changed: 2 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | | - | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | 63 | | |
65 | | - | |
66 | | - | |
| 64 | + | |
67 | 65 | | |
68 | 66 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
Lines changed: 2 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | 76 | | |
78 | | - | |
79 | 77 | | |
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
83 | 81 | | |
84 | 82 | | |
85 | | - | |
86 | 83 | | |
87 | 84 | | |
88 | 85 | | |
| |||
96 | 93 | | |
97 | 94 | | |
98 | 95 | | |
99 | | - | |
100 | 96 | | |
101 | 97 | | |
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
105 | 101 | | |
106 | 102 | | |
107 | | - | |
108 | 103 | | |
109 | 104 | | |
110 | 105 | | |
111 | 106 | | |
112 | 107 | | |
113 | 108 | | |
114 | | - | |
115 | 109 | | |
116 | 110 | | |
117 | 111 | | |
| |||
Lines changed: 4 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 65 | + | |
| 66 | + | |
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
| |||
126 | 124 | | |
127 | 125 | | |
128 | 126 | | |
129 | | - | |
130 | 127 | | |
131 | 128 | | |
132 | 129 | | |
133 | 130 | | |
134 | 131 | | |
135 | 132 | | |
136 | 133 | | |
137 | | - | |
138 | 134 | | |
139 | 135 | | |
140 | 136 | | |
| |||
149 | 145 | | |
150 | 146 | | |
151 | 147 | | |
152 | | - | |
153 | 148 | | |
154 | 149 | | |
155 | 150 | | |
156 | 151 | | |
157 | 152 | | |
158 | 153 | | |
159 | 154 | | |
160 | | - | |
161 | 155 | | |
162 | 156 | | |
163 | 157 | | |
| |||
175 | 169 | | |
176 | 170 | | |
177 | 171 | | |
178 | | - | |
179 | 172 | | |
180 | 173 | | |
181 | 174 | | |
182 | 175 | | |
183 | | - | |
| 176 | + | |
184 | 177 | | |
185 | 178 | | |
186 | 179 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | 130 | | |
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
137 | 136 | | |
138 | | - | |
| 137 | + | |
139 | 138 | | |
140 | 139 | | |
141 | 140 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
0 commit comments