Example usage for android.widget ListPopupWindow WRAP_CONTENT

List of usage examples for android.widget ListPopupWindow WRAP_CONTENT

Introduction

In this page you can find the example usage for android.widget ListPopupWindow WRAP_CONTENT.

Prototype

int WRAP_CONTENT

To view the source code for android.widget ListPopupWindow WRAP_CONTENT.

Click Source Link

Document

Alias for ViewGroup.LayoutParams#WRAP_CONTENT .

Usage

From source file:org.alfresco.mobile.android.application.fragments.menu.MainMenuFragment.java

private void refresh() {
    if (currentAccount == null) {
        currentAccount = AccountsPreferences.getDefaultAccount(getActivity());
        if (currentAccount == null) {
            return;
        }/*  w w w .j  a v a  2  s .co  m*/
    }

    List<AlfrescoAccount> list = AlfrescoAccountManager.retrieveAccounts(getActivity());
    // We add all extra parameters at the end of the list.
    if (currentAccount.getTypeId() == AlfrescoAccount.TYPE_ALFRESCO_CLOUD) {
        list.add(new AlfrescoAccount(AccountsAdapter.NETWORK_ITEM, getString(R.string.cloud_networks_switch),
                null, null, null, null, "0", null, "false"));
    }

    // We add profiles management option if at least there's 2 profiles
    // available
    if (configManager != null && configManager.getConfig(currentAccount.getId()) != null
            && configManager.getConfig(currentAccount.getId()).getProfiles().size() > 1) {
        list.add(new AlfrescoAccount(AccountsAdapter.PROFILES_ITEM, getString(R.string.profiles_switch), null,
                null, null, null, "0", null, "false"));
    }

    list.add(new AlfrescoAccount(AccountsAdapter.MANAGE_ITEM, getString(R.string.manage_accounts), null, null,
            null, null, "0", null, "false"));

    // Init the adapter and create the menu
    if (accountsAdapter == null) {
        accountsAdapter = new AccountsAdapter(getActivity(), list, R.layout.row_single_line, null);
    } else {
        accountsAdapter.clear();
        accountsAdapter.addAll(list);
    }

    accountsAdapter.setNotifyOnChange(false);

    ((TextView) accountsSpinnerButton.findViewById(R.id.accounts_spinner_title))
            .setText(currentAccount.getTitle());
    AccountsAdapter.displayAvatar(getActivity(), currentAccount, R.drawable.ic_account_light,
            ((ImageView) accountsSpinnerButton.findViewById(R.id.accounts_spinner_icon)));
    accountsSpinnerButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (listPopupWindow != null) {
                listPopupWindow.dismiss();
                listPopupWindow = null;
            } else {
                listPopupWindow = new ListPopupWindow(getActivity());
                GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
                        new int[] { 0xFF282828, 0xFF282828 });
                gd.setCornerRadius(0f);
                listPopupWindow.setBackgroundDrawable(gd);
                listPopupWindow.setAnchorView(accountsSpinnerButton);
                listPopupWindow.setAdapter(accountsAdapter);
                listPopupWindow.setOnItemClickListener(MainMenuFragment.this);
                listPopupWindow.setWidth(ListPopupWindow.WRAP_CONTENT);
                listPopupWindow.show();
            }
        }
    });

    if (OperationsFragment.canDisplay(getActivity(), currentAccount)) {
        show(R.id.menu_notifications);
        showOperationsMenu = true;
    } else {
        hide(R.id.menu_notifications);
        showOperationsMenu = false;
    }
    getActivity().invalidateOptionsMenu();
}