├── .gitignore ├── CONTRIB.md ├── HelloEndpointsProject ├── HelloEndpoints │ ├── build.gradle │ ├── libs │ │ └── android-support-v4.jar │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── ic_launcher-web.png │ │ ├── java │ │ └── com │ │ │ ├── appspot │ │ │ └── your_app_id │ │ │ │ └── helloworld │ │ │ │ ├── Helloworld.java │ │ │ │ ├── HelloworldRequest.java │ │ │ │ ├── HelloworldRequestInitializer.java │ │ │ │ ├── HelloworldScopes.java │ │ │ │ └── model │ │ │ │ ├── HelloGreeting.java │ │ │ │ └── HelloGreetingCollection.java │ │ │ └── google │ │ │ └── devrel │ │ │ └── samples │ │ │ └── helloendpoints │ │ │ ├── AppConstants.java │ │ │ ├── Application.java │ │ │ └── MainActivity.java │ │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── main.xml │ │ ├── values-sw600dp │ │ └── dimens.xml │ │ ├── values-sw720dp-land │ │ └── dimens.xml │ │ ├── values-v11 │ │ └── styles.xml │ │ ├── values-v14 │ │ └── styles.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | HelloEndpointsProject/.idea/** 2 | HelloEndpointsProject/.gradle/** 3 | HelloEndpointsProject/local.properties 4 | HelloEndpointsProject/HelloEndpoints/build/** 5 | HelloEndpointsProject/HelloEndpoints/src/main/gen/** 6 | *.iml 7 | pom.xml 8 | out/** 9 | -------------------------------------------------------------------------------- /CONTRIB.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we have to jump a couple of legal hurdles. 6 | 7 | Please fill out either the individual or corporate Contributor License Agreement (CLA). 8 | 9 | * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). 10 | * If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). 11 | 12 | Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests. 13 | 14 | ## Contributing A Patch 15 | 16 | 1. Submit an issue describing your proposed change to the repo in question. 17 | 1. The repo owner will respond to your issue promptly. 18 | 1. If your proposed change is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 19 | 1. Fork the desired repo, develop and test your code changes. 20 | 1. Ensure that your code adheres to the existing style in the sample to which you are contributing. Refer to the [Google Cloud Platform Samples Style Guide](https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the recommended coding standards for this organization. 21 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 22 | 1. Submit a pull request. 23 | 24 | ## Contributing A New Sample App 25 | 26 | 1. Submit an issue to the GoogleCloudPlatform/Template repo describing your proposed sample app. 27 | 1. The Template repo owner will respond to your enhancement issue promptly. Instructional value is the top priority when evaluating new app proposals for this collection of repos. 28 | 1. If your proposal is accepted, and you haven't already done so, sign a Contributor License Agreement (see details above). 29 | 1. Create your own repo for your app following this naming convention: 30 | * {product}-{app-name}-{language} 31 | * products: appengine, compute, storage, bigquery, prediction, cloudsql 32 | * example: appengine-guestbook-python 33 | * For multi-product apps, concatenate the primary products, like this: compute-appengine-demo-suite-python. 34 | * For multi-language apps, concatenate the primary languages like this: appengine-sockets-python-java-go. 35 | 1. Clone the README.md, CONTRIB.md and LICENSE files from the GoogleCloudPlatform/Template repo. 36 | 1. Ensure that your code adheres to the existing style in the sample to which you are contributing. Refer to the [Google Cloud Platform Samples Style Guide](https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the recommended coding standards for this organization. 37 | 1. Ensure that your code has an appropriate set of unit tests which all pass. 38 | 1. Submit a request to fork your repo in GoogleCloudPlatform organizationt via your proposal issue. 39 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:0.6.+' 7 | } 8 | } 9 | 10 | apply plugin: 'android' 11 | 12 | repositories { 13 | mavenCentral() 14 | maven { 15 | url 'http://google-api-client-libraries.appspot.com/mavenrepo' 16 | } 17 | } 18 | 19 | dependencies { 20 | compile 'com.android.support:support-v4:13.0.+' 21 | 22 | // BEGIN Google APIs 23 | 24 | // Play Services will validate the application prior to allowing OAuth2 access. 25 | compile(group: 'com.google.android.gms', name: 'play-services', version: '3.2.25') 26 | 27 | // The following lines implement maven imports as defined at: 28 | // https://code.google.com/p/google-api-java-client/wiki/Setup 29 | 30 | // Add the Google API client library. 31 | compile(group: 'com.google.api-client', name: 'google-api-client', version: '1.17.0-rc') { 32 | // Exclude artifacts that the Android SDK/Runtime provides. 33 | exclude(group: 'xpp3', module: 'xpp3') 34 | exclude(group: 'org.apache.httpcomponents', module: 'httpclient') 35 | exclude(group: 'junit', module: 'junit') 36 | exclude(group: 'com.google.android', module: 'android') 37 | } 38 | 39 | // Add the Android extensions for the Google API client library. 40 | // This will automatically include play services as long as you have download that library 41 | // from the Android SDK manager. 42 | // Add the Android extensions for the Google API client library. 43 | compile(group: 'com.google.api-client', name: 'google-api-client-android', 44 | version: '1.17.0-rc') { 45 | // Exclude play services. Explicitly include it above after you have installed Play 46 | // services from the Android SDK manager. 47 | exclude(group: 'com.google.android.google-play-services', module: 'google-play-services') 48 | } 49 | 50 | // END Google APIs 51 | 52 | // The following client libraries make HTTP/JSON on Android easier. 53 | 54 | // Android extensions for Google HTTP Client. 55 | compile(group: 'com.google.http-client', name: 'google-http-client-android', 56 | version: '1.17.0-rc') { 57 | exclude(group: 'com.google.android', module: 'android') 58 | } 59 | 60 | // This is used by the Google HTTP client library. 61 | compile(group: 'com.google.guava', name: 'guava', version: '14.0.+') 62 | 63 | } 64 | 65 | android { 66 | compileSdkVersion 19 67 | buildToolsVersion "19.0.0" 68 | 69 | defaultConfig { 70 | minSdkVersion 8 71 | targetSdkVersion 19 72 | } 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/appengine-endpoints-helloendpoints-android/e1c51eb7a7403272f3ef24cbfff887729c4edb22/HelloEndpointsProject/HelloEndpoints/libs/android-support-v4.jar -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/appengine-endpoints-helloendpoints-android/e1c51eb7a7403272f3ef24cbfff887729c4edb22/HelloEndpointsProject/HelloEndpoints/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/appspot/your_app_id/helloworld/Helloworld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 3 | * in compliance with the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License 8 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 9 | * or implied. See the License for the specific language governing permissions and limitations under 10 | * the License. 11 | */ 12 | /* 13 | * This code was generated by https://code.google.com/p/google-apis-client-generator/ 14 | * (build: 2013-09-16 16:01:30 UTC) 15 | * on 2013-09-30 at 22:19:22 UTC 16 | * Modify at your own risk. 17 | */ 18 | 19 | package com.appspot.your_app_id.helloworld; 20 | 21 | /** 22 | * Service definition for Helloworld (v1). 23 | * 24 | *

25 | * This is an API 26 | *

27 | * 28 | *

29 | * For more information about this service, see the 30 | * API Documentation 31 | *

32 | * 33 | *

34 | * This service uses {@link HelloworldRequestInitializer} to initialize global parameters via its 35 | * {@link Builder}. 36 | *

37 | * 38 | * @since 1.3 39 | * @author Google, Inc. 40 | */ 41 | @SuppressWarnings("javadoc") 42 | public class Helloworld extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient { 43 | 44 | // Note: Leave this static initializer at the top of the file. 45 | static { 46 | com.google.api.client.util.Preconditions.checkState( 47 | com.google.api.client.googleapis.GoogleUtils.MAJOR_VERSION == 1 && 48 | com.google.api.client.googleapis.GoogleUtils.MINOR_VERSION >= 15, 49 | "You are currently running with version %s of google-api-client. " + 50 | "You need at least version 1.15 of google-api-client to run version " + 51 | "1.17.0-rc of the helloworld library.", com.google.api.client.googleapis.GoogleUtils.VERSION); 52 | } 53 | 54 | /** 55 | * The default encoded root URL of the service. This is determined when the library is generated 56 | * and normally should not be changed. 57 | * 58 | * @since 1.7 59 | */ 60 | public static final String DEFAULT_ROOT_URL = "https://your-app-id.appspot.com/_ah/api/"; 61 | 62 | /** 63 | * The default encoded service path of the service. This is determined when the library is 64 | * generated and normally should not be changed. 65 | * 66 | * @since 1.7 67 | */ 68 | public static final String DEFAULT_SERVICE_PATH = "helloworld/v1/"; 69 | 70 | /** 71 | * The default encoded base URL of the service. This is determined when the library is generated 72 | * and normally should not be changed. 73 | */ 74 | public static final String DEFAULT_BASE_URL = DEFAULT_ROOT_URL + DEFAULT_SERVICE_PATH; 75 | 76 | /** 77 | * Constructor. 78 | * 79 | *

80 | * Use {@link Builder} if you need to specify any of the optional parameters. 81 | *

82 | * 83 | * @param transport HTTP transport, which should normally be: 84 | * 92 | * @param jsonFactory JSON factory, which may be: 93 | * 99 | * @param httpRequestInitializer HTTP request initializer or {@code null} for none 100 | * @since 1.7 101 | */ 102 | public Helloworld(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, 103 | com.google.api.client.http.HttpRequestInitializer httpRequestInitializer) { 104 | this(new Builder(transport, jsonFactory, httpRequestInitializer)); 105 | } 106 | 107 | /** 108 | * @param builder builder 109 | */ 110 | Helloworld(Builder builder) { 111 | super(builder); 112 | } 113 | 114 | @Override 115 | protected void initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest httpClientRequest) throws java.io.IOException { 116 | super.initialize(httpClientRequest); 117 | } 118 | 119 | /** 120 | * An accessor for creating requests from the Greetings collection. 121 | * 122 | *

The typical use is:

123 | *
124 |    *   {@code Helloworld helloworld = new Helloworld(...);}
125 |    *   {@code Helloworld.Greetings.List request = helloworld.greetings().list(parameters ...)}
126 |    * 
127 | * 128 | * @return the resource collection 129 | */ 130 | public Greetings greetings() { 131 | return new Greetings(); 132 | } 133 | 134 | /** 135 | * The "greetings" collection of methods. 136 | */ 137 | public class Greetings { 138 | 139 | /** 140 | * Create a request for the method "greetings.authed". 141 | * 142 | * This request holds the parameters needed by the helloworld server. After setting any optional 143 | * parameters, call the {@link Authed#execute()} method to invoke the remote operation. 144 | * 145 | * @return the request 146 | */ 147 | public Authed authed() throws java.io.IOException { 148 | Authed result = new Authed(); 149 | initialize(result); 150 | return result; 151 | } 152 | 153 | public class Authed extends HelloworldRequest { 154 | 155 | private static final String REST_PATH = "hellogreeting/authed"; 156 | 157 | /** 158 | * Create a request for the method "greetings.authed". 159 | * 160 | * This request holds the parameters needed by the the helloworld server. After setting any 161 | * optional parameters, call the {@link Authed#execute()} method to invoke the remote operation. 162 | *

{@link 163 | * Authed#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} must 164 | * be called to initialize this instance immediately after invoking the constructor.

165 | * 166 | * @since 1.13 167 | */ 168 | protected Authed() { 169 | super(Helloworld.this, "POST", REST_PATH, null, com.appspot.your_app_id.helloworld.model.HelloGreeting.class); 170 | } 171 | 172 | @Override 173 | public Authed setAlt(java.lang.String alt) { 174 | return (Authed) super.setAlt(alt); 175 | } 176 | 177 | @Override 178 | public Authed setFields(java.lang.String fields) { 179 | return (Authed) super.setFields(fields); 180 | } 181 | 182 | @Override 183 | public Authed setKey(java.lang.String key) { 184 | return (Authed) super.setKey(key); 185 | } 186 | 187 | @Override 188 | public Authed setOauthToken(java.lang.String oauthToken) { 189 | return (Authed) super.setOauthToken(oauthToken); 190 | } 191 | 192 | @Override 193 | public Authed setPrettyPrint(java.lang.Boolean prettyPrint) { 194 | return (Authed) super.setPrettyPrint(prettyPrint); 195 | } 196 | 197 | @Override 198 | public Authed setQuotaUser(java.lang.String quotaUser) { 199 | return (Authed) super.setQuotaUser(quotaUser); 200 | } 201 | 202 | @Override 203 | public Authed setUserIp(java.lang.String userIp) { 204 | return (Authed) super.setUserIp(userIp); 205 | } 206 | 207 | @Override 208 | public Authed set(String parameterName, Object value) { 209 | return (Authed) super.set(parameterName, value); 210 | } 211 | } 212 | /** 213 | * Create a request for the method "greetings.getGreeting". 214 | * 215 | * This request holds the parameters needed by the helloworld server. After setting any optional 216 | * parameters, call the {@link GetGreeting#execute()} method to invoke the remote operation. 217 | * 218 | * @param id 219 | * @return the request 220 | */ 221 | public GetGreeting getGreeting(java.lang.Integer id) throws java.io.IOException { 222 | GetGreeting result = new GetGreeting(id); 223 | initialize(result); 224 | return result; 225 | } 226 | 227 | public class GetGreeting extends HelloworldRequest { 228 | 229 | private static final String REST_PATH = "hellogreeting/{id}"; 230 | 231 | /** 232 | * Create a request for the method "greetings.getGreeting". 233 | * 234 | * This request holds the parameters needed by the the helloworld server. After setting any 235 | * optional parameters, call the {@link GetGreeting#execute()} method to invoke the remote 236 | * operation.

{@link 237 | * GetGreeting#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} 238 | * must be called to initialize this instance immediately after invoking the constructor.

239 | * 240 | * @param id 241 | * @since 1.13 242 | */ 243 | protected GetGreeting(java.lang.Integer id) { 244 | super(Helloworld.this, "GET", REST_PATH, null, com.appspot.your_app_id.helloworld.model.HelloGreeting.class); 245 | this.id = com.google.api.client.util.Preconditions.checkNotNull(id, "Required parameter id must be specified."); 246 | } 247 | 248 | @Override 249 | public com.google.api.client.http.HttpResponse executeUsingHead() throws java.io.IOException { 250 | return super.executeUsingHead(); 251 | } 252 | 253 | @Override 254 | public com.google.api.client.http.HttpRequest buildHttpRequestUsingHead() throws java.io.IOException { 255 | return super.buildHttpRequestUsingHead(); 256 | } 257 | 258 | @Override 259 | public GetGreeting setAlt(java.lang.String alt) { 260 | return (GetGreeting) super.setAlt(alt); 261 | } 262 | 263 | @Override 264 | public GetGreeting setFields(java.lang.String fields) { 265 | return (GetGreeting) super.setFields(fields); 266 | } 267 | 268 | @Override 269 | public GetGreeting setKey(java.lang.String key) { 270 | return (GetGreeting) super.setKey(key); 271 | } 272 | 273 | @Override 274 | public GetGreeting setOauthToken(java.lang.String oauthToken) { 275 | return (GetGreeting) super.setOauthToken(oauthToken); 276 | } 277 | 278 | @Override 279 | public GetGreeting setPrettyPrint(java.lang.Boolean prettyPrint) { 280 | return (GetGreeting) super.setPrettyPrint(prettyPrint); 281 | } 282 | 283 | @Override 284 | public GetGreeting setQuotaUser(java.lang.String quotaUser) { 285 | return (GetGreeting) super.setQuotaUser(quotaUser); 286 | } 287 | 288 | @Override 289 | public GetGreeting setUserIp(java.lang.String userIp) { 290 | return (GetGreeting) super.setUserIp(userIp); 291 | } 292 | 293 | @com.google.api.client.util.Key 294 | private java.lang.Integer id; 295 | 296 | /** 297 | 298 | */ 299 | public java.lang.Integer getId() { 300 | return id; 301 | } 302 | 303 | public GetGreeting setId(java.lang.Integer id) { 304 | this.id = id; 305 | return this; 306 | } 307 | 308 | @Override 309 | public GetGreeting set(String parameterName, Object value) { 310 | return (GetGreeting) super.set(parameterName, value); 311 | } 312 | } 313 | /** 314 | * Create a request for the method "greetings.listGreeting". 315 | * 316 | * This request holds the parameters needed by the helloworld server. After setting any optional 317 | * parameters, call the {@link ListGreeting#execute()} method to invoke the remote operation. 318 | * 319 | * @return the request 320 | */ 321 | public ListGreeting listGreeting() throws java.io.IOException { 322 | ListGreeting result = new ListGreeting(); 323 | initialize(result); 324 | return result; 325 | } 326 | 327 | public class ListGreeting extends HelloworldRequest { 328 | 329 | private static final String REST_PATH = "hellogreeting"; 330 | 331 | /** 332 | * Create a request for the method "greetings.listGreeting". 333 | * 334 | * This request holds the parameters needed by the the helloworld server. After setting any 335 | * optional parameters, call the {@link ListGreeting#execute()} method to invoke the remote 336 | * operation.

{@link 337 | * ListGreeting#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} 338 | * must be called to initialize this instance immediately after invoking the constructor.

339 | * 340 | * @since 1.13 341 | */ 342 | protected ListGreeting() { 343 | super(Helloworld.this, "GET", REST_PATH, null, com.appspot.your_app_id.helloworld.model.HelloGreetingCollection.class); 344 | } 345 | 346 | @Override 347 | public com.google.api.client.http.HttpResponse executeUsingHead() throws java.io.IOException { 348 | return super.executeUsingHead(); 349 | } 350 | 351 | @Override 352 | public com.google.api.client.http.HttpRequest buildHttpRequestUsingHead() throws java.io.IOException { 353 | return super.buildHttpRequestUsingHead(); 354 | } 355 | 356 | @Override 357 | public ListGreeting setAlt(java.lang.String alt) { 358 | return (ListGreeting) super.setAlt(alt); 359 | } 360 | 361 | @Override 362 | public ListGreeting setFields(java.lang.String fields) { 363 | return (ListGreeting) super.setFields(fields); 364 | } 365 | 366 | @Override 367 | public ListGreeting setKey(java.lang.String key) { 368 | return (ListGreeting) super.setKey(key); 369 | } 370 | 371 | @Override 372 | public ListGreeting setOauthToken(java.lang.String oauthToken) { 373 | return (ListGreeting) super.setOauthToken(oauthToken); 374 | } 375 | 376 | @Override 377 | public ListGreeting setPrettyPrint(java.lang.Boolean prettyPrint) { 378 | return (ListGreeting) super.setPrettyPrint(prettyPrint); 379 | } 380 | 381 | @Override 382 | public ListGreeting setQuotaUser(java.lang.String quotaUser) { 383 | return (ListGreeting) super.setQuotaUser(quotaUser); 384 | } 385 | 386 | @Override 387 | public ListGreeting setUserIp(java.lang.String userIp) { 388 | return (ListGreeting) super.setUserIp(userIp); 389 | } 390 | 391 | @Override 392 | public ListGreeting set(String parameterName, Object value) { 393 | return (ListGreeting) super.set(parameterName, value); 394 | } 395 | } 396 | /** 397 | * Create a request for the method "greetings.multiply". 398 | * 399 | * This request holds the parameters needed by the helloworld server. After setting any optional 400 | * parameters, call the {@link Multiply#execute()} method to invoke the remote operation. 401 | * 402 | * @param times 403 | * @param content the {@link com.appspot.your_app_id.helloworld.model.HelloGreeting} 404 | * @return the request 405 | */ 406 | public Multiply multiply(java.lang.Integer times, com.appspot.your_app_id.helloworld.model.HelloGreeting content) throws java.io.IOException { 407 | Multiply result = new Multiply(times, content); 408 | initialize(result); 409 | return result; 410 | } 411 | 412 | public class Multiply extends HelloworldRequest { 413 | 414 | private static final String REST_PATH = "hellogreeting/{times}"; 415 | 416 | /** 417 | * Create a request for the method "greetings.multiply". 418 | * 419 | * This request holds the parameters needed by the the helloworld server. After setting any 420 | * optional parameters, call the {@link Multiply#execute()} method to invoke the remote operation. 421 | *

{@link 422 | * Multiply#initialize(com.google.api.client.googleapis.services.AbstractGoogleClientRequest)} 423 | * must be called to initialize this instance immediately after invoking the constructor.

424 | * 425 | * @param times 426 | * @param content the {@link com.appspot.your_app_id.helloworld.model.HelloGreeting} 427 | * @since 1.13 428 | */ 429 | protected Multiply(java.lang.Integer times, com.appspot.your_app_id.helloworld.model.HelloGreeting content) { 430 | super(Helloworld.this, "POST", REST_PATH, content, com.appspot.your_app_id.helloworld.model.HelloGreeting.class); 431 | this.times = com.google.api.client.util.Preconditions.checkNotNull(times, "Required parameter times must be specified."); 432 | } 433 | 434 | @Override 435 | public Multiply setAlt(java.lang.String alt) { 436 | return (Multiply) super.setAlt(alt); 437 | } 438 | 439 | @Override 440 | public Multiply setFields(java.lang.String fields) { 441 | return (Multiply) super.setFields(fields); 442 | } 443 | 444 | @Override 445 | public Multiply setKey(java.lang.String key) { 446 | return (Multiply) super.setKey(key); 447 | } 448 | 449 | @Override 450 | public Multiply setOauthToken(java.lang.String oauthToken) { 451 | return (Multiply) super.setOauthToken(oauthToken); 452 | } 453 | 454 | @Override 455 | public Multiply setPrettyPrint(java.lang.Boolean prettyPrint) { 456 | return (Multiply) super.setPrettyPrint(prettyPrint); 457 | } 458 | 459 | @Override 460 | public Multiply setQuotaUser(java.lang.String quotaUser) { 461 | return (Multiply) super.setQuotaUser(quotaUser); 462 | } 463 | 464 | @Override 465 | public Multiply setUserIp(java.lang.String userIp) { 466 | return (Multiply) super.setUserIp(userIp); 467 | } 468 | 469 | @com.google.api.client.util.Key 470 | private java.lang.Integer times; 471 | 472 | /** 473 | 474 | */ 475 | public java.lang.Integer getTimes() { 476 | return times; 477 | } 478 | 479 | public Multiply setTimes(java.lang.Integer times) { 480 | this.times = times; 481 | return this; 482 | } 483 | 484 | @Override 485 | public Multiply set(String parameterName, Object value) { 486 | return (Multiply) super.set(parameterName, value); 487 | } 488 | } 489 | 490 | } 491 | 492 | /** 493 | * Builder for {@link Helloworld}. 494 | * 495 | *

496 | * Implementation is not thread-safe. 497 | *

498 | * 499 | * @since 1.3.0 500 | */ 501 | public static final class Builder extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient.Builder { 502 | 503 | /** 504 | * Returns an instance of a new builder. 505 | * 506 | * @param transport HTTP transport, which should normally be: 507 | *
    508 | *
  • Google App Engine: 509 | * {@code com.google.api.client.extensions.appengine.http.UrlFetchTransport}
  • 510 | *
  • Android: {@code newCompatibleTransport} from 511 | * {@code com.google.api.client.extensions.android.http.AndroidHttp}
  • 512 | *
  • Java: {@link com.google.api.client.googleapis.javanet.GoogleNetHttpTransport#newTrustedTransport()} 513 | *
  • 514 | *
515 | * @param jsonFactory JSON factory, which may be: 516 | *
    517 | *
  • Jackson: {@code com.google.api.client.json.jackson2.JacksonFactory}
  • 518 | *
  • Google GSON: {@code com.google.api.client.json.gson.GsonFactory}
  • 519 | *
  • Android Honeycomb or higher: 520 | * {@code com.google.api.client.extensions.android.json.AndroidJsonFactory}
  • 521 | *
522 | * @param httpRequestInitializer HTTP request initializer or {@code null} for none 523 | * @since 1.7 524 | */ 525 | public Builder(com.google.api.client.http.HttpTransport transport, com.google.api.client.json.JsonFactory jsonFactory, 526 | com.google.api.client.http.HttpRequestInitializer httpRequestInitializer) { 527 | super( 528 | transport, 529 | jsonFactory, 530 | DEFAULT_ROOT_URL, 531 | DEFAULT_SERVICE_PATH, 532 | httpRequestInitializer, 533 | false); 534 | } 535 | 536 | /** Builds a new instance of {@link Helloworld}. */ 537 | @Override 538 | public Helloworld build() { 539 | return new Helloworld(this); 540 | } 541 | 542 | @Override 543 | public Builder setRootUrl(String rootUrl) { 544 | return (Builder) super.setRootUrl(rootUrl); 545 | } 546 | 547 | @Override 548 | public Builder setServicePath(String servicePath) { 549 | return (Builder) super.setServicePath(servicePath); 550 | } 551 | 552 | @Override 553 | public Builder setHttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer httpRequestInitializer) { 554 | return (Builder) super.setHttpRequestInitializer(httpRequestInitializer); 555 | } 556 | 557 | @Override 558 | public Builder setApplicationName(String applicationName) { 559 | return (Builder) super.setApplicationName(applicationName); 560 | } 561 | 562 | @Override 563 | public Builder setSuppressPatternChecks(boolean suppressPatternChecks) { 564 | return (Builder) super.setSuppressPatternChecks(suppressPatternChecks); 565 | } 566 | 567 | @Override 568 | public Builder setSuppressRequiredParameterChecks(boolean suppressRequiredParameterChecks) { 569 | return (Builder) super.setSuppressRequiredParameterChecks(suppressRequiredParameterChecks); 570 | } 571 | 572 | @Override 573 | public Builder setSuppressAllChecks(boolean suppressAllChecks) { 574 | return (Builder) super.setSuppressAllChecks(suppressAllChecks); 575 | } 576 | 577 | /** 578 | * Set the {@link HelloworldRequestInitializer}. 579 | * 580 | * @since 1.12 581 | */ 582 | public Builder setHelloworldRequestInitializer( 583 | HelloworldRequestInitializer helloworldRequestInitializer) { 584 | return (Builder) super.setGoogleClientRequestInitializer(helloworldRequestInitializer); 585 | } 586 | 587 | @Override 588 | public Builder setGoogleClientRequestInitializer( 589 | com.google.api.client.googleapis.services.GoogleClientRequestInitializer googleClientRequestInitializer) { 590 | return (Builder) super.setGoogleClientRequestInitializer(googleClientRequestInitializer); 591 | } 592 | } 593 | } 594 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/appspot/your_app_id/helloworld/HelloworldRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 3 | * in compliance with the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License 8 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 9 | * or implied. See the License for the specific language governing permissions and limitations under 10 | * the License. 11 | */ 12 | /* 13 | * This code was generated by https://code.google.com/p/google-apis-client-generator/ 14 | * (build: 2013-09-16 16:01:30 UTC) 15 | * on 2013-09-30 at 22:19:22 UTC 16 | * Modify at your own risk. 17 | */ 18 | 19 | package com.appspot.your_app_id.helloworld; 20 | 21 | /** 22 | * Helloworld request. 23 | * 24 | * @since 1.3 25 | */ 26 | @SuppressWarnings("javadoc") 27 | public abstract class HelloworldRequest extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest { 28 | 29 | /** 30 | * @param client Google client 31 | * @param method HTTP Method 32 | * @param uriTemplate URI template for the path relative to the base URL. If it starts with a "/" 33 | * the base path from the base URL will be stripped out. The URI template can also be a 34 | * full URL. URI template expansion is done using 35 | * {@link com.google.api.client.http.UriTemplate#expand(String, String, Object, boolean)} 36 | * @param content A POJO that can be serialized into JSON or {@code null} for none 37 | * @param responseClass response class to parse into 38 | */ 39 | public HelloworldRequest( 40 | Helloworld client, String method, String uriTemplate, Object content, Class responseClass) { 41 | super( 42 | client, 43 | method, 44 | uriTemplate, 45 | content, 46 | responseClass); 47 | } 48 | 49 | /** Data format for the response. */ 50 | @com.google.api.client.util.Key 51 | private java.lang.String alt; 52 | 53 | /** 54 | * Data format for the response. [default: json] 55 | */ 56 | public java.lang.String getAlt() { 57 | return alt; 58 | } 59 | 60 | /** Data format for the response. */ 61 | public HelloworldRequest setAlt(java.lang.String alt) { 62 | this.alt = alt; 63 | return this; 64 | } 65 | 66 | /** Selector specifying which fields to include in a partial response. */ 67 | @com.google.api.client.util.Key 68 | private java.lang.String fields; 69 | 70 | /** 71 | * Selector specifying which fields to include in a partial response. 72 | */ 73 | public java.lang.String getFields() { 74 | return fields; 75 | } 76 | 77 | /** Selector specifying which fields to include in a partial response. */ 78 | public HelloworldRequest setFields(java.lang.String fields) { 79 | this.fields = fields; 80 | return this; 81 | } 82 | 83 | /** 84 | * API key. Your API key identifies your project and provides you with API access, quota, and 85 | * reports. Required unless you provide an OAuth 2.0 token. 86 | */ 87 | @com.google.api.client.util.Key 88 | private java.lang.String key; 89 | 90 | /** 91 | * API key. Your API key identifies your project and provides you with API access, quota, and 92 | * reports. Required unless you provide an OAuth 2.0 token. 93 | */ 94 | public java.lang.String getKey() { 95 | return key; 96 | } 97 | 98 | /** 99 | * API key. Your API key identifies your project and provides you with API access, quota, and 100 | * reports. Required unless you provide an OAuth 2.0 token. 101 | */ 102 | public HelloworldRequest setKey(java.lang.String key) { 103 | this.key = key; 104 | return this; 105 | } 106 | 107 | /** OAuth 2.0 token for the current user. */ 108 | @com.google.api.client.util.Key("oauth_token") 109 | private java.lang.String oauthToken; 110 | 111 | /** 112 | * OAuth 2.0 token for the current user. 113 | */ 114 | public java.lang.String getOauthToken() { 115 | return oauthToken; 116 | } 117 | 118 | /** OAuth 2.0 token for the current user. */ 119 | public HelloworldRequest setOauthToken(java.lang.String oauthToken) { 120 | this.oauthToken = oauthToken; 121 | return this; 122 | } 123 | 124 | /** Returns response with indentations and line breaks. */ 125 | @com.google.api.client.util.Key 126 | private java.lang.Boolean prettyPrint; 127 | 128 | /** 129 | * Returns response with indentations and line breaks. [default: true] 130 | */ 131 | public java.lang.Boolean getPrettyPrint() { 132 | return prettyPrint; 133 | } 134 | 135 | /** Returns response with indentations and line breaks. */ 136 | public HelloworldRequest setPrettyPrint(java.lang.Boolean prettyPrint) { 137 | this.prettyPrint = prettyPrint; 138 | return this; 139 | } 140 | 141 | /** 142 | * Available to use for quota purposes for server-side applications. Can be any arbitrary string 143 | * assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided. 144 | */ 145 | @com.google.api.client.util.Key 146 | private java.lang.String quotaUser; 147 | 148 | /** 149 | * Available to use for quota purposes for server-side applications. Can be any arbitrary string 150 | * assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided. 151 | */ 152 | public java.lang.String getQuotaUser() { 153 | return quotaUser; 154 | } 155 | 156 | /** 157 | * Available to use for quota purposes for server-side applications. Can be any arbitrary string 158 | * assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided. 159 | */ 160 | public HelloworldRequest setQuotaUser(java.lang.String quotaUser) { 161 | this.quotaUser = quotaUser; 162 | return this; 163 | } 164 | 165 | /** 166 | * IP address of the site where the request originates. Use this if you want to enforce per-user 167 | * limits. 168 | */ 169 | @com.google.api.client.util.Key 170 | private java.lang.String userIp; 171 | 172 | /** 173 | * IP address of the site where the request originates. Use this if you want to enforce per-user 174 | * limits. 175 | */ 176 | public java.lang.String getUserIp() { 177 | return userIp; 178 | } 179 | 180 | /** 181 | * IP address of the site where the request originates. Use this if you want to enforce per-user 182 | * limits. 183 | */ 184 | public HelloworldRequest setUserIp(java.lang.String userIp) { 185 | this.userIp = userIp; 186 | return this; 187 | } 188 | 189 | @Override 190 | public final Helloworld getAbstractGoogleClient() { 191 | return (Helloworld) super.getAbstractGoogleClient(); 192 | } 193 | 194 | @Override 195 | public HelloworldRequest setDisableGZipContent(boolean disableGZipContent) { 196 | return (HelloworldRequest) super.setDisableGZipContent(disableGZipContent); 197 | } 198 | 199 | @Override 200 | public HelloworldRequest setRequestHeaders(com.google.api.client.http.HttpHeaders headers) { 201 | return (HelloworldRequest) super.setRequestHeaders(headers); 202 | } 203 | 204 | @Override 205 | public HelloworldRequest set(String parameterName, Object value) { 206 | return (HelloworldRequest) super.set(parameterName, value); 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/appspot/your_app_id/helloworld/HelloworldRequestInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 3 | * in compliance with the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License 8 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 9 | * or implied. See the License for the specific language governing permissions and limitations under 10 | * the License. 11 | */ 12 | /* 13 | * This code was generated by https://code.google.com/p/google-apis-client-generator/ 14 | * (build: 2013-09-16 16:01:30 UTC) 15 | * on 2013-09-30 at 22:19:22 UTC 16 | * Modify at your own risk. 17 | */ 18 | 19 | package com.appspot.your_app_id.helloworld; 20 | 21 | /** 22 | * Helloworld request initializer for setting properties like key and userIp. 23 | * 24 | *

25 | * The simplest usage is to use it to set the key parameter: 26 | *

27 | * 28 | *
 29 |   public static final GoogleClientRequestInitializer KEY_INITIALIZER =
 30 |       new HelloworldRequestInitializer(KEY);
 31 |  * 
32 | * 33 | *

34 | * There is also a constructor to set both the key and userIp parameters: 35 | *

36 | * 37 | *
 38 |   public static final GoogleClientRequestInitializer INITIALIZER =
 39 |       new HelloworldRequestInitializer(KEY, USER_IP);
 40 |  * 
41 | * 42 | *

43 | * If you want to implement custom logic, extend it like this: 44 | *

45 | * 46 | *
 47 |   public static class MyRequestInitializer extends HelloworldRequestInitializer {
 48 | 
 49 |     {@literal @}Override
 50 |     public void initializeHelloworldRequest(HelloworldRequest{@literal <}?{@literal >} request)
 51 |         throws IOException {
 52 |       // custom logic
 53 |     }
 54 |   }
 55 |  * 
56 | * 57 | *

58 | * Finally, to set the key and userIp parameters and insert custom logic, extend it like this: 59 | *

60 | * 61 | *
 62 |   public static class MyRequestInitializer2 extends HelloworldRequestInitializer {
 63 | 
 64 |     public MyKeyRequestInitializer() {
 65 |       super(KEY, USER_IP);
 66 |     }
 67 | 
 68 |     {@literal @}Override
 69 |     public void initializeHelloworldRequest(HelloworldRequest{@literal <}?{@literal >} request)
 70 |         throws IOException {
 71 |       // custom logic
 72 |     }
 73 |   }
 74 |  * 
75 | * 76 | *

77 | * Subclasses should be thread-safe. 78 | *

79 | * 80 | * @since 1.12 81 | */ 82 | public class HelloworldRequestInitializer extends com.google.api.client.googleapis.services.json.CommonGoogleJsonClientRequestInitializer { 83 | 84 | public HelloworldRequestInitializer() { 85 | super(); 86 | } 87 | 88 | /** 89 | * @param key API key or {@code null} to leave it unchanged 90 | */ 91 | public HelloworldRequestInitializer(String key) { 92 | super(key); 93 | } 94 | 95 | /** 96 | * @param key API key or {@code null} to leave it unchanged 97 | * @param userIp user IP or {@code null} to leave it unchanged 98 | */ 99 | public HelloworldRequestInitializer(String key, String userIp) { 100 | super(key, userIp); 101 | } 102 | 103 | @Override 104 | public final void initializeJsonRequest(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest request) throws java.io.IOException { 105 | super.initializeJsonRequest(request); 106 | initializeHelloworldRequest((HelloworldRequest) request); 107 | } 108 | 109 | /** 110 | * Initializes Helloworld request. 111 | * 112 | *

113 | * Default implementation does nothing. Called from 114 | * {@link #initializeJsonRequest(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest)}. 115 | *

116 | * 117 | * @throws java.io.IOException I/O exception 118 | */ 119 | protected void initializeHelloworldRequest(HelloworldRequest request) throws java.io.IOException { 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/appspot/your_app_id/helloworld/HelloworldScopes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 3 | * in compliance with the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License 8 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 9 | * or implied. See the License for the specific language governing permissions and limitations under 10 | * the License. 11 | */ 12 | /* 13 | * This code was generated by https://code.google.com/p/google-apis-client-generator/ 14 | * (build: 2013-09-16 16:01:30 UTC) 15 | * on 2013-09-30 at 22:19:22 UTC 16 | * Modify at your own risk. 17 | */ 18 | 19 | package com.appspot.your_app_id.helloworld; 20 | 21 | /** 22 | * Available OAuth 2.0 scopes for use with the helloworld. 23 | * 24 | * @since 1.4 25 | */ 26 | public class HelloworldScopes { 27 | 28 | /** View your email address. */ 29 | public static final String USERINFO_EMAIL = "https://www.googleapis.com/auth/userinfo.email"; 30 | 31 | /** 32 | * Returns an unmodifiable set that contains all scopes declared by this class. 33 | * 34 | * @since 1.16 35 | */ 36 | public static java.util.Set all() { 37 | java.util.Set set = new java.util.HashSet(); 38 | set.add(USERINFO_EMAIL); 39 | return java.util.Collections.unmodifiableSet(set); 40 | } 41 | 42 | private HelloworldScopes() { 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/appspot/your_app_id/helloworld/model/HelloGreeting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 3 | * in compliance with the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License 8 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 9 | * or implied. See the License for the specific language governing permissions and limitations under 10 | * the License. 11 | */ 12 | /* 13 | * This code was generated by https://code.google.com/p/google-apis-client-generator/ 14 | * (build: 2013-09-16 16:01:30 UTC) 15 | * on 2013-09-30 at 22:19:22 UTC 16 | * Modify at your own risk. 17 | */ 18 | 19 | package com.appspot.your_app_id.helloworld.model; 20 | 21 | /** 22 | * Model definition for HelloGreeting. 23 | * 24 | *

This is the Java data model class that specifies how to parse/serialize into the JSON that is 25 | * transmitted over HTTP when working with the helloworld. For a detailed explanation see: 26 | * http://code.google.com/p/google-http-java-client/wiki/JSON 27 | *

28 | * 29 | * @author Google, Inc. 30 | */ 31 | @SuppressWarnings("javadoc") 32 | public final class HelloGreeting extends com.google.api.client.json.GenericJson { 33 | 34 | /** 35 | * The value may be {@code null}. 36 | */ 37 | @com.google.api.client.util.Key 38 | private java.lang.String message; 39 | 40 | /** 41 | * @return value or {@code null} for none 42 | */ 43 | public java.lang.String getMessage() { 44 | return message; 45 | } 46 | 47 | /** 48 | * @param message message or {@code null} for none 49 | */ 50 | public HelloGreeting setMessage(java.lang.String message) { 51 | this.message = message; 52 | return this; 53 | } 54 | 55 | @Override 56 | public HelloGreeting set(String fieldName, Object value) { 57 | return (HelloGreeting) super.set(fieldName, value); 58 | } 59 | 60 | @Override 61 | public HelloGreeting clone() { 62 | return (HelloGreeting) super.clone(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/appspot/your_app_id/helloworld/model/HelloGreetingCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 3 | * in compliance with the License. You may obtain a copy of the License at 4 | * 5 | * http://www.apache.org/licenses/LICENSE-2.0 6 | * 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License 8 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 9 | * or implied. See the License for the specific language governing permissions and limitations under 10 | * the License. 11 | */ 12 | /* 13 | * This code was generated by https://code.google.com/p/google-apis-client-generator/ 14 | * (build: 2013-09-16 16:01:30 UTC) 15 | * on 2013-09-30 at 22:19:22 UTC 16 | * Modify at your own risk. 17 | */ 18 | 19 | package com.appspot.your_app_id.helloworld.model; 20 | 21 | /** 22 | * Model definition for HelloGreetingCollection. 23 | * 24 | *

This is the Java data model class that specifies how to parse/serialize into the JSON that is 25 | * transmitted over HTTP when working with the helloworld. For a detailed explanation see: 26 | * http://code.google.com/p/google-http-java-client/wiki/JSON 27 | *

28 | * 29 | * @author Google, Inc. 30 | */ 31 | @SuppressWarnings("javadoc") 32 | public final class HelloGreetingCollection extends com.google.api.client.json.GenericJson { 33 | 34 | /** 35 | * The value may be {@code null}. 36 | */ 37 | @com.google.api.client.util.Key 38 | private java.util.List items; 39 | 40 | static { 41 | // hack to force ProGuard to consider HelloGreeting used, since otherwise it would be stripped out 42 | // see http://code.google.com/p/google-api-java-client/issues/detail?id=528 43 | com.google.api.client.util.Data.nullOf(HelloGreeting.class); 44 | } 45 | 46 | /** 47 | * @return value or {@code null} for none 48 | */ 49 | public java.util.List getItems() { 50 | return items; 51 | } 52 | 53 | /** 54 | * @param items items or {@code null} for none 55 | */ 56 | public HelloGreetingCollection setItems(java.util.List items) { 57 | this.items = items; 58 | return this; 59 | } 60 | 61 | @Override 62 | public HelloGreetingCollection set(String fieldName, Object value) { 63 | return (HelloGreetingCollection) super.set(fieldName, value); 64 | } 65 | 66 | @Override 67 | public HelloGreetingCollection clone() { 68 | return (HelloGreetingCollection) super.clone(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/google/devrel/samples/helloendpoints/AppConstants.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Google Inc. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.google.devrel.samples.helloendpoints; 17 | 18 | import android.accounts.Account; 19 | import android.accounts.AccountManager; 20 | import android.app.Activity; 21 | import android.app.Dialog; 22 | import android.content.Context; 23 | 24 | import com.google.android.gms.auth.GoogleAuthUtil; 25 | import com.google.android.gms.common.GooglePlayServicesUtil; 26 | import com.google.api.client.extensions.android.http.AndroidHttp; 27 | import com.google.api.client.extensions.android.json.AndroidJsonFactory; 28 | import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; 29 | import com.google.api.client.http.HttpTransport; 30 | import com.google.api.client.json.JsonFactory; 31 | import com.appspot.your_app_id.helloworld.Helloworld; 32 | 33 | import javax.annotation.Nullable; 34 | 35 | /** 36 | * Application constants and simple utilities. 37 | */ 38 | public class AppConstants { 39 | /** 40 | * Your WEB CLIENT ID from the API Access screen of the Developer Console for your project. This 41 | * is NOT the Android client id from that screen. 42 | * 43 | * @see https://developers.google.com/console 44 | */ 45 | public static final String WEB_CLIENT_ID = "your_web_client_id"; 46 | 47 | /** 48 | * The audience is defined by the web client id, not the Android client id. 49 | */ 50 | public static final String AUDIENCE = "server:client_id:" + WEB_CLIENT_ID; 51 | 52 | /** 53 | * Class instance of the JSON factory. 54 | */ 55 | public static final JsonFactory JSON_FACTORY = new AndroidJsonFactory(); 56 | 57 | /** 58 | * Class instance of the HTTP transport. 59 | */ 60 | public static final HttpTransport HTTP_TRANSPORT = AndroidHttp.newCompatibleTransport(); 61 | 62 | /** 63 | * Count Google accounts on the device. 64 | */ 65 | public static int countGoogleAccounts(Context context) { 66 | AccountManager am = AccountManager.get(context); 67 | Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); 68 | if (accounts == null || accounts.length < 1) { 69 | return 0; 70 | } else { 71 | return accounts.length; 72 | } 73 | } 74 | 75 | /** 76 | * Retrieve a Helloworld api service handle to access the API. 77 | */ 78 | public static Helloworld getApiServiceHandle(@Nullable GoogleAccountCredential credential) { 79 | // Use a builder to help formulate the API request. 80 | Helloworld.Builder helloWorld = new Helloworld.Builder(AppConstants.HTTP_TRANSPORT, 81 | AppConstants.JSON_FACTORY, credential); 82 | 83 | // If running the Cloud Endpoint API locally then point the API stub there by un-commenting the 84 | // next line. 85 | // helloWorld.setRootUrl("http://192.168.1.100:8080/_ah/api/"); 86 | 87 | return helloWorld.build(); 88 | } 89 | 90 | /** 91 | * Check that Google Play services APK is installed and up to date. 92 | */ 93 | public static boolean checkGooglePlayServicesAvailable(Activity activity) { 94 | final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); 95 | if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) { 96 | showGooglePlayServicesAvailabilityErrorDialog(activity, connectionStatusCode); 97 | return false; 98 | } 99 | return true; 100 | } 101 | 102 | /** 103 | * Called if the device does not have Google Play Services installed. 104 | */ 105 | public static void showGooglePlayServicesAvailabilityErrorDialog(final Activity activity, 106 | final int connectionStatusCode) { 107 | final int REQUEST_GOOGLE_PLAY_SERVICES = 0; 108 | activity.runOnUiThread(new Runnable() { 109 | @Override 110 | public void run() { 111 | Dialog dialog = GooglePlayServicesUtil.getErrorDialog( 112 | connectionStatusCode, activity, REQUEST_GOOGLE_PLAY_SERVICES); 113 | dialog.show(); 114 | } 115 | }); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/google/devrel/samples/helloendpoints/Application.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Google Inc. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.google.devrel.samples.helloendpoints; 17 | 18 | import com.appspot.your_app_id.helloworld.model.HelloGreeting; 19 | import com.google.api.client.util.Lists; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * Dummy Application class that can hold static data for use only in sample applications. 25 | * 26 | * TODO(developer): Implement a proper data storage technique for your application. 27 | */ 28 | public class Application extends android.app.Application { 29 | ArrayList greetings = Lists.newArrayList(); 30 | } 31 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/java/com/google/devrel/samples/helloendpoints/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Google Inc. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package com.google.devrel.samples.helloendpoints; 17 | 18 | import android.accounts.Account; 19 | import android.accounts.AccountManager; 20 | import android.content.Intent; 21 | import android.os.AsyncTask; 22 | import android.os.Bundle; 23 | import android.app.Activity; 24 | import android.util.Log; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.view.WindowManager; 28 | import android.widget.ArrayAdapter; 29 | import android.widget.ListView; 30 | import android.widget.TextView; 31 | import android.widget.Toast; 32 | 33 | import com.google.android.gms.auth.GoogleAuthException; 34 | import com.google.android.gms.auth.GoogleAuthUtil; 35 | import com.google.android.gms.common.AccountPicker; 36 | import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential; 37 | import com.appspot.your_app_id.helloworld.Helloworld; 38 | import com.appspot.your_app_id.helloworld.Helloworld.Greetings.Authed; 39 | import com.appspot.your_app_id.helloworld.Helloworld.Greetings.GetGreeting; 40 | import com.appspot.your_app_id.helloworld.Helloworld.Greetings.ListGreeting; 41 | import com.appspot.your_app_id.helloworld.Helloworld.Greetings.Multiply; 42 | import com.appspot.your_app_id.helloworld.model.HelloGreeting; 43 | import com.appspot.your_app_id.helloworld.model.HelloGreetingCollection; 44 | import com.google.common.base.Strings; 45 | 46 | import java.io.IOException; 47 | import java.util.Arrays; 48 | import java.util.List; 49 | import java.util.Set; 50 | 51 | import com.google.devrel.samples.helloendpoints.R.id; 52 | 53 | import static com.google.devrel.samples.helloendpoints.BuildConfig.DEBUG; 54 | 55 | /** 56 | * Sample Android application for the Hello World tutorial for Google Cloud Endpoints. The sample 57 | * code shows many of the better practices described in the links below. 58 | * 59 | * @see https://developers.google.com/appengine/docs/java/endpoints 60 | * @see https://developers.google.com/appengine/docs/java/endpoints/consume_android 61 | * 62 | */ 63 | public class MainActivity extends Activity { 64 | private static final String LOG_TAG = "MainActivity"; 65 | 66 | /** 67 | * Activity result indicating a return from the Google account selection intent. 68 | */ 69 | private static final int ACTIVITY_RESULT_FROM_ACCOUNT_SELECTION = 2222; 70 | 71 | private AuthorizationCheckTask mAuthTask; 72 | private String mEmailAccount = ""; 73 | private GreetingsDataAdapter listAdapter; 74 | 75 | @Override 76 | protected void onCreate(Bundle savedInstanceState) { 77 | super.onCreate(savedInstanceState); 78 | setContentView(R.layout.activity_main); 79 | 80 | // Prevent the keyboard from being visible upon startup. 81 | getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 82 | 83 | ListView listView = (ListView)this.findViewById(R.id.greetings_list_view); 84 | listAdapter = new GreetingsDataAdapter((Application)this.getApplication()); 85 | listView.setAdapter(listAdapter); 86 | } 87 | 88 | @Override 89 | protected void onDestroy() { 90 | super.onDestroy(); 91 | if (mAuthTask!=null) { 92 | mAuthTask.cancel(true); 93 | mAuthTask = null; 94 | } 95 | } 96 | 97 | @Override 98 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 99 | super.onActivityResult(requestCode, resultCode, data); 100 | 101 | if (requestCode == ACTIVITY_RESULT_FROM_ACCOUNT_SELECTION && resultCode == RESULT_OK) { 102 | // This path indicates the account selection activity resulted in the user selecting a 103 | // Google account and clicking OK. 104 | 105 | // Set the selected account. 106 | String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); 107 | TextView emailAccountTextView = (TextView)this.findViewById(id.email_address_tv); 108 | emailAccountTextView.setText(accountName); 109 | 110 | // Fire off the authorization check for this account and OAuth2 scopes. 111 | performAuthCheck(accountName); 112 | } 113 | } 114 | 115 | private boolean isSignedIn() { 116 | if (!Strings.isNullOrEmpty(mEmailAccount)) { 117 | return true; 118 | } else { 119 | return false; 120 | } 121 | } 122 | 123 | /** 124 | * This method is invoked when the "Get Greeting" button is clicked. See activity_main.xml for 125 | * the dynamic reference to this method. 126 | */ 127 | public void onClickGetGreeting(View view) { 128 | View rootView = view.getRootView(); 129 | TextView greetingIdInputTV = (TextView)rootView.findViewById(R.id.greeting_id_edit_text); 130 | if (greetingIdInputTV.getText()==null || 131 | Strings.isNullOrEmpty(greetingIdInputTV.getText().toString())) { 132 | Toast.makeText(this, "Input a Greeting ID", Toast.LENGTH_SHORT).show(); 133 | return; 134 | }; 135 | 136 | String greetingIdString = greetingIdInputTV.getText().toString(); 137 | int greetingId = Integer.parseInt(greetingIdString); 138 | 139 | // Use of an anonymous class is done for sample code simplicity. {@code AsyncTasks} should be 140 | // static-inner or top-level classes to prevent memory leak issues. 141 | // @see http://goo.gl/fN1fuE @26:00 for an great explanation. 142 | AsyncTask getAndDisplayGreeting = 143 | new AsyncTask () { 144 | @Override 145 | protected HelloGreeting doInBackground(Integer... integers) { 146 | // Retrieve service handle using null credential since this is an unauthenticated call. 147 | Helloworld apiServiceHandle = AppConstants.getApiServiceHandle(null); 148 | 149 | try { 150 | GetGreeting getGreetingCommand = apiServiceHandle.greetings().getGreeting(integers[0]); 151 | HelloGreeting greeting = getGreetingCommand.execute(); 152 | return greeting; 153 | } catch (IOException e) { 154 | Log.e(LOG_TAG, "Exception during API call", e); 155 | } 156 | return null; 157 | } 158 | 159 | @Override 160 | protected void onPostExecute(HelloGreeting greeting) { 161 | if (greeting!=null) { 162 | displayGreetings(greeting); 163 | } else { 164 | Log.e(LOG_TAG, "No greetings were returned by the API."); 165 | } 166 | } 167 | }; 168 | 169 | getAndDisplayGreeting.execute(greetingId); 170 | } 171 | 172 | /** 173 | * This method is invoked when the "List Greetings" button is clicked. See activity_main.xml for 174 | * the dynamic reference to this method. 175 | */ 176 | public void onClickListGreetings(View unused) { 177 | 178 | // Use of an anonymous class is done for sample code simplicity. {@code AsyncTasks} should be 179 | // static-inner or top-level classes to prevent memory leak issues. 180 | // @see http://goo.gl/fN1fuE @26:00 for an great explanation. 181 | AsyncTask getAndDisplayGreeting = 182 | new AsyncTask () { 183 | @Override 184 | protected HelloGreetingCollection doInBackground(Void... unused) { 185 | // Retrieve service handle using null credential since this is an unauthenticated call. 186 | Helloworld apiServiceHandle = AppConstants.getApiServiceHandle(null); 187 | 188 | try { 189 | ListGreeting getGreetingCommand = apiServiceHandle.greetings().listGreeting(); 190 | HelloGreetingCollection greeting = getGreetingCommand.execute(); 191 | return greeting; 192 | } catch (IOException e) { 193 | Log.e(LOG_TAG, "Exception during API call", e); 194 | } 195 | return null; 196 | } 197 | 198 | @Override 199 | protected void onPostExecute(HelloGreetingCollection greeting) { 200 | if (greeting!=null && greeting.getItems()!=null) { 201 | displayGreetings(greeting.getItems().toArray(new HelloGreeting[] {})); 202 | } else { 203 | Log.e(LOG_TAG, "No greetings were returned by the API."); 204 | } 205 | } 206 | }; 207 | 208 | getAndDisplayGreeting.execute((Void)null); 209 | } 210 | 211 | /** 212 | * This method is invoked when the "Multiply Greeting" button is clicked. See activity_main.xml 213 | * for the dynamic reference to this method. 214 | */ 215 | public void onClickSendGreetings(View view) { 216 | View rootView = view.getRootView(); 217 | 218 | TextView greetingCountInputTV = (TextView)rootView.findViewById(id.greeting_count_edit_text); 219 | if (greetingCountInputTV.getText()==null || 220 | Strings.isNullOrEmpty(greetingCountInputTV.getText().toString())) { 221 | Toast.makeText(this, "Input a Greeting Count", Toast.LENGTH_SHORT).show(); 222 | return; 223 | }; 224 | 225 | String greetingCountString = greetingCountInputTV.getText().toString(); 226 | final int greetingCount = Integer.parseInt(greetingCountString); 227 | 228 | TextView greetingTextInputTV = (TextView)rootView.findViewById(id.greeting_text_edit_text); 229 | if (greetingTextInputTV.getText()==null || 230 | Strings.isNullOrEmpty(greetingTextInputTV.getText().toString())) { 231 | Toast.makeText(this, "Input a Greeting Message", Toast.LENGTH_SHORT).show(); 232 | return; 233 | }; 234 | 235 | final String greetingMessageString = greetingTextInputTV.getText().toString(); 236 | 237 | // Use of an anonymous class is done for sample code simplicity. {@code AsyncTasks} should be 238 | // static-inner or top-level classes to prevent memory leak issues. 239 | // @see http://goo.gl/fN1fuE @26:00 for an great explanation. 240 | AsyncTask sendGreetings = new AsyncTask () { 241 | @Override 242 | protected HelloGreeting doInBackground(Void... unused) { 243 | // Retrieve service handle using null credential since this is an unauthenticated call. 244 | Helloworld apiServiceHandle = AppConstants.getApiServiceHandle(null); 245 | 246 | try { 247 | HelloGreeting greeting = new HelloGreeting(); 248 | greeting.setMessage(greetingMessageString); 249 | 250 | Multiply multiplyGreetingCommand = apiServiceHandle.greetings().multiply(greetingCount, 251 | greeting); 252 | greeting = multiplyGreetingCommand.execute(); 253 | return greeting; 254 | } catch (IOException e) { 255 | Log.e(LOG_TAG, "Exception during API call", e); 256 | } 257 | return null; 258 | } 259 | 260 | @Override 261 | protected void onPostExecute(HelloGreeting greeting) { 262 | if (greeting!=null) { 263 | displayGreetings(greeting); 264 | } else { 265 | Log.e(LOG_TAG, "No greetings were returned by the API."); 266 | } 267 | } 268 | }; 269 | 270 | sendGreetings.execute((Void)null); 271 | } 272 | 273 | /** 274 | * This method is invoked when the "Get Authenticated Greeting" button is clicked. See 275 | * activity_main.xml for the dynamic reference to this method. 276 | */ 277 | public void onClickGetAuthenticatedGreeting(View unused) { 278 | if (!isSignedIn()) { 279 | Toast.makeText(this, "You must sign in for this action.", Toast.LENGTH_LONG).show(); 280 | return; 281 | } 282 | 283 | // Use of an anonymous class is done for sample code simplicity. {@code AsyncTasks} should be 284 | // static-inner or top-level classes to prevent memory leak issues. 285 | // @see http://goo.gl/fN1fuE @26:00 for an great explanation. 286 | AsyncTask getAuthedGreetingAndDisplay = 287 | new AsyncTask () { 288 | @Override 289 | protected HelloGreeting doInBackground(Void... unused) { 290 | if (!isSignedIn()) { 291 | return null; 292 | }; 293 | 294 | if (!AppConstants.checkGooglePlayServicesAvailable(MainActivity.this)) { 295 | return null; 296 | } 297 | 298 | // Create a Google credential since this is an authenticated request to the API. 299 | GoogleAccountCredential credential = GoogleAccountCredential.usingAudience( 300 | MainActivity.this, AppConstants.AUDIENCE); 301 | credential.setSelectedAccountName(mEmailAccount); 302 | 303 | // Retrieve service handle using credential since this is an authenticated call. 304 | Helloworld apiServiceHandle = AppConstants.getApiServiceHandle(credential); 305 | 306 | try { 307 | Authed getAuthedGreetingCommand = apiServiceHandle.greetings().authed(); 308 | HelloGreeting greeting = getAuthedGreetingCommand.execute(); 309 | return greeting; 310 | } catch (IOException e) { 311 | Log.e(LOG_TAG, "Exception during API call", e); 312 | } 313 | return null; 314 | } 315 | 316 | @Override 317 | protected void onPostExecute(HelloGreeting greeting) { 318 | if (greeting!=null) { 319 | displayGreetings(greeting); 320 | } else { 321 | Log.e(LOG_TAG, "No greetings were returned by the API."); 322 | } 323 | } 324 | }; 325 | 326 | getAuthedGreetingAndDisplay.execute((Void)null); 327 | } 328 | 329 | private void displayGreetings(HelloGreeting... greetings) { 330 | String msg; 331 | if (greetings==null || greetings.length < 1) { 332 | msg = "Greeting was not present"; 333 | Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); 334 | } else { 335 | if (DEBUG) { 336 | Log.d(LOG_TAG, "Displaying " + greetings.length + " greetings."); 337 | } 338 | 339 | List greetingsList = Arrays.asList(greetings); 340 | listAdapter.replaceData(greetings); 341 | } 342 | } 343 | 344 | /** 345 | * This method is invoked when the "Sign In" button is clicked. See activity_main.xml for the 346 | * dynamic reference to this method. 347 | */ 348 | public void onClickSignIn(View view) { 349 | TextView emailAddressTV = (TextView) view.getRootView().findViewById(id.email_address_tv); 350 | // Check to see how many Google accounts are registered with the device. 351 | int googleAccounts = AppConstants.countGoogleAccounts(this); 352 | if (googleAccounts == 0) { 353 | // No accounts registered, nothing to do. 354 | Toast.makeText(this, R.string.toast_no_google_accounts_registered, 355 | Toast.LENGTH_LONG).show(); 356 | } else if (googleAccounts == 1) { 357 | // If only one account then select it. 358 | Toast.makeText(this, R.string.toast_only_one_google_account_registered, 359 | Toast.LENGTH_LONG).show(); 360 | AccountManager am = AccountManager.get(this); 361 | Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE); 362 | if (accounts != null && accounts.length > 0) { 363 | // Select account and perform authorization check. 364 | emailAddressTV.setText(accounts[0].name); 365 | mEmailAccount = accounts[0].name; 366 | performAuthCheck(accounts[0].name); 367 | } 368 | } else { 369 | // More than one Google Account is present, a chooser is necessary. 370 | 371 | // Reset selected account. 372 | emailAddressTV.setText(""); 373 | 374 | // Invoke an {@code Intent} to allow the user to select a Google account. 375 | Intent accountSelector = AccountPicker.newChooseAccountIntent(null, null, 376 | new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, false, 377 | "Select the account to access Google Compute Engine API.", null, null, null); 378 | startActivityForResult(accountSelector, 379 | ACTIVITY_RESULT_FROM_ACCOUNT_SELECTION); 380 | } 381 | 382 | } 383 | 384 | /** 385 | * Schedule the authorization check in an {@code Tasks}. 386 | */ 387 | public void performAuthCheck(String emailAccount) { 388 | // Cancel previously running tasks. 389 | if (mAuthTask != null) { 390 | try { 391 | mAuthTask.cancel(true); 392 | } catch (Exception e) { 393 | e.printStackTrace(); 394 | } 395 | return; 396 | } 397 | 398 | // Start task to check authorization. 399 | mAuthTask = new AuthorizationCheckTask(); 400 | mAuthTask.execute(emailAccount); 401 | } 402 | 403 | /** 404 | * Verifies OAuth2 token access for the application and Google account combination with 405 | * the {@code AccountManager} and the Play Services installed application. If the appropriate 406 | * OAuth2 access hasn't been granted (to this application) then the task may fire an 407 | * {@code Intent} to request that the user approve such access. If the appropriate access does 408 | * exist then the button that will let the user proceed to the next activity is enabled. 409 | */ 410 | class AuthorizationCheckTask extends AsyncTask { 411 | @Override 412 | protected Boolean doInBackground(String... emailAccounts) { 413 | Log.i(LOG_TAG, "Background task started."); 414 | 415 | if (!AppConstants.checkGooglePlayServicesAvailable(MainActivity.this)) { 416 | return false; 417 | } 418 | 419 | String emailAccount = emailAccounts[0]; 420 | // Ensure only one task is running at a time. 421 | mAuthTask = this; 422 | 423 | // Ensure an email was selected. 424 | if (Strings.isNullOrEmpty(emailAccount)) { 425 | publishProgress(R.string.toast_no_google_account_selected); 426 | // Failure. 427 | return false; 428 | } 429 | 430 | if (DEBUG) { 431 | Log.d(LOG_TAG, "Attempting to get AuthToken for account: " + mEmailAccount); 432 | } 433 | 434 | try { 435 | // If the application has the appropriate access then a token will be retrieved, otherwise 436 | // an error will be thrown. 437 | GoogleAccountCredential credential = GoogleAccountCredential.usingAudience( 438 | MainActivity.this, AppConstants.AUDIENCE); 439 | credential.setSelectedAccountName(emailAccount); 440 | 441 | String accessToken = credential.getToken(); 442 | 443 | if (DEBUG) { 444 | Log.d(LOG_TAG, "AccessToken retrieved"); 445 | } 446 | 447 | // Success. 448 | return true; 449 | } catch (GoogleAuthException unrecoverableException) { 450 | Log.e(LOG_TAG, "Exception checking OAuth2 authentication.", unrecoverableException); 451 | publishProgress(R.string.toast_exception_checking_authorization); 452 | // Failure. 453 | return false; 454 | } catch (IOException ioException) { 455 | Log.e(LOG_TAG, "Exception checking OAuth2 authentication.", ioException); 456 | publishProgress(R.string.toast_exception_checking_authorization); 457 | // Failure or cancel request. 458 | return false; 459 | } 460 | } 461 | 462 | @Override 463 | protected void onProgressUpdate(Integer... stringIds) { 464 | // Toast only the most recent. 465 | Integer stringId = stringIds[0]; 466 | Toast.makeText(MainActivity.this, stringId, Toast.LENGTH_SHORT).show(); 467 | } 468 | 469 | @Override 470 | protected void onPreExecute() { 471 | mAuthTask = this; 472 | } 473 | 474 | @Override 475 | protected void onPostExecute(Boolean success) { 476 | TextView emailAddressTV = (TextView) MainActivity.this.findViewById(id.email_address_tv); 477 | if (success) { 478 | // Authorization check successful, set internal variable. 479 | mEmailAccount = emailAddressTV.getText().toString(); 480 | } else { 481 | // Authorization check unsuccessful, reset TextView to empty. 482 | emailAddressTV.setText(""); 483 | } 484 | mAuthTask = null; 485 | } 486 | 487 | @Override 488 | protected void onCancelled() { 489 | mAuthTask = null; 490 | } 491 | } 492 | 493 | /** 494 | * Simple use of an ArrayAdapter but we're using a static class to ensure no references to the 495 | * Activity exists. 496 | */ 497 | static class GreetingsDataAdapter extends ArrayAdapter { 498 | GreetingsDataAdapter(Application application) { 499 | super(application.getApplicationContext(), android.R.layout.simple_list_item_1, 500 | application.greetings); 501 | } 502 | 503 | void replaceData(HelloGreeting[] greetings) { 504 | clear(); 505 | for (HelloGreeting greeting : greetings) { 506 | add(greeting); 507 | } 508 | } 509 | 510 | @Override 511 | public View getView(int position, View convertView, ViewGroup parent) { 512 | TextView view = (TextView)super.getView(position, convertView, parent); 513 | 514 | HelloGreeting greeting = (HelloGreeting)this.getItem(position); 515 | 516 | StringBuilder sb = new StringBuilder(); 517 | 518 | Set fields = greeting.keySet(); 519 | boolean firstLoop = true; 520 | for (String fieldName : fields) { 521 | // Append next line chars to 2.. loop runs. 522 | if (firstLoop) { 523 | firstLoop = false; 524 | } else { 525 | sb.append("\n"); 526 | } 527 | 528 | sb.append(fieldName) 529 | .append(": ") 530 | .append(greeting.get(fieldName)); 531 | } 532 | 533 | view.setText(sb.toString()); 534 | return view; 535 | } 536 | } 537 | } 538 | -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/appengine-endpoints-helloendpoints-android/e1c51eb7a7403272f3ef24cbfff887729c4edb22/HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/appengine-endpoints-helloendpoints-android/e1c51eb7a7403272f3ef24cbfff887729c4edb22/HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/appengine-endpoints-helloendpoints-android/e1c51eb7a7403272f3ef24cbfff887729c4edb22/HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlearchive/appengine-endpoints-helloendpoints-android/e1c51eb7a7403272f3ef24cbfff887729c4edb22/HelloEndpointsProject/HelloEndpoints/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /HelloEndpointsProject/HelloEndpoints/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 14 | 15 | 18 | 24 | 25 |