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

public static void closeSoftKeyboard(Context context) {
    if (context == null || !(context instanceof Activity) || ((Activity) context).getCurrentFocus() == null) {
        return;//w  w w .  j av a2 s  . c om
    }
    try {
        InputMethodManager inputMethodManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Hides the soft keyboard.// w w w . j  a  v  a  2s  . co m
 *
 * @param context Application context
 * @param windowToken Window token
 */
public static void hideSoftKeyboard(final Context context, final IBinder windowToken) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(windowToken, 0);
}

From source file:Main.java

private static void hideKeyboard() {
    // Check if no view has focus:
    View view = mainActivity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) mainActivity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//from ww  w .ja va2  s. co  m
}

From source file:Main.java

public static void hideSoftKeyPad(Context context, View view) {
    try {//from   w w w  .  j  av  a  2 s .  c om
        if (view == null) {
            return;
        } else if (view.getWindowToken() == null) {
            return;
        }

        InputMethodManager inputManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    } catch (Throwable ex) {
    }
}

From source file:Main.java

public static void minimizeKeyboard(Activity activity) {
    // Check if no view has focus:
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//from  w  w w  . j  a  va2  s .  c o  m
}

From source file:Main.java

/**
 * Hide soft key board./* w  w w .  j a  v  a  2s .  co m*/
 *
 * @param activity the activity
 */
public static void hideSoftKeyBoard(Activity activity) {
    InputMethodManager inputManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);

    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        IBinder windowToken = currentFocus.getWindowToken();
        inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
    } else {
        activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    }
}

From source file:Main.java

public static void hideInputKeyboard(Context context) {
    try {/*from  ww  w  .j a  v a 2 s . com*/
        View view = ((Activity) context).getWindow().peekDecorView();
        if (view != null && view.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void showInputKeyboard(Context context) {
    try {/*from   w ww . j  ava 2s .  co m*/
        View view = ((Activity) context).getWindow().peekDecorView();
        if (view != null && view.getWindowToken() != null) {
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
            imm.showSoftInput(view, 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void showSoftKeyboard(View view) {
    if (view == null)
        return;/*w  w w  . j av a2  s.  c  om*/
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    if (!view.isFocused())
        view.requestFocus();

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

From source file:Main.java

public static void showKeyboard(View view) {
    view.requestFocus();/*  w  w w .j a v a  2s .c o  m*/
    InputMethodManager inputManager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.showSoftInput(view, 0);
}