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:es.usc.citius.servando.calendula.activities.MedicinesActivity.java

public void showSearchView(final String text) {
    addButton.setVisibility(View.GONE);
    searchEditText.requestFocus();/*www.  j  a va  2  s  .c o  m*/
    searchView.setVisibility(View.VISIBLE);

    if (text != null) {
        searchEditText.setText(text);
        searchEditText.setSelection(text.length());
        adapter.getFilter().filter(text);
    }

    searchEditText.postDelayed(new Runnable() {
        @Override
        public void run() {
            InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            keyboard.showSoftInput(searchEditText, 0);
        }
    }, 30);

}

From source file:com.quicklookbusy.narwhalNotifier.AccountEditor.java

/**
 * Shows the virtual keyboard//from  ww  w  .j  av  a2 s.  com
 * 
 * @param et
 *            Text field to have focus
 */
private void showKeyboard(EditText et) {
    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    // only will trigger it if no physical keyboard is open
    mgr.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
}

From source file:org.exoplatform.ui.social.ComposeMessageActivity.java

private void initLayout() {
    postDestinationView = (TextView) findViewById(R.id.post_destination_text_view);
    postDestinationIcon = (ImageView) findViewById(R.id.post_destination_image);
    composeEditText = (EditText) findViewById(R.id.compose_text_view);
    textFieldScrollView = (ScrollView) findViewById(R.id.compose_textfield_scroll);
    textFieldScrollView.setOnTouchListener(new View.OnTouchListener() {
        @Override/*from  w  ww  .ja  v  a2 s. c  o  m*/
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.showSoftInput(composeEditText, InputMethodManager.RESULT_UNCHANGED_SHOWN);
            }
            return false;
        }
    });

    fileAttachWrap = (LinearLayout) findViewById(R.id.compose_attach_file_wrap);
    sendButton = (Button) findViewById(R.id.compose_send_button);
    sendButton.setText(sendText);
    sendButton.setOnClickListener(this);
    cancelButton = (Button) findViewById(R.id.compose_cancel_button);
    cancelButton.setText(cancelText);
    cancelButton.setOnClickListener(this);
}

From source file:com.farmerbb.taskbar.fragment.AdvancedFragment.java

@SuppressLint("SetTextI18n")
@Override/*  ww w .  ja va 2s .  c o m*/
public boolean onPreferenceClick(final Preference p) {
    final SharedPreferences pref = U.getSharedPreferences(getActivity());

    switch (p.getKey()) {
    case "clear_pinned_apps":
        Intent clearIntent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            clearIntent = new Intent(getActivity(), ClearDataActivity.class);
            break;
        case "dark":
            clearIntent = new Intent(getActivity(), ClearDataActivityDark.class);
            break;
        }

        startActivity(clearIntent);
        break;
    case "launcher":
        if (U.canDrawOverlays(getActivity())) {
            ComponentName component = new ComponentName(getActivity(), HomeActivity.class);
            getActivity().getPackageManager().setComponentEnabledSetting(component,
                    ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        } else {
            U.showPermissionDialog(getActivity());
            ((CheckBoxPreference) p).setChecked(false);
        }

        if (!((CheckBoxPreference) p).isChecked())
            LocalBroadcastManager.getInstance(getActivity())
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.KILL_HOME_ACTIVITY"));
        break;
    case "keyboard_shortcut":
        ComponentName component = new ComponentName(getActivity(), KeyboardShortcutActivity.class);
        getActivity().getPackageManager()
                .setComponentEnabledSetting(component,
                        ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
        break;
    case "dashboard_grid_size":
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LinearLayout dialogLayout = (LinearLayout) View.inflate(getActivity(), R.layout.dashboard_size_dialog,
                null);

        boolean isPortrait = getActivity().getApplicationContext().getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
        boolean isLandscape = getActivity().getApplicationContext().getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;

        int editTextId = -1;
        int editText2Id = -1;

        if (isPortrait) {
            editTextId = R.id.fragmentEditText2;
            editText2Id = R.id.fragmentEditText1;
        }

        if (isLandscape) {
            editTextId = R.id.fragmentEditText1;
            editText2Id = R.id.fragmentEditText2;
        }

        final EditText editText = (EditText) dialogLayout.findViewById(editTextId);
        final EditText editText2 = (EditText) dialogLayout.findViewById(editText2Id);

        builder.setView(dialogLayout).setTitle(R.string.dashboard_grid_size)
                .setPositiveButton(R.string.action_ok, (dialog, id) -> {
                    boolean successfullyUpdated = false;

                    String widthString = editText.getText().toString();
                    String heightString = editText2.getText().toString();

                    if (widthString.length() > 0 && heightString.length() > 0) {
                        int width = Integer.parseInt(widthString);
                        int height = Integer.parseInt(heightString);

                        if (width > 0 && height > 0) {
                            SharedPreferences.Editor editor = pref.edit();
                            editor.putInt("dashboard_width", width);
                            editor.putInt("dashboard_height", height);
                            editor.apply();

                            updateDashboardGridSize(true);
                            successfullyUpdated = true;
                        }
                    }

                    if (!successfullyUpdated)
                        U.showToast(getActivity(), R.string.invalid_grid_size);
                }).setNegativeButton(R.string.action_cancel, null);

        editText.setText(Integer.toString(pref.getInt("dashboard_width",
                getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_width))));
        editText2.setText(Integer.toString(pref.getInt("dashboard_height",
                getActivity().getApplicationContext().getResources().getInteger(R.integer.dashboard_height))));

        AlertDialog dialog = builder.create();
        dialog.show();

        new Handler().post(() -> {
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT);
        });

        break;
    case "navigation_bar_buttons":
        Intent intent = null;

        switch (pref.getString("theme", "light")) {
        case "light":
            intent = new Intent(getActivity(), NavigationBarButtonsActivity.class);
            break;
        case "dark":
            intent = new Intent(getActivity(), NavigationBarButtonsActivityDark.class);
            break;
        }

        startActivity(intent);
        break;
    }

    return true;
}

From source file:io.realm.realmtasks.list.ItemViewHolder.java

public void setEditable(boolean set) {
    if (set) {// ww w.  j a v  a  2  s  .  c o m
        if (isEditable() == false) {
            editText.setText(text.getText().toString());
        }
        hideReadOnlyTaskText();
        editText.setVisibility(View.VISIBLE);
        editText.requestFocus();
        final Context context = editText.getContext();
        final InputMethodManager inputMethodManager = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

    } else {
        if (isEditable() == true) {
            text.setText(editText.getText().toString());
        }
        showReadOnlyTaskText();
        editText.setVisibility(View.GONE);
    }
}

From source file:com.pixplicity.castdemo.MainActivity.java

private void setConnected(boolean connected) {
    mBtSend.setEnabled(connected);/*from w ww. j a v a2  s  .  com*/
    mBtSpeak.setEnabled(connected);
    mEtMessage.setEnabled(connected);
    if (connected) {
        mEtMessage.requestFocus();
        // Implicity request a soft input mode
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(mEtMessage, InputMethodManager.SHOW_IMPLICIT);
    }

}

From source file:com.king.base.BaseFragment.java

/**
 * //ww  w  . j a va  2 s  .  c o m
 *
 * @param v
 */
public void showInputMethod(final EditText v) {

    v.requestFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(v, 0);
}

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

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

    mMessenger = getArguments().getParcelable(ARG_MESSENGER);

    CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity);

    alert.setTitle(R.string.add_keyserver_dialog_title);

    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);
    mVerifyKeyserverCheckBox = (CheckBox) view.findViewById(R.id.verify_keyserver_checkbox);

    // we don't want dialog to be dismissed on click, 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
        }
    });

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

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

    // 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:org.rm3l.ddwrt.tiles.admin.nvram.EditNVRAMKeyValueDialogFragment.java

@Override
public void onStart() {
    super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point

    final AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {

        ((TextView) d.findViewById(R.id.tile_admin_nvram_edit_key)).setText(this.mKey);
        final EditText valueEditText = (EditText) d.findViewById(R.id.tile_admin_nvram_edit_value);
        valueEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override/*from  w ww . j  a  v a2s .  c om*/
            public void onFocusChange(View v, boolean hasFocus) {
                ((TextView) d.findViewById(R.id.tile_admin_nvram_edit_value_textview)).setTypeface(null,
                        hasFocus ? Typeface.BOLD_ITALIC : Typeface.NORMAL);
            }
        });
        valueEditText.setText(this.mValue, TextView.BufferType.EDITABLE);

        d.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Validate data
                final EditText editText = (EditText) d.findViewById(R.id.tile_admin_nvram_edit_value);
                final Editable newValue = editText.getText();

                if (mValue != null && StringUtils.equals(newValue.toString(), mValue.toString())) {
                    //Crouton
                    Crouton.makeText(getActivity(), "No change", ALERT,
                            (ViewGroup) (d.findViewById(R.id.tile_admin_nvram_edit_notification_viewgroup)))
                            .show();
                    editText.requestFocus();
                    //Open Keyboard
                    final InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    if (imm != null) {
                        // only will trigger it if no physical keyboard is open
                        imm.showSoftInput(editText, 0);
                    }
                    return;
                }

                final CharSequence variableKey = ((TextView) d.findViewById(R.id.tile_admin_nvram_edit_key))
                        .getText();

                final Bundle token = new Bundle();
                token.putInt(POSITION, mPosition);
                token.putCharSequence(VALUE, newValue);
                token.putCharSequence(KEY, variableKey);

                //nvram set data changed
                new UndoBarController.UndoBar(getSherlockActivity())
                        .message(String.format("Variable '%s' will be updated", variableKey))
                        .listener(nvramDataRecyclerViewAdapter).token(token).show();

                d.cancel();
            }
        });
    }
}

From source file:th.in.ffc.person.PersonListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    case R.id.add:
        Intent add = new Intent(Action.INSERT);
        add.addCategory(Category.PERSON);
        add.addCategory(Category.DEFAULT);
        if (mHcode != null) {
            add.putExtra(Person.HCODE, mHcode);
        }/*from  ww  w. j a  va 2  s .  com*/
        getFFCActivity().startActivity(add);
        break;
    case R.id.search:
        InputMethodManager imm = (InputMethodManager) getFFCActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!mInput.isShown()) {
            mInput.setVisibility(View.VISIBLE);
            mInput.requestFocus();
            imm.showSoftInput(mInput, InputMethodManager.SHOW_FORCED);
            item.setIcon(R.drawable.ic_action_close);
        } else {
            imm.hideSoftInputFromInputMethod(mInput.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            mInput.setVisibility(View.GONE);
            mInput.setText(null);
            item.setIcon(R.drawable.ic_action_search);
        }
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}