Search in sources :

Example 21 with ListPopupWindow

use of android.widget.ListPopupWindow in project XobotOS by xamarin.

the class MenuPopupHelper method tryShow.

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, com.android.internal.R.attr.popupMenuStyle);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mAdapter = new MenuAdapter(mMenu);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        // Refresh to latest
        mTreeObserver = anchor.getViewTreeObserver();
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        anchor.addOnAttachStateChangeListener(this);
        mPopup.setAnchorView(anchor);
    } else {
        return false;
    }
    mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 22 with ListPopupWindow

use of android.widget.ListPopupWindow in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DateTimeSettingsSetupWizard method showTimezonePicker.

private void showTimezonePicker(int anchorViewId) {
    View anchorView = findViewById(anchorViewId);
    if (anchorView == null) {
        Log.e(TAG, "Unable to find zone picker anchor view " + anchorViewId);
        return;
    }
    mTimeZonePopup = new ListPopupWindow(this, null);
    mTimeZonePopup.setWidth(anchorView.getWidth());
    mTimeZonePopup.setAnchorView(anchorView);
    mTimeZonePopup.setAdapter(mTimeZoneAdapter);
    mTimeZonePopup.setOnItemClickListener(this);
    mTimeZonePopup.setModal(true);
    mTimeZonePopup.show();
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 23 with ListPopupWindow

use of android.widget.ListPopupWindow in project android_packages_apps_Settings by DirtyUnicorns.

the class EditUserPhotoController method showUpdatePhotoPopup.

private void showUpdatePhotoPopup() {
    final boolean canTakePhoto = canTakePhoto();
    final boolean canChoosePhoto = canChoosePhoto();
    if (!canTakePhoto && !canChoosePhoto) {
        return;
    }
    final Context context = mImageView.getContext();
    final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>();
    if (canTakePhoto) {
        final String title = context.getString(R.string.user_image_take_photo);
        final Runnable action = new Runnable() {

            @Override
            public void run() {
                takePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }
    if (canChoosePhoto) {
        final String title = context.getString(R.string.user_image_choose_photo);
        final Runnable action = new Runnable() {

            @Override
            public void run() {
                choosePhoto();
            }
        };
        items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action));
    }
    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);
    listPopupWindow.setAnchorView(mImageView);
    listPopupWindow.setModal(true);
    listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items));
    final int width = Math.max(mImageView.getWidth(), context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width));
    listPopupWindow.setWidth(width);
    listPopupWindow.setDropDownGravity(Gravity.START);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position);
            item.doAction();
        }
    });
    listPopupWindow.show();
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Paint(android.graphics.Paint) ListPopupWindow(android.widget.ListPopupWindow) AdapterView(android.widget.AdapterView)

Example 24 with ListPopupWindow

use of android.widget.ListPopupWindow in project LibreraReader by foobnix.

the class MyPopupMenu method show.

public void show(int pos) {
    final ListPopupWindow p1 = new ListPopupWindow(c);
    p1.setModal(true);
    p1.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss() {
            p1.dismiss();
            if (isTabsActivity) {
                if (AppState.get().isFullScreenMain) {
                    Keyboards.hideNavigation((Activity) c);
                }
            } else {
                if (AppState.get().isFullScreen) {
                    Keyboards.hideNavigation((Activity) c);
                }
            }
        }
    });
    BaseItemLayoutAdapter<Menu> a = new BaseItemLayoutAdapter<Menu>(c, R.layout.item_dict_line, list) {

        @Override
        public void populateView(View layout, int position, final Menu item) {
            TextView textView = (TextView) layout.findViewById(R.id.text1);
            textView.setText(item.stringRes);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
            if (TxtUtils.isNotEmpty(item.fontPath)) {
                textView.setTypeface(BookCSS.getTypeFaceForFont(item.fontPath));
            }
            ImageView imageView = (ImageView) layout.findViewById(R.id.image1);
            if (item.iconRes != 0) {
                imageView.setImageResource(item.iconRes);
                if (item.iconRes == R.drawable.icon_pdf_pro) {
                    TintUtil.setNoTintImage(imageView);
                } else {
                    if (isTabsActivity) {
                        if (AppState.get().isInkMode || AppState.get().isWhiteTheme) {
                            TintUtil.setTintImageWithAlpha(imageView, TintUtil.color);
                        } else {
                            TintUtil.setTintImageWithAlpha(imageView, Color.LTGRAY);
                        }
                    } else {
                        if (AppState.get().isDayNotInvert) {
                            TintUtil.setTintImageWithAlpha(imageView, TintUtil.color);
                        } else {
                            TintUtil.setTintImageWithAlpha(imageView, Color.LTGRAY);
                        }
                    }
                }
            } else {
                imageView.setVisibility(View.GONE);
            }
            layout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    item.click.onMenuItemClick(null);
                    try {
                        p1.dismiss();
                    } catch (Exception e) {
                        LOG.e(e);
                    }
                }
            });
            layout.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    if (item.onLongClick == null) {
                        return false;
                    }
                    item.onLongClick.onMenuItemClick(null);
                    try {
                        p1.dismiss();
                    } catch (Exception e) {
                        LOG.e(e);
                    }
                    return true;
                }
            });
        }
    };
    p1.setAnchorView(anchor);
    p1.setAdapter(a);
    try {
        p1.setWidth(measureContentWidth(a, c) + Dips.dpToPx(20));
    } catch (Exception e) {
        p1.setWidth(200);
    }
    p1.show();
    if (pos != -1) {
        p1.setSelection(pos - 2);
    }
}
Also used : OnDismissListener(android.widget.PopupWindow.OnDismissListener) Activity(android.app.Activity) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListPopupWindow(android.widget.ListPopupWindow) OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Example 25 with ListPopupWindow

use of android.widget.ListPopupWindow 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

ListPopupWindow (android.widget.ListPopupWindow)33 View (android.view.View)27 AdapterView (android.widget.AdapterView)25 TextView (android.widget.TextView)17 ImageView (android.widget.ImageView)14 Context (android.content.Context)8 Paint (android.graphics.Paint)8 ArrayList (java.util.ArrayList)8 ArrayAdapter (android.widget.ArrayAdapter)4 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3 ImageButton (android.widget.ImageButton)3 Activity (android.app.Activity)2 Intent (android.content.Intent)2 TypedArray (android.content.res.TypedArray)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 ViewGroup (android.view.ViewGroup)2