Example usage for android.widget HeaderViewListAdapter getHeadersCount

List of usage examples for android.widget HeaderViewListAdapter getHeadersCount

Introduction

In this page you can find the example usage for android.widget HeaderViewListAdapter getHeadersCount.

Prototype

public int getHeadersCount() 

Source Link

Usage

From source file:com.poloure.simplerss.Utilities.java

static void setTitlesAndDrawerAndPage(Fragment fragment, int absolutePos) {
    String[] navTitles = s_resources.getStringArray(R.array.navigation_titles);

    if (null != fragment) {
        switchToFragment(fragment, false);
    }//from   w  ww .j  av  a 2s .c  o m

    ListView list = s_fragmentDrawer.m_listView;
    HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) list.getAdapter();
    int headers = headerAdapter.getHeadersCount();

    int listPosition = -10 == absolutePos ? s_viewPager.getCurrentItem() + headers : absolutePos;
    int viewPagerPos = -10 == absolutePos ? s_viewPager.getCurrentItem() : absolutePos - headers;

    // Check the drawer item.
    String title = PagerAdapterTags.s_tagList.get(0);
    String subTitle = null;
    int imageRes = R.drawable.ic_action_labels;

    if (s_fragmentFavourites.isVisible()) {
        listPosition = 0;
        title = navTitles[0];
        imageRes = R.drawable.ic_action_important;
    } else if (s_fragmentManage.isVisible()) {
        listPosition = 1;
        title = navTitles[1];
        imageRes = R.drawable.ic_action_storage;
    } else if (s_fragmentSettings.isVisible()) {
        listPosition = 2;
        title = navTitles[2];
        imageRes = R.drawable.ic_action_settings;
    } else {
        ArrayAdapter<String[]> adapter = (ArrayAdapter<String[]>) headerAdapter.getWrappedAdapter();

        if (null != adapter && 0 < adapter.getCount()) {
            String[] item = adapter.getItem(viewPagerPos);
            title = item[0];
            int count = null == item[1] || item[1].isEmpty() ? 0 : Integer.parseInt(item[1]);
            String countString = s_resources.getQuantityString(R.plurals.actionbar_subtitle_unread, count,
                    count);
            subTitle = 0 == count ? null : countString;
        }
    }
    s_actionBar.setTitle(title);
    s_actionBar.setSubtitle(subTitle);
    s_actionBar.setIcon(imageRes);

    list.setItemChecked(listPosition, true);

    // If we must change the view pager page.
    if (0 <= viewPagerPos) {
        // Switch the view pager page if different.
        if (s_viewPager.getCurrentItem() != viewPagerPos) {
            s_viewPager.setCurrentItem(viewPagerPos);
        }
    }
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

/**
 * Attempts to find the view for the menu item that owns the specified
 * submenu./*from   w ww.j  a  va2 s.com*/
 *
 * @param parentInfo info for the parent menu
 * @param submenu the submenu whose parent view should be obtained
 * @return the parent view, or {@code null} if one could not be found
 */
@Nullable
private View findParentViewForSubmenu(@NonNull CascadingMenuInfo parentInfo, @NonNull MenuBuilder submenu) {
    final MenuItem owner = findMenuItemForSubmenu(parentInfo.menu, submenu);
    if (owner == null) {
        // Couldn't find the submenu owner.
        return null;
    }

    // The adapter may be wrapped. Adjust the index if necessary.
    final int headersCount;
    final MenuAdapter menuAdapter;
    final ListView listView = parentInfo.getListView();
    final ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter instanceof HeaderViewListAdapter) {
        final HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) listAdapter;
        headersCount = headerAdapter.getHeadersCount();
        menuAdapter = (MenuAdapter) headerAdapter.getWrappedAdapter();
    } else {
        headersCount = 0;
        menuAdapter = (MenuAdapter) listAdapter;
    }

    // Find the index within the menu adapter's data set of the menu item.
    int ownerPosition = AbsListView.INVALID_POSITION;
    for (int i = 0, count = menuAdapter.getCount(); i < count; i++) {
        if (owner == menuAdapter.getItem(i)) {
            ownerPosition = i;
            break;
        }
    }
    if (ownerPosition == AbsListView.INVALID_POSITION) {
        // Couldn't find the owner within the menu adapter.
        return null;
    }

    // Adjust the index for the adapter used to display views.
    ownerPosition += headersCount;

    // Adjust the index for the visible views.
    final int ownerViewPosition = ownerPosition - listView.getFirstVisiblePosition();
    if (ownerViewPosition < 0 || ownerViewPosition >= listView.getChildCount()) {
        // Not visible on screen.
        return null;
    }

    return listView.getChildAt(ownerViewPosition);
}