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;
public HttpTransport httpTransport;
public JsonFactory jsonFactory;
public PersistentStore store;
-
-
public String authErrorMessage;
public Oracle(final Resources res, final PersistentStore store) {
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 +
"\", 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();