]> average.org Git - WhereAmI.git/commitdiff
make accessProtectedResource a method
authorEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 6 Feb 2012 17:00:37 +0000 (21:00 +0400)
committerEugene Crosser <Eugene.Crosser@ru.ibm.com>
Mon, 6 Feb 2012 17:00:37 +0000 (21:00 +0400)
src/org/average/whereami/LastLocation.java
src/org/average/whereami/Oracle.java
src/org/average/whereami/PhoneLog.java
src/org/average/whereami/WhereAmI.java

index 76e8ef28c73e02c82288f2a71eaefd0398592e69..47fd4b388029a7aba3c026a0ccb4600f174b09fd 100644 (file)
@@ -21,8 +21,6 @@ public final class LastLocation extends Oracle {
 
        final String TAG = getClass().getName();
 
-       private Latitude latitude;
-
        private String[] loc_names;
        private String[] loc_lats;
        private String[] loc_lons;
@@ -40,14 +38,13 @@ 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(accessProtectedResource)
-                       .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 ab4431c8957f36ed53073576475332b43e7422c6..7ba16a5ec2dfde72e118e4b339783a6979895760 100644 (file)
@@ -20,16 +20,20 @@ abstract public class Oracle {
 
        public HttpTransport httpTransport;
        public JsonFactory jsonFactory;
+       public PersistentStore store;
 
-       public GoogleAccessProtectedResource accessProtectedResource;
 
        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();
+}
+
+       public GoogleAccessProtectedResource accessProtectedResource() {
                AccessTokenResponse token = store.readTokens();
                Log.v(TAG, "tokens - access: \"" + token.accessToken +
                        "\", refresh: \"" + token.refreshToken +
@@ -37,7 +41,7 @@ abstract public class Oracle {
                        "\", client_secret: \"" +
                                        ClientCredentials.CLIENT_SECRET +
                        "\"");
-               accessProtectedResource = new GoogleAccessProtectedResource(
+               return new GoogleAccessProtectedResource(
                        token.accessToken, httpTransport, jsonFactory,
                        ClientCredentials.CLIENT_ID,
                        ClientCredentials.CLIENT_SECRET,
index 74bb9ebebe264e10c2bc7cec8fc277f3db67bd9b..6e13f2f4422248e5899c41f56259652d4fc2df57 100644 (file)
@@ -60,14 +60,13 @@ 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(accessProtectedResource)
-                       .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 == "") {
index 8a7da5929db3c068038ef629235edb7577882023..c08453a28057b4b665fc28df5863277451849347 100644 (file)
@@ -7,6 +7,7 @@ import org.average.whereami.LastLocation;
 
 import android.app.Activity;
 import android.net.wifi.WifiManager;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.AsyncTask;
 import android.os.Handler;
@@ -199,6 +200,14 @@ public class WhereAmI extends Activity
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) {
+            Log.v(TAG, "Disabling keepalive for build version " +
+                       Build.VERSION.SDK_INT);
+            System.setProperty("http.keepAlive", "false");
+        } else {
+            Log.v(TAG, "Post-Froyo version " +
+                        Build.VERSION.SDK_INT);
+       }
         prefs = PreferenceManager.getDefaultSharedPreferences(this);
         store = new PersistentStore(prefs);
         wifiman = (WifiManager)getSystemService(Context.WIFI_SERVICE);