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:sjizl.com.ChatActivity.java

public void showSoftKeyboard(View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    // view.requestFocus();
    inputMethodManager.showSoftInput(view, 0);
}

From source file:org.cryptsecure.Utility.java

/**
 * Show keyboard explicitly for a text input field known to be able to get
 * the focus.//w w  w . j  ava  2  s. c  o m
 * 
 * @param textInput
 *            the text input
 */
public static void showKeyboardExplicit(EditText textInput) {
    InputMethodManager keyboard = (InputMethodManager) textInput.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    keyboard.showSoftInput(textInput, 0);
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

private void showKeyboard(boolean showSystemKeyboard, boolean showExtendedKeyboard) {
    // no matter what we are doing ... hide the zoom controls
    // TODO: this is not working correctly as hiding the keyboard issues a onScrollChange notification showing the control again ...
    uiHandler.removeMessages(UIHandler.HIDE_ZOOMCONTROLS);
    if (zoomControls.getVisibility() == View.VISIBLE)
        zoomControls.hide();//from www. j a va  2 s . co m

    InputMethodManager mgr;
    if (showSystemKeyboard) {
        // hide extended keyboard
        keyboardView.setVisibility(View.GONE);

        // show system keyboard
        mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!mgr.isActive(sessionView))
            Log.e(TAG, "Failed to show system keyboard: SessionView is not the active view!");
        mgr.showSoftInput(sessionView, 0);

        // show modifiers keyboard
        modifiersKeyboardView.setVisibility(View.VISIBLE);
    } else if (showExtendedKeyboard) {
        // hide system keyboard
        mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(sessionView.getWindowToken(), 0);

        // show extended keyboard
        keyboardView.setKeyboard(specialkeysKeyboard);
        keyboardView.setVisibility(View.VISIBLE);
        modifiersKeyboardView.setVisibility(View.VISIBLE);
    } else {
        // hide both
        mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(sessionView.getWindowToken(), 0);
        keyboardView.setVisibility(View.GONE);
        modifiersKeyboardView.setVisibility(View.GONE);

        // clear any active key modifiers)
        keyboardMapper.clearlAllModifiers();
    }

    sysKeyboardVisible = showSystemKeyboard;
    extKeyboardVisible = showExtendedKeyboard;
}

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

/**
 * initialize the emojiconKeyboard/*ww  w  .  java  2 s. c om*/
 */
private void initEmoji() {
    // save the views I will use
    final EmojiconEditText emojiconEditText = (EmojiconEditText) getActivity().findViewById(R.id.chat_in);
    final ImageButton emojiBtn = (ImageButton) getActivity().findViewById(R.id.emoti_switch);
    final EmojiconPopup popup = new EmojiconPopup(getActivity().findViewById(R.id.root_view), getContext(),
            new EmojiconGridView.OnEmojiconClickedListener() {
                @Override
                public void OnEmojiconClicked(Emojicon emojicon) {
                    if (emojiconEditText == null || emojicon == null)
                        return;
                    int start = emojiconEditText.getSelectionStart();
                    int end = emojiconEditText.getSelectionEnd();
                    if (start < 0)
                        emojiconEditText.append(emojicon.getEmoji());
                    else
                        emojiconEditText.getText().replace(Math.min(start, end), Math.max(start, end),
                                emojicon.getEmoji(), 0, emojicon.getEmoji().length());
                }
            });
    popup.setSoftKeyboardSize();

    popup.setOnSoftKeyboardOpenCloseListener(new EmojiconPopup.OnSoftKeyboardOpenCloseListener() {
        @Override
        public void onKeyboardOpen(int keyboardHeight) {
        }

        @Override
        public void onKeyboardClose() {
            if (popup.isShowing())
                popup.dismiss();
        }
    });
    // open/close the emojicon keyboard when pressing the button
    emojiBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!popup.isShowing()) {
                if (popup.isKeyboardOpen())
                    popup.showAtBottom();
                else {
                    emojiconEditText.setFocusableInTouchMode(true);
                    emojiconEditText.requestFocus();
                    popup.showAtBottomPending();
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
                }
            } else
                popup.dismiss();
        }
    });

    popup.setOnEmojiconBackspaceClickedListener(new EmojiconPopup.OnEmojiconBackspaceClickedListener() {
        @Override
        public void onEmojiconBackspaceClicked(View view) {
            emojiconEditText.dispatchKeyEvent(
                    new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL));
        }
    });
}

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    // Get the SearchView and set the searchable configuration
    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);
    searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from www . java  2  s  .c  o m
        public boolean onQueryTextSubmit(String query) {
            MenuItem searchMenuItem = getSearchMenuItem();
            searchMenuItem.collapseActionView();
            searchView.setQuery("", false);
            //Hide Keyboard
            View view = MainActivity.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String 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;
        }
    });
    if (prefHelper.hideDonate())
        menu.findItem(R.id.action_donate).setVisible(false);
    return true;
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

private static void showSoftInputUnchecked(View view, InputMethodManager imm, int flags) {
    try {//from  w ww  . j a  va2s  .c o m
        Method method = imm.getClass().getMethod("showSoftInputUnchecked", int.class, ResultReceiver.class);
        method.setAccessible(true);
        method.invoke(imm, flags, null);
    } catch (Exception e) {
        // Fallback to public API which hopefully does mostly the same thing
        imm.showSoftInput(view, flags);
    }
}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

private void showKeyboard() {
    // For some reason, this doesn't always work the first time.
    // One way to replicate the problem:
    // Press the "task switch" button repeatedly to pause and resume
    for (int delay = 1; delay <= 101; delay += 100) {
        searchView.postDelayed(new Runnable() {
            @Override//  ww  w.ja v  a 2  s.  c  o m
            public void run() {
                Log.d(LOG, "Trying to show soft keyboard.");
                final boolean searchTextHadFocus = searchView.hasFocus();
                searchView.requestFocusFromTouch();
                final InputMethodManager manager = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                manager.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
                if (!searchTextHadFocus) {
                    defocusSearchText();
                }
            }
        }, delay);
    }
}

From source file:jackpal.androidterm.Term.java

private void doShowSoftKeyboard() {
    if (getCurrentEmulatorView() == null)
        return;/*from   w  w  w .j a va  2s  . co  m*/
    Activity activity = this;
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(getCurrentEmulatorView(), InputMethodManager.SHOW_FORCED);
}

From source file:org.akop.crosswords.view.CrosswordView.java

protected void showKeyboard() {
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(CrosswordView.this, InputMethodManager.SHOW_IMPLICIT);
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

private void init(Context context, AttributeSet attrs) {
    detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override/*www.ja  v a  2 s.c  o m*/
        public boolean onDown(MotionEvent event) {
            boolean isMarkerInChord = false;
            int fret = NO_FRET, string = -1;
            fret = getSelectedFret(event);
            string = getSelectedString(event);
            touchEventMarker = new ChordMarker(string, fret, NO_FINGER);
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event) {
            if (editable && touchEventMarker != null && chord != null && chord.contains(touchEventMarker)) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(GuitarChordView.this, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });
    chord = new Chord();
    showFretNumbers = true;
    showFingerNumbers = true;
    editable = false;
    stringCount = 6;
    listeners = new ArrayList<>();
    fretNumberListeners = new ArrayList<>();
    stringListeners = new ArrayList<>();
    touchEventMarker = null;
    mutedText = MUTED_TEXT;
    openStringText = OPEN_STRING_TEXT;
    initPaint();
    if (attrs != null) {
        //TODO handle custom attribute values
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.GuitarChordView, 0, 0);
        try {
            bridgeNutColor = a.getColor(R.styleable.GuitarChordView_bridgeNutColor, DEFAULT_COLOR);
            bridgeNutPaint.setColor(bridgeNutColor);
            fretMarkerColor = a.getColor(R.styleable.GuitarChordView_fretMarkerColor, DEFAULT_COLOR);
            fretMarkerPaint.setColor(fretMarkerColor);
            stringColor = a.getColor(R.styleable.GuitarChordView_stringColor, DEFAULT_COLOR);
            stringPaint.setColor(stringColor);
            fretNumberColor = a.getColor(R.styleable.GuitarChordView_fretNumberColor, DEFAULT_COLOR);
            fretNumberPaint.setColor(fretNumberColor);
            stringMarkerColor = a.getColor(R.styleable.GuitarChordView_stringMarkerColor, DEFAULT_COLOR);
            stringMarkerPaint.setColor(stringMarkerColor);
            noteColor = a.getColor(R.styleable.GuitarChordView_noteColor, DEFAULT_COLOR);
            notePaint.setColor(noteColor);
            noteNumberColor = a.getColor(R.styleable.GuitarChordView_noteNumberColor, WHITE);
            noteNumberPaint.setColor(noteNumberColor);
            barLineColor = a.getColor(R.styleable.GuitarChordView_barLineColor, DEFAULT_COLOR);
            barLinePaint.setColor(barLineColor);
            mutedText = a.getString(R.styleable.GuitarChordView_mutedText);
            mutedText = (mutedText == null) ? MUTED_TEXT : mutedText;
            openStringText = a.getString(R.styleable.GuitarChordView_openStringText);
            openStringText = (openStringText == null) ? OPEN_STRING_TEXT : openStringText;
            stringCount = a.getInt(R.styleable.GuitarChordView_stringAmount, 6);
            editable = a.getBoolean(R.styleable.GuitarChordView_editable, false);
            showFingerNumbers = a.getBoolean(R.styleable.GuitarChordView_showFingerNumbers, true);
            showFretNumbers = a.getBoolean(R.styleable.GuitarChordView_showFretNumbers, true);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
    }
}