From 97933c816c37fb8860eb4e980cde3967ea6bb3ad Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Thu, 2 Feb 2012 16:51:01 +0400 Subject: [PATCH] prototype for Calendar --- src/org/average/whereami/PhoneLog.java | 72 ++++++++++++++++++++------ 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/src/org/average/whereami/PhoneLog.java b/src/org/average/whereami/PhoneLog.java index 020690b..8522e84 100644 --- a/src/org/average/whereami/PhoneLog.java +++ b/src/org/average/whereami/PhoneLog.java @@ -2,36 +2,78 @@ package org.average.whereami; import org.average.whereami.CredentialStore; +//import java.lang.Long; + import com.google.api.client.extensions.android2.AndroidHttp; -import com.google.api.client.googleapis.GoogleHeaders; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpResponse; +import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse; +import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource; import com.google.api.client.http.HttpResponseException; import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson.JacksonFactory; import com.google.api.client.util.DateTime; +import com.google.api.services.calendar.Calendar; +import com.google.api.services.calendar.CalendarRequest; +import com.google.api.services.calendar.model.CalendarList; +import com.google.api.services.calendar.model.CalendarListEntry; +import com.google.api.services.calendar.model.Event; +import com.google.api.services.calendar.model.Events; +import com.google.common.collect.Lists; -//import com.google.api.services.calendar.CalendarClient; -//import com.google.api.services.calendar.CalendarRequestInitializer; -//import com.google.api.services.calendar.CalendarUrl; -//import com.google.api.services.calendar.model.CalendarEntry; -//import com.google.api.services.calendar.model.CalendarFeed; -//import com.google.common.collect.Lists; - -import android.util.Log; -import android.os.SystemClock; import android.content.Context; import android.content.SharedPreferences; +import android.util.Log; public final class PhoneLog extends Oracle { final String TAG = getClass().getName(); - public PhoneLog(CredentialStore store) { + private Calendar calendar; + + public PhoneLog(final CredentialStore store) { + HttpTransport transport = AndroidHttp.newCompatibleTransport(); + JsonFactory jsonFactory = new JacksonFactory(); + AccessTokenResponse token = store.read(); + Log.v(TAG, "tokens - access: \"" + token.accessToken + + "\", refresh: \"" + token.refreshToken + + "\", client_id: \"" + ClientCredentials.CLIENT_ID + + "\", client_secret: \"" + + ClientCredentials.CLIENT_SECRET + + "\""); + GoogleAccessProtectedResource accessProtectedResource = + new GoogleAccessProtectedResource( + token.accessToken, + transport, 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); + } + } + ; + Calendar.Builder cbldr = Calendar.builder(transport, + jsonFactory); + cbldr.setHttpRequestInitializer(accessProtectedResource); + cbldr.setApplicationName("WhereAmI/1.0"); + calendar = cbldr.build(); } @Override public final String getResult() { - SystemClock.sleep(5000); - return "Response from PhoneLog.getResult"; + try { + Log.v(TAG, "entering getResult"); + return TAG + " complete"; + } catch (Exception ex) { + Log.v(TAG, "exception in getResult: " + ex); + ex.printStackTrace(); + return ex.getMessage(); + } } } -- 2.43.0