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.farmerbb.notepad.fragment.NoteEditFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from www  .  j av  a 2s. c o  m
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Set values
    setRetainInstance(true);
    setHasOptionsMenu(true);

    // Show the Up button in the action bar.
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Animate elevation change
    if (getActivity() instanceof MainActivity
            && getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large")
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = getActivity().findViewById(R.id.noteList);

        noteList.animate().z(0f);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
            noteViewEdit.animate()
                    .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land));
        else
            noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation));
    }

    // Set up content view
    noteContents = getActivity().findViewById(R.id.editText1);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView scrollView = getActivity().findViewById(R.id.scrollView1);
    String theme = pref.getString("theme", "light-sans");

    if (theme.contains("light")) {
        noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary));
        noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    }

    if (theme.contains("dark")) {
        noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark));
        noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
        scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark));
    }

    if (theme.contains("sans"))
        noteContents.setTypeface(Typeface.SANS_SERIF);

    if (theme.contains("serif"))
        noteContents.setTypeface(Typeface.SERIF);

    if (theme.contains("monospace"))
        noteContents.setTypeface(Typeface.MONOSPACE);

    switch (pref.getString("font_size", "normal")) {
    case "smallest":
        noteContents.setTextSize(12);
        break;
    case "small":
        noteContents.setTextSize(14);
        break;
    case "normal":
        noteContents.setTextSize(16);
        break;
    case "large":
        noteContents.setTextSize(18);
        break;
    case "largest":
        noteContents.setTextSize(20);
        break;
    }

    // Get filename
    try {
        if (!getArguments().getString("filename").equals("new")) {
            filename = getArguments().getString("filename");
            if (!filename.equals("draft"))
                isSavedNote = true;
        }
    } catch (NullPointerException e) {
        filename = "new";
    }

    // Load note from existing file
    if (isSavedNote) {
        try {
            contentsOnLoad = listener.loadNote(filename);
        } catch (IOException e) {
            showToast(R.string.error_loading_note);
            finish(null);
        }

        // Set TextView contents
        length = contentsOnLoad.length();
        noteContents.setText(contentsOnLoad);

        if (!pref.getBoolean("direct_edit", false))
            noteContents.setSelection(length, length);
    } else if (filename.equals("draft")) {
        SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
        String draftContents = sharedPref.getString("draft-contents", null);
        length = draftContents.length();
        noteContents.setText(draftContents);

        if (!pref.getBoolean("direct_edit", false))
            noteContents.setSelection(length, length);
    }

    // Show soft keyboard
    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(noteContents, InputMethodManager.SHOW_IMPLICIT);

}

From source file:com.github.irshulx.Components.InputExtensions.java

public void setFocus(CustomEditText view) {
    if (editorCore.isStateFresh() && !editorCore.getAutoFucus()) {
        editorCore.setStateFresh(false);
        return;/* w  w w  . j  av  a 2s.  c om*/
    }
    view.requestFocus();
    InputMethodManager mgr = (InputMethodManager) editorCore.getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    view.setSelection(view.getText().length());
    editorCore.setActiveView(view);
}

From source file:mbullington.dialogue.activity.ConversationActivity.java

@OnClick(R.id.input)
public void onClickInput(View v) {
    InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    input.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
}

From source file:com.nearnotes.NoteEdit.java

@SuppressWarnings("deprecation")
private void populateFields() {

    if (mRowId != null) {
        int settingsResult = mDbHelper.fetchSetting();
        if (settingsResult == mRowId) {
            mCheckBox.setChecked(true);/*from w  w w  . j a  v  a2  s . c om*/
        } else
            mCheckBox.setChecked(false);
        Cursor note = mDbHelper.fetchNote(mRowId);
        getActivity().startManagingCursor(note);
        mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
        mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)),
                TextView.BufferType.SPANNABLE);
        autoCompView.setAdapter(null);
        autoCompView.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LOCATION)));
        autoCompView.setAdapter(new PlacesAutoCompleteAdapter(getActivity(), R.layout.list_item));
        location = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LOCATION));
        longitude = note.getDouble(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LNG));
        latitude = note.getDouble(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LAT));
        checkString = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_CHECK));
        mChecklist = Boolean.parseBoolean(checkString);
    } else {
        autoCompView.requestFocus();
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(autoCompView, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

/**
 * initialize the emojiconKeyboard/* w w w. j a  va  2 s . c  om*/
 */
private void initEmoji(View view) {

    // save the views I will use
    final EmojiconEditText emojiconEditText = (EmojiconEditText) getActivity()
            .findViewById(R.id.send_image_description);
    final ImageButton emojiBtn = (ImageButton) view.findViewById(R.id.send_image_emoti_switch);
    mListener.setCurrentEmojiconEditText(emojiconEditText);
    // open/close the emojicon keyboard when pressing the button
    emojiBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (emojiconEditText == null)
                return;
            getActivity().getSupportFragmentManager().beginTransaction()
                    .replace(R.id.emojicon_keyboard, EmojiconsFragment.newInstance(!emojiKeyBoardOpen))
                    .commit();
            emojiconEditText.setFocusableInTouchMode(true);
            emojiconEditText.requestFocus();
            InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (emojiKeyBoardOpen)
                inputMethodManager.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
            else
                inputMethodManager.hideSoftInputFromWindow(emojiconEditText.getWindowToken(), 0);

            emojiKeyBoardOpen = !emojiKeyBoardOpen;
        }
    });
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

protected void toggleSearch(boolean reset) {
    if (reset) {//from w w w . j  a  v  a  2  s .  c o m
        // hide search box and show search icon
        searchBox.setText("");
        searchBox.setVisibility(View.GONE);
        toggle_btn.setVisible(true);
        // hide the keyboard
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(searchBox.getWindowToken(), 0);
    } else {
        // hide search icon and show search box
        toggle_btn.setVisible(false);
        searchBox.setVisibility(View.VISIBLE);
        searchBox.requestFocus();
        // show the keyboard
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(searchBox, InputMethodManager.SHOW_IMPLICIT);
    }
}

From source file:it.reyboz.bustorino.ActivityMain.java

private void showKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    View view = searchMode == SEARCH_BY_ID ? busStopSearchByIDEditText : busStopSearchByNameEditText;
    imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}

From source file:com.gelakinetic.mtgfam.activities.MainActivity.java

public void showKeyboard(View v) {
    try {/* w  w w  .  ja va2s  .  co m*/
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(v, 0);
    } catch (NullPointerException e) {
        // eat it
    }
}

From source file:com.filterdevice.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//w w w .j av  a2  s . co  m
    inflater.inflate(R.menu.global, menu);
    final EditText mEditText = (EditText) menu.findItem(R.id.search).getActionView();
    mEditText.addTextChangedListener(textWatcher);

    MenuItem pairCache = menu.findItem(R.id.pairing);
    if (Utils.getBooleanSharedPreference(getActivity(), Constants.PREF_PAIR_CACHE_STATUS)) {
        pairCache.setChecked(true);
    } else {
        pairCache.setChecked(false);
    }

    MenuItem mSearch = menu.findItem(R.id.search);
    mSearch.setVisible(true);
    mSearch.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            Logger.e("Collapsed");
            return true; // Return true to collapse action view
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            Logger.e("Expanded");
            mEditText.requestFocus();
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager inputManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
            }
            return true; // Return true to expand action view
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.jaredrummler.android.colorpicker.ColorPickerDialog.java

View createPickerView() {
    View contentView = View.inflate(getActivity(), R.layout.cpv_dialog_color_picker, null);
    colorPicker = (ColorPickerView) contentView.findViewById(R.id.cpv_color_picker_view);
    ColorPanelView oldColorPanel = (ColorPanelView) contentView.findViewById(R.id.cpv_color_panel_old);
    newColorPanel = (ColorPanelView) contentView.findViewById(R.id.cpv_color_panel_new);
    ImageView arrowRight = (ImageView) contentView.findViewById(R.id.cpv_arrow_right);
    hexEditText = (EditText) contentView.findViewById(R.id.cpv_hex);

    try {//from ww w  .  ja v  a 2 s  . co m
        final TypedValue value = new TypedValue();
        TypedArray typedArray = getActivity().obtainStyledAttributes(value.data,
                new int[] { android.R.attr.textColorPrimary });
        int arrowColor = typedArray.getColor(0, Color.BLACK);
        typedArray.recycle();
        arrowRight.setColorFilter(arrowColor);
    } catch (Exception ignored) {
    }

    colorPicker.setAlphaSliderVisible(showAlphaSlider);
    oldColorPanel.setColor(getArguments().getInt(ARG_COLOR));
    colorPicker.setColor(color, true);
    newColorPanel.setColor(color);
    setHex(color);

    if (!showAlphaSlider) {
        hexEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
    }

    newColorPanel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (newColorPanel.getColor() == color) {
                colorPickerDialogListener.onColorSelected(dialogId, color);
                dismiss();
            }
        }
    });

    contentView.setOnTouchListener(this);
    colorPicker.setOnColorChangedListener(this);
    hexEditText.addTextChangedListener(this);

    hexEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(hexEditText, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });

    return contentView;
}