Example usage for android.view.inputmethod InputMethodManager toggleSoftInput

List of usage examples for android.view.inputmethod InputMethodManager toggleSoftInput

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager toggleSoftInput.

Prototype

public void toggleSoftInput(int showFlags, int hideFlags) 

Source Link

Document

This method toggles the input method window display.

Usage

From source file:me.panpf.tool4a.util.InputMethodUtils.java

/**
 * ????/*from w  ww  . j ava  2 s .  c  om*/
 *
 * @param editText        
 * @param moveCursorToEnd ??
 */
@SuppressWarnings("WeakerAccess")
public static void showSoftInput(EditText editText, boolean moveCursorToEnd) {
    // ?
    editText.requestFocus();

    InputMethodManager imm = (InputMethodManager) editText.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);

    // ??
    if (moveCursorToEnd) {
        moveCursorToEnd(editText);
    }
}

From source file:com.shopgun.android.utils.KeyboardUtils.java

/**
 * Request to show/hide the soft input window from the context of the window that is currently accepting input.
 *
 * @param context     A context/*from w  ww .ja v a 2  s  .  c  o m*/
 * @param windowToken A window token (IBinder)
 * @param visible     True to show input window, false to hide
 */
public static void setKeyboardVisible(Context context, IBinder windowToken, boolean visible) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (visible) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    } else if (windowToken != null) {
        imm.hideSoftInputFromWindow(windowToken, 0);
    }
}

From source file:org.mitre.svmp.client.IntentHandler.java

public static void inspect(SVMPProtocol.Response response, Context context) {
    SVMPProtocol.Intent intent = response.getIntent();
    switch (intent.getAction()) {
    case ACTION_DIAL:
        Log.d(TAG, String.format("Received 'call' Intent for number '%s'", intent.getData()));
        int telephonyEnabled = isTelephonyEnabled(context);
        if (telephonyEnabled == 0) {
            Intent call = new Intent(Intent.ACTION_CALL);
            call.setData(Uri.parse(intent.getData()));
            context.startActivity(call);
        } else {/*  w  ww .j  av a2  s  . co  m*/
            // phone calls are not supported on this device; send a Toast to
            // the user to let them know
            Toast toast = Toast.makeText(context, telephonyEnabled, Toast.LENGTH_LONG);
            toast.show();
        }
        break;
    case ACTION_VIEW:
        String jsonStr = intent.getData().toString();
        JSONObject jObj = null;
        String message = null;
        try {
            jObj = new JSONObject(jsonStr);
            message = jObj.getString("message");

            if (jObj != null && message != null) {
                switch (message) {
                case "keyboardStarted":

                    InputMethodManager imm = (InputMethodManager) context
                            .getSystemService(context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                    break;

                case "appInstalled":

                    String success = jObj.getString("success");
                    String packageName = jObj.getString("packageId");

                    if (success != null) {
                        if (success.equals("true"))
                            startApp(packageName, context);
                    }
                    break;

                default:
                    break;
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        break;
    default:
        break;
    }
}

From source file:Main.java

public static void changeKeyBoard(Context context, EditText editText) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    editText.setFocusable(true);// w  w w.  j a  v a  2  s  .  c  o m
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    if (imm.isActive()) {
        // imm.hideSoftInputFromWindow(getCurrentFocus()
        // .getWindowToken(),
        // InputMethodManager.HIDE_NOT_ALWAYS);
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:com.app.sample.chatting.widget.KJChatKeyboard.java

/**
 * //  w w  w. jav  a  2s.c  om
 */
public static void showKeyboard(Context context) {
    Activity activity = (Activity) context;
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

From source file:com.jefftharris.passwdsafe.lib.view.GuiUtils.java

/**
 * Set the keyboard visibility on a view
 */// w w w.j  a v  a 2 s  .  com
public static void setKeyboardVisible(View v, Context ctx, boolean visible) {
    InputMethodManager imm = (InputMethodManager) ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (visible) {
        if (ApiCompat.SDK_VERSION >= ApiCompat.SDK_HONEYCOMB) {
            imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
        } else {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    } else {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
}

From source file:com.orange.ocara.ui.activity.BaseActivity.java

public static void showKeyboard(Context context) {
    InputMethodManager service = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    service.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.SHOW_IMPLICIT);
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * /*from  w  w  w  .  j  ava  2 s .com*/
 * @param context
 */
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:org.csware.ee.utils.Tools.java

/**
 * ??/*from   ww  w. j a v a2 s .c  om*/
 * ??,??
 */
public static void toggleInput(Context context) {
    InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static void showKeyboard(Context context) {
    if (hasHardKeyboard(context))
        return;/*from w  w  w  .j  a v a2s .com*/
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null)
        L.d("No input method manager");
    else
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}