From: Eugene Crosser Date: Mon, 6 Feb 2012 17:00:37 +0000 (+0400) Subject: make accessProtectedResource a method X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=e7ecf60a526f2f410d586895429e208370517bc9;p=WhereAmI.git make accessProtectedResource a method --- diff --git a/src/org/average/whereami/LastLocation.java b/src/org/average/whereami/LastLocation.java index 76e8ef2..47fd4b3 100644 --- a/src/org/average/whereami/LastLocation.java +++ b/src/org/average/whereami/LastLocation.java @@ -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 = diff --git a/src/org/average/whereami/Oracle.java b/src/org/average/whereami/Oracle.java index ab4431c..7ba16a5 100644 --- a/src/org/average/whereami/Oracle.java +++ b/src/org/average/whereami/Oracle.java @@ -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, diff --git a/src/org/average/whereami/PhoneLog.java b/src/org/average/whereami/PhoneLog.java index 74bb9eb..6e13f2f 100644 --- a/src/org/average/whereami/PhoneLog.java +++ b/src/org/average/whereami/PhoneLog.java @@ -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 == "") { diff --git a/src/org/average/whereami/WhereAmI.java b/src/org/average/whereami/WhereAmI.java index 8a7da59..c08453a 100644 --- a/src/org/average/whereami/WhereAmI.java +++ b/src/org/average/whereami/WhereAmI.java @@ -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);