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:de.ddast.xandra.MainActivity.java

private void showSoftKeyboard(View view) {
    if (view.requestFocus()) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }/*  w  w w .j a v  a2s. c o m*/
    if (mSpecialKeysVisibility == View.VISIBLE) {
        mLayoutKeys = (HorizontalScrollView) findViewById(R.id.layout_keys);
        Assert.assertNotNull(mLayoutKeys);
        mLayoutKeys.setVisibility(View.VISIBLE);
    }
}

From source file:mp.paschalis.BookSearchActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    if (isMakingSearch) {
        menu.findItem(App.MENU_SEARCH_SEARCH_BOOKS).setVisible(false);
        menu.findItem(App.MENU_CLEAR).setVisible(true);

        // Show on screen keyboard
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
        editTextSearchKeyword.requestFocus();
        imm.showSoftInput(editTextSearchKeyword, 0);
    } else {/*from  w w  w  .j a  v a2 s .c  o m*/
        menu.findItem(App.MENU_SEARCH_SEARCH_BOOKS).setVisible(true);
        menu.findItem(App.MENU_CLEAR).setVisible(false);
        // Hide on screen keyboard
        InputMethodManager imm = (InputMethodManager) BookSearchActivity.this
                .getSystemService(Service.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(editTextSearchKeyword.getWindowToken(), 0);
    }

    // If book is selected, show edit/view options
    if (isItemChecked) {

        String bookTitle;
        try {
            if (app.deviceType.equals(DeviceType.Large)) {
                bookTitle = app.selectedBook.title;
            } else {
                // If smaller device
                bookTitle = app.selectedBook.title.substring(0, 9) + "..";
            }

        } catch (Exception e) {
            menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(false);
            return false;
        }

        if (app.selectedBook.status != App.BOOK_STATE_USER_DONT_OWNS) {
            menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(true)
                    .setTitle(getString(R.string.edit) + ": " + bookTitle);
        } else {

            menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(true)
                    .setTitle(getString(R.string.view) + ": " + bookTitle);

        }

    } else {
        menu.findItem(App.MENU_MY_BOOKS_BOOK_SELECTED).setVisible(false);

    }

    return true;
}

From source file:com.silentcircle.accounts.AccountStep3.java

private void authTokenError() {
    View view = getView();//w  ww  .  j  a  va2 s  . c  o  m
    if (view == null)
        return;

    // Two-factor authentication token required. Rearrange the UI, the show the error text, input field, and Back and Next buttons
    mProgress.setVisibility(View.INVISIBLE);
    getView().findViewById(R.id.ProvisioningInProgress).setVisibility(View.INVISIBLE);
    mScroll.setVisibility(View.VISIBLE);
    mButtons.setVisibility(View.VISIBLE);
    view.findViewById(R.id.CheckBoxTCText).setVisibility(View.GONE);
    mTcCheckbox.setVisibility(View.GONE);
    mAuthToken.setVisibility(View.VISIBLE);
    mAuthToken.setText("");
    mAuthToken.requestFocus();
    View v = mParent.getCurrentFocus();
    if (v != null) {
        InputMethodManager imm = (InputMethodManager) mParent.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
    }

    TextView errorText = (TextView) view.findViewById(R.id.license_error);

    errorText.setText(getString(R.string.provisioning_auth_token_text));
    errorText.setVisibility(View.VISIBLE);
}

From source file:org.ohmage.prompt.multichoicecustom.MultiChoiceCustomPrompt.java

private void showAddItemControls(Context context, boolean show) {
    ImageView imageView = (ImageView) mFooterView.findViewById(R.id.image);
    TextView textView = (TextView) mFooterView.findViewById(R.id.text);
    EditText editText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
    ImageButton mButton = (ImageButton) mFooterView.findViewById(R.id.ok_button);
    ImageButton mCancelButton = (ImageButton) mFooterView.findViewById(R.id.cancel_button);

    //editText.setText("");

    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

    if (show) {// www .  j  a  v  a2  s.c  o m
        editText.setText(mEnteredText);
        mIsAddingNewItem = true;
        imageView.setVisibility(View.GONE);
        textView.setVisibility(View.GONE);
        editText.setVisibility(View.VISIBLE);
        mButton.setVisibility(View.VISIBLE);
        mCancelButton.setVisibility(View.VISIBLE);
        editText.requestFocus();
        imm.showSoftInput(editText, 0);
    } else {
        mEnteredText = "";
        mIsAddingNewItem = false;
        imageView.setVisibility(View.VISIBLE);
        textView.setVisibility(View.VISIBLE);
        editText.setVisibility(View.GONE);
        mButton.setVisibility(View.GONE);
        mCancelButton.setVisibility(View.GONE);
        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    }
}

From source file:mp.paschalis.BookSearchActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case App.MENU_LIBRARY_SETTINGS: {
        Intent myIntent = new Intent(BookSearchActivity.this, LibPreferences.class);
        BookSearchActivity.this.startActivity(myIntent);

    }/*from ww  w  .j a  va  2s  .  co  m*/
        return true;
    case App.MENU_GLOBAL_SETTINGS: {
        Intent myIntent = new Intent(BookSearchActivity.this, PreferencesActivity.class);
        BookSearchActivity.this.startActivity(myIntent);

    }
        return true;

    case App.MENU_SEARCH_SEARCH_BOOKS: {
        linearLayoutSearchLayout.setVisibility(View.VISIBLE);
        isMakingSearch = true;
        isItemChecked = false;
        invalidateOptionsMenu();

        // Show on screen keyboard
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
        editTextSearchKeyword.requestFocus();
        imm.showSoftInput(editTextSearchKeyword, 0);

    }
        return true;

    case App.MENU_CLEAR: {

        // If data was already cleared, hide search panel
        if (editTextSearchKeyword.getText().length() == 0 && resultsShowing) {
            // Close panel & soft keyboard
            linearLayoutSearchLayout.setVisibility(View.GONE);
            textViewSearchResults.setVisibility(View.VISIBLE);
            isMakingSearch = false;
            invalidateOptionsMenu();
        }
        // else just clear data
        else {
            editTextSearchKeyword.setText("");
        }

    }
        return true;

    case App.MENU_MY_BOOKS_BOOK_SELECTED: {
        // If user owns that book, open edit book
        if (app.selectedBook.status != App.BOOK_STATE_USER_DONT_OWNS) {
            // Workaround - Change the status of book, to users
            // specific status
            for (Book.DataClassUser u : app.selectedBook.owners) {
                // Find real status for that book
                if (u.username.equalsIgnoreCase(app.user.username)) {
                    app.selectedBook.status = u.status;
                    break;
                }
            }

            Intent intent = new Intent(BookSearchActivity.this, EditBookActivity.class);

            intent.putExtra(App.ExtrasForEditBookActivityFromBookSearch, true);

            openedEditBook = true;

            startActivity(intent);
        } else {
            Boolean isAvail = false;

            // Find all users who lent this book
            for (Book.DataClassUser u : app.selectedBook.owners) {
                if (u.status == App.BOOK_STATE_USER_AVAILABLE) {
                    isAvail = true;
                }
            }

            Intent intent = new Intent(BookSearchActivity.this, WatchBookActivity.class);

            intent.putExtra(App.ExtrasForWatchBookActivityFromBookSearch, isAvail);

            startActivity(intent);
        }

    }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.azapps.mirakel.main_activity.tasks_fragment.TasksFragment.java

protected boolean newTask(final String name) {
    this.newTask.setText(null);
    final InputMethodManager imm = (InputMethodManager) this.main
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(this.newTask.getWindowToken(), 0);
    this.newTask.clearFocus();
    if (name.equals("")) {
        this.newTask.setOnFocusChangeListener(null);
        imm.showSoftInput(this.newTask, InputMethodManager.HIDE_IMPLICIT_ONLY);
        return true;
    }/*w  w  w. j ava2s.  c o m*/
    final ListMirakel list = this.main.getCurrentList();
    final Task createdTask = Semantic.createTask(name, Optional.fromNullable(list), true, getActivity());
    getLoaderManager().restartLoader(0, null, this);
    this.main.setCurrentTask(createdTask, false);
    this.main.getListFragment().update();
    if (!MirakelCommonPreferences.hideKeyboard()) {
        focusNew(true);
    }
    this.main.updateShare();
    return true;
}

From source file:pl.mrwojtek.sensrec.app.SamplingPeriodDialog.java

private void initializeSamplingSpinner(View view) {
    TextView samplingCaption = (TextView) view.findViewById(R.id.sampling_caption);
    MaterialUtils.transformForSpinner(samplingCaption);

    samplingSpinner = (Spinner) view.findViewById(R.id.sampling_spinner);
    samplingSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from www  .j av  a 2s.  com
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (position != POSITION_CUSTOM) {
                millisecondsEdit.setText("");
                if (!initializing) {
                    millisecondsEdit.clearFocus();
                    inputMethodManager.hideSoftInputFromWindow(millisecondsEdit.getWindowToken(), 0);
                } else {
                    initializing = false;
                }
            } else {
                if (!initializing) {
                    millisecondsEdit.requestFocus();
                    inputMethodManager.showSoftInput(millisecondsEdit, InputMethodManager.SHOW_IMPLICIT);
                } else {
                    initializing = false;
                }
            }
            updateOkButton();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // Do nothing
        }
    });
}

From source file:com.bitants.wally.fragments.SearchFragment.java

public void showKeyboard(View viewThatWantsKeyboard) {
    if (getActivity() != null && getActivity().getCurrentFocus() != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(viewThatWantsKeyboard, 0);
        //            inputMethodManager.toggleSoftInputFromWindow(quickReturnEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
    }//from ww w.j  av a  2s .  c  om
}

From source file:com.notepadlite.NoteEditFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*from   w  w  w  .  j  a  va  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 = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = (LinearLayout) 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 = (EditText) getActivity().findViewById(R.id.editText1);

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

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

    if (theme.contains("dark")) {
        noteContents.setTextColor(getResources().getColor(R.color.text_color_primary_dark));
        noteContents.setBackgroundColor(getResources().getColor(R.color.window_background_dark));
        scrollView.setBackgroundColor(getResources().getColor(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);
        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);
        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.anjalimacwan.fragment.NoteEditFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/*from w  w  w.  j a v a  2 s . c om*/
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 = (LinearLayout) getActivity().findViewById(R.id.noteViewEdit);
        LinearLayout noteList = (LinearLayout) 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 = (EditText) getActivity().findViewById(R.id.editText1);

    // Apply theme
    SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences",
            Context.MODE_PRIVATE);
    ScrollView 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);

}