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:com.alimuzaffar.lib.pin.PinEntryEditText.java

/**
 * Request focus on this PinEntryEditText
 *///w ww.j  av a  2  s . c o m
public void focus() {
    requestFocus();

    // Show keyboard
    InputMethodManager inputMethodManager = (InputMethodManager) getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(this, 0);
}

From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment.java

@NonNull
@Override/*from  w ww.j  a  va  2s . com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    mMessenger = getArguments().getParcelable(ARG_MESSENGER);
    mDialogAction = (DialogAction) getArguments().getSerializable(ARG_ACTION);
    mPosition = getArguments().getInt(ARG_POSITION);

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.add_keyserver_dialog, null);
    alert.setView(view);

    mKeyserverEditText = (EditText) view.findViewById(R.id.keyserver_url_edit_text);
    mKeyserverEditTextLayout = (TextInputLayout) view.findViewById(R.id.keyserver_url_edit_text_layout);
    mKeyserverEditOnionText = (EditText) view.findViewById(R.id.keyserver_onion_edit_text);
    mKeyserverEditOnionTextLayout = (TextInputLayout) view.findViewById(R.id.keyserver_onion_edit_text_layout);
    mVerifyKeyserverCheckBox = (CheckBox) view.findViewById(R.id.verify_connection_checkbox);
    mOnlyTrustedKeyserverCheckBox = (CheckBox) view.findViewById(R.id.only_trusted_keyserver_checkbox);
    mVerifyKeyserverCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mOnlyTrustedKeyserverCheckBox.setEnabled(isChecked);
        }
    });

    switch (mDialogAction) {
    case ADD: {
        alert.setTitle(R.string.add_keyserver_dialog_title);
        break;
    }
    case EDIT: {
        alert.setTitle(R.string.edit_keyserver_dialog_title);
        ParcelableHkpKeyserver keyserver = getArguments().getParcelable(ARG_KEYSERVER);
        mKeyserverEditText.setText(keyserver.getUrl());
        mKeyserverEditOnionText.setText(keyserver.getOnion());
        break;
    }
    }

    // we don't want dialog to be dismissed on click for keyserver addition or edit,
    // thereby requiring the hack seen below and in onStart
    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            // we need to have an empty listener to prevent errors on some devices as mentioned
            // at http://stackoverflow.com/q/13746412/3000919
            // actual listener set in onStart for adding keyservers or editing them
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

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

    switch (mDialogAction) {
    case EDIT: {
        alert.setNeutralButton(R.string.label_keyserver_dialog_delete, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                deleteKeyserver(mPosition);
            }
        });
        break;
    }
    case ADD: {
        // do nothing
        break;
    }
    }

    // Hack to open keyboard.
    // This is the only method that I found to work across all Android versions
    // http://turbomanage.wordpress.com/2012/05/02/show-soft-keyboard-automatically-when-edittext-receives-focus/
    // Notes: * onCreateView can't be used because we want to add buttons to the dialog
    //        * opening in onActivityCreated does not work on Android 4.4
    mKeyserverEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            mKeyserverEditText.post(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mKeyserverEditText, InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    });
    mKeyserverEditText.requestFocus();

    mKeyserverEditText.setImeActionLabel(getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE);
    mKeyserverEditText.setOnEditorActionListener(this);

    return alert.show();
}

From source file:kr.wdream.storyshop.AndroidUtilities.java

public static void showKeyboard(View view) {
    if (view == null) {
        return;/*from   ww w  . jav  a  2  s.  c o  m*/
    }
    try {
        InputMethodManager inputManager = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.tozny.e3db.android.DefaultKeyAuthenticator.java

@Override
public void getPassword(final PasswordHandler handler) {
    this.activity.runOnUiThread(new Runnable() {
        @Override/*from  ww  w.  j ava2s.com*/
        public void run() {
            Context ctx = DefaultKeyAuthenticator.this.activity;

            final EditText input = new EditText(ctx);
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);

            new AlertDialog.Builder(DefaultKeyAuthenticator.this.activity)
                    .setMessage(ctx.getString(R.string.key_provider_please_enter_pin))
                    .setPositiveButton(ctx.getString(R.string.key_provider_ok),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    try {
                                        handler.handlePassword(input.getText().toString());

                                    } catch (UnrecoverableKeyException e) {
                                        wrongPasswordCount[0]++;

                                        if (wrongPasswordCount[0] >= 3) {
                                            handler.handleError(
                                                    new RuntimeException("Too many password tries."));
                                        } else {
                                            Toast.makeText(DefaultKeyAuthenticator.this.activity,
                                                    e.getMessage(), Toast.LENGTH_SHORT).show();
                                            getPassword(handler);
                                        }
                                    }
                                }
                            })
                    .setNegativeButton(ctx.getString(R.string.key_provider_cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    handler.handleCancel();
                                }
                            })
                    .setView(input).show();

            input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View view, boolean b) {
                    if (input.isEnabled() && input.isFocusable()) {
                        input.post(new Runnable() {
                            @Override
                            public void run() {
                                final InputMethodManager imm = (InputMethodManager) DefaultKeyAuthenticator.this.activity
                                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                                imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
                            }
                        });
                    }
                }
            });
        }
    });
}

From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java

private void setInitialFocus() {
    InputMethodManager imm = (InputMethodManager) mDialog.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    View view = mShouldRequestExpirationDate ? mMonthInput : mCardUnmaskInput;
    imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    if (sObserverForTest != null) {
        sObserverForTest.onCardUnmaskPromptReadyForInput(this);
    }/*from  w  ww. j av a 2  s. c om*/
}

From source file:com.android.contacts.activities.ActionBarAdapter.java

private void showInputMethod(View view) {
    final InputMethodManager imm = (InputMethodManager) mActivity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.showSoftInput(view, 0);
    }/*ww  w  . ja va  2  s .  c  om*/
}

From source file:org.odk.collect.android.widgets.ExStringWidget.java

@Override
public void setFocus(Context context) {
    // Put focus on text input field and display soft keyboard if appropriate.
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (hasExApp) {
        // hide keyboard
        inputManager.hideSoftInputFromWindow(answer.getWindowToken(), 0);
        // focus on launch button
        launchIntentButton.requestFocus();
    } else {//from   ww  w . j av  a 2s . c  o  m
        if (!formEntryPrompt.isReadOnly()) {
            answer.requestFocus();
            inputManager.showSoftInput(answer, 0);
            /*
             * If you do a multi-question screen after a "add another group" dialog, this won't
             * automatically pop up. It's an Android issue.
             *
             * That is, if I have an edit text in an activity, and pop a dialog, and in that
             * dialog's button's OnClick() I call edittext.requestFocus() and
             * showSoftInput(edittext, 0), showSoftinput() returns false. However, if the
             * edittext
             * is focused before the dialog pops up, everything works fine. great.
             */
        } else {
            inputManager.hideSoftInputFromWindow(answer.getWindowToken(), 0);
        }
    }
}

From source file:de.tap.easy_xkcd.Activities.SearchResultsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search_results, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/* w  w  w . j  av  a2  s  . c o m*/
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (task != null) {
                task.cancel(true);
            }
            task = new searchTask();
            task.execute(newText);
            return false;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    return true;
}

From source file:com.silentcircle.contacts.activities.ScContactSelectionActivity.java

private void showInputMethod(View view) {
    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        if (!imm.showSoftInput(view, 0)) {
            Log.w(TAG, "Failed to show soft input method.");
        }/*from www .  j a va2 s . c om*/
    }
}

From source file:co.beem.project.beem.ui.wizard.AccountConfigureFragment.java

public void showSoftKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    view.requestFocus();// w  ww  .  j  a v a2 s  .  c om
    inputMethodManager.showSoftInput(view, 0);
}