diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2011-08-28 09:12:53 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2011-08-28 09:12:53 +0200 |
| commit | c56576fbae758d16d5698be0c7de6a0b19b744e8 (patch) | |
| tree | 10de4af77932de1bf11d15977a3a63c0d7e6676c /src | |
| parent | afbe8c5164e1157e38e0f8c4b28942cbd9fe3d41 (diff) | |
| download | cgeo-c56576fbae758d16d5698be0c7de6a0b19b744e8.zip cgeo-c56576fbae758d16d5698be0c7de6a0b19b744e8.tar.gz cgeo-c56576fbae758d16d5698be0c7de6a0b19b744e8.tar.bz2 | |
new: open context menu on offline button on home screen for faster
selection of cache list
Diffstat (limited to 'src')
| -rw-r--r-- | src/cgeo/geocaching/cgeo.java | 22 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeocaches.java | 60 |
2 files changed, 49 insertions, 33 deletions
diff --git a/src/cgeo/geocaching/cgeo.java b/src/cgeo/geocaching/cgeo.java index fcc1248..df167fb 100644 --- a/src/cgeo/geocaching/cgeo.java +++ b/src/cgeo/geocaching/cgeo.java @@ -38,8 +38,8 @@ public class cgeo extends AbstractActivity { private static final int MENU_SETTINGS = 2; private static final int MENU_HISTORY = 3; private static final int MENU_SCAN = 4; - private static final int SCAN_REQUEST_CODE = 1; + private static final int MENU_OPEN_LIST = 100; private Context context = null; private Integer version = null; @@ -307,6 +307,20 @@ public class cgeo extends AbstractActivity { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); + + // context menu for offline button + if (v.getId() == R.id.search_offline) { + ArrayList<cgList> cacheLists = app.getLists(); + int listCount = cacheLists.size(); + menu.setHeaderTitle(res.getString(R.string.list_title)); + for (int i = 0; i < listCount; i++) { + cgList list = cacheLists.get(i); + menu.add(Menu.NONE, MENU_OPEN_LIST + list.id, Menu.NONE, list.title); + } + return; + } + + // standard context menu menu.setHeaderTitle(res.getString(R.string.menu_filter)); //first add the most used types @@ -356,6 +370,11 @@ public class cgeo extends AbstractActivity { setFilterTitle(); return true; + } else if (id > MENU_OPEN_LIST) { + int listId = id - MENU_OPEN_LIST; + settings.saveLastList(listId); + cgeocaches.startActivityOffline(context); + return true; } else if (id > 0) { String itemTitle = item.getTitle().toString(); String choice = null; @@ -435,6 +454,7 @@ public class cgeo extends AbstractActivity { final RelativeLayout findByOffline = (RelativeLayout) findViewById(R.id.search_offline); findByOffline.setClickable(true); findByOffline.setOnClickListener(new cgeoFindByOfflineListener()); + registerForContextMenu(findByOffline); (new countBubbleUpdate()).start(); diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java index e8586cc..27cb5b3 100644 --- a/src/cgeo/geocaching/cgeocaches.java +++ b/src/cgeo/geocaching/cgeocaches.java @@ -16,6 +16,7 @@ import java.util.Locale; import android.app.AlertDialog; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; @@ -61,6 +62,7 @@ import cgeo.geocaching.sorting.VoteComparator; public class cgeocaches extends AbstractListActivity { + private static final String EXTRAS_LIST_TYPE = "type"; private static final int MENU_COMPASS = 1; private static final int MENU_REFRESH_STORED = 2; private static final int MENU_CACHE_DETAILS = 4; @@ -123,8 +125,7 @@ public class cgeocaches extends AbstractListActivity { private static final int CONTEXT_MENU_MOVE_TO_LIST = 1000; private static final int MENU_MOVE_SELECTED_OR_ALL_TO_LIST = 1200; - - + private String action = null; private String type = null; private Double latitude = null; @@ -342,7 +343,7 @@ public class cgeocaches extends AbstractListActivity { int secondsElapsed = (int)((System.currentTimeMillis() - detailProgressTime) / 1000); int minutesRemaining = (int) ((detailTotal - detailProgress) * secondsElapsed / ((detailProgress > 0) ? detailProgress : 1) / 60); - + waitDialog.setProgress(detailProgress); if (minutesRemaining < 1) { waitDialog.setMessage(res.getString(R.string.caches_downloading) + " " + res.getString(R.string.caches_eta_ltm)); @@ -399,8 +400,8 @@ public class cgeocaches extends AbstractListActivity { } else if (msg.what == 2) { //Cache downloaded waitDialog.setMessage(res.getString(R.string.web_downloaded)+" "+(String)msg.obj+"."); //Once a cache is downloaded I used switchList to refresh it. - switchList(listId, -1); - } else if (msg.what == -2) { + switchListById(listId); + } else if (msg.what == -2) { if (waitDialog != null) { waitDialog.dismiss(); waitDialog.setOnCancelListener(null); @@ -445,7 +446,7 @@ public class cgeocaches extends AbstractListActivity { adapter.setSelectMode(false, true); } - switchList(listId, -1); + switchListById(listId); cacheList.clear(); @@ -545,7 +546,7 @@ public class cgeocaches extends AbstractListActivity { // get parameters Bundle extras = getIntent().getExtras(); if (extras != null) { - type = extras.getString("type"); + type = extras.getString(EXTRAS_LIST_TYPE); latitude = extras.getDouble("latitude"); longitude = extras.getDouble("longitude"); cachetype = extras.getString("cachetype"); @@ -1032,7 +1033,7 @@ public class cgeocaches extends AbstractListActivity { if (adapter == null) { return; } - + if (contextMenuMoveToList) { createFakeContextMenuMoveToList(menu); return; @@ -1225,7 +1226,7 @@ public class cgeocaches extends AbstractListActivity { cgBase.dropCache(app, this, cache, new Handler() { @Override public void handleMessage(Message msg) { - switchList(listId, -1); // refresh + switchListById(listId); // refresh } }); return true; @@ -1265,12 +1266,12 @@ public class cgeocaches extends AbstractListActivity { HashMap<String, String> params = new HashMap<String, String>(); params.put("geocode", cache.geocode); Long singleSearchId = base.searchByGeocode(params, 0, false); - + if (NavigationAppFactory.onMenuItemSelected(item, geo, this, res, cache, singleSearchId, null, null)) { return true; } - + int logType = id - MENU_LOG_VISIT_OFFLINE; cache.logOffline(this, logType); } @@ -2382,7 +2383,7 @@ public class cgeocaches extends AbstractListActivity { builder.setTitle(res.getString(R.string.list_title)); builder.setItems(listsTitle.toArray(items), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int item) { - switchListByOrder(item); + switchListById(lists.get(item).id); return; } @@ -2390,30 +2391,11 @@ public class cgeocaches extends AbstractListActivity { builder.create().show(); } - public void switchListByOrder(int order) { - switchList(-1, order); - } - public void switchListById(int id) { - switchList(id, -1); - } - - private class MoveHandler extends Handler { - @Override - public void handleMessage(Message msg) { - Thread threadPure = new geocachesLoadByOffline(loadCachesHandler, latitude, longitude, msg.what); - threadPure.start(); - } - } - - public void switchList(int id, int order) { cgList list = null; if (id >= 0) { list = app.getList(id); - } else if (order >= 0) { - lists = app.getLists(); - list = lists.get(order); } else { return; } @@ -2433,6 +2415,14 @@ public class cgeocaches extends AbstractListActivity { (new moveCachesToList(listId, new MoveHandler())).start(); } + private class MoveHandler extends Handler { + @Override + public void handleMessage(Message msg) { + Thread threadPure = new geocachesLoadByOffline(loadCachesHandler, latitude, longitude, msg.what); + threadPure.start(); + } + } + private class moveCachesToList extends Thread { int listId = -1; Handler handler = null; @@ -2542,4 +2532,10 @@ public class cgeocaches extends AbstractListActivity { ActivityMixin.goManual(this, "c:geo-nearby"); } } -} + + public static void startActivityOffline(final Context context) { + final Intent cachesIntent = new Intent(context, cgeocaches.class); + cachesIntent.putExtra(EXTRAS_LIST_TYPE, "offline"); + context.startActivity(cachesIntent); + } +}
\ No newline at end of file |
