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.actinarium.nagbox.ui.EditTaskDialogFragment.java

@NonNull
@Override/*w  ww .j  a  va  2s .co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Task taskToEdit = getArguments().getParcelable(ARG_TASK);
    final boolean isEdit = taskToEdit != null;

    // Set up our live model:
    if (savedInstanceState != null) {
        // a) restore after config change
        mTask = savedInstanceState.getParcelable(ARG_TASK);
    } else if (isEdit) {
        // b) populate from the one under editing
        mTask = new Task(taskToEdit);
    } else {
        // c) create a blank task with default interval = 5 mins
        mTask = new Task();
    }

    mBinding = EditTaskDialogBinding.inflate(LayoutInflater.from(getContext()), null, false);
    mBinding.setTask(mTask);

    final AlertDialog dialog = new AlertDialog.Builder(getContext())
            .setTitle(getString(isEdit ? R.string.dialog_edit_task : R.string.dialog_new_task))
            .setView(mBinding.getRoot()).setPositiveButton(R.string.dialog_save, null)
            .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            }).create();

    // At this moment dialog is not yet inflated, so we need to use this listener to defer some logic
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(final DialogInterface di) {
            // Set the positive button listener. This is needed to prevent dismissing the dialog when validation fails
            dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    boolean isValid = validateForm();
                    if (isValid) {
                        // Actually I could call the service right here instead of delegating it to the activity
                        // But for the sake of consistency let the activity serve as a controller and handle this
                        if (isEdit) {
                            mHost.saveEditedTask(mTask);
                        } else {
                            mHost.saveNewTask(mTask);
                        }
                        dismiss();
                    }
                }
            });

            // Also try requesting the input method
            if (mBinding.taskTitleInput.getEditText().requestFocus()) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(mBinding.taskTitleInput.getEditText(), InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });

    return dialog;
}

From source file:com.liferay.alerts.activity.ComposeActivity.java

protected void showKeyboard() {
    final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    Runnable runnable = new Runnable() {

        @Override//from  w w  w. j  a  v a 2  s.  c  o  m
        public void run() {
            manager.showSoftInput(_edit, InputMethodManager.SHOW_IMPLICIT);
        }

    };

    int delay = getResources().getInteger(R.integer.compose_show_keyboard_delay);

    Handler handler = new Handler();
    handler.postDelayed(runnable, delay);

    _edit.setKeyboardHideListener(new KeyboardHideListener() {

        @Override
        public void onHide() {
            finish();
        }

    });
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_new_project, null);

    newProjectEditText = (EditText) dialogView.findViewById(R.id.project_name_edittext);

    newProjectEditText.setText("");

    newProjectDialog = new AlertDialog.Builder(getActivity()).setView(dialogView)
            .setTitle(R.string.new_project_dialog_title)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override//from w  w  w. ja  va2  s.co m
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    newProjectDialog.setCanceledOnTouchOutside(true);
    newProjectDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    newProjectDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    newProjectDialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            if (getActivity() == null) {
                Log.e(TAG, "onShow() Activity was null!");
                return;
            }

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(newProjectEditText, InputMethodManager.SHOW_IMPLICIT);

            ((AlertDialog) newProjectDialog).getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
            newProjectEditText.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 s) {
                    if (newProjectEditText.length() == 0) {
                        ((AlertDialog) newProjectDialog).getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
                    } else {
                        ((AlertDialog) newProjectDialog).getButton(Dialog.BUTTON_POSITIVE).setEnabled(true);
                    }
                }
            });

            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {
                    handleOkButtonClick();
                }
            });
        }
    });

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean shouldBeEmpty = sharedPreferences.getBoolean(SHARED_PREFERENCES_EMPTY_PROJECT, false);

    emptyProjectCheckBox = (CheckBox) dialogView.findViewById(R.id.project_empty_checkbox);
    emptyProjectCheckBox.setChecked(shouldBeEmpty);

    return newProjectDialog;
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());/* w  w  w . java 2s.com*/
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener(dialog);

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());/*from w  w w. j a  v a  2  s  . co  m*/
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity())
            .inflate(hku.fyp14017.blencode.R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());// w  w w. ja  v  a 2  s  . c o m
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:net.gsantner.opoc.ui.FilesystemDialog.java

@OnClick({ R.id.ui__filesystem_dialog__home, R.id.ui__filesystem_dialog__search_button,
        R.id.ui__filesystem_dialog__button_cancel, R.id.ui__filesystem_dialog__button_ok })
public void onClicked(View view) {
    switch (view.getId()) {
    case R.id.ui__filesystem_dialog__button_ok:
    case R.id.ui__filesystem_dialog__home: {
        _filesystemDialogAdapter.onClick(view);
        break;/*from  www  .  j  a  va2 s . c om*/
    }
    case R.id.ui__filesystem_dialog__search_button: {
        _buttonSearch.setVisibility(View.GONE);
        _searchEdit.setVisibility(View.VISIBLE);
        _searchEdit.requestFocus();
        InputMethodManager imm = (InputMethodManager) getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(_searchEdit, InputMethodManager.SHOW_IMPLICIT);
        break;
    }
    case R.id.ui__filesystem_dialog__button_cancel: {
        onFsNothingSelected(_dopt.requestId);
        break;
    }

    }
}

From source file:com.cerema.cloud2.ui.fragment.SearchShareesFragment.java

@Override
public void onStart() {
    super.onStart();
    // focus the search view and request the software keyboard be shown
    View searchView = getView().findViewById(R.id.searchView);
    if (searchView.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.showSoftInput(searchView.findFocus(), InputMethodManager.SHOW_IMPLICIT);
        }//from w w  w. j av a 2 s .  c  o  m
    }
}

From source file:org.openintents.historify.ui.fragments.ContactsListFragment.java

public void onSearchSelected() {
    boolean needToShow = mSearchBar.getVisibility() == View.GONE;

    if (needToShow && mAdapter.isEmpty())
        return;/*from  w  w w . ja  v a  2 s .c o  m*/

    if (!needToShow) { //hide search
        mEditSearch.setText("");
    }

    mSearchBar.setVisibility(needToShow ? View.VISIBLE : View.GONE);
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (needToShow) {
        mEditSearch.requestFocus();
        imm.showSoftInput(mEditSearch, InputMethodManager.SHOW_FORCED);
    } else {
        imm.hideSoftInputFromWindow(mEditSearch.getWindowToken(), 0);
    }

}

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

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

    newProjectEditText = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.project_name_edittext);

    newProjectEditText.setText("");

    newProjectDialog = new AlertDialog.Builder(getActivity()).setView(dialogView)
            .setTitle(hku.fyp14017.blencode.R.string.new_project_dialog_title)
            .setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override//from   w  w  w. j a v  a2  s. co  m
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                        }
                    })
            .create();

    newProjectDialog.setCanceledOnTouchOutside(true);
    newProjectDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    newProjectDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    newProjectDialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(newProjectEditText, InputMethodManager.SHOW_IMPLICIT);

            ((AlertDialog) newProjectDialog).getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
            newProjectEditText.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 s) {
                    if (newProjectEditText.length() == 0) {
                        ((AlertDialog) newProjectDialog).getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
                    } else {
                        ((AlertDialog) newProjectDialog).getButton(Dialog.BUTTON_POSITIVE).setEnabled(true);
                    }
                }
            });

            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {
                    handleOkButtonClick();
                }
            });
        }
    });

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    boolean shouldBeEmpty = sharedPreferences.getBoolean(SHARED_PREFERENCES_EMPTY_PROJECT, false);

    emptyProjectCheckBox = (CheckBox) dialogView
            .findViewById(hku.fyp14017.blencode.R.id.project_empty_checkbox);
    emptyProjectCheckBox.setChecked(shouldBeEmpty);

    return newProjectDialog;
}