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

The following examples show how to use android.view.View#getWindowToken() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public void showIndicator(View parent, Rect touchBounds) {
    if (isShowing()) {
        mPopupView.mMarker.animateOpen();
        return;
    }

    IBinder windowToken = parent.getWindowToken();
    if (windowToken != null) {
        WindowManager.LayoutParams p = createPopupLayout(windowToken);

        p.gravity = Gravity.TOP | GravityCompat.START;
        updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
        mShowing = true;

        translateViewIntoPosition(touchBounds.centerX());
        invokePopup(p);
    }
}
 
Example 2
public void showIndicator(View parent) {
        if (isShowing()) {
//            mPopupView.mMarker.animateOpen();
            return;
        }

        IBinder windowToken = parent.getWindowToken();

        if (windowToken != null) {
            WindowManager.LayoutParams p = createPopupLayout(windowToken);

            p.gravity = Gravity.TOP | GravityCompat.START;
            updateLayoutParamsForPosiion(parent, p);
            mShowing = true;
            invokePopup(p);
        }

    }
 
Example 3
Source Project: Genius-Android   File: PopupIndicator.java    License: Apache License 2.0 6 votes vote down vote up
public void showIndicator(View parent, Point point) {
    if (isShowing()) {
        mPopupView.mMarker.animateOpen();
        return;
    }

    IBinder windowToken = parent.getWindowToken();
    if (windowToken != null) {
        WindowManager.LayoutParams p = createPopupLayout(windowToken);

        /** Raw bit controlling whether the layout direction is relative or not (START/END instead of
         * absolute LEFT/RIGHT).
         */
        int RELATIVE_LAYOUT_DIRECTION = 0x00800000;

        /** Push object to x-axis position at the start of its container, not changing its size. */
        int START = RELATIVE_LAYOUT_DIRECTION | Gravity.LEFT;

        p.gravity = Gravity.TOP | START;
        updateLayoutParamsForPosition(parent, p, point.y);
        mShowing = true;

        translateViewIntoPosition(point.x);
        invokePopup(p);
    }
}
 
Example 4
Source Project: CountryPicker   File: CountryPicker.java    License: Apache License 2.0 6 votes vote down vote up
/**
* Method to hide keyboard if it's open
*/
public void hideKeyboard() {
  try {
    Activity activity = getActivity();
    if (activity == null) {
      return;
    }
    InputMethodManager input
          = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (input == null) {
      return;
    }
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus == null || currentFocus.getWindowToken() == null) {
      return;
    }

    input.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);
  } catch (Exception e) {
      // ignoring any exceptions
  }
}
 
Example 5
/**
 * Bind the dialog with a window token.
 * <p>Useful to display it from a service.
 *
 * @param view The view to bind the dialog.
 * @param dialog The dialog to be displayed.
 * @param type The dialog type.
 * @param windowAnimations The custom animation used for the window.
 *
 * @return The bound dialog with the supplied view.
 */
public static Dialog bindDialog(@Nullable View view,
        @NonNull Dialog dialog, int type, @StyleRes int windowAnimations) {
    Window window = dialog.getWindow();

    if (window != null) {
        if (view != null && view.getWindowToken() != null) {
            window.getAttributes().token = view.getWindowToken();
        }

        window.setType(type);
        window.setWindowAnimations(windowAnimations);
        window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }

    return dialog;
}
 
Example 6
Source Project: YiZhi   File: AppUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据传入控件的坐标和用户的焦点坐标,判断是否隐藏键盘,如果点击的位置在控件内,则不隐藏键盘
 *
 * @param view
 *            控件view
 * @param event
 *            焦点位置
 * @return 是否隐藏
 */
public static void hideKeyboard(MotionEvent event, View view,
                                Activity activity) {
    try {
        if (view != null && view instanceof EditText) {
            int[] location = { 0, 0 };
            view.getLocationInWindow(location);
            int left = location[0], top = location[1], right = left
                    + view.getWidth(), bootom = top + view.getHeight();
            // 判断焦点位置坐标是否在空间内,如果位置在控件外,则隐藏键盘
            if (event.getRawX() < left || event.getRawX() > right
                    || event.getY() < top || event.getRawY() > bootom) {
                // 隐藏键盘
                IBinder token = view.getWindowToken();
                InputMethodManager inputMethodManager = (InputMethodManager) activity
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(token,
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
public void showIndicator(View parent, Rect touchBounds) {
    if (isShowing()) {
        mPopupView.mMarker.animateOpen();
        return;
    }

    IBinder windowToken = parent.getWindowToken();
    if (windowToken != null) {
        WindowManager.LayoutParams p = createPopupLayout(windowToken);

        p.gravity = Gravity.TOP | GravityCompat.START;
        updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
        mShowing = true;

        translateViewIntoPosition(touchBounds.centerX());
        invokePopup(p);
    }
}
 
Example 8
Source Project: zen4android   File: PopupWindowCompat.java    License: MIT License 6 votes vote down vote up
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 9
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
public void run() {
    mMenu.changeMenuMode();
    final View menuView = (View) mMenuView;
    if (menuView != null && menuView.getWindowToken() != null && mPopup.tryShow()) {
        mOverflowPopup = mPopup;
    }
    mPostedOpenRunnable = null;
}
 
Example 11
Source Project: CoolChat   File: KeyboardUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏输入法
 *
 * @param currentFocusView 当前焦点view
 */
public static void hideKeyboard(View currentFocusView) {
    if (currentFocusView != null) {
        IBinder token = currentFocusView.getWindowToken();
        if (token != null) {
            InputMethodManager im = (InputMethodManager) currentFocusView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            im.hideSoftInputFromWindow(token, 0);
        }
    }
}
 
Example 12
Source Project: rxjava-RxLife   File: ViewScope.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onScopeStart(Disposable d) {
    disposable = d;
    final View view = this.view;
    if (view == null)
        throw new NullPointerException("view is null");
    boolean isAttached = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && view.isAttachedToWindow())
        || view.getWindowToken() != null;
    if (!isAttached && !ignoreAttach)
        throw new OutsideScopeException("View is not attached!");
    view.addOnAttachStateChangeListener(this);
}
 
Example 13
public void run() {
    mMenu.changeMenuMode();
    final View menuView = (View) mMenuView;
    if (menuView != null && menuView.getWindowToken() != null && mPopup.tryShow()) {
        mOverflowPopup = mPopup;
    }
    mPostedOpenRunnable = null;
}
 
Example 14
Source Project: Bitocle   File: PullToRefreshAttacher.java    License: Apache License 2.0 5 votes vote down vote up
protected void removeHeaderViewFromActivity(View headerView) {
    mAddHeaderViewRunnable.finish();

    if (headerView.getWindowToken() != null) {
        mActivity.getWindowManager().removeViewImmediate(headerView);
    }
}
 
Example 15
Source Project: zen4android   File: ActionMenuPresenter.java    License: MIT License 5 votes vote down vote up
public void run() {
    mMenu.changeMenuMode();
    final View menuView = (View) mMenuView;
    if (menuView != null && menuView.getWindowToken() != null && mPopup.tryShow()) {
        mOverflowPopup = mPopup;
    }
    mPostedOpenRunnable = null;
}
 
Example 16
Source Project: PinView   File: PinViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Hides the already popped up keyboard from the screen.
 *
 * @param context Context to get current focus.
 */
public static void hideKeyboard(Context context) {
    try {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        View currentFocus = ((Activity) context).getCurrentFocus();
        if (imm != null && currentFocus != null) {
            IBinder windowToken = currentFocus.getWindowToken();
            if (windowToken != null) {
                imm.hideSoftInputFromWindow(windowToken, 0);
            }
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "Can't even hide keyboard " + e.getMessage());
    }
}
 
Example 17
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
public static void hideSoftKeyboard(Activity act) {
    InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
    if(inputMethodManager != null ) {
        View localView = act.getCurrentFocus();
        if(localView != null && localView.getWindowToken() != null ) {
            IBinder windowToken = localView.getWindowToken();
            inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
        }
    }
}
 
Example 19
private void handleDestroyActivity(IBinder token, boolean finishing,
        int configChanges, boolean getNonConfigInstance) {
    ActivityClientRecord r = performDestroyActivity(token, finishing,
            configChanges, getNonConfigInstance);
    if (r != null) {
        cleanUpPendingRemoveWindows(r);
        WindowManager wm = r.activity.getWindowManager();
        View v = r.activity.mDecor;
        if (v != null) {
            if (r.activity.mVisibleFromServer) {
                mNumVisibleActivities--;
            }
            IBinder wtoken = v.getWindowToken();
            if (r.activity.mWindowAdded) {
                if (r.onlyLocalRequest) {
                    // Hold off on removing this until the new activity's
                    // window is being added.
                    r.mPendingRemoveWindow = v;
                    r.mPendingRemoveWindowManager = wm;
                } else {
                    wm.removeViewImmediate(v);
                }
            }
            if (wtoken != null && r.mPendingRemoveWindow == null) {
                WindowManagerImpl.getDefault().closeAll(wtoken,
                        r.activity.getClass().getName(), "Activity");
            }
            r.activity.mDecor = null;
        }
        if (r.mPendingRemoveWindow == null) {
            // If we are delaying the removal of the activity window, then
            // we can't clean up all windows here.  Note that we can't do
            // so later either, which means any windows that aren't closed
            // by the app will leak.  Well we try to warning them a lot
            // about leaking windows, because that is a bug, so if they are
            // using this recreate facility then they get to live with leaks.
            WindowManagerImpl.getDefault().closeAll(token,
                    r.activity.getClass().getName(), "Activity");
        }

        // Mocked out contexts won't be participating in the normal
        // process lifecycle, but if we're running with a proper
        // ApplicationContext we need to have it tear down things
        // cleanly.
        Context c = r.activity.getBaseContext();
        if (c instanceof ContextImpl) {
            ((ContextImpl) c).scheduleFinalCleanup(
                    r.activity.getClass().getName(), "Activity");
        }
    }
    if (finishing) {
        try {
            ActivityManagerNative.getDefault().activityDestroyed(token);
        } catch (RemoteException ex) {
            // If the system process has died, it's game over for everyone.
        }
    }
}
 
Example 20
Source Project: letv   File: ViewCompatBase.java    License: Apache License 2.0 4 votes vote down vote up
static boolean isAttachedToWindow(View view) {
    return view.getWindowToken() != null;
}