Example usage for android.widget PopupWindow INPUT_METHOD_NEEDED

List of usage examples for android.widget PopupWindow INPUT_METHOD_NEEDED

Introduction

In this page you can find the example usage for android.widget PopupWindow INPUT_METHOD_NEEDED.

Prototype

int INPUT_METHOD_NEEDED

To view the source code for android.widget PopupWindow INPUT_METHOD_NEEDED.

Click Source Link

Document

Mode for #setInputMethodMode(int) : this popup always needs to work with an input method, regardless of whether it is focusable.

Usage

From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java

public IcsListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
    mContext = context;/*  w w w  . j a va  2s  . c  om*/
    mPopup = new PopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
}

From source file:com.actionbarsherlock.internal.widget.IcsListPopupWindow.java

public IcsListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;//from   w w w  .  j  a  v  a  2 s .  c o  m
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        Context wrapped = new ContextThemeWrapper(context, defStyleRes);
        mPopup = new PopupWindow(wrapped, attrs, defStyleAttr);
    } else {
        mPopup = new PopupWindow(context, attrs, defStyleAttr, defStyleRes);
    }
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
}

From source file:com.justwayward.reader.ui.activity.SearchActivity.java

@Override
public void showAutoCompleteList(List<String> list) {
    mAutoList.clear();/*from   w  w  w.j  a  v a2s .c  om*/
    mAutoList.addAll(list);

    if (!mListPopupWindow.isShowing()) {
        mListPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        mListPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        mListPopupWindow.show();
    }
    mAutoAdapter.notifyDataSetChanged();

}

From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java

public void showError() {
    if (DEBUG)//from  w  ww  . j a  va2 s .  c  om
        Log.d(TAG, ".showError()...");
    if (mView.getWindowToken() == null) {
        mShowErrorAfterAttach = true;
        return;
    }

    if (mPopup == null) {
        LayoutInflater inflater = LayoutInflater.from(mView.getContext());
        final TextView err = (TextView) inflater.inflate(R.layout.textview_hint, null);
        err.setText(mError);

        final float scale = mContext.getResources().getDisplayMetrics().density;
        mPopup = new ErrorPopup(mContext, err, (int) (200 * scale + 0.5f), (int) (50 * scale + 0.5f));
        mPopup.setFocusable(false);
        //LD - non EditTexts may not require this:
        // The user is entering text, so the input method is needed.  We
        // don't want the popup to be displayed on top of it.
        mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
    }

    if (DEBUG)
        Log.d(TAG, "...error: " + mError);
    TextView tv = (TextView) mPopup.getContentView();
    //tv.setPadding(mErrorPopupPaddingLeft, mErrorPopupPaddingTop, mErrorPopupPaddingRight, mErrorPopupPaddingBottom);
    chooseSize(mPopup, mError, tv);
    tv.setText(mError);

    mPopup.showAsDropDown(mView, getErrorX(), getErrorY());
    mPopup.fixDirection(mPopup.isAboveAnchor());
}

From source file:lewa.support.v7.widget.ListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Default style attribute to use for popup content.
 *//*  w ww  . j  av a  2  s.c  o  m*/
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr, 0);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
}

From source file:android.support.v7.widget.ListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Style attribute to read for default styling of popup content.
 * @param defStyleRes Style resource ID to use for default styling of popup content.
 *///from   ww w.j a va  2s  .  c om
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
}

From source file:android.support.v7ox.widget.ListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Style attribute to read for default styling of popup content.
 * @param defStyleRes Style resource ID to use for default styling of popup content.
 */// ww  w  .  j  a va  2  s .  c  om
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;
    mHandler = new Handler(context.getMainLooper());

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Style attribute to read for default styling of popup content.
 * @param defStyleRes Style resource ID to use for default styling of popup content.
 *///from ww  w . j  a va 2s . c o  m
public AbstractXpListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;
    mHandler = new Handler(context.getMainLooper());

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    int defaultMargin = Util.dpToPxOffset(context, 8);
    final TypedArray b = context.obtainStyledAttributes(attrs, R.styleable.XpListPopupWindow, defStyleAttr,
            defStyleRes);
    if (b.hasValue(R.styleable.XpListPopupWindow_android_layout_margin)) {
        int margin = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_margin,
                defaultMargin);
        mMargins.bottom = margin;
        mMargins.top = margin;
        mMargins.left = margin;
        mMargins.right = margin;
    } else {
        if (API_18 && b.hasValue(R.styleable.XpListPopupWindow_android_layout_marginEnd)) {
            int margin = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginEnd, 0);
            if (mLayoutDirection == LayoutDirection.RTL) {
                mMargins.left = margin;
            } else {
                mMargins.right = margin;
            }
        } else {
            mMargins.right = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginRight,
                    defaultMargin);
        }
        if (API_18 && b.hasValue(R.styleable.XpListPopupWindow_android_layout_marginStart)) {
            int margin = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginStart, 0);
            if (mLayoutDirection == LayoutDirection.RTL) {
                mMargins.right = margin;
            } else {
                mMargins.left = margin;
            }
        } else {
            mMargins.left = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginLeft,
                    defaultMargin);
        }
        mMargins.top = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginTop,
                defaultMargin);
        mMargins.bottom = b.getDimensionPixelOffset(R.styleable.XpListPopupWindow_android_layout_marginBottom,
                defaultMargin);
    }
    b.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);

    setAllowScrollingAnchorParent(false);
}

From source file:com.justwayward.reader.ui.activity.ReadActivity.java

@OnClick(R.id.tvBookReadToc)
public void onClickToc() {
    gone(rlReadAaSet, rlReadMark);//from  ww  w . j a va 2s  . c  o  m
    if (!mTocListPopupWindow.isShowing()) {
        visible(mTvBookReadTocTitle);
        gone(mTvBookReadReading, mTvBookReadCommunity, mTvBookReadChangeSource);
        mTocListPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        mTocListPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        mTocListPopupWindow.show();
        mTocListPopupWindow.setSelection(currentChapter - 1);
        mTocListPopupWindow.getListView().setFastScrollEnabled(true);
    }
}

From source file:android.support.v7.widget.ListPopupWindow.java

/**
 * Filter key down events. By forwarding key down 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 onKeyDown
 * @param event event param passed to the host view's onKeyDown
 * @return true if the event was handled, false if it was ignored.
 *
 * @see #setModal(boolean)//  w  w w  . j a v a  2s  . c  om
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // when the drop down is shown, we drive it directly
    if (isShowing()) {
        // the key events are forwarded to the list in the drop down view
        // note that ListView handles space but we don't want that to happen
        // also if selection is not currently in the drop down, then don't
        // let center or enter presses go there since that would cause it
        // to select one of its items
        if (keyCode != KeyEvent.KEYCODE_SPACE
                && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) {
            int curIndex = mDropDownList.getSelectedItemPosition();
            boolean consumed;

            final boolean below = !mPopup.isAboveAnchor();

            final ListAdapter adapter = mAdapter;

            boolean allEnabled;
            int firstItem = Integer.MAX_VALUE;
            int lastItem = Integer.MIN_VALUE;

            if (adapter != null) {
                allEnabled = adapter.areAllItemsEnabled();
                firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true);
                lastItem = allEnabled ? adapter.getCount() - 1
                        : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
            }

            if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem)
                    || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
                // When the selection is at the top, we block the key
                // event to prevent focus from moving.
                clearListSelection();
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
                show();
                return true;
            } else {
                // WARNING: Please read the comment where mListSelectionHidden
                //          is declared
                mDropDownList.mListSelectionHidden = false;
            }

            consumed = mDropDownList.onKeyDown(keyCode, event);
            if (DEBUG)
                Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed);

            if (consumed) {
                // If it handled the key event, then the user is
                // navigating in the list, so we should put it in front.
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
                // Here's a little trick we need to do to make sure that
                // the list view is actually showing its focus indicator,
                // by ensuring it has focus and getting its window out
                // of touch mode.
                mDropDownList.requestFocusFromTouch();
                show();

                switch (keyCode) {
                // avoid passing the focus from the text view to the
                // next component
                case KeyEvent.KEYCODE_ENTER:
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_DPAD_DOWN:
                case KeyEvent.KEYCODE_DPAD_UP:
                    return true;
                }
            } else {
                if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    // when the selection is at the bottom, we block the
                    // event to avoid going to the next focusable widget
                    if (curIndex == lastItem) {
                        return true;
                    }
                } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) {
                    return true;
                }
            }
        }
    }

    return false;
}