diff --git a/.gitignore b/.gitignore index b4ae271d..bc32f55c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ local.properties .project project.properties secure.properties +secrets.properties .DS_Store diff --git a/README.md b/README.md index 4003d394..b0a4f427 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,11 @@ It enables you to write more concise, idiomatic Kotlin. Each set of extensions c ## Requirements * Kotlin-enabled project * Kotlin coroutines -* API level 15+ +* API level 21+ +* An [API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key) ## Installation -If you are using the Maps SDK through Google Play Services: - ```groovy dependencies { @@ -33,8 +32,6 @@ dependencies { } ``` -_**Note**_: The Beta version of the SDK is deprecated and scheduled for decommissioning. A future version of the SDK will provide similar support for Beta features. See the [release notes](https://developers.google.com/maps/documentation/android-sdk/releases#2021-08-18) for more information. - ## Example Usage With this KTX library, you should be able to take advantage of several Kotlin language features such as extension functions, named parameters and default arguments, destructuring declarations, and coroutines. @@ -48,8 +45,8 @@ This repository includes a [demo app](app) that illustrates the use of this KTX To run the demo app, you'll have to: 1. [Get a Maps API key](https://developers.google.com/maps/documentation/android-sdk/get-api-key) -1. Create a file in the root directory called `secure.properties` (this file should *NOT* be under version control to protect your API key) -1. Add a single line to `secure.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step +1. Create a file in the root directory called `secrets.properties` (this file should *NOT* be under version control to protect your API key) +1. Add a single line to `secrets.properties` that looks like `MAPS_API_KEY=YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you obtained in the first step 1. Build and run ### Maps SDK KTX diff --git a/app/build.gradle b/app/build.gradle index 1127e73e..d6587dcf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,28 +49,24 @@ android { namespace 'com.google.maps.android.ktx.demo' } -// [START maps_android_utils_ktx_install_snippet] dependencies { - // [START_EXCLUDE silent] implementation fileTree(dir: 'libs', include: ['*.jar']) implementation deps.kotlin implementation deps.androidx.appcompat implementation deps.androidx.coreKtx - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1' - implementation 'com.google.android.gms:play-services-maps:18.2.0' - // implementation 'com.google.maps.android:maps-ktx:3.4.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2' + + // Instead of the lines below, regular apps would load these libraries from Maven according to + // the README installation instructions implementation project(':maps-ktx') - // implementation project(':maps-utils-ktx') - // [END_EXCLUDE] - implementation 'com.google.maps.android:maps-utils-ktx:3.4.0' + implementation project(':maps-utils-ktx') } -// [END maps_android_utils_ktx_install_snippet] secrets { // To add your Maps API key to this project: - // 1. Create a file ./secure.properties + // 1. Create a file ./secrets.properties // 2. Add this line, where YOUR_API_KEY is your API key: // MAPS_API_KEY=YOUR_API_KEY - propertiesFileName 'secure.properties' - defaultPropertiesFileName 'secure.defaults.properties' + propertiesFileName 'secrets.properties' + defaultPropertiesFileName 'secrets.defaults.properties' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2712d803..dcb2b57b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,7 +20,7 @@ diff --git a/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt b/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt index 7709fdc1..ceaabba9 100644 --- a/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt +++ b/app/src/main/java/com/google/maps/android/ktx/demo/MainActivity.kt @@ -51,7 +51,7 @@ import org.json.JSONException * A demo of multiple layers on the map. * * To add your Maps API key to this project: - * 1. Create a file ./secure.properties + * 1. Create a file ./secrets.properties * 2. Add this line, where YOUR_API_KEY is your API key: * MAPS_API_KEY=YOUR_API_KEY */ @@ -67,7 +67,7 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) if (BuildConfig.MAPS_API_KEY.isEmpty()) { - Toast.makeText(this, "Add your own API key in ./secure.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show() + Toast.makeText(this, "Add your own API key in ./secrets.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show() } val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment diff --git a/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt b/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt index 3ac99f4d..5cdaa8d3 100644 --- a/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt +++ b/app/src/main/java/com/google/maps/android/ktx/demo/io/MyItemReader.kt @@ -1,5 +1,5 @@ /* - * Copyright 2013 Google Inc. + * Copyright 2023 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ class MyItemReader { for (i in 0 until array.length()) { var title: String? = null var snippet: String? = null + var zIndex: Double? = null val `object` = array.getJSONObject(i) val lat = `object`.getDouble("lat") val lng = `object`.getDouble("lng") @@ -53,7 +54,10 @@ class MyItemReader { if (!`object`.isNull("snippet")) { snippet = `object`.getString("snippet") } - items.add(MyItem(LatLng(lat, lng), title, snippet)) + if (!`object`.isNull("zIndex")) { + zIndex = `object`.getDouble("zIndex") + } + items.add(MyItem(LatLng(lat, lng), title, snippet, zIndex?.toFloat())) } return items } diff --git a/app/src/main/java/com/google/maps/android/ktx/demo/model/MyItem.kt b/app/src/main/java/com/google/maps/android/ktx/demo/model/MyItem.kt index c8e5053d..93290592 100644 --- a/app/src/main/java/com/google/maps/android/ktx/demo/model/MyItem.kt +++ b/app/src/main/java/com/google/maps/android/ktx/demo/model/MyItem.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google Inc. + * Copyright 2023 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,9 @@ import com.google.maps.android.clustering.ClusterItem * (https://youtrack.jetbrains.com/issue/KT-6653?_ga=2.30406975.1494223917.1585591891-1137021041.1573759593) * so we must name our fields differently and then pass them to the ClusterItem methods. */ -data class MyItem(val latLng: LatLng, val myTitle: String?, val mySnippet: String?) : ClusterItem { +data class MyItem(val latLng: LatLng, val myTitle: String?, val mySnippet: String?, val myZIndex: Float?) : ClusterItem { override fun getPosition() = latLng override fun getTitle() = myTitle override fun getSnippet() = mySnippet + override fun getZIndex() = myZIndex } \ No newline at end of file diff --git a/build.gradle b/build.gradle index cc974360..be11ab4a 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ buildscript { "minSdk" : 19, "targetSdk" : 34 ], - 'androidMapsUtils' : '3.5.3', + 'androidMapsUtils' : '3.7.0', 'androidx' : [ 'appcompat': '1.1.0', 'coreKtx' : '1.2.0', @@ -35,7 +35,7 @@ buildscript { 'kotlinxCoroutines': '1.6.0', 'mockito' : '3.0.0', 'mockitoKotlin' : '2.2.0', - 'playServices' : '18.1.0', + 'androidMapsSdk' : '18.2.0', 'volley' : '1.2.0', ] @@ -53,11 +53,10 @@ buildscript { 'junit' : "junit:junit:$versions.junit", 'kotlin' : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlin", 'kotlinxCoroutines': "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.kotlinxCoroutines", - 'mapsBeta' : "com.google.android.libraries.maps:maps:$versions.mapsBeta", 'mockito' : "org.mockito:mockito-core:$versions.mockito", 'mockitoKotlin' : "com.nhaarman.mockitokotlin2:mockito-kotlin:$versions.mockitoKotlin", 'playServices' : [ - 'maps' : "com.google.android.gms:play-services-maps:$versions.playServices", + 'maps' : "com.google.android.gms:play-services-maps:$versions.androidMapsSdk", ], 'volley' : "com.android.volley:volley:$versions.volley", ] @@ -71,7 +70,7 @@ buildscript { classpath 'com.android.tools.build:gradle:7.4.2' classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.9.10' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" - classpath 'com.hiya:jacoco-android:0.2' + classpath 'com.mxalbert.gradle:jacoco-android:0.2.1' classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1" } } @@ -109,7 +108,7 @@ subprojects { project -> if (project.ext.artifactId == null) return apply plugin: 'com.android.library' - apply plugin: 'com.hiya.jacoco-android' + apply plugin: 'com.mxalbert.gradle.jacoco-android' apply plugin: 'maven-publish' apply plugin: 'org.jetbrains.dokka' apply plugin: 'signing' diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f..249e5832 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9582453b..59bc51a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Sep 15 07:45:22 CEST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..a69d9cb6 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..53a6b238 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/maps-utils-ktx/build.gradle b/maps-utils-ktx/build.gradle index bbc1fffa..51ef8178 100644 --- a/maps-utils-ktx/build.gradle +++ b/maps-utils-ktx/build.gradle @@ -1,5 +1,5 @@ /** - * Copyright 2020 Google Inc. + * Copyright 2023 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,6 @@ android { dependencies { implementation deps.kotlin api deps.androidMapsUtils.gms - api deps.playServices.maps // Tests testImplementation deps.androidx.test diff --git a/secure.defaults.properties b/secrets.defaults.properties similarity index 100% rename from secure.defaults.properties rename to secrets.defaults.properties