Search in sources :

Example 11 with HeaderViewListAdapter

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

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

use of android.widget.HeaderViewListAdapter in project cloudrail-si-android-sdk by CloudRail.

the class POIResult method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_poiresult, container, false);
    LinearLayout layout = (LinearLayout) v.findViewById(R.id.poiFragment);
    listViews = new ArrayList<ListView>();
    for (int i = 0; i < poiServices.size(); i++) {
        final ListView listView = new ListView(context);
        listView.setScrollbarFadingEnabled(false);
        if (i % 2 == 1) {
            listView.setBackgroundColor(0xFFBBBBBB);
        }
        TextView header = new TextView(context);
        header.setText(poiServices.get(i).toString());
        header.setTextAppearance(context, android.R.style.TextAppearance_Medium);
        listView.addHeaderView(header);
        listViews.add(listView);
        layout.addView(listView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
        System.out.println("adding listview " + i);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position <= 0) {
                    return;
                }
                POIAdapter poiAdapter = (POIAdapter) ((HeaderViewListAdapter) listView.getAdapter()).getWrappedAdapter();
                Pair<POI, Long> item = poiAdapter.getItem(position - 1);
                com.cloudrail.si.types.Location location = item.first.getLocation();
                Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + location.getLatitude() + "," + location.getLongitude() + "(" + Uri.encode(item.first.getName()) + ")");
                Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                mapIntent.setPackage("com.google.android.apps.maps");
                startActivity(mapIntent);
            }
        });
    }
    return v;
}
Also used : Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Uri(android.net.Uri) ListView(android.widget.ListView) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout) Pair(android.util.Pair) Location(android.location.Location)

Example 13 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project SmartCampus by Vegen.

the class EaseSidebar method setHeaderTextAndscroll.

private void setHeaderTextAndscroll(MotionEvent event) {
    if (mListView == null) {
        // need to check the call stack later
        return;
    }
    String headerString = sections[sectionForPoint(event.getY())];
    header.setText(headerString);
    ListAdapter adapter = mListView.getAdapter();
    if (sectionIndex == null) {
        if (adapter instanceof HeaderViewListAdapter) {
            sectionIndex = (SectionIndexer) ((HeaderViewListAdapter) adapter).getWrappedAdapter();
        } else if (adapter instanceof SectionIndexer) {
            sectionIndex = (SectionIndexer) adapter;
        } else {
            throw new RuntimeException("listview sets adapter does not implement SectionIndexer interface");
        }
    }
    String[] adapterSections = (String[]) sectionIndex.getSections();
    try {
        for (int i = adapterSections.length - 1; i > -1; i--) {
            if (adapterSections[i].equals(headerString)) {
                mListView.setSelection(sectionIndex.getPositionForSection(i));
                break;
            }
        }
    } catch (Exception e) {
        Log.e("setHeaderTextAndScroll", e.getMessage());
    }
}
Also used : HeaderViewListAdapter(android.widget.HeaderViewListAdapter) SectionIndexer(android.widget.SectionIndexer) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) ListAdapter(android.widget.ListAdapter) Paint(android.graphics.Paint)

Example 14 with HeaderViewListAdapter

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

the class ShadowListView method getFooterViews.

public List<View> getFooterViews() {
    HeaderViewListAdapter adapter = (HeaderViewListAdapter) realListView.getAdapter();
    ArrayList<View> footerViews = new ArrayList<>();
    int offset = adapter.getHeadersCount() + adapter.getCount() - adapter.getFootersCount();
    int itemCount = adapter.getCount();
    for (int i = offset; i < itemCount; i++) {
        footerViews.add(adapter.getView(i, null, realListView));
    }
    return footerViews;
}
Also used : ArrayList(java.util.ArrayList) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) View(android.view.View) ListView(android.widget.ListView)

Example 15 with HeaderViewListAdapter

use of android.widget.HeaderViewListAdapter in project Etar-Calendar by Etar-Group.

the class AgendaFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    int screenWidth = mActivity.getResources().getDisplayMetrics().widthPixels;
    View v = inflater.inflate(R.layout.agenda_fragment, null);
    mAgendaListView = (AgendaListView) v.findViewById(R.id.agenda_events_list);
    mAgendaListView.setClickable(true);
    if (savedInstanceState != null) {
        long instanceId = savedInstanceState.getLong(BUNDLE_KEY_RESTORE_INSTANCE_ID, -1);
        if (instanceId != -1) {
            mAgendaListView.setSelectedInstanceId(instanceId);
        }
    }
    View eventView = v.findViewById(R.id.agenda_event_info);
    if (!mShowEventDetailsWithAgenda) {
        eventView.setVisibility(View.GONE);
    }
    View topListView;
    // Set adapter & HeaderIndexer for StickyHeaderListView
    StickyHeaderListView lv = (StickyHeaderListView) v.findViewById(R.id.agenda_sticky_header_list);
    if (lv != null) {
        Adapter a = mAgendaListView.getAdapter();
        lv.setAdapter(a);
        if (a instanceof HeaderViewListAdapter) {
            mAdapter = (AgendaWindowAdapter) ((HeaderViewListAdapter) a).getWrappedAdapter();
            lv.setIndexer(mAdapter);
            lv.setHeaderHeightListener(mAdapter);
        } else if (a instanceof AgendaWindowAdapter) {
            mAdapter = (AgendaWindowAdapter) a;
            lv.setIndexer(mAdapter);
            lv.setHeaderHeightListener(mAdapter);
        } else {
            Log.wtf(TAG, "Cannot find HeaderIndexer for StickyHeaderListView");
        }
        // Set scroll listener so that the date on the ActionBar can be set while
        // the user scrolls the view
        lv.setOnScrollListener(this);
        topListView = lv;
    } else {
        topListView = mAgendaListView;
    }
    if (!mShowEventDetailsWithAgenda) {
        ViewGroup.LayoutParams params = topListView.getLayoutParams();
        params.width = screenWidth;
        topListView.setLayoutParams(params);
    } else {
        ViewGroup.LayoutParams listParams = topListView.getLayoutParams();
        listParams.width = screenWidth * 4 / 10;
        topListView.setLayoutParams(listParams);
        ViewGroup.LayoutParams detailsParams = eventView.getLayoutParams();
        detailsParams.width = screenWidth - listParams.width;
        eventView.setLayoutParams(detailsParams);
    }
    return v;
}
Also used : StickyHeaderListView(com.android.calendar.StickyHeaderListView) ViewGroup(android.view.ViewGroup) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) Adapter(android.widget.Adapter) HeaderViewListAdapter(android.widget.HeaderViewListAdapter) View(android.view.View) StickyHeaderListView(com.android.calendar.StickyHeaderListView) AbsListView(android.widget.AbsListView)

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