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.yanzhenjie.album.mvp.BaseView.java

protected final void openInputMethod(View view) {
    view.requestFocus();//w  w  w  .  j av  a 2s .  com
    InputMethodManager manager = (InputMethodManager) view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (manager != null) {
        manager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
 * @see android.app.Activity#onOptionsItemSelected(MenuItem item)
 *//*  www .j a  v a 2  s. c  o  m*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        serverList.refresh();
        lastRefresh = System.currentTimeMillis();
        return true;
    case R.id.menu_add_server:
        Intent addServer = new Intent(this, AddServerActivity.class);
        startActivityForResult(addServer, AddServerActivity.ADD_SERVER_ACTIVITY_ID);
        return true;
    case R.id.menu_search:
        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.showSoftInput(getListView(), InputMethodManager.SHOW_FORCED);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:app.CT.BTCCalculator.fragments.BreakevenFragment.java

public void showSoftKeyboard(View view) {
    if (view.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }/*from   w  w w .  ja va2  s.  co  m*/
}

From source file:org.solovyev.android.messenger.ListViewFilter.java

public void toggleView() {
    final View view = fragment.getView();
    final FragmentActivity activity = fragment.getActivity();

    if (view != null && activity != null && filterEditText != null) {
        final ViewGroup filterBox = (ViewGroup) view.findViewById(R.id.mpp_list_filter);
        if (filterBox != null) {
            int visibility = filterBox.getVisibility();

            final InputMethodManager manager = (InputMethodManager) activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);

            if (visibility != View.VISIBLE) {
                filterBox.setVisibility(View.VISIBLE);
                filterEditText.requestFocus();

                manager.showSoftInput(filterEditText, InputMethodManager.SHOW_IMPLICIT);

            } else if (visibility != View.GONE) {
                // if filter box is visible before hiding it clear filter query
                filterEditText.getText().clear();
                filterEditText.clearFocus();

                manager.hideSoftInputFromWindow(filterEditText.getWindowToken(),
                        InputMethodManager.HIDE_IMPLICIT_ONLY);

                filterBox.setVisibility(View.GONE);
            }/*from  w ww.  ja v  a  2  s.  c om*/
        }
    } else {
        Log.e(TAG, "toggleView() is called when view or activity is detached from fragment!");
    }
}

From source file:com.mastercard.masterpasswallet.fragments.addcard.VerifyCardFragment.java

private void prePopulateWidgets() {
    if (mListener.hasCardNumber()) {
        mEdtCardNumber.setText(mListener.getCardNumber());

        mTxtScannedCardPan.setText(getString(R.string.masked_pan,
                mListener.getCardNumber().substring(mListener.getCardNumber().length() - 4)));

        // set the focus to the next field
        if (mListener.hasCardExpiry()) {
            mEdtCvc.requestFocus();//w  w  w.j a  v a2  s .co m
        } else {
            mEdtExpiry.requestFocus();
        }

        // show the keyboard
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(mEdtCvc, InputMethodManager.SHOW_IMPLICIT);

        if (mListener.hasCardExpiry()) {
            // Otherwise attempt to use the expiry date
            String cardExpiryMonth = String.format("%02d", Integer.parseInt(mListener.getCardExpiryMonth()));
            String cardExpiryYear = mListener.getCardExpiryYear().substring(2);
            mEdtExpiry.setText(String.format("%s/%s", cardExpiryMonth, cardExpiryYear));
        }

        // Use the image we've decided upon, this will either be the correct one for the card
        // or default to the green one
        mImgScannedCard.setImageResource(Card.getDefaultCardImageFull());

        // Set the cardholder name
        mEdtCardholderName.setText(mListener.getCardholderName());
    } else {
        // If no card was scanned then we don't show any image
        mLayScannedCard.setVisibility(View.GONE);
    }
}

From source file:org.tigase.messenger.phone.pro.conversations.chat.ChatItemFragment.java

public void openIME() {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

    imm.showSoftInput(message, InputMethodManager.SHOW_FORCED);
}

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

@NonNull
@Override//  w w  w . j  a v  a2s. c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    mMessenger = getArguments().getParcelable(IN_MESSENGER);
    mAction = (Action) getArguments().getSerializable(IN_ACTION);
    mPosition = getArguments().getInt(IN_POSITION);
    if (getArguments().getString(IN_URI) == null)
        mURI = null;
    else
        mURI = Uri.parse(getArguments().getString(IN_URI));

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

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

    mAuthorityAliasText = (EditText) view.findViewById(R.id.smartpgp_authority_alias_edit_text);
    mAuthorityAliasTextLayout = (TextInputLayout) view
            .findViewById(R.id.smartpgp_authority_alias_edit_text_layout);
    mAuthorityAdd = (Button) view.findViewById(R.id.smartpgp_authority_filename);

    mAuthorityAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            FileHelper.openDocument(AddEditSmartPGPAuthorityDialogFragment.this, null, "*/*", false,
                    EncryptFilesFragment.REQUEST_CODE_INPUT);
        }
    });

    mAuthorityAliasText.setText(getArguments().getString(IN_ALIAS));

    switch (mAction) {
    case ADD:
        alert.setTitle(R.string.add_smartpgp_authority_dialog_title);
        break;
    case EDIT:
    case DELETE:
        alert.setTitle(R.string.show_smartpgp_authority_dialog_title);
        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
            dismiss();
        }
    });

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

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

    switch (mAction) {
    case EDIT:
    case DELETE:
        alert.setNeutralButton(R.string.label_smartpgp_authority_dialog_delete,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        deleteAuthority();
                    }
                });
        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
    mAuthorityAliasText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            mAuthorityAliasText.post(new Runnable() {
                @Override
                public void run() {
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(mAuthorityAliasText, InputMethodManager.SHOW_IMPLICIT);
                }
            });
        }
    });
    mAuthorityAliasText.requestFocus();

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

    return alert.show();
}

From source file:com.oldster.swiftmovedriver.fragment.EditCarFragment.java

private void requestFocus(View view) {
    if (view.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }/* w w w.  ja  v  a  2 s .  c  o  m*/
}

From source file:io.github.hidroh.materialistic.BaseWebFragment.java

private void toggleSoftKeyboard(boolean visible) {
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (visible) {
        imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
    } else {//from w w  w  .  j a v a  2s  . c  o m
        imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    }
}

From source file:com.rong.library.widget.mapsearchbar.MapSearchBar.java

@Override
public void onFocusChange(View v, boolean hasFocus) {
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    if (hasFocus) {
        if (!focusCameFromHistory)
            imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
        focusCameFromHistory = false;/*from   w  ww  .  j a va 2s . c o  m*/

        isSearchEditFocused = true;
        if (adapter.getItemCount() > 0 && !suggestionsVisible)
            animateSuggestionList(0, getSuggestionHeight());

    } else {
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

        isSearchEditFocused = false;
        if (suggestionsVisible)
            animateSuggestionList(-1, 0);
    }
}