Support samples using centrally managed play services version number

Change-Id: Idfec75a5d02c46ebb875e1e8b51078b1a2023cd6
diff --git a/templates/Wear/Wearable/build.gradle.ftl b/templates/Wear/Wearable/build.gradle.ftl
index 9bd4a7b..3ff2e86 100644
--- a/templates/Wear/Wearable/build.gradle.ftl
+++ b/templates/Wear/Wearable/build.gradle.ftl
@@ -35,7 +35,9 @@
 dependencies {
 
 <#list sample.dependency_wearable as dep>
-    compile "${dep}"
+    <#-- Output dependency after checking if it is a play services depdency and
+    needs the latest version number attached. -->
+    <@update_play_services_dependency dep="${dep}" />
 </#list>
 
     compile ${play_services_wearable_dependency}
diff --git a/templates/WearPlusShared/Shared/build.gradle.ftl b/templates/WearPlusShared/Shared/build.gradle.ftl
index bdc7817..7e9a3aa 100644
--- a/templates/WearPlusShared/Shared/build.gradle.ftl
+++ b/templates/WearPlusShared/Shared/build.gradle.ftl
@@ -31,11 +31,11 @@
 
 <#if sample.dependency_shared?has_content>
 dependencies {
-
 <#list sample.dependency_shared as dep>
-    compile "${dep}"
+    <#-- Output dependency after checking if it is a play services depdency and
+    needs the latest version number attached. -->
+    <@update_play_services_dependency dep="${dep}" />
 </#list>
-
 }</#if>
 
 // The sample build uses multiple directories to
diff --git a/templates/WearPlusShared/Wearable/build.gradle.ftl b/templates/WearPlusShared/Wearable/build.gradle.ftl
index a509379..68bdf64 100644
--- a/templates/WearPlusShared/Wearable/build.gradle.ftl
+++ b/templates/WearPlusShared/Wearable/build.gradle.ftl
@@ -37,11 +37,11 @@
 }
 
 dependencies {
-
 <#list sample.dependency_wearable as dep>
-    compile "${dep}"
+    <#-- Output dependency after checking if it is a play services depdency and
+    needs the latest version number attached. -->
+    <@update_play_services_dependency dep="${dep}" />
 </#list>
-
     compile ${play_services_wearable_dependency}
     compile ${android_support_v13_dependency}
     compile ${wearable_support_dependency}
diff --git a/templates/WearPlusShared/_MODULE_/build.gradle.ftl b/templates/WearPlusShared/_MODULE_/build.gradle.ftl
index fc6be53..1254113 100644
--- a/templates/WearPlusShared/_MODULE_/build.gradle.ftl
+++ b/templates/WearPlusShared/_MODULE_/build.gradle.ftl
@@ -38,14 +38,14 @@
 }
 
 dependencies {
-
 <#list sample.dependency as dep>
-    compile "${dep}"
+    <#-- Output dependency after checking if it is a play services depdency and
+    needs the latest version number attached. -->
+    <@update_play_services_dependency dep="${dep}" />
 </#list>
 <#list sample.dependency_external as dep>
     compile files(${dep})
 </#list>
-
     compile ${play_services_wearable_dependency}
     compile ${android_support_v13_dependency}
     compile project(':Shared')
diff --git a/templates/base-application/_MODULE_/build.gradle.ftl b/templates/base-application/_MODULE_/build.gradle.ftl
index 6395ee2..9f98c82 100644
--- a/templates/base-application/_MODULE_/build.gradle.ftl
+++ b/templates/base-application/_MODULE_/build.gradle.ftl
@@ -50,7 +50,9 @@
 </#if>
 
 <#list sample.dependency as dep>
-    compile "${dep}"
+    <#-- Output dependency after checking if it is a play services depdency and
+    needs the latest version number attached. -->
+    <@update_play_services_dependency dep="${dep}" />
 </#list>
 <#list sample.dependency_external as dep>
     compile files(${dep})
diff --git a/templates/base/_MODULE_/build.gradle.ftl b/templates/base/_MODULE_/build.gradle.ftl
index 0b89e4b..6488647 100644
--- a/templates/base/_MODULE_/build.gradle.ftl
+++ b/templates/base/_MODULE_/build.gradle.ftl
@@ -49,7 +49,9 @@
   </#if>
 </#if>
 <#list sample.dependency as dep>
-    compile "${dep}"
+    <#-- Output dependency after checking if it is a play services depdency and
+    needs the latest version number attached. -->
+    <@update_play_services_dependency dep="${dep}" />
 </#list>
 <#list sample.dependency_external as dep>
     compile files(${dep})
diff --git a/templates/include/common.ftl b/templates/include/common.ftl
index c6fac9b..b45bd30 100644
--- a/templates/include/common.ftl
+++ b/templates/include/common.ftl
@@ -62,10 +62,26 @@
 <#else>
     <#assign min_sdk = "22"/>
 </#if>
+
+<#-- Global macros -->
+
+<#-- Check if dependency is a play services dependency and if it doesn't
+     have a version number attached use the global value
+     play_services_version -->
+<#macro update_play_services_dependency dep>
+    <#if "${dep}"?starts_with("com.google.android.gms:play-services")
+            && "${dep}"?index_of(":") == "${dep}"?last_index_of(":")>
+    compile '${dep}:${play_services_version}'
+    <#else>
+    compile '${dep}'
+    </#if>
+</#macro>
+
 <#-- Set the global build tools version -->
 <#assign build_tools_version='"22.0.1"'/>
 
-<#assign play_services_wearable_dependency="'com.google.android.gms:play-services-wearable:7.3.0+'"/>
+<#assign play_services_version="7.3.0"/>
+<#assign play_services_wearable_dependency="'com.google.android.gms:play-services-wearable:${play_services_version}'"/>
 
 <#assign android_support_v13_dependency="'com.android.support:support-v13:22.1.0'"/>