Example usage for android.view View getWindowToken

List of usage examples for android.view View getWindowToken

Introduction

In this page you can find the example usage for android.view View getWindowToken.

Prototype

public IBinder getWindowToken() 

Source Link

Document

Retrieve a unique token identifying the window this view is attached to.

Usage

From source file:Main.java

public static void hideSoftInput(Context context) {
    View view = ((Activity) context).getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from w  ww . ja v a  2s  .  co m
}

From source file:Main.java

public static void closeKeyboard(Activity activity) {
    View view = activity.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*  ww  w. j  av a2  s .  co m*/
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void hideSoftInput(Context context) {
    View view = ((Activity) context).getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*  ww  w . j  a va 2 s .  c o m*/
}

From source file:Main.java

public static void autoHideInput(final View view, final InputMethodManager imm) {

    if (!(view instanceof EditText)) {
        view.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                return false;
            }//from   ww  w . j a v a 2  s .c  o  m

        });
    }

    if (view instanceof ViewGroup) {

        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            View innerView = ((ViewGroup) view).getChildAt(i);
            autoHideInput(innerView, imm);
        }
    }
}

From source file:Main.java

public static void closeKeyboard(Dialog dialog) {
    View view = dialog.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) dialog.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from  w w w  .  j a va 2 s.c  om
}

From source file:Main.java

public static void popSoftkeyboard(Context ctx, View view, boolean wantPop) {
    InputMethodManager imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (wantPop) {
        view.requestFocus();/*from  www.j  a  va 2 s  .c  om*/
        imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(View view) {
    if (view == null) {
        return;//from   w w  w.  j  av  a 2  s.  c o  m
    }
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (!imm.isActive()) {
        return;
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void popSoftKeyboard(Context context, View view, boolean isShow) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (isShow) {
        view.requestFocus();/*from  w  w w  .j  av a 2s.com*/
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void popSoftKeyboard(Context context, View view, boolean wantPop) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (wantPop) {
        view.requestFocus();/*w  w  w  .j  a  v  a 2s .c o m*/
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    } else {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity, View view) {
    if (activity != null) {
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }//w  ww . j  av  a  2  s  . co m
        } else {
            hideKeyboard(activity);
        }
    }
}