summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/menuhandler/MenuItemUtils.java
blob: c4a96ac3fd5ddb260b66125bb893300089ee79e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package de.danoeh.antennapod.menuhandler;

import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuItem;

import de.danoeh.antennapod.core.R;

/**
 * Utilities for menu items
 */
public class MenuItemUtils {

    public static MenuItem addSearchItem(Menu menu, SearchView searchView) {
        MenuItem item = menu.add(Menu.NONE, R.id.search_item, Menu.NONE, R.string.search_label);
        MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
        MenuItemCompat.setActionView(item, searchView);
        return item;
    }

    /**
     * Checks if the navigation drawer of the DrawerActivity is opened. This can be useful for Fragments
     * that hide their menu if the navigation drawer is open.
     *
     * @return True if the drawer is open, false otherwise (also if the parameter is null)
     */
    public static boolean isActivityDrawerOpen(NavDrawerActivity activity) {
        return activity != null && activity.isDrawerOpen();
    }
}