Example usage for android.view LayoutInflater setFactory2

List of usage examples for android.view LayoutInflater setFactory2

Introduction

In this page you can find the example usage for android.view LayoutInflater setFactory2.

Prototype

public void setFactory2(Factory2 factory) 

Source Link

Document

Like #setFactory , but allows you to set a Factory2 interface.

Usage

From source file:de.vanita5.twittnuker.popup.AccountSelectorPopupWindow.java

public AccountSelectorPopupWindow(Context context, View anchor) {
    mContext = context;//from   ww  w.java  2 s.  com
    mAnchor = anchor;
    final int themeAttr;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        themeAttr = android.R.attr.actionOverflowMenuStyle;
    } else {
        themeAttr = android.R.attr.popupMenuStyle;
    }
    mAdapter = new AccountsGridAdapter(context);
    final Resources resources = context.getResources();
    final LayoutInflater inflater = LayoutInflater.from(context);
    final int themeColor = ThemeUtils.getUserAccentColor(context);
    if (!(context instanceof Factory)) {
        inflater.setFactory2(new ThemedViewFactory(themeColor));
    }
    final View contentView = inflater.inflate(R.layout.popup_account_selector, null);
    mGridView = (GridView) contentView.findViewById(R.id.grid_view);
    mGridView.setAdapter(mAdapter);
    mGridView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    mGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mAccountSelectionListener == null)
                return;

            mAccountSelectionListener.onSelectionChanged(getSelectedAccountIds());
        }
    });
    mPopup = new PopupWindow(context, null, themeAttr);
    mPopup.setFocusable(true);
    mPopup.setWidth(Utils.getActionBarHeight(context) * 2);
    mPopup.setWindowLayoutMode(0, ViewGroup.LayoutParams.WRAP_CONTENT);
    mPopup.setContentView(contentView);
}