Example usage for android.content Context INPUT_METHOD_SERVICE

List of usage examples for android.content Context INPUT_METHOD_SERVICE

Introduction

In this page you can find the example usage for android.content Context INPUT_METHOD_SERVICE.

Prototype

String INPUT_METHOD_SERVICE

To view the source code for android.content Context INPUT_METHOD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.

Usage

From source file:Main.java

/**
 * <pre>/*www.  j  av a  2  s .c  o m*/
 * Hide keyboard.
 * </pre>
 */
public static void hideKeyboard() {
    Activity activity = (Activity) getCurrentContext();
    View currentFocusedView = activity.getCurrentFocus();
    if (currentFocusedView != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(currentFocusedView.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void closeSoftKeyboard(Context context) {
    if (context == null || !(context instanceof Activity) || ((Activity) context).getCurrentFocus() == null) {
        return;/*from  w w w  . ja v  a2  s.  c  o m*/
    }
    try {
        View view = ((Activity) context).getCurrentFocus();
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        view.clearFocus();
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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);
    }/*from w ww.  j av a 2s  .  c o  m*/
}

From source file:Main.java

/**
 * Dismiss the keyboard if it is displayed by any of the listed views
 * @param views - a list of views that might potentially be displaying the keyboard
 *///from w  ww . j  a v a  2s  .c  o  m
public static void hideSoftInputForViews(Context context, View... views) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    for (View v : views) {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void closeInputMethod(final Activity activity, final View view) {
    final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static void softKeyboardDelayed(final View view) {
    view.post(new Runnable() {
        @Override//from  w w w  . j a  va2s.  c  o m
        public void run() {
            if (!isHardwareKeyboardAvailable(view.getContext())) {
                InputMethodManager imm = (InputMethodManager) view.getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
                }
            }
        }
    });
}

From source file:Main.java

public static void hideKeyboard(View view) {
    if (view == null) {
        return;/*from ww w .  j a  v  a2s  .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 showKeyboard(View view) {
    if (view == null) {
        return;/*from   ww  w. j  ava  2  s  .  c om*/
    }
    InputMethodManager inputManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}

From source file:Main.java

public static void showKeyboard(View view) {
    if (view == null) {
        return;//from www.  j  a  v  a  2 s.c  o  m
    }
    InputMethodManager inputManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);

    ((InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view,
            0);
}

From source file:Main.java

public static boolean isKeyboardShowed(View view) {
    if (view == null) {
        return false;
    }//from  w w w . j  a  va  2s .  c  om
    InputMethodManager inputManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    return inputManager.isActive(view);
}