aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-04-28 12:07:21 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-04-28 13:30:09 +0200
commit7f376a5f33d54b0d5d3d223b45b823433f3d9764 (patch)
treec763a94f06f3bae0f435515fa56d3f6cf0612807 /main/src
parent49716bc6a97ca76ff2b0ff90f0b06d826a1a6220 (diff)
downloadcgeo-7f376a5f33d54b0d5d3d223b45b823433f3d9764.zip
cgeo-7f376a5f33d54b0d5d3d223b45b823433f3d9764.tar.gz
cgeo-7f376a5f33d54b0d5d3d223b45b823433f3d9764.tar.bz2
Refactoring: use switch instead of chained if/else
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java54
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java37
-rw-r--r--main/src/cgeo/geocaching/cgeotrackable.java27
-rw-r--r--main/src/cgeo/geocaching/cgeowaypoint.java29
4 files changed, 73 insertions, 74 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index fc92d28..54943f9 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -551,33 +551,32 @@ public class CacheDetailActivity extends AbstractActivity {
public boolean onOptionsItemSelected(MenuItem item) {
final int menuItem = item.getItemId();
- // no menu selected, but a new sub menu shown
- if (menuItem == 0) {
- return false;
- }
-
- if (menuItem == MENU_DEFAULT_NAVIGATION) {
- startDefaultNavigation();
- return true;
- } else if (menuItem == MENU_LOG_VISIT) {
- refreshOnResume = true;
- cache.logVisit(this);
- return true;
- } else if (menuItem == MENU_BROWSER) {
- cache.openInBrowser(this);
- return true;
- } else if (menuItem == MENU_CACHES_AROUND) {
- cgeocaches.startActivityCachesAround(this, cache.getCoords());
- return true;
- } else if (menuItem == MENU_CALENDAR) {
- addToCalendarWithIntent();
- return true;
- } else if (menuItem == MENU_SHARE) {
- if (cache != null) {
- cache.shareCache(this, res);
+ switch(menuItem) {
+ case 0:
+ // no menu selected, but a new sub menu shown
+ return false;
+ case MENU_DEFAULT_NAVIGATION:
+ startDefaultNavigation();
return true;
- }
- return false;
+ case MENU_LOG_VISIT:
+ refreshOnResume = true;
+ cache.logVisit(this);
+ return true;
+ case MENU_BROWSER:
+ cache.openInBrowser(this);
+ return true;
+ case MENU_CACHES_AROUND:
+ cgeocaches.startActivityCachesAround(this, cache.getCoords());
+ return true;
+ case MENU_CALENDAR:
+ addToCalendarWithIntent();
+ return true;
+ case MENU_SHARE:
+ if (cache != null) {
+ cache.shareCache(this, res);
+ return true;
+ }
+ return false;
}
if (NavigationAppFactory.onMenuItemSelected(item, app.currentGeo(), this, cache, null, null)) {
return true;
@@ -586,8 +585,7 @@ public class CacheDetailActivity extends AbstractActivity {
return true;
}
- int logType = menuItem - MENU_LOG_VISIT_OFFLINE;
- cache.logOffline(this, LogType.getById(logType));
+ cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
return true;
}
diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java
index 6760a1d..dc98928 100644
--- a/main/src/cgeo/geocaching/cgeopopup.java
+++ b/main/src/cgeo/geocaching/cgeopopup.java
@@ -197,26 +197,27 @@ public class cgeopopup extends AbstractActivity {
public boolean onOptionsItemSelected(MenuItem item) {
final int menuItem = item.getItemId();
- if (menuItem == 2) {
- navigateTo();
- return true;
- } else if (menuItem == 3) {
- NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, cache, null, null);
- return true;
- } else if (menuItem == 5) {
- cachesAround();
- return true;
- } else if (menuItem == MENU_LOG_VISIT) {
- cache.logVisit(this);
- finish();
- return true;
- } else if (menuItem == 7) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode())));
- return true;
+ switch (menuItem) {
+ case 2:
+ navigateTo();
+ break;
+ case 3:
+ NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, cache, null, null);
+ break;
+ case 5:
+ cachesAround();
+ break;
+ case MENU_LOG_VISIT:
+ cache.logVisit(this);
+ finish();
+ break;
+ case 7:
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode())));
+ break;
+ default:
+ cache.logOffline(this, LogType.getById(menuItem - MENU_LOG_VISIT_OFFLINE));
}
- int logType = menuItem - MENU_LOG_VISIT_OFFLINE;
- cache.logOffline(this, LogType.getById(logType));
return true;
}
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java
index 7078200..2a0a017 100644
--- a/main/src/cgeo/geocaching/cgeotrackable.java
+++ b/main/src/cgeo/geocaching/cgeotrackable.java
@@ -350,21 +350,20 @@ public class cgeotrackable extends AbstractActivity {
}
@Override
- public boolean onContextItemSelected(MenuItem item) {
- final int id = item.getItemId();
-
- if (id == 1) {
- cgeocaches.startActivityOwner(this, contextMenuUser);
- return true;
- } else if (id == 2) {
- cgeocaches.startActivityUserName(this, contextMenuUser);
- return true;
- } else if (id == 3) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser))));
-
- return true;
+ public boolean onContextItemSelected(final MenuItem item) {
+ switch (item.getItemId()) {
+ case 1:
+ cgeocaches.startActivityOwner(this, contextMenuUser);
+ return true;
+ case 2:
+ cgeocaches.startActivityUserName(this, contextMenuUser);
+ return true;
+ case 3:
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/profile/?u=" + URLEncoder.encode(contextMenuUser))));
+ return true;
+ default:
+ return false;
}
- return false;
}
@Override
diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java
index 697ffd0..e8aa770 100644
--- a/main/src/cgeo/geocaching/cgeowaypoint.java
+++ b/main/src/cgeo/geocaching/cgeowaypoint.java
@@ -217,21 +217,22 @@ public class cgeowaypoint extends AbstractActivity implements IObserver<IGeoData
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- final int menuItem = item.getItemId();
- if (menuItem == MENU_ID_DEFAULT_NAVIGATION) {
- goDefaultNavigation(null);
- return true;
- } else if (menuItem == MENU_ID_CACHES_AROUND) {
- cachesAround();
- return true;
- } else if (menuItem == MENU_ID_OPEN_GEOCACHE) {
- goToGeocache();
- return true;
- } else if (menuItem == MENU_ID_NAVIGATION) {
- NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, null, waypoint, null);
- return true;
+ switch (item.getItemId()) {
+ case MENU_ID_DEFAULT_NAVIGATION:
+ goDefaultNavigation(null);
+ return true;
+ case MENU_ID_CACHES_AROUND:
+ cachesAround();
+ return true;
+ case MENU_ID_OPEN_GEOCACHE:
+ goToGeocache();
+ return true;
+ case MENU_ID_NAVIGATION:
+ NavigationAppFactory.showNavigationMenu(app.currentGeo(), this, null, waypoint, null);
+ return true;
+ default:
+ return false;
}
- return false;
}
private void cachesAround() {