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

/**
 * Toggle Soft Input.//from   w w w. ja v  a  2  s  .com
 * @param context
 * @param showFlags
 * @param hideFlags
 */
public static void toggleSoftInput(Context context, int showFlags, int hideFlags) {
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.toggleSoftInput(showFlags, hideFlags);
}

From source file:Main.java

public static void openKeyboard(final Context context, final EditText editText) {
    new Handler().postDelayed(new Runnable() {
        @Override/*w  ww .ja v  a2 s .co m*/
        public void run() {
            editText.requestFocus();
            editText.setSelection(editText.getText().toString().length());
            InputMethodManager imm = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
        }
    }, 300);
}

From source file:Main.java

/**
 * Helper Method to hide the keyboard//  w w w  .j a v  a  2 s.co  m
 */
public static void hideKeyboard(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:Main.java

public static boolean hideSoftInput(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        return imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }/*from w w w  .  j a  v a 2s .co  m*/
    return false;
}

From source file:Main.java

/**
 * Request to hide the soft input window from the context of the window that
 * is currently accepting input./* w  w  w  .  j  ava  2s.co  m*/
 * 
 * @param activity
 *            The currently activity, which shows the view receives soft
 *            keyboard input
 */
public static void showKeyboard(Activity activity) {
    if (null == activity) {
        return;
    }
    InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    View v = activity.getCurrentFocus();
    if (v != null) {
        im.showSoftInput(v, InputMethodManager.RESULT_UNCHANGED_SHOWN);
    }
}

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, InputMethodManager.SHOW_FORCED);
    }//from   www . j  a  v a2  s .co  m
    return false;
}

From source file:Main.java

public static void showSoftInput(Context context) {
    InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static void showSoftInput(final Context context, final EditText et) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public void run() {
            InputMethodManager inputManager = (InputMethodManager) context
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(et, 0);
        }/* w  ww  . ja va 2  s  .c  om*/
    }, 998);
}

From source file:Main.java

/**
 * Request to hide the soft input window from the context of the window that
 * is currently accepting input.//from ww w.j av a  2  s . c  o  m
 * 
 * @param view
 *            he currently focused view, which would like to receive soft
 *            keyboard input.
 */
public static void hideKeyboard(View view) {
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

From source file:Main.java

public static void hideSoftInput(Dialog dialog) {
    View view = dialog.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) dialog.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from   w  ww .j  a  v a  2s  .c o m*/
}