Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add and use the secrets plugin in the snippets #633

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions snippets/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}

android {
compileSdk 33
Expand Down Expand Up @@ -52,3 +55,13 @@ dependencies {
// [END maps_android_places_upgrade_snippet]
}
// [END maps_android_places_install_snippet]

secrets {
// To add your Google Maps Platform API key to this project:
// 1. Create or open file secrets.properties in the root folder of the project, which will be
// read by secrets_gradle_plugin
// 2. Add this line, replacing YOUR_API_KEY with a key from a project with Places API enabled:
// PLACES_API_KEY=YOUR_API_KEY
propertiesFileName = "secrets.properties"
defaultPropertiesFileName 'local.defaults.properties'
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final String apiKey = "You API key";
// [START maps_places_get_started]
// Initialize the SDK
final String apiKey = BuildConfig.PLACES_API_KEY;
Places.initialize(getApplicationContext(), apiKey);

// Create a new PlacesClient instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final String apiKey = "You API key";
// [START maps_places_get_started]
// Initialize the SDK
final String apiKey = BuildConfig.PLACES_API_KEY;
Places.initialize(getApplicationContext(), apiKey);

// Create a new PlacesClient instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.google.places.kotlin
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.libraries.places.api.Places
import com.google.places.BuildConfig
import com.google.places.R

class GetStartedActivity : AppCompatActivity() {
Expand All @@ -25,9 +26,9 @@ class GetStartedActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val apiKey = "Your API key"
// [START maps_places_get_started]
// Initialize the SDK
val apiKey = BuildConfig.PLACES_API_KEY
Places.initialize(applicationContext, apiKey)

// Create a new PlacesClient instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.google.android.libraries.places.widget.Autocomplete
import com.google.android.libraries.places.widget.AutocompleteSupportFragment
import com.google.android.libraries.places.widget.listener.PlaceSelectionListener
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode
import com.google.places.BuildConfig
import com.google.places.R

class PlaceAutocompleteActivity : AppCompatActivity() {
Expand All @@ -44,9 +45,9 @@ class PlaceAutocompleteActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val apiKey = "Your API key"
// [START maps_places_get_started]
// Initialize the SDK
val apiKey = BuildConfig.PLACES_API_KEY
Places.initialize(applicationContext, apiKey)

// Create a new PlacesClient instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class PlacePhotosActivity : AppCompatActivity() {
val place = response.place

// Get the photo metadata.
val metada = place.photoMetadatas
if (metada == null || metada.isEmpty()) {
val metadata = place.photoMetadatas
if (metadata == null || metadata.isEmpty()) {
Log.w(TAG, "No photo metadata.")
return@addOnSuccessListener
}
val photoMetadata = metada.first()
val photoMetadata = metadata.first()

// Get the attribution text.
val attributions = photoMetadata?.attributions
Expand Down
1 change: 1 addition & 0 deletions snippets/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1'
}
}

Expand Down
1 change: 1 addition & 0 deletions snippets/local.defaults.properties
dkhawk marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLACES_API_KEY="DEFAULT_API_KEY"