]> average.org Git - WhereAmI.git/commitdiff
prototype for Calendar
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 2 Feb 2012 12:51:01 +0000 (16:51 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Thu, 2 Feb 2012 12:51:01 +0000 (16:51 +0400)
src/org/average/whereami/PhoneLog.java

index 020690b89367e0fa1b2c986d82ce4cde70d84b15..8522e841b05df02c524bf0975c8dcecb16b83969 100644 (file)
@@ -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();
+                }
        }
 }