Search in sources :

Example 6 with LocalIndexInfo

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);
    }
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo) ActionBar(android.support.v7.app.ActionBar) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

LocalIndexInfo (net.osmand.plus.activities.LocalIndexInfo)6 MenuItem (android.view.MenuItem)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Paint (android.graphics.Paint)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 PopupMenu (android.support.v7.widget.PopupMenu)1 TextPaint (android.text.TextPaint)1 SubMenu (android.view.SubMenu)1 OnClickListener (android.view.View.OnClickListener)1 ArrayAdapter (android.widget.ArrayAdapter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 BinaryMapDataObject (net.osmand.binary.BinaryMapDataObject)1 TagValuePair (net.osmand.binary.BinaryMapIndexReader.TagValuePair)1 LatLon (net.osmand.data.LatLon)1