From 7bb8241a9ad8edc2045e12d24679a0a72626f728 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Tue, 7 Feb 2012 19:48:58 +0400 Subject: [PATCH] move everything that can be mvoed to initialization --- src/org/average/whereami/LastLocation.java | 8 +++++--- src/org/average/whereami/Oracle.java | 18 ++++++++---------- src/org/average/whereami/PhoneLog.java | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/org/average/whereami/LastLocation.java b/src/org/average/whereami/LastLocation.java index 47fd4b3..ba67228 100644 --- a/src/org/average/whereami/LastLocation.java +++ b/src/org/average/whereami/LastLocation.java @@ -28,6 +28,7 @@ public final class LastLocation extends Oracle { private String myname; private String registered; private SayWhen sayWhen; + private Latitude latitude; public LastLocation(final Resources res, final PersistentStore store) { super(res, store); @@ -38,13 +39,14 @@ public final class LastLocation extends Oracle { myname = res.getString(R.string.myname); registered = res.getString(R.string.registered); sayWhen = new SayWhen(res); + latitude = Latitude.builder(httpTransport, jsonFactory) + .setHttpRequestInitializer( + newMyAccessProtectedResource()) + .setApplicationName("WhereAmI/1.0").build(); } @Override public final String getResult() { - Latitude latitude = Latitude.builder(httpTransport, jsonFactory) - .setHttpRequestInitializer(accessProtectedResource()) - .setApplicationName("WhereAmI/1.0").build(); try { Log.v(TAG, "entering getResult"); Latitude.CurrentLocation.Get request = diff --git a/src/org/average/whereami/Oracle.java b/src/org/average/whereami/Oracle.java index 1de3879..405e2dd 100644 --- a/src/org/average/whereami/Oracle.java +++ b/src/org/average/whereami/Oracle.java @@ -20,23 +20,20 @@ abstract public class Oracle { final String TAG = getClass().getName(); - public HttpTransport httpTransport; - public JsonFactory jsonFactory; - public PersistentStore store; - public String authErrorMessage; + static public PersistentStore store; + static public HttpTransport httpTransport = + AndroidHttp.newCompatibleTransport(); + static public JsonFactory jsonFactory = new JacksonFactory(); + static public String authErrorMessage; public Oracle(final Resources res, final PersistentStore store) { authErrorMessage = res.getString(R.string.autherror); this.store = 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, @@ -62,13 +59,14 @@ abstract public class Oracle { } } - public MyAccessProtectedResource accessProtectedResource() { + public MyAccessProtectedResource + newMyAccessProtectedResource() { AccessTokenResponse token = store.readTokens(); Log.v(TAG, "tokens - access: \"" + token.accessToken + "\", refresh: \"" + token.refreshToken + "\", client_id: \"" + ClientCredentials.CLIENT_ID + "\", client_secret: \"" + - ClientCredentials.CLIENT_SECRET + + ClientCredentials.CLIENT_SECRET + "\""); return new MyAccessProtectedResource( token.accessToken, httpTransport, jsonFactory, diff --git a/src/org/average/whereami/PhoneLog.java b/src/org/average/whereami/PhoneLog.java index 6e13f2f..b8f29d6 100644 --- a/src/org/average/whereami/PhoneLog.java +++ b/src/org/average/whereami/PhoneLog.java @@ -25,8 +25,6 @@ public final class PhoneLog extends Oracle { final String TAG = getClass().getName(); - private Calendar calendar; - private PersistentStore store; private String calendar_name; private String peer_name; @@ -42,6 +40,7 @@ public final class PhoneLog extends Oracle { private String minutes2to4; private String minutes5up; private SayWhen sayWhen; + private Calendar calendar; public PhoneLog(final Resources res, final PersistentStore store) { super(res, store); @@ -60,13 +59,14 @@ public final class PhoneLog extends Oracle { calendar_name = store.get("calendar_name"); peer_name = store.get("peer_name"); calendar_id = store.get("calendar_id"); + calendar = Calendar.builder(httpTransport, jsonFactory) + .setHttpRequestInitializer( + newMyAccessProtectedResource()) + .setApplicationName("WhereAmI/1.0").build(); } @Override public final String getResult() { - calendar = Calendar.builder(httpTransport, jsonFactory) - .setHttpRequestInitializer(accessProtectedResource()) - .setApplicationName("WhereAmI/1.0").build(); try { Log.v(TAG, "entering getResult"); if (calendar_id == null || calendar_id == "") { -- 2.43.0