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 hideSoftInput(Activity activity) {
    View currentFocus = activity.getCurrentFocus();
    if (currentFocus != null) {
        IBinder windowToken = currentFocus.getWindowToken();
        if (windowToken != null) {
            InputMethodManager manager = (InputMethodManager) (activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE));
            if (manager != null) {
                manager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS);
            }/*w  w  w.java2  s  . c  o  m*/
        }
    }
}

From source file:Main.java

public static void hideKeyboard(Activity activity) {
    imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

/**
 * Dismisses the soft keyboard if it's present on the screen, otherwise this call is silent.
 *
 * @param context// w  w  w . ja v  a2 s.c  om
 * @param editText the EditText that the soft keyboard is "attached" to
 */
public static void closeSoftKeyboard(Context context, EditText editText) {
    InputMethodManager manager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    manager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}

From source file:Main.java

public static void hideKeyboard(View view) {
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from   w  w w .  ja  v  a2s  . c o m*/
}

From source file:Main.java

/**
 * Hides the SoftKeyboard input careful as if you pass a view that didn't open the
 * soft-keyboard it will ignore this call and not close
 *
 * @param context the context / usually the activity that the view is being shown within
 * @param v       the view that opened the soft-keyboard
 *//*from ww w .  j  a v a  2s. co m*/
public static void requestHideKeyboard(Context context, View v) {
    InputMethodManager imm = ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE));
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}

From source file:Main.java

/**
 * Force show soft keyboard with show flag = InputMethodManager.SHOW_FORCED and hide flag = 0.
 * @param context Context to get system service input method.
 * @param viewBinder View has current focus.
 *///from w w w .  j  a va 2 s .c om
public static void forceShowSoftInput(Context context, View view) {
    if (view != null) {
        view.requestFocus();
    }
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); //Hide Flag = 0
}

From source file:Main.java

public static boolean showSoftInput(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        return imm.showSoftInput(view, 2);
    } else {/*  w ww. j  ava2s  . c o  m*/
        return false;
    }
}

From source file:Main.java

/**
 * Explicitly request that the current input method's soft input area be
 * shown to the user, if needed.//from w  ww. ja v  a2s  . c om
 * 
 * @param view
 *            The currently focused view, which would like to receive soft
 *            keyboard input.
 */
public static void showKeyboard(View view) {
    view.requestFocus();
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(view, InputMethodManager.RESULT_UNCHANGED_SHOWN);
}

From source file:Main.java

public static void hideInput(Activity activity) {
    if (activity != null && activity.getCurrentFocus() != null) {
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//from  www.j ava  2  s .  c  o m
}

From source file:Main.java

public static void hideKeyboard(View view) {
    InputMethodManager imm = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}