Search in sources :

Example 1 with HeaderViewListAdapter

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

the class SuperSaiyanScrollView 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 2 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project UltimateAndroid by cymcsg.

the class DynamicListView method swapElements.

private void swapElements(int indexOne, int indexTwo) {
    mLastMovedToIndex = indexTwo;
    ListAdapter adapter = getAdapter();
    if (adapter instanceof HeaderViewListAdapter) {
        adapter = ((HeaderViewListAdapter) adapter).getWrappedAdapter();
    }
    if (adapter instanceof Swappable) {
        ((Swappable) adapter).swapItems(indexOne - getHeaderViewsCount(), indexTwo - getHeaderViewsCount());
    }
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter)

Example 3 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project UltimateAndroid by cymcsg.

the class DynamicListView method handleCellSwitch.

/**
     * This method determines whether the hover cell has been shifted far enough
     * to invoke a cell swap. If so, then the respective cell swap candidate is
     * determined and the data set is changed. Upon posting a notification of the
     * data set change, a layout is invoked to place the cells in the right place.
     * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
     * offset the cell being swapped to where it previously was and then animate it to
     * its new position.
     */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;
    View belowView = getViewForId(mBelowItemId);
    View mobileView = getViewForId(mMobileItemId);
    View aboveView = getViewForId(mAboveItemId);
    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());
    if (isBelow || isAbove) {
        final long switchItemId = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView);
        if (switchView == null) {
            updateNeighborViewsForId(mMobileItemId);
            return;
        }
        if (getPositionForView(switchView) < getHeaderViewsCount()) {
            return;
        }
        swapElements(originalItem, getPositionForView(switchView));
        BaseAdapter adapter;
        if (getAdapter() instanceof HeaderViewListAdapter) {
            adapter = (BaseAdapter) ((HeaderViewListAdapter) getAdapter()).getWrappedAdapter();
        } else {
            adapter = (BaseAdapter) getAdapter();
        }
        adapter.notifyDataSetChanged();
        mDownY = mLastEventY;
        mDownX = mLastEventX;
        final int switchViewStartTop = switchView.getTop();
        mobileView.setVisibility(View.VISIBLE);
        switchView.setVisibility(View.INVISIBLE);
        updateNeighborViewsForId(mMobileItemId);
        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);
                View switchView = getViewForId(switchItemId);
                mTotalOffset += deltaY;
                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;
                ViewHelper.setTranslationY(switchView, delta);
                ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, "translationY", 0);
                animator.setDuration(MOVE_DURATION);
                animator.start();
                return true;
            }
        });
    }
}
Also used : ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) BaseAdapter(android.widget.BaseAdapter) ViewTreeObserver(android.view.ViewTreeObserver)

Example 4 with HeaderViewListAdapter

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

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 5 with HeaderViewListAdapter

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

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)

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