diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 175 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgData.java | 34 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgFileList.java | 15 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgOAuth.java | 12 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgSettings.java | 8 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeodetail.java | 4 | ||||
| -rw-r--r-- | src/cgeo/geocaching/compatibility/Compatibility.java | 6 |
7 files changed, 93 insertions, 161 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index ab17c04..b12366f 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -869,7 +869,7 @@ public class cgBase { while (matcherTotalCnt.find()) { if (matcherTotalCnt.groupCount() > 0) { if (matcherTotalCnt.group(1) != null) { - caches.totalCnt = new Integer(matcherTotalCnt.group(1)); + caches.totalCnt = Integer.valueOf(matcherTotalCnt.group(1)); } } } @@ -2581,12 +2581,12 @@ public class cgBase { continue; } if (trackableMatcher.group(3) != null) { - trackable.ctl = new Integer(trackableMatcher.group(3)); + trackable.ctl = Integer.valueOf(trackableMatcher.group(3)); } else { continue; } if (trackableMatcher.group(5) != null) { - trackable.id = new Integer(trackableMatcher.group(5)); + trackable.id = Integer.valueOf(trackableMatcher.group(5)); } else { continue; } @@ -4289,63 +4289,7 @@ public class cgBase { scheme = "https://"; } - // prepare cookies - String cookiesDone = null; - if (cookies == null || cookies.isEmpty()) { - if (cookies == null) { - cookies = new HashMap<String, String>(); - } - - final Map<String, ?> prefsAll = prefs.getAll(); - final Set<? extends Map.Entry<String, ?>> entrySet = prefsAll.entrySet(); - - for(Map.Entry<String, ?> entry : entrySet){ - String key = entry.getKey(); - if (key.matches("cookie_.+")) { - final String cookieKey = key.substring(7); - final String cookieValue = (String) entry.getValue(); - - cookies.put(cookieKey, cookieValue); - } - } - } - - if (cookies != null) { - final Set<Map.Entry<String, String>> entrySet = cookies.entrySet(); - final ArrayList<String> cookiesEncoded = new ArrayList<String>(); - - for(Map.Entry<String, String> entry : entrySet){ - cookiesEncoded.add(entry.getKey() + "=" + entry.getValue()); - } - - if (cookiesEncoded.size() > 0) { - cookiesDone = implode("; ", cookiesEncoded.toArray()); - } - } - - if (cookiesDone == null) { - Map<String, ?> prefsValues = prefs.getAll(); - - if (prefsValues != null && prefsValues.size() > 0 && prefsValues.keySet().size() > 0) { - final Set<? extends Map.Entry<String, ?>> entrySet = prefsValues.entrySet(); - final ArrayList<String> cookiesEncoded = new ArrayList<String>(); - - for(Map.Entry<String, ?> entry : entrySet){ - String key = entry.getKey(); - if (key.length() > 7 && key.substring(0, 7).equals("cookie_")) { - cookiesEncoded.add(key + "=" + entry.getValue()); - } - } - - if (cookiesEncoded.size() > 0) { - cookiesDone = implode("; ", cookiesEncoded.toArray()); - } - } - } - - if (cookiesDone == null) { - cookiesDone = ""; - } + String cookiesDone = getCookiesAsString(); URLConnection uc = null; HttpURLConnection connection = null; @@ -4447,16 +4391,7 @@ public class cgBase { } prefsEditor.commit(); - 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(); - } + InputStream ins = getInputstreamFromConnection(connection); final InputStreamReader inr = new InputStreamReader(ins); final BufferedReader br = new BufferedReader(inr, 16 * 1024); @@ -4525,32 +4460,7 @@ public class cgBase { return response; } - private static void replaceWhitespace(final StringBuffer buffer) { - final int length = buffer.length(); - final char[] chars = new char[length]; - buffer.getChars(0, length, chars, 0); - int resultSize = 0; - boolean lastWasWhitespace = false; - for (int i = 0; i < length; i++) { - char c = chars[i]; - if (c == ' ' || c == '\n' || c == '\r' || c == '\t') { - if (!lastWasWhitespace) { - chars[resultSize++] =' '; - } - lastWasWhitespace = true; - } else { - chars[resultSize++] = c; - lastWasWhitespace = false; - } - } - buffer.setLength(0); - buffer.append(chars); - } - - public String requestJSONgc(String host, String path, String params) { - int httpCode = -1; - String httpLocation = null; - + private String getCookiesAsString() { // prepare cookies String cookiesDone = null; if (cookies == null || cookies.isEmpty()) { @@ -4608,6 +4518,35 @@ public class cgBase { if (cookiesDone == null) { cookiesDone = ""; } + return cookiesDone; + } + + private static void replaceWhitespace(final StringBuffer buffer) { + final int length = buffer.length(); + final char[] chars = new char[length]; + buffer.getChars(0, length, chars, 0); + int resultSize = 0; + boolean lastWasWhitespace = false; + for (char c : chars) { + if (c == ' ' || c == '\n' || c == '\r' || c == '\t') { + if (!lastWasWhitespace) { + chars[resultSize++] =' '; + } + lastWasWhitespace = true; + } else { + chars[resultSize++] = c; + lastWasWhitespace = false; + } + } + buffer.setLength(0); + buffer.append(chars); + } + + public String requestJSONgc(String host, String path, String params) { + int httpCode = -1; + String httpLocation = null; + + String cookiesDone = getCookiesAsString(); URLConnection uc = null; HttpURLConnection connection = null; @@ -4679,16 +4618,7 @@ public class cgBase { } prefsEditor.commit(); - 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(); - } + InputStream ins = getInputstreamFromConnection(connection); final InputStreamReader inr = new InputStreamReader(ins); final BufferedReader br = new BufferedReader(inr); @@ -4735,6 +4665,20 @@ public class cgBase { } } + 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 static String requestJSON(String host, String path, String params) { return requestJSON("http://", host, path, "GET", params); } @@ -4814,16 +4758,7 @@ public class cgBase { } - 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(); - } + InputStream ins = getInputstreamFromConnection(connection); final InputStreamReader inr = new InputStreamReader(ins); final BufferedReader br = new BufferedReader(inr, 1024); @@ -4949,11 +4884,11 @@ public class cgBase { if (path.exists()) { File[] files = path.listFiles(); - for (int i = 0; i < files.length; i++) { - if (files[i].isDirectory()) { - deleteDirectory(files[i]); + for (File file : files) { + if (file.isDirectory()) { + deleteDirectory(file); } else { - files[i].delete(); + file.delete(); } } } diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java index 78a3442..f5b2dd8 100644 --- a/src/cgeo/geocaching/cgData.java +++ b/src/cgeo/geocaching/cgData.java @@ -2804,14 +2804,15 @@ public class cgData { if (size > 0) { Log.d(cgSettings.tag, "Database clean: removing " + size + " geocaches"); - databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableAttributes + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableSpoilers + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableLogs + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableLogCount + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableLogsOffline + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableWaypoints + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ") and type <> \"own\""); - databaseRW.execSQL("delete from " + dbTableTrackables + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); + String geocodeList = cgBase.implode(", ", geocodes.toArray()); + databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableAttributes + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableSpoilers + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableLogs + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableLogCount + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableLogsOffline + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableWaypoints + " where geocode in (" + geocodeList + ") and type <> \"own\""); + databaseRW.execSQL("delete from " + dbTableTrackables + " where geocode in (" + geocodeList + ")"); geocodes.clear(); } @@ -2861,14 +2862,15 @@ public class cgData { } if (geocodes.size() > 0) { - databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableAttributes + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableSpoilers + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableLogs + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableLogCount + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableLogsOffline + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); - databaseRW.execSQL("delete from " + dbTableWaypoints + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ") and type <> \"own\""); - databaseRW.execSQL("delete from " + dbTableTrackables + " where geocode in (" + cgBase.implode(", ", geocodes.toArray()) + ")"); + String geocodeList = cgBase.implode(", ", geocodes.toArray()); + databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableAttributes + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableSpoilers + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableLogs + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableLogCount + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableLogsOffline + " where geocode in (" + geocodeList + ")"); + databaseRW.execSQL("delete from " + dbTableWaypoints + " where geocode in (" + geocodeList + ") and type <> \"own\""); + databaseRW.execSQL("delete from " + dbTableTrackables + " where geocode in (" + geocodeList + ")"); geocodes.clear(); } diff --git a/src/cgeo/geocaching/cgFileList.java b/src/cgeo/geocaching/cgFileList.java index 3536ba6..8e762d9 100644 --- a/src/cgeo/geocaching/cgFileList.java +++ b/src/cgeo/geocaching/cgFileList.java @@ -190,15 +190,14 @@ public abstract class cgFileList<T extends ArrayAdapter<File>> extends AbstractL String fileExt = getFileExtension(); if (listPre != null && listPre.length > 0) { - final int listCnt = listPre.length; - for (int i = 0; i < listCnt; i++) { + for (File file : listPre) { if (endSearching) { return; } - if (listPre[i].canRead() && listPre[i].isFile()) { - final String[] nameParts = listPre[i].getName().split("\\."); + if (file.canRead() && file.isFile()) { + final String[] nameParts = file.getName().split("\\."); if (nameParts.length > 1) { final String extension = nameParts[(nameParts.length - 1)].toLowerCase(); @@ -209,10 +208,10 @@ public abstract class cgFileList<T extends ArrayAdapter<File>> extends AbstractL continue; // file has no extension } - list.add(listPre[i]); // add file to list - } else if (listPre[i].canRead() && listPre[i].isDirectory()) { + list.add(file); // add file to list + } else if (file.canRead() && file.isDirectory()) { final Message msg = new Message(); - String name = listPre[i].getName(); + String name = file.getName(); if (name.substring(0, 1).equals(".")) { continue; // skip hidden directories } @@ -222,7 +221,7 @@ public abstract class cgFileList<T extends ArrayAdapter<File>> extends AbstractL msg.obj = name; changeWaitDialogHandler.sendMessage(msg); - listDir(list, listPre[i]); // go deeper + listDir(list, file); // go deeper } } } diff --git a/src/cgeo/geocaching/cgOAuth.java b/src/cgeo/geocaching/cgOAuth.java index 48592eb..46e9c7d 100644 --- a/src/cgeo/geocaching/cgOAuth.java +++ b/src/cgeo/geocaching/cgOAuth.java @@ -27,15 +27,15 @@ public class cgOAuth { params.put("oauth_timestamp", Long.toString(currentTime)); params.put("oauth_token", token); params.put("oauth_version", "1.0"); - - Object[] keys = params.keySet().toArray(); + + String[] keys = new String[params.keySet().size()]; + params.keySet().toArray(keys); Arrays.sort(keys); ArrayList<String> paramsEncoded = new ArrayList<String>(); - for (int i = 0; i < keys.length; i++) { - String value = params.get(keys[i].toString()); - - paramsEncoded.add(keys[i] + "=" + cgBase.urlencode_rfc3986(value)); + for (String key : keys) { + String value = params.get(key); + paramsEncoded.add(key + "=" + cgBase.urlencode_rfc3986(value)); } String keysPacked; diff --git a/src/cgeo/geocaching/cgSettings.java b/src/cgeo/geocaching/cgSettings.java index 87eacdd..8e6686e 100644 --- a/src/cgeo/geocaching/cgSettings.java +++ b/src/cgeo/geocaching/cgSettings.java @@ -429,11 +429,9 @@ public class cgSettings { if (prefsValues != null && prefsValues.size() > 0) { Log.i(cgSettings.tag, "Removing cookies"); - Object[] keys = prefsValues.keySet().toArray(); - - for (int i = 0; i < keys.length; i++) { - if (keys[i].toString().length() > 7 && keys[i].toString().substring(0, 7).equals("cookie_")) { - edit.remove(keys[i].toString()); + for (String key : prefsValues.keySet()) { + if (key.length() > 7 && key.substring(0, 7).equals("cookie_")) { + edit.remove(key); } } } diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java index 89dea60..7ee0d93 100644 --- a/src/cgeo/geocaching/cgeodetail.java +++ b/src/cgeo/geocaching/cgeodetail.java @@ -815,9 +815,7 @@ public class cgeodetail extends AbstractActivity { final TextView attribView = (TextView) findViewById(R.id.attributes); StringBuilder buffer = new StringBuilder(); - String attribute; - for (int i = 0; i < cache.attributes.size(); i++) { - attribute = cache.attributes.get(i); + for (String attribute : cache.attributes) { // dynamically search for a translation of the attribute int id = res.getIdentifier("attribute_" + attribute, "string", base.context.getPackageName()); diff --git a/src/cgeo/geocaching/compatibility/Compatibility.java b/src/cgeo/geocaching/compatibility/Compatibility.java index 7d83fb6..18ee8a8 100644 --- a/src/cgeo/geocaching/compatibility/Compatibility.java +++ b/src/cgeo/geocaching/compatibility/Compatibility.java @@ -15,7 +15,7 @@ public final class Compatibility { private static AndroidLevel8 getLevel8() { if (!initialized) { try { - final int sdk = new Integer(Build.VERSION.SDK).intValue(); + final int sdk = Integer.valueOf(Build.VERSION.SDK).intValue(); if (sdk >= 8) { level8 = new AndroidLevel8(); } @@ -52,7 +52,7 @@ public final class Compatibility { } public static Uri getCalendarProviderURI() { - final int sdk = new Integer(Build.VERSION.SDK).intValue(); + final int sdk = Integer.valueOf(Build.VERSION.SDK).intValue(); if (sdk >= 8) { return Uri.parse("content://com.android.calendar/calendars"); } else { @@ -61,7 +61,7 @@ public final class Compatibility { } public static Uri getCalenderEventsProviderURI() { - final int sdk = new Integer(Build.VERSION.SDK).intValue(); + final int sdk = Integer.valueOf(Build.VERSION.SDK).intValue(); if (sdk >= 8) { return Uri.parse("content://com.android.calendar/events"); } else { |
