Java Code Examples for android.widget.ListPopupWindow#setOnDismissListener()

The following examples show how to use android.widget.ListPopupWindow#setOnDismissListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectorView.java    From NovelReader with MIT License 5 votes vote down vote up
private void createPopWindow(){
    popupWindow = new ListPopupWindow(getContext());
    popupAdapter = new SelectorAdapter();
    popupWindow.setAnchorView(parent.getChildAt(0));
    popupWindow.setAdapter(popupAdapter);
    popupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    //获取焦点
    popupWindow.setModal(true);

    popupWindow.setOnItemClickListener(this);
    popupWindow.setOnDismissListener(this);
}
 
Example 2
Source File: EditSpinner.java    From EditSpinner with Apache License 2.0 5 votes vote down vote up
private void initPopupWindow() {
    popupWindow = new ListPopupWindow(mContext) {

        @Override
        public void show() {
            super.show();
            mRightImageTopView.setClickable(true);
            mRightIv.startAnimation(mAnimation);
        }

        @Override
        public void dismiss() {
            super.dismiss();
        }

    };
    popupWindow.setOnItemClickListener(this);
    popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    popupWindow.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
    popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setAnchorView(editText);
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            popupWindowHideTime = System.currentTimeMillis();
            mRightIv.startAnimation(mResetAnimation);
        }
    });
}
 
Example 3
Source File: EditSpinner.java    From Edit-Spinner with Apache License 2.0 4 votes vote down vote up
private void initFromAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EditSpinner, defStyleAttr, defStyleRes);

    mPopup = new ListPopupWindow(context, attrs);
    mPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);

    Drawable selector = a.getDrawable(R.styleable.EditSpinner_dropDownSelector);
    if (selector != null) {
        mPopup.setListSelector(selector);
    }

    int dropDownAnimStyleResId = a.getResourceId(R.styleable.EditSpinner_dropDownAnimStyle, -1);
    if (dropDownAnimStyleResId > 0) {
        setDropDownAnimationStyle(dropDownAnimStyleResId);
    }

    mDropDownDrawable = a.getDrawable(R.styleable.EditSpinner_dropDownDrawable);
    int dropDownDrawableSpacing = a.getDimensionPixelOffset(R.styleable.EditSpinner_dropDownDrawableSpacing, 0);

    if (mDropDownDrawable != null) {
        int dropDownDrawableWidth = a.getDimensionPixelOffset(R.styleable.EditSpinner_dropDownDrawableWidth, -1);
        int dropDownDrawableHeight = a.getDimensionPixelOffset(R.styleable.EditSpinner_dropDownDrawableHeight, -1);
        setDropDownDrawable(mDropDownDrawable, dropDownDrawableWidth, dropDownDrawableHeight);
        setDropDownDrawableSpacing(dropDownDrawableSpacing);
    }

    // Get the anchor's id now, but the view won't be ready, so wait to actually get the
    // view and store it in mDropDownAnchorView lazily in getDropDownAnchorView later.
    // Defaults to NO_ID, in which case the getDropDownAnchorView method will simply return
    // this TextView, as a default anchoring point.
    mDropDownAnchorId = a.getResourceId(R.styleable.EditSpinner_dropDownAnchor,
            View.NO_ID);


    // For dropdown width, the developer can specify a specific width, or MATCH_PARENT
    // (for full screen width) or WRAP_CONTENT (to match the width of the anchored view).
    mPopup.setWidth(a.getLayoutDimension(R.styleable.EditSpinner_dropDownWidth,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mPopup.setHeight(a.getLayoutDimension(R.styleable.EditSpinner_dropDownHeight,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    mPopup.setOnItemClickListener(new DropDownItemClickListener());
    mPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            mLastDismissTime = SystemClock.elapsedRealtime();
            if (mOnDismissListener != null) {
                mOnDismissListener.onDismiss();
            }
        }
    });
    a.recycle();

    mIsEditable = getKeyListener() != null;

    setFocusable(true);
    addTextChangedListener(new MyWatcher());

    Log.d(TAG, "mIsEditable = " + mIsEditable);
}
 
Example 4
Source File: AdapterBookmarks.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
private void showFilterPopup() {
    try {
        final ListPopupWindow popupWindow = new ListPopupWindow(context);
        List<Item> itemList = new ArrayList<>();
        itemList.add(new Item(context.getResources().getString(R.string.delete_bookmark), R.drawable.ic_delete));
        itemList.add(new Item(context.getResources().getString(R.string.rename_bookmark), R.drawable.ic_rename));
        itemList.add(new Item(context.getResources().getString(R.string.share_bookmark), R.drawable.ic_share));
        ListAdapter adapter = new ListPopupWindowAdapter(context, itemList);
        popupWindow.setAnchorView(delete);
        popupWindow.setAdapter(adapter);
        popupWindow.setOnDismissListener(popupWindow::dismiss);
        popupWindow.setOnItemClickListener((adapterView, view, i, l) -> {
            switch (i) {
                case 0:
                    popupWindow.dismiss();
                    deleteAlert();
                    break;
                case 1:
                    popupWindow.dismiss();
                    editAlert();
                    break;
                case 2:
                    popupWindow.dismiss();
                    try {
                        Intent share = new Intent(Intent.ACTION_SEND);
                        share.setType("text/plain");
                        share.putExtra(Intent.EXTRA_TEXT, bookmark.getUrl());
                        context.startActivity(Intent.createChooser(share, bookmark.getTitle()));
                    }catch (ActivityNotFoundException ignored){
                    }catch (Exception p){
                        p.printStackTrace();
                    }
                    break;
                default:
                    popupWindow.dismiss();
                    break;
            }

        });
        popupWindow.show();

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 5
Source File: NiceSpinner.java    From nice-spinner with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    Resources resources = getResources();
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
    int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding,
            defaultPadding);
    setClickable(true);
    backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector);
    setBackgroundResource(backgroundSelector);
    textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context));
    setTextColor(textColor);
    popupWindow = new ListPopupWindow(context);
    popupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // The selected item is not displayed within the list, so when the selected position is equal to
            // the one of the currently selected item it gets shifted to the next item.
            if (position >= selectedIndex && position < adapter.getCount()) {
                position++;
            }
            selectedIndex = position;

            if (onSpinnerItemSelectedListener != null) {
                onSpinnerItemSelectedListener.onItemSelected(NiceSpinner.this, view, position, id);
            }

            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(parent, view, position, id);
            }

            if (onItemSelectedListener != null) {
                onItemSelectedListener.onItemSelected(parent, view, position, id);
            }

            adapter.setSelectedIndex(position);

            setTextInternal(adapter.getItemInDataset(position));

            dismissDropDown();
        }
    });

    popupWindow.setModal(true);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (!isArrowHidden) {
                animateArrow(false);
            }
        }
    });

    isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false);
    arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, getResources().getColor(android.R.color.black));
    arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow);
    dropDownListPaddingBottom =
            typedArray.getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0);
    horizontalAlignment = PopUpTextAlignment.fromId(
            typedArray.getInt(R.styleable.NiceSpinner_popupTextAlignment, PopUpTextAlignment.CENTER.ordinal())
    );

    CharSequence[] entries = typedArray.getTextArray(R.styleable.NiceSpinner_entries);
    if (entries != null) {
        attachDataSource(Arrays.asList(entries));
    }

    typedArray.recycle();

    measureDisplayHeight();

}