use of net.osmand.plus.activities.LocalIndexInfo in project Osmand by osmandapp.
the class LocalIndexesFragment method onCreateOptionsMenu.
@SuppressWarnings("deprecation")
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
if (!this.isAdded()) {
return;
}
// Next line throws NPE in some circumstances when called from dashboard and listAdpater=null is not checked for. (Checking !this.isAdded above is not sufficient!)
if (listAdapter != null && listAdapter.getGroupCount() == 0 && getDownloadActivity().getLocalIndexInfos().size() > 0) {
for (LocalIndexInfo info : getDownloadActivity().getLocalIndexInfos()) {
listAdapter.addLocalIndexInfo(info);
}
listAdapter.sortData();
getExpandableListView().setAdapter(listAdapter);
expandAllGroups();
}
ActionBar actionBar = getDownloadActivity().getSupportActionBar();
// hide action bar from downloadindexfragment
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
optionsMenuAdapter = new ContextMenuAdapter();
ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
localOptionsMenu(itemId);
return true;
}
};
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_reload, getContext()).setIcon(R.drawable.ic_action_refresh_dark).setListener(listener).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_delete, getContext()).setIcon(R.drawable.ic_action_delete_dark).setListener(listener).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_backup, getContext()).setListener(listener).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.local_index_mi_restore, getContext()).setListener(listener).createItem());
// doesn't work correctly
// int max = getResources().getInteger(R.integer.abs__max_action_buttons);
int max = 3;
SubMenu split = null;
for (int j = 0; j < optionsMenuAdapter.length(); j++) {
MenuItem item;
ContextMenuItem contextMenuItem = optionsMenuAdapter.getItem(j);
if (j + 1 >= max && optionsMenuAdapter.length() > max) {
if (split == null) {
split = menu.addSubMenu(0, 1, j + 1, R.string.shared_string_more_actions);
split.setIcon(R.drawable.ic_overflow_menu_white);
split.getItem();
MenuItemCompat.setShowAsAction(split.getItem(), MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
item = split.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
} else {
item = menu.add(0, contextMenuItem.getTitleId(), j + 1, contextMenuItem.getTitle());
MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}
if (contextMenuItem.getIcon() != -1) {
item.setIcon(contextMenuItem.getIcon());
}
}
if (operationTask == null || operationTask.getStatus() == AsyncTask.Status.FINISHED) {
menu.setGroupVisible(0, true);
} else {
menu.setGroupVisible(0, false);
}
}
Aggregations