Example usage for android.widget HeaderViewListAdapter getWrappedAdapter

List of usage examples for android.widget HeaderViewListAdapter getWrappedAdapter

Introduction

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

Prototype

public ListAdapter getWrappedAdapter() 

Source Link

Usage

From source file:Main.java

public static BaseAdapter getAdapter(Adapter adapter) {
    if (adapter == null) {
        return null;
    }//from ww  w  .ja v  a2s  .c  o m

    BaseAdapter baseAdapter = null;
    if (adapter instanceof BaseAdapter) {
        baseAdapter = (BaseAdapter) adapter;
    } else if (adapter instanceof HeaderViewListAdapter) {
        HeaderViewListAdapter headerViewAdapter = (HeaderViewListAdapter) adapter;
        if (headerViewAdapter.getWrappedAdapter() instanceof BaseAdapter) {
            baseAdapter = (BaseAdapter) headerViewAdapter.getWrappedAdapter();
        }
    }

    return baseAdapter;
}

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  ww  w. ja  v a  2s  . co 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:com.simas.vc.nav_drawer.NavCAB.java

private NavAdapter getAdapter() {
    if (getListView().getAdapter() instanceof HeaderViewListAdapter) {
        HeaderViewListAdapter hvla = (HeaderViewListAdapter) getListView().getAdapter();
        return (NavAdapter) hvla.getWrappedAdapter();
    } else {/*from   w  w w.j a v a2  s  . com*/
        return (NavAdapter) getListView().getAdapter();
    }
}

From source file:org.blanco.techmun.android.MensajesActivity.java

@Override
public Object onRetainNonConfigurationInstance() {
    if (list.getAdapter() != null) {
        HeaderViewListAdapter adapter = (HeaderViewListAdapter) list.getAdapter();
        return ((MensajesListAdapter) adapter.getWrappedAdapter()).getMensajesList();
    } else {/*from ww  w.  ja  v a 2s  .  c  o m*/
        return super.onRetainNonConfigurationInstance();
    }
}

From source file:com.josecalles.tistiq.mvp.view.MainActivity.java

private void refreshContactList() {
    for (int j = 0, count = mNavigationView.getChildCount(); j < count; j++) {
        final View child = mNavigationView.getChildAt(j);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }//from   w w w  .  j  ava 2 s  . c  om
    }
}

From source file:org.bienvenidoainternet.app.MainActivity.java

public void refreshNavigator() {
    for (int i = 0, count = navigationView.getChildCount(); i < count; i++) {
        final View child = navigationView.getChildAt(i);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }/*w  w w .j  a v a2  s.c o m*/
    }
}

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

private void updateAccounts() {
    final Menu menu = binding.navigation.getMenu();
    final MenuItem libraries = menu.findItem(R.id.nav_libraries);
    final SubMenu subMenu = libraries.getSubMenu();

    while (subMenu.size() > 0) {
        subMenu.removeItem(subMenu.getItem(0).getItemId());
    }//from  w w w. j  a  v a  2  s .  co m

    final List<Account> accounts = getServer().getAccounts();
    for (int index = 0; index < accounts.size(); index++) {
        final Account account = accounts.get(index);
        final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName());
        if (account.getId().equals("local")) {
            menuItem.setIcon(R.drawable.ic_folder_24dp);
        } else {
            menuItem.setIcon(R.drawable.ic_cloud_24dp);
        }
        menuItem.setCheckable(true);
    }

    final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE,
            R.string.nav_addaccount);
    menuItem.setIcon(R.drawable.ic_add_24dp);

    for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) {
        final View child = binding.navigation.getChildAt(i);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }
    }

    getServer().loadRecent(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem recent = menu.findItem(R.id.nav_recent);
            if (recent != null) {
                recent.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
    getServer().loadStarred(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem starred = menu.findItem(R.id.nav_starred);
            if (starred != null) {
                starred.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
}

From source file:com.money.manager.ex.fragment.HomeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
        return null;
    }/*from www. jav a 2s. c  o m*/
    // inflate layout
    View view = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false);
    // reference view into layout
    linearHome = (LinearLayout) view.findViewById(R.id.linearLayoutHome);
    linearWelcome = (ViewGroup) view.findViewById(R.id.linearLayoutWelcome);

    // add account button
    Button btnAddAccount = (Button) view.findViewById(R.id.buttonAddAccount);
    if (btnAddAccount != null) {
        btnAddAccount.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), AccountListEditActivity.class);
                intent.setAction(Constants.INTENT_ACTION_INSERT);
                startActivity(intent);
            }
        });
    }

    // link to dropbox
    Button btnLinkDropbox = (Button) view.findViewById(R.id.buttonLinkDropbox);
    if (btnLinkDropbox != null) {
        btnLinkDropbox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), PreferencesActivity.class);
                intent.putExtra(Constants.INTENT_REQUEST_PREFERENCES_SCREEN,
                        PreferencesConstant.PREF_DROPBOX_HOWITWORKS);
                startActivity(intent);
            }
        });
    }

    txtTotalAccounts = (TextView) view.findViewById(R.id.textViewTotalAccounts);
    lstAccountBills = (ListView) view.findViewById(R.id.listViewAccountBills);
    lstAccountBills.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            MainActivity activity = (MainActivity) getActivity();
            //Cursor cursor = ((CursorAdapter)lstAccountBills.getAdapter()).getCursor();
            HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) lstAccountBills.getAdapter();
            AccountBillsAdapter accountBillsAdapter = (AccountBillsAdapter) headerViewListAdapter
                    .getWrappedAdapter();
            Cursor cursor = accountBillsAdapter.getCursor();
            int accountId = -1;
            if (cursor != null && cursor.moveToPosition(position)) {
                accountId = cursor.getInt(cursor.getColumnIndex(QueryAccountBills.ACCOUNTID));
            }
            // show account clicked
            if (activity != null && activity instanceof MainActivity) {
                activity.showFragmentAccount(position, accountId);
            }
        }
    });
    // set highlight item
    if (getActivity() != null && getActivity() instanceof MainActivity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            lstAccountBills.setSelector(R.color.holo_blue_light);
        lstAccountBills.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        //lstAccountBills.setSelection(ListView.INVALID_POSITION);
    }

    prgAccountBills = (ProgressBar) view.findViewById(R.id.progressAccountBills);

    return view;
}

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

/**
 * Attempts to find the view for the menu item that owns the specified
 * submenu./*ww w .  jav a2 s. c o  m*/
 *
 * @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);
}