From 015cb569bd35a081666ac4849c661cd525d9b1d5 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Mon, 6 Feb 2012 22:31:52 +0400 Subject: [PATCH] subclass MyAccessProtectedResource --- src/org/average/whereami/Oracle.java | 51 +++++++++++++++++++--------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/org/average/whereami/Oracle.java b/src/org/average/whereami/Oracle.java index 7ba16a5..1de3879 100644 --- a/src/org/average/whereami/Oracle.java +++ b/src/org/average/whereami/Oracle.java @@ -2,6 +2,8 @@ package org.average.whereami; import org.average.whereami.PersistentStore; +import java.io.IOException; + import com.google.api.client.extensions.android2.AndroidHttp; import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse; import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; @@ -21,8 +23,6 @@ abstract public class Oracle { public HttpTransport httpTransport; public JsonFactory jsonFactory; public PersistentStore store; - - public String authErrorMessage; public Oracle(final Resources res, final PersistentStore store) { @@ -31,9 +31,38 @@ abstract public class Oracle { httpTransport = AndroidHttp.newCompatibleTransport(); jsonFactory = new JacksonFactory(); -} + } + + private class MyAccessProtectedResource + extends GoogleAccessProtectedResource { + + // Why on earth contructors are not inherited?!?! + public MyAccessProtectedResource( + String accessToken, + HttpTransport transport, + JsonFactory jsonFactory, + String clientId, + String clientSecret, + String refreshToken) { + super(accessToken, transport, jsonFactory, + clientId, clientSecret, refreshToken); + } + + @Override + public void onAccessToken(String accessToken) { + Log.v(TAG, "Update access token to \"" + + accessToken + "\""); + store.updateAccessToken( accessToken); + } + + @Override + protected boolean executeRefreshToken() throws IOException { + Log.v(TAG, "executeRefreshToken was called"); + return super.executeRefreshToken(); + } + } - public GoogleAccessProtectedResource accessProtectedResource() { + public MyAccessProtectedResource accessProtectedResource() { AccessTokenResponse token = store.readTokens(); Log.v(TAG, "tokens - access: \"" + token.accessToken + "\", refresh: \"" + token.refreshToken + @@ -41,21 +70,11 @@ abstract public class Oracle { "\", client_secret: \"" + ClientCredentials.CLIENT_SECRET + "\""); - return new GoogleAccessProtectedResource( + return new MyAccessProtectedResource( token.accessToken, httpTransport, jsonFactory, ClientCredentials.CLIENT_ID, ClientCredentials.CLIENT_SECRET, - token.refreshToken) - { - @Override - public void onAccessToken( - String accessToken) { - Log.v(TAG, "Update access token to \"" - + accessToken + "\""); - store.updateAccessToken( - accessToken); - } - }; + token.refreshToken); } abstract public String getResult(); -- 2.43.0