Example usage for android.view.inputmethod InputMethodManager showSoftInput

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

Introduction

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

Prototype

public boolean showSoftInput(View view, int flags) 

Source Link

Document

Synonym for #showSoftInput(View,int,ResultReceiver) without a result receiver: explicitly request that the current input method's soft input area be shown to the user, if needed.

Usage

From source file:ch.jeda.platform.android.InputDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
    builder.setTitle(this.request.getTitle());
    builder.setMessage(this.request.getMessage());
    this.input = new EditText(this.getActivity());
    // This is required in order to show soft keyboard when input is focused.
    this.input.setFocusableInTouchMode(true);
    this.input.setImeOptions(EditorInfo.IME_ACTION_DONE);
    this.input.setInputType(EditorInfo.TYPE_CLASS_TEXT);
    this.input.addTextChangedListener(this);
    final InputMethodManager imm = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(this.input, InputMethodManager.SHOW_IMPLICIT);
    builder.setView(this.input);
    builder.setPositiveButton("OK", this);
    builder.setNegativeButton("Abbrechen", this);
    return builder.create();
}

From source file:de.grobox.liberario.favorites.trips.SpecialLocationFragment.java

@Override
public void onResume() {
    super.onResume();

    getDialog().setCanceledOnTouchOutside(true);

    // set width to match parent
    Window window = getDialog().getWindow();
    if (window != null) {
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.TOP);//from  ww  w .  j a va2 s  .c o  m
    }

    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(loc, InputMethodManager.SHOW_FORCED);
}

From source file:com.nicefontaine.seanachie.ui.form.FormFragment.java

private void initEditText() {
    editText.requestFocus();/*from ww w .ja v a  2s  .c o  m*/
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    editText.setOnFocusChangeListener((v, hasFocus) -> {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    });
}

From source file:eu.basicairdata.graziano.gpslogger.FragmentPlacemarkDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder createPlacemarkAlert = new AlertDialog.Builder(getActivity(), R.style.StyledDialog);

    createPlacemarkAlert.setTitle(R.string.dlg_add_placemark);
    createPlacemarkAlert.setIcon(R.mipmap.ic_add_location_white_24dp);

    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = (View) inflater.inflate(R.layout.fragment_placemark_dialog, null);

    DescEditText = (EditText) view.findViewById(R.id.placemark_description);
    DescEditText.postDelayed(new Runnable() {
        public void run() {
            if (isAdded()) {
                DescEditText.requestFocus();
                InputMethodManager mgr = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.showSoftInput(DescEditText, InputMethodManager.SHOW_IMPLICIT);
            }/*from w  w  w.  j ava  2 s  . c o m*/
        }
    }, 200);

    createPlacemarkAlert.setView(view)

            //.setPositiveButton(R.string.conti_nue, new DialogInterface.OnClickListener() {
            .setPositiveButton(R.string.dlg_button_add, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {
                    if (isAdded()) {
                        String PlacemarkDescription = DescEditText.getText().toString();
                        final GPSApplication GlobalVariables = (GPSApplication) getActivity()
                                .getApplicationContext();
                        GlobalVariables.setPlacemarkDescription(PlacemarkDescription.trim());
                        EventBus.getDefault().post(EventBusMSG.ADD_PLACEMARK);
                        //Log.w("myApp", "[#] FragmentPlacemarkDialog.java - posted ADD_PLACEMARK: " + PlacemarkDescription);
                    }
                }
            })
            //.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            .setNegativeButton(R.string.dlg_button_cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int id) {

                }
            });
    return createPlacemarkAlert.create();
}

From source file:com.raspi.chatapp.ui.password.PinFragment.java

@Override
public void onResume() {
    super.onResume();

    EditText pin = (EditText) getView().findViewById(R.id.pin);
    // always focus the pinEditText
    pin.setFocusableInTouchMode(true);//from   w w w .  ja  va  2s  .  c  om
    pin.requestFocus();
    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(pin, InputMethodManager.SHOW_IMPLICIT);
    pin.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            // if the text reached a length of 4 chars check the password and
            // clear the editText
            if (s.length() == 4) {
                char[] pwd = new char[4];
                s.getChars(0, 4, pwd, 0);
                mListener.onPasswordEntered(pwd);
                s.clear();
                // otherwise make sure that the invalid pwd textView is gone
            } else
                getView().findViewById(R.id.password_invalid).setVisibility(View.GONE);
        }
    });
}

From source file:org.catrobat.catroid.ui.dialogs.LoginRegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_register, null);

    usernameEditText = (EditText) rootView.findViewById(R.id.username);
    passwordEditText = (EditText) rootView.findViewById(R.id.password);
    termsOfUseLinkTextView = (TextView) rootView.findViewById(R.id.register_terms_link);

    String termsOfUseUrl = getString(R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(R.string.register_pocketcode_terms_of_use_text));
    termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance());
    termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl));

    usernameEditText.setText("");
    passwordEditText.setText("");

    final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView)
            .setTitle(R.string.login_register_dialog_title).setPositiveButton(R.string.login_or_register, null)
            .setNeutralButton(R.string.password_forgotten, null).create();
    loginRegisterDialog.setCanceledOnTouchOutside(true);
    loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    loginRegisterDialog.setOnShowListener(new OnShowListener() {
        @Override/*  www .j  a v a2s .  c o  m*/
        public void onShow(DialogInterface dialog) {
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT);

            Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            loginRegisterButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleLoginRegisterButtonClick();
                }
            });

            Button passwordForgottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
            passwordForgottenButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handlePasswordForgottenButtonClick();
                }
            });
        }
    });

    return loginRegisterDialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.LoginRegisterDialog.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    View rootView = LayoutInflater.from(getActivity())
            .inflate(hku.fyp14017.blencode.R.layout.dialog_login_register, null);

    usernameEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.username);
    passwordEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.password);
    termsOfUseLinkTextView = (TextView) rootView.findViewById(hku.fyp14017.blencode.R.id.register_terms_link);

    String termsOfUseUrl = getString(hku.fyp14017.blencode.R.string.about_link_template,
            Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(hku.fyp14017.blencode.R.string.register_pocketcode_terms_of_use_text));
    termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance());
    termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl));

    usernameEditText.setText("");
    passwordEditText.setText("");

    final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView)
            .setTitle(hku.fyp14017.blencode.R.string.login_register_dialog_title)
            .setPositiveButton(hku.fyp14017.blencode.R.string.login_or_register, null)
            .setNeutralButton(hku.fyp14017.blencode.R.string.password_forgotten, null).create();
    loginRegisterDialog.setCanceledOnTouchOutside(true);
    loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    loginRegisterDialog.setOnShowListener(new OnShowListener() {
        @Override//from w  w  w .  j a va 2s.  co m
        public void onShow(DialogInterface dialog) {
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT);

            Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            loginRegisterButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleLoginRegisterButtonClick();
                }
            });

            Button passwordFhkuottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL);
            passwordFhkuottenButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    handlePasswordForgottenButtonClick();
                }
            });
        }
    });

    return loginRegisterDialog;
}

From source file:com.app.blockydemo.ui.dialogs.ScriptNameDialog.java

private void handleOnShow(final Dialog dialogEditName) {
    final Button positiveButton = ((AlertDialog) dialogEditName).getButton(AlertDialog.BUTTON_POSITIVE);
    positiveButton.setEnabled(false);/*from  w ww.j av  a2  s . c  o m*/

    EditText dialogEditText = (EditText) dialogEditName.findViewById(R.id.dialog_editor_script_name_edit_text);

    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(dialogEditText, InputMethodManager.SHOW_IMPLICIT);

    dialogEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable editable) {

            String variableName = editable.toString();
            positiveButton.setEnabled(true);
            for (Script local_script : ProjectManager.getInstance().getCurrentSprite().getScriptList()) {
                if (local_script.getName().equals(variableName)
                        && !local_script.getName().equals(script.getName())) {
                    Toast.makeText(getActivity(), R.string.formula_editor_existing_variable, Toast.LENGTH_SHORT)
                            .show();
                    positiveButton.setEnabled(false);
                }
            }

            if (editable.length() == 0) {
                positiveButton.setEnabled(false);
            }
            if (editable.toString().equals(script.getName())) {
                positiveButton.setEnabled(false);
            }
        }
    });
    dialogEditText.setText(script.getName());

}

From source file:nl.eduvpn.app.fragment.CustomProviderFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // Put the cursor in the field and show the keyboard automatically.
    _customProviderUrl.requestFocus();/*from w  ww .ja v  a2  s.c o  m*/
    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        inputMethodManager.showSoftInput(_customProviderUrl, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:org.videolan.vlc.gui.SearchFragment.java

public void onSearchKeyPressed() {
    if (mSearchText == null)
        return;/*from www.j  a v a 2s. com*/
    mSearchText.requestFocus();
    mSearchText.setSelection(mSearchText.getText().length());
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mSearchText, InputMethodManager.RESULT_SHOWN);
}