Java Code Examples for android.view.View.getWindowToken()

The following are Jave code examples for showing how to use getWindowToken() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: MusicX-music-player   File: AudioWidget.java   Source Code and License Vote up 7 votes
private void show(View view, int left, int top) {
    if (view.getParent() != null || view.getWindowToken() != null) {
        windowManager.removeView(view);
    }
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                    | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.START | Gravity.TOP;
    params.x = left;
    params.y = top;
    windowManager.addView(view, params);
}
 
Example 2
Project: javaide   File: ProjectManagerActivity.java   Source Code and License Vote up 6 votes
protected void closeKeyBoard() throws NullPointerException {
    // Central system API to the overall input method framework (IMF) architecture
    InputMethodManager inputManager =
            (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    View currentFocus = getCurrentFocus();
    if (currentFocus != null) {
        // Base interface for a remotable object
        IBinder windowToken = currentFocus.getWindowToken();

        // Hide type
        int hideType = InputMethodManager.HIDE_NOT_ALWAYS;

        // Hide the KeyBoard
        inputManager.hideSoftInputFromWindow(windowToken, hideType);
    }
}
 
Example 3
Project: CSipSimple   File: PopupWindowCompat.java   Source Code and License Vote up 6 votes
private void registerListener(View anchor) {
    // Don't do anything if we haven't managed to patch the super listener.
    // And don't bother attaching the listener if the anchor view isn't
    // attached. This means we'll only have to deal with the real VTO owned
    // by the ViewRoot.
    if (mSuperScrollListener != null) {
        ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver()
                : null;
        if (vto != mViewTreeObserver) {
            if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            }
            if ((mViewTreeObserver = vto) != null) {
                vto.addOnScrollChangedListener(mSuperScrollListener);
            }
        }
    }
}
 
Example 4
Project: FragmentCapsulation   File: KeyboardUtils.java   Source Code and License Vote up 6 votes
/**
 * 关闭软键盘
 * @param activity
 */
public static void closeInputKeyboard(Activity activity) {
    if(activity != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if(inputMethodManager != null) {
            boolean active = inputMethodManager.isActive();
            if (active) {
                View currentFocus = activity.getCurrentFocus();
                if (currentFocus != null) {
                    IBinder windowToken = currentFocus.getWindowToken();
                    if (windowToken != null) {
                        inputMethodManager.hideSoftInputFromWindow(
                                windowToken,
                                InputMethodManager.HIDE_NOT_ALWAYS);
                    }
                }
            }
        }
    }
}
 
Example 5
Project: Unofficial-Ups   File: UiUtils.java   Source Code and License Vote up 5 votes
public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager =
            (InputMethodManager) activity.getSystemService(
                    Activity.INPUT_METHOD_SERVICE);
    View focusedView = activity.getCurrentFocus();
    if(focusedView == null)
        return;
    IBinder token = focusedView.getWindowToken();
    if(token != null)
        inputMethodManager.hideSoftInputFromWindow(token, 0);
}
 
Example 6
Project: GitHub   File: EmoticonsKeyboardUtils.java   Source Code and License Vote up 5 votes
/**
 * 关闭软键盘
 * 当使用全屏主题的时候,XhsEmoticonsKeyBoard屏蔽了焦点.关闭软键盘时,直接指定 closeSoftKeyboard(EditView)
 * @param view
 */
public static void closeSoftKeyboard(View view) {
    if (view == null || view.getWindowToken() == null) {
        return;
    }
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
 
Example 7
Project: GitHub   File: DialogUtils.java   Source Code and License Vote up 5 votes
public static void hideKeyboard(@NonNull final DialogInterface di,
                                @NonNull final MaterialDialog.Builder builder) {
    final MaterialDialog dialog = (MaterialDialog) di;
    if (dialog.getInputEditText() == null) return;
    InputMethodManager imm = (InputMethodManager) builder.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        final View currentFocus = dialog.getCurrentFocus();
        final IBinder windowToken = currentFocus != null ?
                currentFocus.getWindowToken() : dialog.getView().getWindowToken();
        if (windowToken != null) {
            imm.hideSoftInputFromWindow(windowToken, 0);
        }
    }
}
 
Example 8
Project: LaunchEnr   File: Launcher.java   Source Code and License Vote up 5 votes
public static void closeKeyboard(Activity activity) {

        final View v = activity.getWindow().peekDecorView();
        if (v != null && v.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) activity.getSystemService(
                    INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }
 
Example 9
Project: PlusGram   File: EmojiView.java   Source Code and License Vote up 5 votes
private void registerListener(View anchor) {
    if (mSuperScrollListener != null) {
        ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
        if (vto != mViewTreeObserver) {
            if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            }
            if ((mViewTreeObserver = vto) != null) {
                vto.addOnScrollChangedListener(mSuperScrollListener);
            }
        }
    }
}
 
Example 10
Project: yyox   File: EmoticonsKeyboardUtils.java   Source Code and License Vote up 5 votes
/**
 * 关闭软键盘
 * 当使用全屏主题的时候,XhsEmoticonsKeyBoard屏蔽了焦点.关闭软键盘时,直接指定 closeSoftKeyboard(EditView)
 * @param view
 */
public static void closeSoftKeyboard(View view) {
    if (view == null || view.getWindowToken() == null) {
        return;
    }
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
 
Example 11
Project: airgram   File: ActionBarPopupWindow.java   Source Code and License Vote up 5 votes
private void registerListener(View anchor) {
    if (mSuperScrollListener != null) {
        ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
        if (vto != mViewTreeObserver) {
            if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            }
            if ((mViewTreeObserver = vto) != null) {
                vto.addOnScrollChangedListener(mSuperScrollListener);
            }
        }
    }
}
 
Example 12
Project: CSipSimple   File: MenuPopupHelper.java   Source Code and License Vote up 5 votes
public boolean tryShow() {
    mPopup = new IcsListPopupWindow(mContext, null, 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) {
        // Don't attach to the VTO unless the anchor itself is attached to avoid VTO-related leaks.
        if (anchor.getWindowToken() != null) {
            ViewTreeObserver vto = anchor.getViewTreeObserver();
            if (vto != mTreeObserver) {
                if (mTreeObserver != null && mTreeObserver.isAlive()) {
                    mTreeObserver.removeGlobalOnLayoutListener(this);
                }
                if ((mTreeObserver = vto) != null) {
                    vto.addOnGlobalLayoutListener(this);
                }
            }
        } else if (anchor instanceof View_HasStateListenerSupport) {
            ((View_HasStateListenerSupport) 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;
}
 
Example 13
Project: chromium-for-android-56-debug-video   File: CompositorViewHolder.java   Source Code and License Vote up 5 votes
/**
 * Resize {@code view} to match the size of this {@link FrameLayout}.  This will only happen if
 * {@code view} is not {@code null} and if {@link View#getWindowToken()} returns {@code null}
 * (the {@link View} is not part of the view hierarchy).
 * @param view The {@link View} to resize.
 * @return     Whether or not {@code view} was resized.
 */
private boolean setSizeOfUnattachedView(View view) {
    // Need to call layout() for the following View if it is not attached to the view hierarchy.
    // Calling onSizeChanged() is dangerous because if the View has a different size than the
    // ContentViewCore it might think a future size update is a NOOP and not call
    // onSizeChanged() on the ContentViewCore.
    if (view == null || view.getWindowToken() != null) return false;
    int width = getWidth();
    int height = getHeight();
    view.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
    return true;
}
 
Example 14
Project: PlusGram   File: ActionBarPopupWindow.java   Source Code and License Vote up 5 votes
private void registerListener(View anchor) {
    if (mSuperScrollListener != null) {
        ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
        if (vto != mViewTreeObserver) {
            if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            }
            if ((mViewTreeObserver = vto) != null) {
                vto.addOnScrollChangedListener(mSuperScrollListener);
            }
        }
    }
}
 
Example 15
Project: youkes_browser   File: CCPActivityBase.java   Source Code and License Vote up 5 votes
/**
 * hide inputMethod
 */
public void hideSoftKeyboard() {
    InputMethodManager inputMethodManager = (InputMethodManager) mActionBarActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if(inputMethodManager != null ) {
        View localView = mActionBarActivity.getCurrentFocus();
        if(localView != null && localView.getWindowToken() != null ) {
            IBinder windowToken = localView.getWindowToken();
            inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
        }
    }
}
 
Example 16
Project: browser   File: CCPActivityBase.java   Source Code and License Vote up 5 votes
/**
 *
 */
public void displaySoftKeyboard() {
    final FragmentActivity activity = mActionBarActivity;
    // Display the soft keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        View localView = activity.getCurrentFocus();
        if (localView != null && localView.getWindowToken() != null) {
            inputMethodManager.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
 
Example 17
Project: KrGallery   File: ActionBarPopupWindow.java   Source Code and License Vote up 5 votes
private void registerListener(View anchor) {
    if (mSuperScrollListener != null) {
        ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
        if (vto != mViewTreeObserver) {
            if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
                mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
            }
            if ((mViewTreeObserver = vto) != null) {
                vto.addOnScrollChangedListener(mSuperScrollListener);
            }
        }
    }
}
 
Example 18
Project: youkes_browser   File: CCPActivityBase.java   Source Code and License Vote up 5 votes
/**
 *
 */
public void displaySoftKeyboard() {
    final FragmentActivity activity = mActionBarActivity;
    // Display the soft keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        View localView = activity.getCurrentFocus();
        if (localView != null && localView.getWindowToken() != null) {
            inputMethodManager.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
 
Example 19
Project: letv   File: ViewCompatBase.java   Source Code and License Vote up 4 votes
static boolean isAttachedToWindow(View view) {
    return view.getWindowToken() != null;
}
 
Example 20
Project: boohee_v5.6   File: ViewCompatBase.java   Source Code and License Vote up 4 votes
static boolean isAttachedToWindow(View view) {
    return view.getWindowToken() != null;
}