@Override public void setAdapter(ListAdapter adapter) { super.setAdapter(adapter); mAdapter = (DropDownAdapter)adapter; mAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Spinner.this.performItemClick(v, position, mAdapter.getItemId(position)); dismiss(); } }); }
/** * Set a view to act as a user prompt for this popup window. Where the prompt view will appear * is controlled by {@link #setPromptPosition(int)}. * * @param prompt View to use as an informational prompt. */ public void setPromptView(View prompt) { boolean showing = isShowing(); if (showing) { removePromptView(); } mPromptView = prompt; if (showing) { show(); } }
mReplacementAdapter.setRecipient(mSelectedSpan.getRecipient()); mReplacementPopup = new ListPopupWindow(getContext()); mReplacementPopup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { mReplacementPopup.setAnchorView(this); mReplacementPopup.setModal(true); mReplacementPopup.setAdapter(mReplacementAdapter); mReplacementPopup.show(); mReplacementPopup.getListView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() {
@Override public void onGlobalLayout() { ListView lv = mReplacementPopup.getListView(); ViewTreeObserver observer = lv.getViewTreeObserver(); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) observer.removeOnGlobalLayoutListener(this); else observer.removeGlobalOnLayoutListener(this); View v = lv.getChildAt(0); v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mReplacementPopup.setContentWidth(v.getMeasuredWidth()); int[] popupLocation = new int[2]; lv.getLocationOnScreen(popupLocation); int[] inputLocation = new int[2]; mInputView.getLocationOnScreen(inputLocation); Drawable background = mReplacementPopup.getPopup().getBackground(); Rect backgroundPadding = new Rect(); int verticalOffset; int horizontalOffset = inputLocation[0] + (int)mSelectedSpan.mX - (popupLocation[0] + backgroundPadding.left); if(background != null) background.getPadding(backgroundPadding); if(inputLocation[1] < popupLocation[1]) //popup show at bottom verticalOffset = inputLocation[1] + mSelectedSpan.mY - (popupLocation[1] + backgroundPadding.top); else verticalOffset = inputLocation[1] + mSelectedSpan.mY + mSpanHeight - (popupLocation[1] + lv.getHeight() - backgroundPadding.bottom); mReplacementPopup.setVerticalOffset(verticalOffset); mReplacementPopup.setHorizontalOffset(horizontalOffset); mReplacementPopup.show(); } });
if (isShowing()) { || !isConfirmKey(keyCode))) { int curIndex = mDropDownList.getSelectedItemPosition(); boolean consumed; clearListSelection(); mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); show(); return true; } else { show();
/** * Filter key down events. By forwarding key up events to this function, * views using non-modal ListPopupWindow can have it handle key selection of items. * * @param keyCode keyCode param passed to the host view's onKeyUp * @param event event param passed to the host view's onKeyUp * @return true if the event was handled, false if it was ignored. * * @see #setModal(boolean) */ public boolean onKeyUp(int keyCode, KeyEvent event) { if (isShowing() && mDropDownList.getSelectedItemPosition() >= 0) { boolean consumed = mDropDownList.onKeyUp(keyCode, event); if (consumed && isConfirmKey(keyCode)) { // if the list accepts the key events and the key event was a click, the text view // gets the selected item from the drop down as its content dismiss(); } return consumed; } return false; }
int height = buildDropDown(); boolean noInputMethod = isInputMethodNotNeeded(); widthSpec = getAnchorView().getWidth(); } else { widthSpec = mDropDownWidth; mPopup.update(getAnchorView(), mDropDownHorizontalOffset, mDropDownVerticalOffset, widthSpec, heightSpec); } else { } else { if (mDropDownWidth == ViewGroup.LayoutParams.WRAP_CONTENT) { mPopup.setWidth(getAnchorView().getWidth()); } else { mPopup.setWidth(mDropDownWidth); setPopupClipToScreenEnabled(true); PopupWindowCompat.showAsDropDown(mPopup, getAnchorView(), mDropDownHorizontalOffset, mDropDownVerticalOffset, mDropDownGravity); mDropDownList.setSelection(ListView.INVALID_POSITION); clearListSelection();
/** * @return The currently selected item or null if the popup is not showing. */ public Object getSelectedItem() { if (!isShowing()) { return null; } return mDropDownList.getSelectedItem(); }
public void run() { // View layout should be all done before displaying the drop down. View view = getAnchorView(); if (view != null && view.getWindowToken() != null) { show(); } } };
public void show() { final boolean wasShowing = isShowing(); computeContentWidth(); setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); super.show(); if (wasShowing) { // Skip setting up the layout/dismiss listener below. If we were previously // showing it will still stick around. return; } // Make sure we hide if our anchor goes away. // TODO: This might be appropriate to push all the way down to PopupWindow, // but it may have other side effects to investigate first. (Text editing handles, etc.) final ViewTreeObserver vto = getViewTreeObserver(); if (vto != null) vto.addOnGlobalLayoutListener(layoutListener); } }
@Override public void onInvalidated() { dismiss(); } }
getSystemBarHeight("status_bar_height"), getSystemBarHeight("navigation_bar_height") ); mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED; final int maxHeight = mPopup.getMaxAvailableHeight( getAnchorView(), mDropDownVerticalOffset /*, ignoreBottomDecorations*/) - systemBarsReservedSpace;
public void run() { clearListSelection(); } }
/** * Called when forwarding would like to start. <p> By default, this will show the popup * returned by {@link #getPopup()}. It may be overridden to perform another action, like * clicking the source view or preparing the popup before showing it. * * @return true to start forwarding, false otherwise */ protected boolean onForwardingStarted() { final ListPopupWindow popup = getPopup(); if (popup != null && !popup.isShowing()) { popup.show(); } return true; }
/** * @return The position of the currently selected item or {@link ListView#INVALID_POSITION} * if {@link #isShowing()} == {@code false}. * * @see ListView#getSelectedItemPosition() */ public int getSelectedItemPosition() { if (!isShowing()) { return ListView.INVALID_POSITION; } return mDropDownList.getSelectedItemPosition(); }
public void run() { if (mDropDownList != null && mDropDownList.getCount() > mDropDownList.getChildCount() && mDropDownList.getChildCount() <= mListItemExpandMaximum) { mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); show(); } } }
/** * Called when forwarding would like to stop. <p> By default, this will dismiss the popup * returned by {@link #getPopup()}. It may be overridden to perform some other action. * * @return true to stop forwarding, false otherwise */ protected boolean onForwardingStopped() { final ListPopupWindow popup = getPopup(); if (popup != null && popup.isShowing()) { popup.dismiss(); } return true; }
/** * @return The ID of the currently selected item or {@link ListView#INVALID_ROW_ID} * if {@link #isShowing()} == {@code false}. * * @see ListView#getSelectedItemId() */ public long getSelectedItemId() { if (!isShowing()) { return ListView.INVALID_ROW_ID; } return mDropDownList.getSelectedItemId(); }