Search in sources :

Example 6 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project platform_frameworks_base by android.

the class CascadingMenuPopup method findParentViewForSubmenu.

/**
     * Attempts to find the view for the menu item that owns the specified
     * submenu.
     *
     * @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);
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) MenuItem(android.view.MenuItem) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter) Nullable(android.annotation.Nullable)

Example 7 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project android_frameworks_base by crdroidandroid.

the class CascadingMenuPopup method findParentViewForSubmenu.

/**
     * Attempts to find the view for the menu item that owns the specified
     * submenu.
     *
     * @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);
}
Also used : AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) MenuItem(android.view.MenuItem) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter) Nullable(android.annotation.Nullable)

Example 8 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project wechat by motianhuo.

the class SideBar method onTouchEvent.

public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    int i = (int) event.getY();
    int idx = i / m_nItemHeight;
    if (idx >= l.length) {
        idx = l.length - 1;
    } else if (idx < 0) {
        idx = 0;
    }
    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
        mDialogText.setVisibility(View.VISIBLE);
        mDialogText.setText("" + l[idx]);
        if (sectionIndexter == null) {
            HeaderViewListAdapter ha = (HeaderViewListAdapter) list.getAdapter();
            sectionIndexter = (SectionIndexer) ha.getWrappedAdapter();
        }
        int position = sectionIndexter.getPositionForSection(l[idx]);
        if (position == -1) {
            return true;
        }
        list.setSelection(position);
    } else {
        mDialogText.setVisibility(View.INVISIBLE);
    }
    return true;
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) Paint(android.graphics.Paint)

Example 9 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project KeepScore by nolanlawson.

the class CustomFastScrollView method getSections.

private void getSections() {
    Adapter adapter = mList.getAdapter();
    if (adapter instanceof HeaderViewListAdapter) {
        mListOffset = ((HeaderViewListAdapter) adapter).getHeadersCount();
        adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter();
    }
    if (adapter instanceof SectionIndexer) {
        mListAdapter = (BaseAdapter) adapter;
        mSections = ((SectionIndexer) mListAdapter).getSections();
    }
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) Adapter(android.widget.Adapter) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) BaseAdapter(android.widget.BaseAdapter) SectionIndexer(android.widget.SectionIndexer)

Example 10 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project robolectric by robolectric.

the class ShadowListView method getHeaderViews.

public List<View> getHeaderViews() {
    HeaderViewListAdapter adapter = (HeaderViewListAdapter) realListView.getAdapter();
    ArrayList<View> headerViews = new ArrayList<>();
    int headersCount = adapter.getHeadersCount();
    for (int i = 0; i < headersCount; i++) {
        headerViews.add(adapter.getView(i, null, realListView));
    }
    return headerViews;
}
Also used : ArrayList(java.util.ArrayList) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) View(android.view.View) ListView(android.widget.ListView)

Aggregations

HeaderViewListAdapter (android.widget.HeaderViewListAdapter)15 ListView (android.widget.ListView)9 AbsListView (android.widget.AbsListView)7 ListAdapter (android.widget.ListAdapter)7 Nullable (android.annotation.Nullable)5 MenuItem (android.view.MenuItem)5 View (android.view.View)5 Adapter (android.widget.Adapter)3 BaseAdapter (android.widget.BaseAdapter)3 SectionIndexer (android.widget.SectionIndexer)3 Paint (android.graphics.Paint)2 AdapterView (android.widget.AdapterView)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 Location (android.location.Location)1 Uri (android.net.Uri)1 Pair (android.util.Pair)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 LinearLayout (android.widget.LinearLayout)1