diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2011-09-23 21:52:14 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2011-09-26 08:55:08 +0200 |
| commit | dbd8cc56d1826103a05d1cefbfbeefb43f6bfd82 (patch) | |
| tree | 10940791e5958f1a4222cb7eb67d715cff2158bc | |
| parent | f29a5ef2fbe59b607692561bfc7ddcc1271c3132 (diff) | |
| download | cgeo-dbd8cc56d1826103a05d1cefbfbeefb43f6bfd82.zip cgeo-dbd8cc56d1826103a05d1cefbfbeefb43f6bfd82.tar.gz cgeo-dbd8cc56d1826103a05d1cefbfbeefb43f6bfd82.tar.bz2 | |
Reorganize HTTP traffic
| -rw-r--r-- | main/src/cgeo/geocaching/CookieJar.java | 100 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/LogTemplateProvider.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Parameters.java | 16 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/activity/AbstractActivity.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/activity/AbstractListActivity.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 446 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgGeo.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgResponse.java | 26 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 18 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoinit.java | 9 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeotouch.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeovisit.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 10 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/test/cgeoApplicationTest.java | 2 |
14 files changed, 216 insertions, 425 deletions
diff --git a/main/src/cgeo/geocaching/CookieJar.java b/main/src/cgeo/geocaching/CookieJar.java deleted file mode 100644 index b6ccf8f..0000000 --- a/main/src/cgeo/geocaching/CookieJar.java +++ /dev/null @@ -1,100 +0,0 @@ -package cgeo.geocaching; - -import org.apache.commons.lang3.StringUtils; - -import android.content.SharedPreferences; -import android.util.Log; - -import java.net.URLConnection; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Handle cookies obtained from web sites. - * - * No other place should touch cookies directly, as we want to make sure - * that the stored information is up-to-date. - * - */ -final public class CookieJar { - - static private boolean cookiesLoaded = false; - final static private HashMap<String, String> cookies = new HashMap<String, String>(); - - static private String cache = null; // Cache information, or null if it has been invalidated - - static private void loadCookiesIfNeeded(final SharedPreferences prefs) { - if (!cookiesLoaded) { - cookies.clear(); - for (final Map.Entry<String, ?> entry : prefs.getAll().entrySet()) { - if (entry.getKey().startsWith("cookie_")) { - cookies.put(entry.getKey().substring(7), (String) entry.getValue()); - } - } - cookiesLoaded = true; - } - } - - static public synchronized void setCookie(final SharedPreferences prefs, final String name, final String value) { - loadCookiesIfNeeded(prefs); - if (!cookies.containsKey(name) || !cookies.get(name).equals(value)) { - final SharedPreferences.Editor editor = prefs.edit(); - cookies.put(name, value); - editor.putString(name, value); - cache = null; - editor.commit(); - } - } - - static public synchronized void setCookie(final SharedPreferences prefs, final String headerField) { - final int semiIndex = headerField.indexOf(';'); - final String cookie = semiIndex == -1 ? headerField : headerField.substring(0, semiIndex); - final int equalIndex = headerField.indexOf('='); - if (equalIndex > 0) { - setCookie(prefs, cookie.substring(0, equalIndex), cookie.substring(equalIndex + 1)); - } else { - Log.w(cgSettings.tag, "CookieJar.setCookie: ignoring header " + headerField); - } - } - - static public synchronized void setCookies(final SharedPreferences prefs, final URLConnection uc) { - final Map<String, List<String>> headers = uc.getHeaderFields(); - if (headers == null) { - // If a request failed, there might not be headers. - return; - } - for (final Map.Entry<String, List<String>> entry : headers.entrySet()) { - if ("set-cookie".equalsIgnoreCase(entry.getKey())) { - for (final String field : entry.getValue()) { - setCookie(prefs, field); - } - } - } - } - - static public synchronized String getCookiesAsString(final SharedPreferences prefs) { - if (cache == null) { - loadCookiesIfNeeded(prefs); - final ArrayList<String> built = new ArrayList<String>(); - for (final Map.Entry<String, String> entry : cookies.entrySet()) { - built.add(entry.getKey() + "=" + entry.getValue()); - } - cache = StringUtils.join(built, ';'); - } - return cache; - } - - static public synchronized void deleteCookies(final SharedPreferences prefs) { - loadCookiesIfNeeded(prefs); - final SharedPreferences.Editor editor = prefs.edit(); - for (final String key : cookies.keySet()) { - editor.remove("cookie_" + key); - } - editor.commit(); - cookies.clear(); - cache = ""; - } - -} diff --git a/main/src/cgeo/geocaching/LogTemplateProvider.java b/main/src/cgeo/geocaching/LogTemplateProvider.java index bfcfc63..8d60bc6 100644 --- a/main/src/cgeo/geocaching/LogTemplateProvider.java +++ b/main/src/cgeo/geocaching/LogTemplateProvider.java @@ -91,7 +91,7 @@ public class LogTemplateProvider { } String findCount = ""; final Map<String, String> params = new HashMap<String, String>(); - final String page = base.request(URI_GC_EMAIL, "GET", params, false, false, false).getData(); + final String page = cgBase.getResponseData(base.request(URI_GC_EMAIL, "GET", params, false, false, false)); int current = parseFindCount(page); if (current >= 0) { diff --git a/main/src/cgeo/geocaching/Parameters.java b/main/src/cgeo/geocaching/Parameters.java new file mode 100644 index 0000000..3339a5e --- /dev/null +++ b/main/src/cgeo/geocaching/Parameters.java @@ -0,0 +1,16 @@ +package cgeo.geocaching; + +import org.apache.http.NameValuePair; +import org.apache.http.message.BasicNameValuePair; + +import java.util.ArrayList; + +public class Parameters extends ArrayList<NameValuePair> { + + private static final long serialVersionUID = 1L; + + public void put(final String name, final String value) { + add(new BasicNameValuePair(name, value)); + } + +} diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java index 358aba3..be3a8f9 100644 --- a/main/src/cgeo/geocaching/activity/AbstractActivity.java +++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java @@ -72,7 +72,7 @@ public abstract class AbstractActivity extends Activity implements IAbstractActi app = (cgeoapplication) this.getApplication(); prefs = getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE); settings = new cgSettings(this, prefs); - base = new cgBase(app, settings, prefs); + base = new cgBase(app, settings); } final public cgSettings getSettings() { diff --git a/main/src/cgeo/geocaching/activity/AbstractListActivity.java b/main/src/cgeo/geocaching/activity/AbstractListActivity.java index 0afa69c..25c188b 100644 --- a/main/src/cgeo/geocaching/activity/AbstractListActivity.java +++ b/main/src/cgeo/geocaching/activity/AbstractListActivity.java @@ -69,7 +69,7 @@ public abstract class AbstractListActivity extends ListActivity implements app = (cgeoapplication) this.getApplication(); prefs = getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE); settings = new cgSettings(this, prefs); - base = new cgBase(app, settings, prefs); + base = new cgBase(app, settings); } final public void setTitle(final String title) { diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 747b3f6..499f5ef 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -13,9 +13,17 @@ import cgeo.geocaching.utils.CollectionUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.cookie.Cookie; +import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.protocol.HTTP; +import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -23,7 +31,6 @@ import org.json.JSONObject; import android.app.Activity; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Resources; @@ -44,6 +51,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.NetworkInterface; @@ -133,8 +141,8 @@ public class cgBase { private final static Pattern PATTERN_TRACKABLE_Distance = Pattern.compile("<h4[^>]*\\W*Tracking History \\(([0-9.,]+(km|mi))[^\\)]*\\)", Pattern.CASE_INSENSITIVE); private final static Pattern PATTERN_TRACKABLE_Log = Pattern.compile("<tr class=\"Data.+?src=\"/images/icons/([^.]+)\\.gif[^>]+> ([^<]+)</td>.+?guid.+?>([^<]+)</a>.+?(?:guid=([^\"]+)\">([^<]+)</a>.+?)?<td colspan=\"4\">(.+?)(?:<ul.+?ul>)?\\s*</td>\\s*</tr>", Pattern.CASE_INSENSITIVE); - private static final Uri URI_GC_LOGIN_DEFAULT = buildURI(true, "www.geocaching.com", "/login/default.aspx"); - private static final Uri URI_GC_DEFAULT = buildURI(false, "www.geocaching.com", "/default.aspx"); + private static final String URI_GC_LOGIN_DEFAULT = "https://www.geocaching.com/login/default.aspx"; + private static final String URI_GC_DEFAULT = "http://www.geocaching.com/default.aspx"; private static final Uri URI_GOOGLE_RECAPTCHA = buildURI(false, "www.google.com", "/recaptcha/api/challenge"); private static final Uri URI_GC_MAP_DEFAULT = buildURI(false, "www.geocaching.com", "/map/default.aspx"); private static final Uri URI_GC_SEEK_NEAREST = buildURI(false, "www.geocaching.com", "/seek/nearest.aspx"); @@ -203,7 +211,6 @@ public class cgBase { public static final float erad = 6371.0f; private cgeoapplication app = null; private cgSettings settings = null; - private SharedPreferences prefs = null; public String version = null; private String idBrowser = "Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.86 Safari/533.4"; Context context = null; @@ -232,7 +239,7 @@ public class cgBase { public static final int LOG_WEBCAM_PHOTO_TAKEN = 11; public static final int LOG_ANNOUNCEMENT = 74; - public cgBase(cgeoapplication appIn, cgSettings settingsIn, SharedPreferences prefsIn) { + public cgBase(cgeoapplication appIn, cgSettings settingsIn) { context = appIn.getBaseContext(); res = appIn.getBaseContext().getResources(); @@ -369,7 +376,6 @@ public class cgBase { // init app = appIn; settings = settingsIn; - prefs = prefsIn; try { PackageManager manager = app.getPackageManager(); @@ -438,7 +444,7 @@ public class cgBase { /** * put viewstates into request parameters */ - private static void setViewstates(String[] viewstates, Map<String, String> params) { + private static void setViewstates(final String[] viewstates, final Parameters params) { if (ArrayUtils.isEmpty(viewstates)) return; params.put("__VIEWSTATE", viewstates[0]); @@ -453,7 +459,7 @@ public class cgBase { * transfers the viewstates variables from a page (response) to parameters * (next request) */ - public static void transferViewstates(String page, Map<String, String> params) { + public static void transferViewstates(final String page, final Parameters params) { setViewstates(getViewstates(page), params); } @@ -483,7 +489,7 @@ public class cgBase { } public int login() { - cgResponse loginResponse = null; + HttpResponse loginResponse = null; String loginData = null; String[] viewstates = null; @@ -494,8 +500,8 @@ public class cgBase { return -3; // no login information stored } - loginResponse = request(URI_GC_LOGIN_DEFAULT, "GET", new HashMap<String, String>(), false, false, false); - loginData = loginResponse.getData(); + loginResponse = request(Uri.parse(URI_GC_LOGIN_DEFAULT), "GET", new HashMap<String, String>(), false, false, false); + loginData = getResponseData(loginResponse); if (StringUtils.isNotBlank(loginData)) { if (checkLogin(loginData)) { Log.i(cgSettings.tag, "Already logged in Geocaching.com as " + loginStart.get("username")); @@ -517,14 +523,15 @@ public class cgBase { } final Map<String, String> login = settings.getLogin(); - final Map<String, String> params = new HashMap<String, String>(); if (login == null || StringUtils.isEmpty(login.get("username")) || StringUtils.isEmpty(login.get("password"))) { Log.e(cgSettings.tag, "cgeoBase.login: No login information stored"); return -3; } - CookieJar.deleteCookies(prefs); + clearCookies(); + + final Parameters params = new Parameters(); params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); @@ -534,8 +541,8 @@ public class cgBase { params.put("ctl00$SiteContent$cbRememberMe", "on"); params.put("ctl00$SiteContent$btnSignIn", "Login"); - loginResponse = request(URI_GC_LOGIN_DEFAULT, "POST", params, false, false, false); - loginData = loginResponse.getData(); + loginResponse = postRequest(URI_GC_LOGIN_DEFAULT, params); + loginData = getResponseData(loginResponse); if (StringUtils.isNotBlank(loginData)) { if (checkLogin(loginData)) { @@ -593,13 +600,13 @@ public class cgBase { } public String switchToEnglish(String[] viewstates) { - final Map<String, String> params = new HashMap<String, String>(); + final Parameters params = new Parameters(); setViewstates(viewstates, params); params.put("__EVENTTARGET", "ctl00$uxLocaleList$uxLocaleList$ctl00$uxLocaleItem"); // switch to english params.put("__EVENTARGUMENT", ""); - return request(URI_GC_DEFAULT, "POST", params, false, false, false).getData(); + return cgBase.getResponseData(postRequest(URI_GC_DEFAULT, params)); } public cgCacheWrap parseSearch(cgSearchThread thread, String url, String page, boolean showCaptcha) { @@ -642,7 +649,7 @@ public class cgBase { } if (recaptchaJsParam != null) { - final String recaptchaJs = request(URI_GOOGLE_RECAPTCHA, "GET", "k=" + urlencode_rfc3986(recaptchaJsParam.trim()), true).getData(); + final String recaptchaJs = cgBase.getResponseData(request(URI_GOOGLE_RECAPTCHA, "GET", "k=" + urlencode_rfc3986(recaptchaJsParam.trim()), true)); if (StringUtils.isNotBlank(recaptchaJs)) { final Matcher matcherRecaptchaChallenge = patternRecaptchaChallenge.matcher(recaptchaJs); @@ -919,7 +926,7 @@ public class cgBase { } params.append("&ctl00%24ContentBody%24uxDownloadLoc=Download+Waypoints"); - final String coordinates = request(URI_GC_SEEK_NEAREST, "POST", params.toString(), true).getData(); + final String coordinates = getResponseData(request(URI_GC_SEEK_NEAREST, "POST", params.toString(), true)); if (StringUtils.isNotBlank(coordinates)) { if (coordinates.contains("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) { @@ -1671,17 +1678,16 @@ public class cgBase { params.put("tkn", userToken); params.put("idx", "1"); params.put("num", "35"); - params.put("sp", "0"); - params.put("sf", "0"); - params.put("decrypt", "1"); - final cgResponse response = request(URI_GC_SEEK_LOGBOOK, "GET", params, false, false, false); - if (response.getStatusCode() != 200) { - Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: error " + response.getStatusCode() + " when requesting log information"); + params.put("decrypt", "true"); + final HttpResponse response = request(URI_GC_SEEK_LOGBOOK, "GET", params, false, false, false); + final int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode != 200) { + Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: error " + statusCode + " when requesting log information"); return; } try { - final JSONObject resp = new JSONObject(response.getData()); + final JSONObject resp = new JSONObject(cgBase.getResponseData(response)); if (!resp.getString("status").equals("success")) { Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: status is " + resp.getString("status")); return; @@ -1822,7 +1828,7 @@ public class cgBase { public void detectGcCustomDate() { - final String result = request(URI_GC_PREFERENCES, "GET", null, false, false, false).getData(); + final String result = getResponseData(request(URI_GC_PREFERENCES, "GET", null, false, false, false)); if (null == result) { Log.w(cgSettings.tag, "cgeoBase.detectGcCustomDate: result is null"); @@ -1884,7 +1890,7 @@ public class cgBase { params.put("waypoints", StringUtils.join(geocodes.toArray(), ',')); } params.put("version", "cgeo"); - final String votes = request(URI_GCVOTE_GETVOTES, "GET", params, false, false, false).getData(); + final String votes = getResponseData(request(URI_GCVOTE_GETVOTES, "GET", params, false, false, false)); if (votes == null) { return null; } @@ -2485,7 +2491,7 @@ public class cgBase { public UUID searchByNextPage(cgSearchThread thread, final UUID searchId, int reason, boolean showCaptcha) { final String[] viewstates = app.getViewstates(searchId); - String url = app.getUrl(searchId); + final String url = app.getUrl(searchId); if (StringUtils.isBlank(url)) { Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No url found"); @@ -2497,42 +2503,19 @@ public class cgBase { return searchId; } - String host = "www.geocaching.com"; - String path = "/"; - final String method = "POST"; - - int dash = -1; - if (url.startsWith("http://")) { - url = url.substring(7); - } + // As in the original code, remove the query string + final String uri = Uri.parse(url).buildUpon().query(null).build().toString(); - dash = url.indexOf("/"); - if (dash > -1) { - host = url.substring(0, dash); - url = url.substring(dash); - } else { - host = url; - url = ""; - } - - dash = url.indexOf("?"); - if (dash > -1) { - path = url.substring(0, dash); - } else { - path = url; - } - - final Map<String, String> params = new HashMap<String, String>(); + final Parameters params = new Parameters(); setViewstates(viewstates, params); params.put("__EVENTTARGET", "ctl00$ContentBody$pgrBottom$ctl08"); params.put("__EVENTARGUMENT", ""); - final Uri uri = buildURI(false, host, path); - String page = request(uri, method, params, false, false, true).getData(); + String page = getResponseData(postRequest(uri, params)); if (checkLogin(page) == false) { int loginState = login(); if (loginState == 1) { - page = request(uri, method, params, false, false, true).getData(); + page = getResponseData(postRequest(uri, params)); } else if (loginState == -3) { Log.i(cgSettings.tag, "Working as guest."); } else { @@ -2888,7 +2871,7 @@ public class cgBase { String params = "{\"dto\":{\"data\":{\"c\":1,\"m\":\"\",\"d\":\"" + latMax + "|" + latMin + "|" + lonMax + "|" + lonMin + "\"},\"ut\":\"" + usertoken + "\"}}"; final Uri uri = buildURI(false, host, path); - page = requestJSONgc(uri, params); + page = getResponseData(requestJSONgc(uri, params)); if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.searchByViewport: No data from server"); @@ -2930,7 +2913,7 @@ public class cgBase { params.put("lnm", String.format((Locale) null, "%.6f", lonMin)); params.put("lnx", String.format((Locale) null, "%.6f", lonMax)); - final String data = request(URI_GO4CACHE_GET, "POST", params, false, false, false).getData(); + final String data = getResponseData(request(URI_GO4CACHE_GET, "POST", params, false, false, false)); if (StringUtils.isBlank(data)) { Log.e(cgSettings.tag, "cgeoBase.getGeocachersInViewport: No data from server"); @@ -3077,7 +3060,7 @@ public class cgBase { Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: 0"); } - final Map<String, String> params = new HashMap<String, String>(); + final Parameters params = new Parameters(); setViewstates(viewstates, params); params.put("__EVENTTARGET", ""); @@ -3107,12 +3090,12 @@ public class cgBase { params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } - final Uri uri = buildURI(false, "www.geocaching.com", "/seek/log.aspx", "ID=" + cacheid); - String page = request(uri, "POST", params, false, false, false).getData(); - if (checkLogin(page) == false) { + final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/seek/log.aspx").encodedQuery("ID=" + cacheid).build().toString(); + String page = getResponseData(postRequest(uri, params)); + if (!checkLogin(page)) { int loginState = login(); if (loginState == 1) { - page = request(uri, "POST", params, false, false, false).getData(); + page = getResponseData(postRequest(uri, params)); } else { Log.e(cgSettings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")"); return loginState; @@ -3169,7 +3152,7 @@ public class cgBase { params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } - page = request(uri, "POST", params, false, false, false).getData(); + page = getResponseData(postRequest(uri, params)); } } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.postLog.confim: " + e.toString()); @@ -3217,7 +3200,7 @@ public class cgBase { log = log.replace("\n", "\r\n"); // windows' eol final Calendar currentDate = Calendar.getInstance(); - final Map<String, String> params = new HashMap<String, String>(); + final Parameters params = new Parameters(); setViewstates(viewstates, params); params.put("__EVENTTARGET", ""); @@ -3237,12 +3220,12 @@ public class cgBase { params.put("ctl00$ContentBody$LogBookPanel1$LogButton", "Submit Log Entry"); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); - final Uri uri = buildURI(false, "www.geocaching.com", "/track/log.aspx", "wid=" + tbid); - String page = request(uri, "POST", params, false, false, false).getData(); + final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/track/log.aspx").encodedQuery("wid=" + tbid).build().toString(); + String page = getResponseData(postRequest(uri, params)); if (checkLogin(page) == false) { int loginState = login(); if (loginState == 1) { - page = request(uri, "POST", params, false, false, false).getData(); + page = getResponseData(postRequest(uri, params)); } else { Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: Can not log in geocaching (error: " + loginState + ")"); return loginState; @@ -3304,8 +3287,8 @@ public class cgBase { * @return -1: error occured */ public int removeFromWatchlist(cgCache cache) { - final Uri uri = buildURI(false, "www.geocaching.com", "/my/watchlist.aspx", "ds=1&action=rem&id=" + cache.cacheId); - String page = requestLogged(uri, "POST", null, false, false, false); + final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/my/watchlist.aspx").encodedQuery("ds=1&action=rem&id=" + cache.cacheId).build().toString(); + String page = postRequestLogged(uri); if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgBase.removeFromWatchlist: No data from server"); @@ -3313,13 +3296,13 @@ public class cgBase { } // removing cache from list needs approval by hitting "Yes" button - final Map<String, String> params = new HashMap<String, String>(); + final Parameters params = new Parameters(); transferViewstates(page, params); params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("ctl00$ContentBody$btnYes", "Yes"); - page = request(uri, "POST", params, false, false, false).getData(); + page = getResponseData(postRequest(uri, params)); boolean guidOnPage = cache.isGuidContainedInPage(page); if (!guidOnPage) { Log.i(cgSettings.tag, "cgBase.removeFromWatchlist: cache removed from watchlist"); @@ -3554,20 +3537,44 @@ public class cgBase { } public String[] requestViewstates(final Uri uri, String method, Map<String, String> params, boolean xContentType, boolean my) { - final cgResponse response = request(uri, method, params, xContentType, my, false); + final HttpResponse response = request(uri, method, params, xContentType, my, false); - return getViewstates(response.getData()); + return getViewstates(getResponseData(response)); + } + + static public String getResponseData(final HttpResponse response) { + if (response == null) { + return null; + } + try { + return EntityUtils.toString(response.getEntity(), "utf-8"); + } catch (Exception e) { + Log.e(cgSettings.tag, "getResponseData", e); + return null; + } + } + + public String postRequestLogged(final String uri) { + final String data = getResponseData(postRequest(uri, null)); + if (!checkLogin(data)) { + if (login() == 1) { + return getResponseData(postRequest(uri, null)); + } else { + Log.i(cgSettings.tag, "Working as guest."); + } + } + return data; } public String requestLogged(final Uri uri, String method, Map<String, String> params, boolean xContentType, boolean my, boolean addF) { - cgResponse response = request(uri, method, params, xContentType, my, addF); - String data = response.getData(); + HttpResponse response = request(uri, method, params, xContentType, my, addF); + String data = getResponseData(response); if (checkLogin(data) == false) { int loginState = login(); if (loginState == 1) { response = request(uri, method, params, xContentType, my, addF); - data = response.getData(); + data = getResponseData(response); } else { Log.i(cgSettings.tag, "Working as guest."); } @@ -3576,144 +3583,101 @@ public class cgBase { return data; } - public cgResponse request(final Uri uri, String method, Map<String, String> params, boolean xContentType, boolean my, boolean addF) { + public HttpResponse request(final Uri uri, String method, Map<String, String> params, boolean xContentType, boolean my, boolean addF) { final String paramsDone = prepareParameters(params, my, addF); return request(uri, method, paramsDone, xContentType); } - public cgResponse request(final Uri uri, String method, String params, Boolean xContentType) { - URL u = null; - int httpCode = -1; - String httpMessage = null; + private static DefaultHttpClient httpClient; - if (method == null || (method.equalsIgnoreCase("GET") == false && method.equalsIgnoreCase("POST") == false)) { - method = "POST"; - } else { - method = method.toUpperCase(); + public static DefaultHttpClient getHttpClient() { + if (httpClient == null) { + synchronized (cgBase.class) { + if (httpClient == null) { + httpClient = new DefaultHttpClient(); + // TODO: check redirect strategy + } + } } + return httpClient; + } - String cookiesDone = CookieJar.getCookiesAsString(prefs); - - URLConnection uc = null; - HttpURLConnection connection = null; - Integer timeout = 30000; - StringBuffer buffer = null; + public static void clearCookies() { + getHttpClient().getCookieStore().clear(); + } - for (int i = 0; i < 5; i++) { - if (i > 0) { - Log.w(cgSettings.tag, "Failed to download data, retrying. Attempt #" + (i + 1)); + public HttpResponse postRequest(final String uri, final List<? extends NameValuePair> params) { + try { + HttpPost request = new HttpPost(uri); + if (params != null) { + request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); } + request.setHeader("X-Requested-With", "XMLHttpRequest"); + if (settings.asBrowser == 1) { + request.setHeader("User-Agent", idBrowser); + } + Log.d(cgSettings.tag, "postRequest: POST to " + uri); + return getHttpClient().execute(request); + } catch (Exception e) { + // Can be UnsupportedEncodingException, ClientProtocolException or IOException + Log.e(cgSettings.tag, "postRequest", e); + return null; + } + } - buffer = new StringBuffer(); - timeout = 30000 + (i * 10000); - + public HttpResponse request(final Uri uri, final String method, final String params, final Boolean xContentType) { + HttpRequestBase request; + if (method.equals("GET")) { + request = new HttpGet(uri.buildUpon().encodedQuery(params).build().toString()); + } else { + request = new HttpPost(uri.toString()); try { - if (method.equals("GET")) { - // GET - u = new URL(uri.buildUpon().encodedQuery(params).build().toString()); - uc = u.openConnection(); - - uc.setRequestProperty("Host", uri.getHost()); - uc.setRequestProperty("Cookie", cookiesDone); - if (xContentType) { - uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - } - - if (settings.asBrowser == 1) { - uc.setRequestProperty("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); - // uc.setRequestProperty("Accept-Encoding", "gzip"); // not supported via cellular network - uc.setRequestProperty("Accept-Charset", "utf-8, iso-8859-1, utf-16, *;q=0.7"); - uc.setRequestProperty("Accept-Language", "en-US"); - uc.setRequestProperty("User-Agent", idBrowser); - uc.setRequestProperty("Connection", "keep-alive"); - uc.setRequestProperty("Keep-Alive", "300"); - } - - connection = (HttpURLConnection) uc; - connection.setReadTimeout(timeout); - connection.setRequestMethod(method); - HttpURLConnection.setFollowRedirects(true); - connection.setDoInput(true); - connection.setDoOutput(false); - } else { - // POST - u = new URL(uri.toString()); - uc = u.openConnection(); - - uc.setRequestProperty("Host", uri.getHost()); - uc.setRequestProperty("Cookie", cookiesDone); - if (xContentType) { - uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - } - - if (settings.asBrowser == 1) { - uc.setRequestProperty("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); - // uc.setRequestProperty("Accept-Encoding", "gzip"); // not supported via cellular network - uc.setRequestProperty("Accept-Charset", "utf-8, iso-8859-1, utf-16, *;q=0.7"); - uc.setRequestProperty("Accept-Language", "en-US"); - uc.setRequestProperty("User-Agent", idBrowser); - uc.setRequestProperty("Connection", "keep-alive"); - uc.setRequestProperty("Keep-Alive", "300"); - } + final ByteArrayEntity paramsEntity = new ByteArrayEntity(params.getBytes("utf-8")); + Log.d(cgSettings.tag, "Entity: " + paramsEntity); + ((HttpPost) request).setEntity(paramsEntity); + } catch (UnsupportedEncodingException e) { + Log.e(cgSettings.tag, "request", e); + return null; + } + } - connection = (HttpURLConnection) uc; - connection.setReadTimeout(timeout); - connection.setRequestMethod(method); - HttpURLConnection.setFollowRedirects(true); - connection.setDoInput(true); - connection.setDoOutput(true); - - final OutputStream out = connection.getOutputStream(); - final OutputStreamWriter wr = new OutputStreamWriter(out); - wr.write(params); - wr.flush(); - wr.close(); - } + request.setHeader("X-Requested-With", "XMLHttpRequest"); - CookieJar.setCookies(prefs, uc); + if (xContentType) { + request.setHeader("Content-Type", "application/x-www-form-urlencoded"); + } - InputStream ins = getInputstreamFromConnection(connection); - final InputStreamReader inr = new InputStreamReader(ins); - final BufferedReader br = new BufferedReader(inr, 16 * 1024); + if (settings.asBrowser == 1) { + request.setHeader("User-Agent", idBrowser); + } - readIntoBuffer(br, buffer); + final DefaultHttpClient client = getHttpClient(); - httpCode = connection.getResponseCode(); - httpMessage = connection.getResponseMessage(); + for (int i = 0; i < 5; i++) { + if (i > 0) { + Log.w(cgSettings.tag, "Failed to download data, retrying. Attempt #" + (i + 1)); + } - final String paramsLog = params.replaceAll(passMatch, "password=***"); - Log.i(cgSettings.tag, "[" + method + " " + (params.length() / 1024) + "k | " + httpCode + " | " + (buffer.length() / 1024) + "k] Downloaded " + uri + "?" + paramsLog); + Log.d(cgSettings.tag, "request: requesting " + request.getMethod() + " " + request.getURI() + " ‑ headers: " + request.getAllHeaders()); - connection.disconnect(); - br.close(); - ins.close(); - inr.close(); - } catch (IOException e) { - Log.e(cgSettings.tag, "cgeoBase.request.IOException", e); + try { + dumpCookies("Cookies before request", client); + final HttpResponse response = client.execute(request); + dumpCookies("Cookies after request", client); + return response; } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.request", e); } - - if (buffer.length() > 0) { - break; - } } - cgResponse response = new cgResponse(); + return null; + } - try { - if (StringUtils.isNotEmpty(buffer)) { - final String data = replaceWhitespace(buffer); - response.setData(data); - response.setStatusCode(httpCode); - response.setStatusMessage(httpMessage); - response.setUrl(u.toString()); - } - } catch (Exception e) { - Log.e(cgSettings.tag, "cgeoBase.page", e); + private void dumpCookies(final String msg, final DefaultHttpClient client) { + Log.d(cgSettings.tag, msg); + for (Cookie cookie : client.getCookieStore().getCookies()) { + Log.d(cgSettings.tag, " - " + cookie.getName() + ": " + cookie.getValue()); } - - return response; } /** @@ -3726,100 +3690,8 @@ public class cgBase { return StringUtils.join(StringUtils.split(buffer.toString(), " \n\r\t"), " "); } - public String requestJSONgc(final Uri uri, String params) { - int httpCode = -1; - - final String cookiesDone = CookieJar.getCookiesAsString(prefs); - - URLConnection uc = null; - HttpURLConnection connection = null; - Integer timeout = 30000; - final StringBuffer buffer = new StringBuffer(); - - for (int i = 0; i < 3; i++) { - if (i > 0) { - Log.w(cgSettings.tag, "Failed to download data, retrying. Attempt #" + (i + 1)); - } - - buffer.delete(0, buffer.length()); - timeout = 30000 + (i * 15000); - - try { - // POST - final URL u = new URL(uri.toString()); - uc = u.openConnection(); - - uc.setRequestProperty("Host", uri.getHost()); - uc.setRequestProperty("Cookie", cookiesDone); - uc.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); - uc.setRequestProperty("X-Requested-With", "XMLHttpRequest"); - uc.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01"); - uc.setRequestProperty("Referer", uri.getHost() + "/" + uri.getPath()); - - if (settings.asBrowser == 1) { - uc.setRequestProperty("Accept-Charset", "utf-8, iso-8859-1, utf-16, *;q=0.7"); - uc.setRequestProperty("Accept-Language", "en-US"); - uc.setRequestProperty("User-Agent", idBrowser); - uc.setRequestProperty("Connection", "keep-alive"); - uc.setRequestProperty("Keep-Alive", "300"); - } - - connection = (HttpURLConnection) uc; - connection.setReadTimeout(timeout); - connection.setRequestMethod("POST"); - HttpURLConnection.setFollowRedirects(true); - connection.setDoInput(true); - connection.setDoOutput(true); - - final OutputStream out = connection.getOutputStream(); - final OutputStreamWriter wr = new OutputStreamWriter(out); - wr.write(params); - wr.flush(); - wr.close(); - - CookieJar.setCookies(prefs, uc); - - InputStream ins = getInputstreamFromConnection(connection); - final InputStreamReader inr = new InputStreamReader(ins); - final BufferedReader br = new BufferedReader(inr); - - readIntoBuffer(br, buffer); - - httpCode = connection.getResponseCode(); - - final String paramsLog = params.replaceAll(passMatch, "password=***"); - Log.i(cgSettings.tag + " | JSON", "[POST " + (params.length() / 1024) + "k | " + httpCode + " | " + (buffer.length() / 1024) + "k] Downloaded " + uri.toString() + "?" + paramsLog); - - connection.disconnect(); - br.close(); - ins.close(); - inr.close(); - } catch (IOException e) { - Log.e(cgSettings.tag, "cgeoBase.requestJSONgc.IOException: " + e.toString()); - } catch (Exception e) { - Log.e(cgSettings.tag, "cgeoBase.requestJSONgc: " + e.toString()); - } - - if (buffer != null && buffer.length() > 0) { - break; - } - } - - return replaceWhitespace(buffer); - } - - private static InputStream getInputstreamFromConnection(HttpURLConnection connection) throws IOException { - final String encoding = connection.getContentEncoding(); - InputStream ins; - - if (encoding != null && encoding.equalsIgnoreCase("gzip")) { - ins = new GZIPInputStream(connection.getInputStream()); - } else if (encoding != null && encoding.equalsIgnoreCase("deflate")) { - ins = new InflaterInputStream(connection.getInputStream(), new Inflater(true)); - } else { - ins = connection.getInputStream(); - } - return ins; + public HttpResponse requestJSONgc(final Uri uri, String params) { + return request(uri, "GET", params, false); } public static JSONObject requestJSON(String host, String path, String params) { @@ -4309,8 +4181,8 @@ public class cgBase { } public String getMapUserToken(Handler noTokenHandler) { - final cgResponse response = request(URI_GC_MAP_DEFAULT, "GET", "", false); - final String data = response.getData(); + final HttpResponse response = request(URI_GC_MAP_DEFAULT, "GET", "", false); + final String data = getResponseData(response); String usertoken = null; if (StringUtils.isNotBlank(data)) { diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java index b23d0d5..41937ee 100644 --- a/main/src/cgeo/geocaching/cgGeo.java +++ b/main/src/cgeo/geocaching/cgGeo.java @@ -404,7 +404,7 @@ public class cgGeo { if (base.version != null) { params.put("v", base.version); } - final String res = base.request(URI_GO4CACHE, "POST", params, false, false, false).getData(); + final String res = cgBase.getResponseData(base.request(URI_GO4CACHE, "POST", params, false, false, false)); if (StringUtils.isNotBlank(res)) { lastGo4cacheCoords = coordsNow; diff --git a/main/src/cgeo/geocaching/cgResponse.java b/main/src/cgeo/geocaching/cgResponse.java index 3ac7770..0319761 100644 --- a/main/src/cgeo/geocaching/cgResponse.java +++ b/main/src/cgeo/geocaching/cgResponse.java @@ -1,33 +1,33 @@ package cgeo.geocaching; +import org.apache.http.HttpResponse; + public class cgResponse { - private String url; - private int statusCode; - private String statusMessage; - private String data; + private String data = null; + + private HttpResponse response = null; - public void setUrl(String url) { - this.url = url; + public cgResponse() { } - public String getUrl() { - return url; + public cgResponse(HttpResponse response) { + this.response = response; } public void setStatusCode(int code) { - statusCode = code; + response.setStatusCode(code); } public int getStatusCode() { - return statusCode; + return response.getStatusLine().getStatusCode(); } public void setStatusMessage(String message) { - statusMessage = message; + response.setReasonPhrase(message); } public String getStatusMessage() { - return statusMessage; + return response.getStatusLine().getReasonPhrase(); } public void setData(String data) { @@ -35,6 +35,6 @@ public class cgResponse { } public String getData() { - return data; + return data == null ? cgBase.getResponseData(response) : data; } } diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index ac5aeb1..47554f7 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -27,6 +27,7 @@ import cgeo.geocaching.sorting.VoteComparator; import cgeo.geocaching.utils.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpResponse; import android.app.AlertDialog; import android.app.ProgressDialog; @@ -221,14 +222,14 @@ public class cgeocaches extends AbstractListActivity { dialog.setNegativeButton(res.getString(R.string.license_dismiss), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - CookieJar.deleteCookies(prefs); + cgBase.clearCookies(); dialog.cancel(); } }); dialog.setPositiveButton(res.getString(R.string.license_show), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - CookieJar.deleteCookies(prefs); + cgBase.clearCookies(); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/software/agreement.aspx?ID=0"))); } }); @@ -2085,12 +2086,13 @@ public class cgeocaches extends AbstractListActivity { if (deviceCode == null) { deviceCode = ""; } - cgResponse responseFromWeb = base.request(URI_SEND2CGEO_READ, "GET", "code=" + cgBase.urlencode_rfc3986(deviceCode), true); + HttpResponse responseFromWeb = base.request(URI_SEND2CGEO_READ, "GET", "code=" + cgBase.urlencode_rfc3986(deviceCode), true); - if (responseFromWeb.getStatusCode() == 200) { - if (responseFromWeb.getData().length() > 2) { + if (responseFromWeb.getStatusLine().getStatusCode() == 200) { + final String response = cgBase.getResponseData(responseFromWeb); + if (response.length() > 2) { - String GCcode = responseFromWeb.getData(); + String GCcode = response; delay = 1; Message mes = new Message(); @@ -2107,7 +2109,7 @@ public class cgeocaches extends AbstractListActivity { mes1.obj = GCcode; handler.sendMessage(mes1); yield(); - } else if ("RG".equals(responseFromWeb.getData())) { + } else if ("RG".equals(cgBase.getResponseData(responseFromWeb))) { //Server returned RG (registration) and this device no longer registered. settings.setWebNameCode(null, null); needToStop = true; @@ -2119,7 +2121,7 @@ public class cgeocaches extends AbstractListActivity { yield(); } } - if (responseFromWeb.getStatusCode() != 200) { + if (responseFromWeb.getStatusLine().getStatusCode() != 200) { needToStop = true; handler.sendEmptyMessage(-2); return; diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index 870c5f9..abd05c8 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -6,6 +6,7 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.compatibility.Compatibility; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpResponse; import android.app.ProgressDialog; import android.content.Intent; @@ -1006,7 +1007,7 @@ public class cgeoinit extends AbstractActivity { loginDialog.setCancelable(false); settings.setLogin(username, password); - CookieJar.deleteCookies(prefs); + cgBase.clearCookies(); (new Thread() { @@ -1048,12 +1049,12 @@ public class cgeoinit extends AbstractActivity { String params = "name=" + cgBase.urlencode_rfc3986(nam) + "&code=" + cgBase.urlencode_rfc3986(cod); - cgResponse response = base.request(URI_SEND2CGEO_AUTH, "GET", params, true); + HttpResponse response = base.request(URI_SEND2CGEO_AUTH, "GET", params, true); - if (response.getStatusCode() == 200) + if (response.getStatusLine().getStatusCode() == 200) { //response was OK - String[] strings = response.getData().split(","); + String[] strings = cgBase.getResponseData(response).split(","); try { pin = Integer.parseInt(strings[1].trim()); } catch (Exception e) { diff --git a/main/src/cgeo/geocaching/cgeotouch.java b/main/src/cgeo/geocaching/cgeotouch.java index 9533911..be267c3 100644 --- a/main/src/cgeo/geocaching/cgeotouch.java +++ b/main/src/cgeo/geocaching/cgeotouch.java @@ -389,7 +389,7 @@ public class cgeotouch extends cgLogForm { return; } - final String page = base.request(URI_GC_TRACK_LOG, "GET", params, false, false, false).getData(); + final String page = cgBase.getResponseData(base.request(URI_GC_TRACK_LOG, "GET", params, false, false, false)); viewstates = cgBase.getViewstates(page); diff --git a/main/src/cgeo/geocaching/cgeovisit.java b/main/src/cgeo/geocaching/cgeovisit.java index 943eeb7..a44f320 100644 --- a/main/src/cgeo/geocaching/cgeovisit.java +++ b/main/src/cgeo/geocaching/cgeovisit.java @@ -385,7 +385,7 @@ public class cgeovisit extends cgLogForm { params.put("voteUser", String.format("%.1f", rating).replace(',', '.')); params.put("version", "cgeo"); - final String result = base.request(URI_GCVOTE_SETVOTE, "GET", params, false, false, false).getData(); + final String result = cgBase.getResponseData(base.request(URI_GCVOTE_SETVOTE, "GET", params, false, false, false)); return result.trim().equalsIgnoreCase("ok"); } @@ -717,7 +717,7 @@ public class cgeovisit extends cgLogForm { return; } - final String page = base.request(URI_GC_SEEK_LOG, "GET", params, false, false, false).getData(); + final String page = cgBase.getResponseData(base.request(URI_GC_SEEK_LOG, "GET", params, false, false, false)); viewstates = cgBase.getViewstates(page); trackables = cgBase.parseTrackableLog(page); diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 9797556..46890a5 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -7,17 +7,17 @@ import cgeo.geocaching.cgCoord; import cgeo.geocaching.cgDirection; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgSettings; +import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.cgUpdateDir; import cgeo.geocaching.cgUpdateLoc; import cgeo.geocaching.cgUser; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.cgSettings.mapSourceEnum; import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.maps.interfaces.MapActivityImpl; import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl; import cgeo.geocaching.maps.interfaces.GeoPointImpl; +import cgeo.geocaching.maps.interfaces.MapActivityImpl; import cgeo.geocaching.maps.interfaces.MapControllerImpl; import cgeo.geocaching.maps.interfaces.MapFactory; import cgeo.geocaching.maps.interfaces.MapViewImpl; @@ -42,12 +42,12 @@ import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; -import android.view.WindowManager; import android.view.ViewGroup.LayoutParams; +import android.view.WindowManager; import android.widget.ImageSwitcher; import android.widget.ImageView; -import android.widget.TextView; import android.widget.ImageView.ScaleType; +import android.widget.TextView; import android.widget.ViewSwitcher.ViewFactory; import java.util.ArrayList; @@ -245,7 +245,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory app = (cgeoapplication) activity.getApplication(); app.setAction(null); settings = new cgSettings(activity, activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE)); - base = new cgBase(app, settings, activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE)); + base = new cgBase(app, settings); prefsEdit = activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE).edit(); MapFactory mapFactory = settings.getMapFactory(); diff --git a/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java index d7140ab..23fa481 100644 --- a/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java +++ b/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java @@ -49,7 +49,7 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> { // create required c:geo objects settings = new cgSettings(context, prefs); - base = new cgBase(this.getApplication(), settings, prefs); + base = new cgBase(this.getApplication(), settings); } /** |
