]> average.org Git - WhereAmI.git/commitdiff
move everything that can be mvoed to initialization
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Tue, 7 Feb 2012 15:48:58 +0000 (19:48 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Tue, 7 Feb 2012 15:48:58 +0000 (19:48 +0400)
src/org/average/whereami/LastLocation.java
src/org/average/whereami/Oracle.java
src/org/average/whereami/PhoneLog.java

index 47fd4b388029a7aba3c026a0ccb4600f174b09fd..ba6722854bb7c1635ccebc956ee58ec00147a36d 100644 (file)
@@ -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 =
index 1de3879b7db2b24b53d768f13a5bf74b09441312..405e2ddd97157eb38fc7fd7b4befcacf4b4ea1a1 100644 (file)
@@ -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,
index 6e13f2f4422248e5899c41f56259652d4fc2df57..b8f29d6eca99043325c657216794efbf8ea01335 100644 (file)
@@ -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 == "") {