use of android.widget.AdapterView.AdapterContextMenuInfo in project c-geo by just-radovan.
the class cgeocaches method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo info) {
super.onCreateContextMenu(menu, view, info);
if (adapter == null) {
return;
}
AdapterContextMenuInfo adapterInfo = null;
try {
adapterInfo = (AdapterContextMenuInfo) info;
} catch (Exception e) {
Log.w(cgSettings.tag, "cgeocaches.onCreateContextMenu: " + e.toString());
}
if ((adapterInfo == null || adapterInfo.position < 0) && selectedFilter != null) {
if (selectedFilter.equals(res.getString(R.string.caches_filter_size))) {
menu.setHeaderTitle(res.getString(R.string.caches_filter_size_title));
menu.add(0, 8, 0, res.getString(R.string.caches_filter_size_micro));
menu.add(0, 9, 0, res.getString(R.string.caches_filter_size_small));
menu.add(0, 10, 0, res.getString(R.string.caches_filter_size_regular));
menu.add(0, 11, 0, res.getString(R.string.caches_filter_size_large));
menu.add(0, 12, 0, res.getString(R.string.caches_filter_size_other));
menu.add(0, 13, 0, res.getString(R.string.caches_filter_size_virtual));
menu.add(0, 14, 0, res.getString(R.string.caches_filter_size_notchosen));
} else if (selectedFilter.equals(res.getString(R.string.caches_filter_type))) {
menu.setHeaderTitle(res.getString(R.string.caches_filter_type_title));
menu.add(0, 15, 0, res.getString(R.string.caches_filter_type_traditional));
menu.add(0, 16, 0, res.getString(R.string.caches_filter_type_multi));
menu.add(0, 17, 0, res.getString(R.string.caches_filter_type_mystery));
menu.add(0, 18, 0, res.getString(R.string.caches_filter_type_letterbox));
menu.add(0, 19, 0, res.getString(R.string.caches_filter_type_event));
menu.add(0, 20, 0, res.getString(R.string.caches_filter_type_mega));
menu.add(0, 21, 0, res.getString(R.string.caches_filter_type_earth));
menu.add(0, 22, 0, res.getString(R.string.caches_filter_type_cito));
menu.add(0, 23, 0, res.getString(R.string.caches_filter_type_webcam));
menu.add(0, 24, 0, res.getString(R.string.caches_filter_type_virtual));
menu.add(0, 25, 0, res.getString(R.string.caches_filter_type_wherigo));
menu.add(0, 26, 0, res.getString(R.string.caches_filter_type_lostfound));
menu.add(0, 27, 0, res.getString(R.string.caches_filter_type_ape));
menu.add(0, 28, 0, res.getString(R.string.caches_filter_type_gchq));
menu.add(0, 29, 0, res.getString(R.string.caches_filter_type_gps));
}
} else {
final cgCache cache = adapter.getItem(adapterInfo.position);
if (cache.name != null && cache.name.length() > 0) {
menu.setHeaderTitle(cache.name);
} else {
menu.setHeaderTitle(cache.geocode);
}
if (cache.latitude != null && cache.longitude != null) {
menu.add(0, 1, 0, res.getString(R.string.cache_menu_compass));
menu.add(0, 2, 0, res.getString(R.string.cache_menu_radar));
menu.add(0, 3, 0, res.getString(R.string.cache_menu_map));
menu.add(0, 4, 0, res.getString(R.string.cache_menu_map_ext));
menu.add(0, 5, 0, res.getString(R.string.cache_menu_tbt));
menu.add(0, 6, 0, res.getString(R.string.cache_menu_visit));
menu.add(0, 7, 0, res.getString(R.string.cache_menu_details));
}
}
ArrayList<cgList> cacheLists = app.getLists();
int listCount = cacheLists.size();
if (listCount > 1) {
SubMenu submenu = menu.addSubMenu(0, 8, 0, res.getString(R.string.cache_menu_move_list));
for (int i = 0; i < listCount; i++) {
cgList list = cacheLists.get(i);
submenu.add(Menu.NONE, 100 + list.id, Menu.NONE, list.title);
}
}
}
use of android.widget.AdapterView.AdapterContextMenuInfo in project c-geo by just-radovan.
the class cgeocaches method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
final int id = item.getItemId();
ContextMenu.ContextMenuInfo info = item.getMenuInfo();
if (info == null) {
if (adapter != null) {
if (id == 8) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_micro)));
} else if (id == 9) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_small)));
} else if (id == 10) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_regular)));
} else if (id == 11) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_large)));
} else if (id == 12) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_other)));
} else if (id == 13) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_virtual)));
} else if (id == 14) {
adapter.setFilter(new cgFilterBySize(res.getString(R.string.caches_filter_size_notchosen)));
} else if (id == 15) {
adapter.setFilter(new cgFilterByType("traditional"));
} else if (id == 16) {
adapter.setFilter(new cgFilterByType("multi"));
} else if (id == 17) {
adapter.setFilter(new cgFilterByType("mystery"));
} else if (id == 18) {
adapter.setFilter(new cgFilterByType("letterbox"));
} else if (id == 19) {
adapter.setFilter(new cgFilterByType("event"));
} else if (id == 20) {
adapter.setFilter(new cgFilterByType("mega"));
} else if (id == 21) {
adapter.setFilter(new cgFilterByType("earth"));
} else if (id == 22) {
adapter.setFilter(new cgFilterByType("cito"));
} else if (id == 23) {
adapter.setFilter(new cgFilterByType("webcam"));
} else if (id == 24) {
adapter.setFilter(new cgFilterByType("virtual"));
} else if (id == 25) {
adapter.setFilter(new cgFilterByType("wherigo"));
} else if (id == 26) {
adapter.setFilter(new cgFilterByType("lostfound"));
} else if (id == 27) {
adapter.setFilter(new cgFilterByType("ape"));
} else if (id == 28) {
adapter.setFilter(new cgFilterByType("gchq"));
} else if (id == 29) {
adapter.setFilter(new cgFilterByType("gps"));
} else {
return false;
}
return true;
} else {
// restore menu info for sub menu items, see https://code.google.com/p/android/issues/detail?id=7139
info = lastMenuInfo;
lastMenuInfo = null;
return false;
}
}
AdapterContextMenuInfo adapterInfo = null;
try {
adapterInfo = (AdapterContextMenuInfo) info;
} catch (Exception e) {
Log.w(cgSettings.tag, "cgeocaches.onContextItemSelected: " + e.toString());
}
final int touchedPos = adapterInfo.position;
final cgCache cache = adapter.getItem(touchedPos);
if (id == 1) {
// compass
Intent navigateIntent = new Intent(activity, cgeonavigate.class);
navigateIntent.putExtra("latitude", cache.latitude);
navigateIntent.putExtra("longitude", cache.longitude);
navigateIntent.putExtra("geocode", cache.geocode.toUpperCase());
navigateIntent.putExtra("name", cache.name);
activity.startActivity(navigateIntent);
return true;
} else if (id == 2) {
// radar
try {
if (cgBase.isIntentAvailable(activity, "com.google.android.radar.SHOW_RADAR") == true) {
Intent radarIntent = new Intent("com.google.android.radar.SHOW_RADAR");
radarIntent.putExtra("latitude", new Float(cache.latitude));
radarIntent.putExtra("longitude", new Float(cache.longitude));
activity.startActivity(radarIntent);
} else {
AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
dialog.setTitle(res.getString(R.string.err_radar_title));
dialog.setMessage(res.getString(R.string.err_radar_message));
dialog.setCancelable(true);
dialog.setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:com.eclipsim.gpsstatus2")));
dialog.cancel();
} catch (Exception e) {
warning.showToast(res.getString(R.string.err_radar_market));
Log.e(cgSettings.tag, "cgeocaches.onContextItemSelected.radar.onClick: " + e.toString());
}
}
});
dialog.setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = dialog.create();
alert.show();
}
} catch (Exception e) {
warning.showToast(res.getString(R.string.err_radar_generic));
Log.e(cgSettings.tag, "cgeocaches.onContextItemSelected.radar: " + e.toString());
}
return true;
} else if (id == 3) {
// show on map
Intent mapIntent = new Intent(activity, settings.getMapFactory().getMapClass());
mapIntent.putExtra("detail", false);
mapIntent.putExtra("geocode", cache.geocode);
activity.startActivity(mapIntent);
return true;
} else if (id == 4) {
// show on external map
base.runExternalMap(0, activity, res, warning, tracker, cache);
return true;
} else if (id == 5) {
// turn-by-turn
if (geo != null) {
base.runNavigation(activity, res, settings, warning, tracker, cache.latitude, cache.longitude, geo.latitudeNow, geo.longitudeNow);
} else {
base.runNavigation(activity, res, settings, warning, tracker, cache.latitude, cache.longitude);
}
return true;
} else if (id == 6) {
// log visit
if (cache.cacheid == null || cache.cacheid.length() == 0) {
warning.showToast(res.getString(R.string.err_cannot_log_visit));
return true;
}
Intent logVisitIntent = new Intent(activity, cgeovisit.class);
logVisitIntent.putExtra("id", cache.cacheid);
logVisitIntent.putExtra("geocode", cache.geocode.toUpperCase());
logVisitIntent.putExtra("type", cache.type.toLowerCase());
activity.startActivity(logVisitIntent);
return true;
} else if (id == 7) {
// cache details
Intent cachesIntent = new Intent(activity, cgeodetail.class);
cachesIntent.putExtra("geocode", cache.geocode.toUpperCase());
cachesIntent.putExtra("name", cache.name);
activity.startActivity(cachesIntent);
return true;
} else if (id == 8) {
// move to list (sub menu)
// we must remember the menu info for the sub menu, there is a bug in Android:
// https://code.google.com/p/android/issues/detail?id=7139
lastMenuInfo = info;
return true;
} else if (id >= 100) {
// move to list
int newListId = id - 100;
app.moveToList(cache.geocode, newListId);
// refresh list by switching to the current list
switchListById(listId);
return true;
}
return false;
}
use of android.widget.AdapterView.AdapterContextMenuInfo in project tree-view-list-android by Polidea.
the class TreeViewListDemo method onCreateContextMenu.
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
final AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo;
final long id = adapterInfo.id;
final TreeNodeInfo<Long> info = manager.getNodeInfo(id);
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.context_menu, menu);
if (info.isWithChildren()) {
if (info.isExpanded()) {
menu.findItem(R.id.context_menu_expand_item).setVisible(false);
menu.findItem(R.id.context_menu_expand_all).setVisible(false);
} else {
menu.findItem(R.id.context_menu_collapse).setVisible(false);
}
} else {
menu.findItem(R.id.context_menu_expand_item).setVisible(false);
menu.findItem(R.id.context_menu_expand_all).setVisible(false);
menu.findItem(R.id.context_menu_collapse).setVisible(false);
}
super.onCreateContextMenu(menu, v, menuInfo);
}
use of android.widget.AdapterView.AdapterContextMenuInfo in project RoboBinding-gallery by RoboBinding.
the class ContextMenuPresentationModel method deleteProduct.
public void deleteProduct(MenuItem menuItem) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) menuItem.getMenuInfo();
Product deletedProduct = productStore.remove(menuInfo.position);
productOperationListener.onProductDeleted(deletedProduct);
}
use of android.widget.AdapterView.AdapterContextMenuInfo in project xabber-android by redsolution.
the class ContactListFragment method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
BaseEntity baseEntity = (BaseEntity) listView.getItemAtPosition(info.position);
if (baseEntity instanceof AbstractContact) {
ContextMenuHelper.createContactContextMenu(getActivity(), adapter, (AbstractContact) baseEntity, menu);
} else if (baseEntity instanceof AccountConfiguration) {
ContextMenuHelper.createAccountContextMenu(getActivity(), adapter, baseEntity.getAccount(), menu);
} else if (baseEntity instanceof GroupConfiguration) {
ContextMenuHelper.createGroupContextMenu(getActivity(), adapter, baseEntity.getAccount(), baseEntity.getUser(), menu);
} else {
throw new IllegalStateException();
}
}
Aggregations