mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
* 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`.
76 lines
2.1 KiB
Plaintext
76 lines
2.1 KiB
Plaintext
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
|
|
|
/*
|
|
* Copyright 2025 Google LLC
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
plugins {
|
|
id("com.android.library")
|
|
id("org.jetbrains.kotlin.android")
|
|
}
|
|
|
|
android {
|
|
namespace = "com.example.common_ui"
|
|
compileSdk = libs.versions.compileSdk.get().toInt()
|
|
|
|
defaultConfig {
|
|
minSdk = libs.versions.minSdk.get().toInt()
|
|
|
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
|
consumerProguardFiles("consumer-rules.pro")
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
isMinifyEnabled = false
|
|
proguardFiles(
|
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
"proguard-rules.pro"
|
|
)
|
|
}
|
|
}
|
|
lint {
|
|
abortOnError = false
|
|
}
|
|
buildFeatures {
|
|
viewBinding = true
|
|
}
|
|
compileOptions {
|
|
sourceCompatibility = JavaVersion.VERSION_17
|
|
targetCompatibility = JavaVersion.VERSION_17
|
|
}
|
|
|
|
lint {
|
|
disable += setOf("MissingInflatedId", "OnClick")
|
|
sarifOutput = layout.buildDirectory.file("reports/lint-results-debug.sarif").get().asFile
|
|
}
|
|
kotlin {
|
|
compilerOptions {
|
|
jvmTarget.set(JvmTarget.JVM_17)
|
|
javaParameters.set(true)
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
|
|
implementation(libs.coreKtx)
|
|
implementation(libs.appcompat)
|
|
implementation(libs.material)
|
|
implementation(libs.playServicesMaps)
|
|
testImplementation(libs.junit)
|
|
androidTestImplementation(libs.androidxJunit)
|
|
androidTestImplementation(libs.espressoCore)
|
|
} |