Search in sources :

Example 1 with CustomMessageMenuAdapter

use of com.xabber.android.ui.adapter.CustomMessageMenuAdapter in project xabber-android by redsolution.

the class CustomMessageMenu method showMenu.

public static void showMenu(Context context, View anchor, List<HashMap<String, String>> items, final AdapterView.OnItemClickListener itemClickListener, PopupWindow.OnDismissListener dismissListener) {
    // build popup
    final ListPopupWindow popup = new ListPopupWindow(context);
    CustomMessageMenuAdapter adapter = new CustomMessageMenuAdapter(context, items);
    popup.setAdapter(adapter);
    popup.setAnchorView(anchor);
    popup.setModal(true);
    popup.setSoftInputMode(SOFT_INPUT_ADJUST_NOTHING);
    popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            itemClickListener.onItemClick(parent, view, position, id);
            popup.dismiss();
        }
    });
    popup.setOnDismissListener(dismissListener);
    // measure content dimens
    ViewGroup mMeasureParent = null;
    int height = 0;
    int maxWidth = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        if (mMeasureParent == null) {
            mMeasureParent = new FrameLayout(context);
        }
        itemView = adapter.getView(i, itemView, mMeasureParent);
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        final int itemHeight = itemView.getMeasuredHeight();
        final int itemWidth = itemView.getMeasuredWidth();
        if (itemWidth > maxWidth) {
            maxWidth = itemWidth;
        }
        height += itemHeight;
    }
    // set dimens and show
    popup.setWidth(maxWidth);
    popup.setHeight(height);
    popup.show();
}
Also used : CustomMessageMenuAdapter(com.xabber.android.ui.adapter.CustomMessageMenuAdapter) ListPopupWindow(android.widget.ListPopupWindow) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 FrameLayout (android.widget.FrameLayout)1 ListPopupWindow (android.widget.ListPopupWindow)1 CustomMessageMenuAdapter (com.xabber.android.ui.adapter.CustomMessageMenuAdapter)1