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

The following examples show how to use android.view.View#getWindowToken() . 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: PopupWindowCompat.java    From zen4android with 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 2
Source File: PopupIndicator.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
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 3
Source File: PopupIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
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 4
Source File: AppUtils.java    From YiZhi with 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 5
Source File: PopupIndicator.java    From AndroidSweetBehavior with Apache License 2.0 6 votes vote down vote up
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 6
Source File: PopupIndicator.java    From Genius-Android with 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 7
Source File: CountryPicker.java    From CountryPicker with 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 8
Source File: DynamicDialogUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * 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 9
Source File: PullToRefreshAttacher.java    From Bitocle with 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 10
Source File: SoftKeyboardUtil.java    From browser with GNU General Public License v2.0 5 votes vote down vote up
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 11
Source File: ActionBarPopupWindow.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: PinViewUtils.java    From PinView with 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 13
Source File: ActionMenuPresenter.java    From zen4android with 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 14
Source File: ActionBarPopupWindow.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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
Source File: ActionMenuPresenter.java    From zhangshangwuda with Apache License 2.0 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 File: ViewScope.java    From rxjava-RxLife with 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 17
Source File: KeyboardUtils.java    From CoolChat with 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 18
Source File: ActionMenuPresenter.java    From CSipSimple with GNU General Public License v3.0 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 19
Source File: ViewCompatBase.java    From letv with Apache License 2.0 4 votes vote down vote up
static boolean isAttachedToWindow(View view) {
    return view.getWindowToken() != null;
}
 
Example 20
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
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.
        }
    }
}