diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2012-12-18 22:22:35 +0100 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2012-12-18 22:54:15 +0100 |
commit | efa9888edd99e722628136b576fd1f081a13d910 (patch) | |
tree | de4b7a96ffe70e07914664d4a176a239e837ee9c /main/src/cgeo/geocaching | |
parent | 6fe12bd37037dff96ac66a6fe903241f04c21497 (diff) | |
download | cgeo-efa9888edd99e722628136b576fd1f081a13d910.zip cgeo-efa9888edd99e722628136b576fd1f081a13d910.tar.gz cgeo-efa9888edd99e722628136b576fd1f081a13d910.tar.bz2 |
Refactoring: narrow scope of variables
Diffstat (limited to 'main/src/cgeo/geocaching')
25 files changed, 64 insertions, 100 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index dee4750..2a7f602 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -232,8 +232,6 @@ public class CacheDetailActivity extends AbstractActivity { setTitle(res.getString(R.string.cache)); String geocode = null; - String guid = null; - String name = null; // TODO Why can it happen that search is not null? onCreate should be called only once and it is not set before. if (search != null) { @@ -248,6 +246,8 @@ public class CacheDetailActivity extends AbstractActivity { final Uri uri = getIntent().getData(); // try to get data from extras + String name = null; + String guid = null; if (geocode == null && extras != null) { geocode = extras.getString("geocode"); name = extras.getString("name"); diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java index a5b445f..378fda7 100644 --- a/main/src/cgeo/geocaching/EditWaypointActivity.java +++ b/main/src/cgeo/geocaching/EditWaypointActivity.java @@ -157,9 +157,8 @@ public class EditWaypointActivity extends AbstractActivity { initializeWaypointTypeSelector(); } - IConnector con; if (geocode != null) { - con = ConnectorFactory.getConnector(geocode); + IConnector con = ConnectorFactory.getConnector(geocode); setUploadingCheckBoxVisibleByConnector(con); } diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index f55d30a..49dfb0f 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -154,12 +154,12 @@ public class StaticMapsProvider { return; } final String latlonMap = cache.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA); - final String markerUrl = MARKERS_URL + "my_location_mdpi.png"; final Display display = ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); final int width = metrics.widthPixels; final int height = (int) (110 * metrics.density); + final String markerUrl = MARKERS_URL + "my_location_mdpi.png"; downloadMap(cache.getGeocode(), 15, ROADMAP, markerUrl, PREFIX_PREVIEW, "shadow:false|", latlonMap, width, height, null); } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 12b63dd..ab5c642 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -764,11 +764,10 @@ public class cgData { "100"); if (cursor != null) { - int index; if (cursor.getCount() > 0) { cursor.moveToFirst(); - index = cursor.getColumnIndex("geocode"); + int index = cursor.getColumnIndex("geocode"); do { list.add(cursor.getString(index)); @@ -825,13 +824,12 @@ public class cgData { } if (cursor != null) { - int index; cnt = cursor.getCount(); if (cnt > 0) { cursor.moveToFirst(); - index = cursor.getColumnIndex("updated"); + int index = cursor.getColumnIndex("updated"); dataUpdated = cursor.getLong(index); index = cursor.getColumnIndex("detailedupdate"); dataDetailedUpdate = cursor.getLong(index); @@ -1033,12 +1031,12 @@ public class cgData { values.put("coordsChanged", cache.hasUserModifiedCoords() ? 1 : 0); values.put("finalDefined", cache.hasFinalDefined() ? 1 : 0); - boolean result = false; init(); //try to update record else insert fresh.. database.beginTransaction(); + boolean result = false; try { saveAttributesWithoutTransaction(cache); saveOriginalWaypointsWithoutTransaction(cache); @@ -1105,10 +1103,10 @@ public class cgData { } public static boolean saveWaypoints(final cgCache cache) { - boolean result = false; init(); database.beginTransaction(); + boolean result = false; try { saveOriginalWaypointsWithoutTransaction(cache); database.setTransactionSuccessful(); @@ -1191,8 +1189,8 @@ public class cgData { init(); - boolean ok = false; database.beginTransaction(); + boolean ok = false; try { ContentValues values = new ContentValues(); values.put("geocode", geocode); @@ -1558,7 +1556,6 @@ public class cgData { * @return Cache from DB */ private static cgCache createCacheFromDatabaseContent(Cursor cursor) { - int index; cgCache cache = new cgCache(); if (cacheColumnIndex == null) { @@ -1627,7 +1624,7 @@ public class cgData { cache.setHint(cursor.getString(cacheColumnIndex[14])); cache.setSize(CacheSize.getById(cursor.getString(cacheColumnIndex[15]))); cache.setDifficulty(cursor.getFloat(cacheColumnIndex[16])); - index = cacheColumnIndex[17]; + int index = cacheColumnIndex[17]; if (cursor.isNull(index)) { cache.setDirection(null); } else { @@ -1714,8 +1711,6 @@ public class cgData { init(); - cgWaypoint waypoint = null; - Cursor cursor = database.query( dbTableWaypoints, WAYPOINT_COLUMNS, @@ -1728,6 +1723,7 @@ public class cgData { Log.d("cgData.loadWaypoint(" + id + ")"); + cgWaypoint waypoint = null; if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); @@ -1880,10 +1876,10 @@ public class cgData { } public static boolean clearSearchedDestinations() { - boolean success = true; init(); database.beginTransaction(); + boolean success = true; try { database.delete(dbTableSearchDestionationHistory, null, null); database.setTransactionSuccessful(); @@ -2344,10 +2340,10 @@ public class cgData { Log.d("Database clean: started"); - Cursor cursor; Set<String> geocodes = new HashSet<String>(); try { + Cursor cursor; if (more) { cursor = database.query( dbTableCaches, @@ -2701,8 +2697,8 @@ public class cgData { init(); - int count = 0; database.beginTransaction(); + int count = 0; try { ContentValues values = new ContentValues(); values.put("title", name); @@ -2730,8 +2726,8 @@ public class cgData { init(); - boolean status = false; database.beginTransaction(); + boolean status = false; try { int cnt = database.delete(dbTableLists, "_id = " + (listId - customListIdOffset), null); @@ -2787,8 +2783,8 @@ public class cgData { } init(); - boolean result = false; database.beginTransaction(); + boolean result = false; try { database.delete(dbTableSearchDestionationHistory, "_id = " + destination.getId(), null); database.setTransactionSuccessful(); diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 0a3177b..a4c1ea9 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -1526,13 +1526,13 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity @Override public void run() { - int ret = MSG_DONE; removeGeoAndDir(); int delay = -1; int times = 0; + int ret = MSG_DONE; while (!needToStop && times < 3 * 60 / 5) // maximum: 3 minutes, every 5 seconds { //download new code diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java index 0e0d98b..d89d324 100644 --- a/main/src/cgeo/geocaching/cgeopoint.java +++ b/main/src/cgeo/geocaching/cgeopoint.java @@ -487,8 +487,6 @@ public class cgeopoint extends AbstractActivity { } private Geopoint getDestination() { - Geopoint result; - Geopoint coords; String bearingText = ((EditText) findViewById(R.id.bearing)).getText().toString(); // combine distance from EditText and distanceUnit saved from Spinner @@ -502,6 +500,7 @@ public class cgeopoint extends AbstractActivity { return null; } + Geopoint coords; if (StringUtils.isNotBlank(latText) && StringUtils.isNotBlank(lonText)) { try { coords = new Geopoint(latText, lonText); @@ -518,6 +517,7 @@ public class cgeopoint extends AbstractActivity { coords = app.currentGeo().getCoords(); } + Geopoint result; if (StringUtils.isNotBlank(bearingText) && StringUtils.isNotBlank(distanceText)) { // bearing & distance double bearing; diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java index 5aa6675..80b9f01 100644 --- a/main/src/cgeo/geocaching/cgeotrackable.java +++ b/main/src/cgeo/geocaching/cgeotrackable.java @@ -222,11 +222,10 @@ public class cgeotrackable extends AbstractActivity { @Override public void run() { - BitmapDrawable image; try { HtmlImage imgGetter = new HtmlImage(geocode, true, 0, false); - image = imgGetter.getDrawable(trackable.getImage()); + BitmapDrawable image = imgGetter.getDrawable(trackable.getImage()); Message message = handler.obtainMessage(0, image); handler.sendMessage(message); } catch (Exception e) { @@ -431,11 +430,9 @@ public class cgeotrackable extends AbstractActivity { LinearLayout listView = (LinearLayout) findViewById(R.id.log_list); listView.removeAllViews(); - RelativeLayout rowView; - if (trackable != null && trackable.getLogs() != null) { for (LogEntry log : trackable.getLogs()) { - rowView = (RelativeLayout) inflater.inflate(R.layout.trackable_logs_item, null); + RelativeLayout rowView = (RelativeLayout) inflater.inflate(R.layout.trackable_logs_item, null); if (log.date > 0) { ((TextView) rowView.findViewById(R.id.added)).setText(Formatter.formatShortDate(log.date)); @@ -544,11 +541,10 @@ public class cgeotrackable extends AbstractActivity { return; } - BitmapDrawable image; try { HtmlImage imgGetter = new HtmlImage(trackable.getGeocode(), false, 0, false); - image = imgGetter.getDrawable(url); + BitmapDrawable image = imgGetter.getDrawable(url); Message message = handler.obtainMessage(0, image); handler.sendMessage(message); } catch (Exception e) { diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java index a821a8e..de6a4d8 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java @@ -186,7 +186,6 @@ public final class GCConstants { * see http://support.groundspeak.com/index.php?pg=kb.printer.friendly&id=1#p221 */ public static long gccodeToGCId(final String gccode) { - long gcid = 0; long base = GC_BASE31; String geocodeWO = gccode.substring(2).toUpperCase(Locale.US); @@ -194,6 +193,7 @@ public final class GCConstants { base = GC_BASE16; } + long gcid = 0; for (int p = 0; p < geocodeWO.length(); p++) { gcid = base * gcid + SEQUENCE_GCID.indexOf(geocodeWO.charAt(p)); } diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index 97e7426..8b2cfc3 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -41,10 +41,10 @@ public class GCMap { final SearchResult result = new SearchResult(); final String geocodeList = StringUtils.join(geocodes.toArray(), "|"); - final String referer = GCConstants.URL_LIVE_MAP_DETAILS; try { final Parameters params = new Parameters("i", geocodeList, "_", String.valueOf(System.currentTimeMillis())); + final String referer = GCConstants.URL_LIVE_MAP_DETAILS; final String data = StringUtils.defaultString(Tile.requestMapInfo(referer, params, referer)); // Example JSON information diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index 170bce3..840afb0 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -67,8 +67,6 @@ public abstract class GCParser { } final List<String> cids = new ArrayList<String>(); - String recaptchaChallenge = null; - String recaptchaText = null; String page = pageContent; final SearchResult searchResult = new SearchResult(); @@ -77,6 +75,7 @@ public abstract class GCParser { // recaptcha AbstractSearchThread thread = AbstractSearchThread.getCurrentInstance(); + String recaptchaChallenge = null; if (showCaptcha) { String recaptchaJsParam = BaseUtils.getMatch(page, GCConstants.PATTERN_SEARCH_RECAPTCHA, false, null); @@ -159,8 +158,6 @@ public abstract class GCParser { continue; } - String inventoryPre = null; - cache.setGeocode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_GEOCODE, true, 1, cache.getGeocode(), true)); // cache type @@ -173,6 +170,7 @@ public abstract class GCParser { // cache inventory final Matcher matcherTbs = GCConstants.PATTERN_SEARCH_TRACKABLES.matcher(row); + String inventoryPre = null; while (matcherTbs.find()) { if (matcherTbs.groupCount() > 0) { try { @@ -235,6 +233,7 @@ public abstract class GCParser { Log.w("GCParser.parseSearch: Failed to parse cache count"); } + String recaptchaText = null; if (thread != null && recaptchaChallenge != null) { if (thread.getText() == null) { thread.waitForUser(); @@ -632,10 +631,7 @@ public abstract class GCParser { } catch (Geopoint.GeopointException e) { } - int wpBegin; - int wpEnd; - - wpBegin = page.indexOf("<table class=\"Table\" id=\"ctl00_ContentBody_Waypoints\">"); + int wpBegin = page.indexOf("<table class=\"Table\" id=\"ctl00_ContentBody_Waypoints\">"); if (wpBegin != -1) { // parse waypoints if (CancellableHandler.isCancelled(handler)) { return null; @@ -644,7 +640,7 @@ public abstract class GCParser { String wpList = page.substring(wpBegin); - wpEnd = wpList.indexOf("</p>"); + int wpEnd = wpList.indexOf("</p>"); if (wpEnd > -1 && wpEnd <= wpList.length()) { wpList = wpList.substring(0, wpEnd); } @@ -661,9 +657,8 @@ public abstract class GCParser { final String[] wpItems = wpList.split("<tr"); - String[] wp; for (int j = 1; j < wpItems.length; j++) { - wp = wpItems[j].split("<td"); + String[] wp = wpItems[j].split("<td"); // waypoint name // res is null during the unit tests @@ -1694,10 +1689,9 @@ public abstract class GCParser { if (StringUtils.isEmpty(userToken)) { return false; } - final String uriPrefix = "http://www.geocaching.com/seek/cache_details.aspx/"; - JSONObject jo; try { + JSONObject jo; if (wpt != null) { jo = new JSONObject().put("dto", (new JSONObject().put("ut", userToken) .put("data", new JSONObject() @@ -1709,6 +1703,7 @@ public abstract class GCParser { final String uriSuffix = wpt != null ? "SetUserCoordinate" : "ResetUserCoordinate"; + final String uriPrefix = "http://www.geocaching.com/seek/cache_details.aspx/"; HttpResponse response = Network.postJsonRequest(uriPrefix + uriSuffix, jo); Log.i("Sending to " + uriPrefix + uriSuffix + " :" + jo.toString()); diff --git a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java index 554760c..1452157 100644 --- a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java +++ b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java @@ -51,12 +51,11 @@ public abstract class IconDecoder { final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); - int[] pngType = new int[7]; - if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) { return false; //out of image position } + int[] pngType = new int[7]; for (int x = topX; x < topX + 4; x++) { for (int y = topY; y < topY + 4; y++) { int color = bitmap.getPixel(x, y); @@ -132,12 +131,11 @@ public abstract class IconDecoder { final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); - int[] pngType = new int[5]; - if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) { return false; //out of image position } + int[] pngType = new int[5]; for (int x = topX; x < topX + 4; x++) { for (int y = topY; y < topY + 4; y++) { int color = bitmap.getPixel(x, y); @@ -212,12 +210,11 @@ public abstract class IconDecoder { final int bitmapWidth = bitmap.getWidth(); final int bitmapHeight = bitmap.getHeight(); - int[] pngType = new int[13]; - if ((topX < 0) || (topY < 0) || (topX + 4 > bitmapWidth) || (topY + 4 > bitmapHeight)) { return false; //out of image position } + int[] pngType = new int[13]; for (int x = topX; x < topX + 4; x++) { for (int y = topY; y < topY + 4; y++) { int color = bitmap.getPixel(x, y); diff --git a/main/src/cgeo/geocaching/connector/gc/Login.java b/main/src/cgeo/geocaching/connector/gc/Login.java index 093de7b..0ce385c 100644 --- a/main/src/cgeo/geocaching/connector/gc/Login.java +++ b/main/src/cgeo/geocaching/connector/gc/Login.java @@ -361,10 +361,10 @@ public abstract class Login { String[] viewstates = new String[count]; // Get the viewstates - int no; final Matcher matcherViewstates = GCConstants.PATTERN_VIEWSTATES.matcher(page); while (matcherViewstates.find()) { String sno = matcherViewstates.group(1); // number of viewstate + int no; if (sno.isEmpty()) { no = 0; } diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java index b135877..1121cc5 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java @@ -153,9 +153,8 @@ final public class OkapiClient { final JSONArray images = response.getJSONArray(CACHE_IMAGES); if (images != null) { - JSONObject imageResponse; for (int i = 0; i < images.length(); i++) { - imageResponse = images.getJSONObject(i); + JSONObject imageResponse = images.getJSONObject(i); if (imageResponse.getBoolean(CACHE_IMAGE_IS_SPOILER)) { final String title = imageResponse.getString(CACHE_IMAGE_CAPTION); final String url = absoluteUrl(imageResponse.getString(CACHE_IMAGE_URL), cache.getGeocode()); diff --git a/main/src/cgeo/geocaching/export/FieldnoteExport.java b/main/src/cgeo/geocaching/export/FieldnoteExport.java index cbb4762..6d0364e 100644 --- a/main/src/cgeo/geocaching/export/FieldnoteExport.java +++ b/main/src/cgeo/geocaching/export/FieldnoteExport.java @@ -160,10 +160,9 @@ class FieldnoteExport extends AbstractExport { SimpleDateFormat fileNameDateFormat = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US); exportFile = new File(exportLocation.toString() + '/' + fileNameDateFormat.format(new Date()) + ".txt"); - OutputStream os; Writer fw = null; try { - os = new FileOutputStream(exportFile); + OutputStream os = new FileOutputStream(exportFile); fw = new OutputStreamWriter(os, "UTF-16"); fw.write(fieldNoteBuffer.toString()); } catch (IOException e) { @@ -186,8 +185,6 @@ class FieldnoteExport extends AbstractExport { if (upload) { publishProgress(STATUS_UPLOAD); - final String uri = "http://www.geocaching.com/my/uploadfieldnotes.aspx"; - if (!Login.isActualLoginStatus()) { // no need to upload (possibly large file) if we're not logged in final StatusCode loginState = Login.login(); @@ -196,6 +193,7 @@ class FieldnoteExport extends AbstractExport { } } + final String uri = "http://www.geocaching.com/my/uploadfieldnotes.aspx"; String page = Network.getResponseData(Network.getRequest(uri)); if (!Login.getLoginStatus(page)) { diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java index d8d0c24..1c6f1af 100644 --- a/main/src/cgeo/geocaching/files/GPXImporter.java +++ b/main/src/cgeo/geocaching/files/GPXImporter.java @@ -132,10 +132,9 @@ public class GPXImporter { @Override
public void run() {
- final Collection<cgCache> caches;
try {
importStepHandler.sendMessage(importStepHandler.obtainMessage(IMPORT_STEP_START));
- caches = doImport();
+ final Collection<cgCache> caches = doImport();
Log.i("Imported successfully " + caches.size() + " caches.");
final SearchResult search = new SearchResult();
diff --git a/main/src/cgeo/geocaching/files/LocalStorage.java b/main/src/cgeo/geocaching/files/LocalStorage.java index da0f981..4cf28f7 100644 --- a/main/src/cgeo/geocaching/files/LocalStorage.java +++ b/main/src/cgeo/geocaching/files/LocalStorage.java @@ -299,9 +299,9 @@ public class LocalStorage { } private static boolean copy(final InputStream input, final OutputStream output) { - final byte[] buffer = new byte[4096]; - int length; try { + int length; + final byte[] buffer = new byte[4096]; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } diff --git a/main/src/cgeo/geocaching/gcvote/GCVote.java b/main/src/cgeo/geocaching/gcvote/GCVote.java index 5a00009..3d87724 100644 --- a/main/src/cgeo/geocaching/gcvote/GCVote.java +++ b/main/src/cgeo/geocaching/gcvote/GCVote.java @@ -98,10 +98,9 @@ public final class GCVote { return null; } - String voteData; final Matcher matcherVoteElement = patternVoteElement.matcher(page); while (matcherVoteElement.find()) { - voteData = matcherVoteElement.group(1); + String voteData = matcherVoteElement.group(1); if (voteData == null) { continue; } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 71d9c73..92018ea 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -578,9 +578,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } - MenuItem item; try { - item = menu.findItem(MENU_TRAIL_MODE); // show trail + MenuItem item = menu.findItem(MENU_TRAIL_MODE); if (Settings.isMapTrail()) { item.setTitle(res.getString(R.string.map_trail_hide)); } else { @@ -751,9 +750,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto currentTheme = currentThemeFile.getName(); } - int currentItem = 0; List<String> names = new ArrayList<String>(); names.add(res.getString(R.string.map_theme_builtin)); + int currentItem = 0; for (File file : themeFiles) { if (currentTheme.equalsIgnoreCase(file.getName())) { currentItem = names.size(); diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index e7c3903..044f69b 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -209,10 +209,9 @@ public class CachesOverlay extends AbstractItemizedOverlay { progress.show(context, context.getResources().getString(R.string.map_live), context.getResources().getString(R.string.cache_dialog_loading_details), true, null); - CachesOverlayItemImpl item = null; - // prevent concurrent changes getOverlayImpl().lock(); + CachesOverlayItemImpl item = null; try { if (index < items.size()) { item = items.get(index); diff --git a/main/src/cgeo/geocaching/maps/PositionOverlay.java b/main/src/cgeo/geocaching/maps/PositionOverlay.java index 1aa2d3b..fec67ef 100644 --- a/main/src/cgeo/geocaching/maps/PositionOverlay.java +++ b/main/src/cgeo/geocaching/maps/PositionOverlay.java @@ -158,7 +158,6 @@ public class PositionOverlay implements GeneralOverlay { if (Settings.isMapTrail()) { int size = history.size(); if (size > 1) { - int alpha; int alphaCnt = size - 201; if (alphaCnt < 1) { alphaCnt = 1; @@ -172,6 +171,7 @@ public class PositionOverlay implements GeneralOverlay { projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(prev)), historyPointP); projection.toPixels(mapItemFactory.getGeoPointBase(new Geopoint(now)), historyPointN); + int alpha; if ((alphaCnt - cnt) > 0) { alpha = 255 / (alphaCnt - cnt); } @@ -211,11 +211,8 @@ public class PositionOverlay implements GeneralOverlay { heightArrowHalf = arrow.getHeight() / 2; } - int marginLeft; - int marginTop; - - marginLeft = center.x - widthArrowHalf; - marginTop = center.y - heightArrowHalf; + int marginLeft = center.x - widthArrowHalf; + int marginTop = center.y - heightArrowHalf; Matrix matrix = new Matrix(); matrix.setRotate(heading, widthArrowHalf, heightArrowHalf); diff --git a/main/src/cgeo/geocaching/network/Network.java b/main/src/cgeo/geocaching/network/Network.java index 54f9eff..52296cc 100644 --- a/main/src/cgeo/geocaching/network/Network.java +++ b/main/src/cgeo/geocaching/network/Network.java @@ -164,8 +164,7 @@ public abstract class Network { * @return the HTTP response, or null in case of an encoding error params */ public static HttpResponse postJsonRequest(final String uri, final JSONObject json) { - HttpPost request; - request = new HttpPost(uri); + HttpPost request = new HttpPost(uri); request.addHeader("Content-Type", "application/json; charset=utf-8"); if (json != null) { try { diff --git a/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java b/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java index 36de104..d1242e8 100644 --- a/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java +++ b/main/src/cgeo/geocaching/twitter/TwitterAuthorizationActivity.java @@ -130,14 +130,13 @@ public class TwitterAuthorizationActivity extends AbstractActivity { } private void requestToken() { - final String host = "api.twitter.com"; - final String pathRequest = "/oauth/request_token"; - final String pathAuthorize = "/oauth/authorize"; - final String method = "GET"; int status = 0; try { final Parameters params = new Parameters(); + final String method = "GET"; + final String pathRequest = "/oauth/request_token"; + final String host = "api.twitter.com"; OAuth.signOAuth(host, pathRequest, method, true, params, null, null); final String line = Network.getResponseData(Network.getRequest("https://" + host + pathRequest, params)); @@ -157,6 +156,7 @@ public class TwitterAuthorizationActivity extends AbstractActivity { try { final Parameters paramsBrowser = new Parameters(); paramsBrowser.put("oauth_callback", "oob"); + final String pathAuthorize = "/oauth/authorize"; OAuth.signOAuth(host, pathAuthorize, "GET", true, paramsBrowser, OAtoken, OAtokenSecret); final String encodedParams = EntityUtils.toString(new UrlEncodedFormEntity(paramsBrowser)); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://" + host + pathAuthorize + "?" + encodedParams))); @@ -174,15 +174,15 @@ public class TwitterAuthorizationActivity extends AbstractActivity { } private void changeToken() { - final String host = "api.twitter.com"; - final String path = "/oauth/access_token"; - final String method = "POST"; int status = 0; try { final Parameters params = new Parameters("oauth_verifier", pinEntry.getText().toString()); + final String method = "POST"; + final String path = "/oauth/access_token"; + final String host = "api.twitter.com"; OAuth.signOAuth(host, path, method, true, params, OAtoken, OAtokenSecret); final String line = StringUtils.defaultString(Network.getResponseData(Network.postRequest("https://" + host + path, params))); diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java index 048e280..0ef3a43 100644 --- a/main/src/cgeo/geocaching/ui/CompassView.java +++ b/main/src/cgeo/geocaching/ui/CompassView.java @@ -185,16 +185,13 @@ public class CompassView extends View { int canvasCenterX = (compassRoseWidth / 2) + ((getWidth() - compassRoseWidth) / 2); int canvasCenterY = (compassRoseHeight / 2) + ((getHeight() - compassRoseHeight) / 2); - int marginLeftTemp; - int marginTopTemp; - super.onDraw(canvas); canvas.save(); canvas.setDrawFilter(setfil); - marginLeftTemp = (getWidth() - compassUnderlayWidth) / 2; - marginTopTemp = (getHeight() - compassUnderlayHeight) / 2; + int marginLeftTemp = (getWidth() - compassUnderlayWidth) / 2; + int marginTopTemp = (getHeight() - compassUnderlayHeight) / 2; canvas.drawBitmap(compassUnderlay, marginLeftTemp, marginTopTemp, null); diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java index 91b4fde..2287726 100644 --- a/main/src/cgeo/geocaching/ui/ImagesList.java +++ b/main/src/cgeo/geocaching/ui/ImagesList.java @@ -95,9 +95,8 @@ public class ImagesList { progressDialog.setMax(count); progressDialog.show(); - LinearLayout rowView; for (final cgImage img : images) { - rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); + LinearLayout rowView = (LinearLayout) inflater.inflate(R.layout.cache_image_item, null); if (StringUtils.isNotBlank(img.getTitle())) { ((TextView) rowView.findViewById(R.id.title)).setText(Html.fromHtml(img.getTitle())); diff --git a/main/src/cgeo/geocaching/utils/CryptUtils.java b/main/src/cgeo/geocaching/utils/CryptUtils.java index f04327e..7a23156 100644 --- a/main/src/cgeo/geocaching/utils/CryptUtils.java +++ b/main/src/cgeo/geocaching/utils/CryptUtils.java @@ -46,16 +46,14 @@ public final class CryptUtils { boolean plaintext = false; final int length = text.length(); - int c; - int capitalized; for (int index = 0; index < length; index++) { - c = text.charAt(index); + int c = text.charAt(index); if (c == '[') { plaintext = true; } else if (c == ']') { plaintext = false; } else if (!plaintext) { - capitalized = c & 32; + int capitalized = c & 32; c &= ~capitalized; c = ((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 13) % 26 + 'A') : c) | capitalized; @@ -116,16 +114,14 @@ public final class CryptUtils { boolean plaintext = false; final int length = span.length(); - int c; - int capitalized; for (int index = 0; index < length; index++) { - c = span.charAt(index); + int c = span.charAt(index); if (c == '[') { plaintext = true; } else if (c == ']') { plaintext = false; } else if (!plaintext) { - capitalized = c & 32; + int capitalized = c & 32; c &= ~capitalized; c = ((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 13) % 26 + 'A') : c) | capitalized; |