Example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

List of usage examples for android.view.inputmethod InputMethodManager hideSoftInputFromWindow

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager hideSoftInputFromWindow.

Prototype

public boolean hideSoftInputFromWindow(IBinder windowToken, int flags) 

Source Link

Document

Synonym for #hideSoftInputFromWindow(IBinder,int,ResultReceiver) without a result: request to hide the soft input window from the context of the window that is currently accepting input.

Usage

From source file:com.bonsai.btcreceive.MainActivity.java

public void hideKeyboard() {
    // Hide the keyboard.
    InputMethodManager imm = ((InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE));
    imm.hideSoftInputFromWindow(mPager.getWindowToken(), 0);
}

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

/**
 * Navigate to the new page//from   w ww  .j a v  a  2s. c o  m
 * 
 * @param url to load
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) this.ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
    if (!url.startsWith("http")) {
        this.webview.loadUrl("http://" + url);
    }
    this.webview.loadUrl(url);
    this.webview.requestFocus();
}

From source file:com.hybris.mobile.activity.StoreLocatorActivity.java

@Override
public boolean onQueryTextSubmit(String arg0) {
    clearStoreList();/*from  w w w  .j  a  v a 2  s  .  c  o m*/

    this.mQuery = new QueryStore();
    this.mCurrentLocation = null;
    mQuery.setQueryText(arg0);

    fetchStores();

    //hide keyboard after submit
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mSearchView.getActionView().getWindowToken(), 0);
    return false;
}

From source file:com.phonegap.childBrowser.ChildBrowser.java

/**
 * Navigate to the new page//from w  w w.j av  a 2 s.  c  o m
 * 
 * @param url to load
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) this.ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

    if (!url.startsWith("http")) {
        this.webview.loadUrl("http://" + url);
    }
    this.webview.loadUrl(url);
    this.webview.requestFocus();
}

From source file:com.brq.wallet.activity.export.MrdDecryptDataActivity.java

private void hideKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(passwordEdit.getWindowToken(), 0);
}

From source file:com.j_o.android.imdb_client.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mediaList = new ArrayList<Media>();
    mediaGrid = (GridView) findViewById(R.id.media_grid_view);
    editTxMediaSearch = (EditText) findViewById(R.id.edit_search_media);

    // Input filter that not allow special characters.
    InputFilter filter = new InputFilter() {
        @Override/*from w  w  w  .ja  va 2 s.c  om*/
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {

            if (source instanceof SpannableStringBuilder) {
                SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source;
                for (int i = end - 1; i >= start; i--) {
                    char currentChar = source.charAt(i);
                    if (!Character.isLetterOrDigit(currentChar) && !Character.isSpaceChar(currentChar)) {
                        sourceAsSpannableBuilder.delete(i, i + 1);
                    }
                }
                return source;
            } else {
                StringBuilder filteredStringBuilder = new StringBuilder();
                for (int i = 0; i < end; i++) {
                    char currentChar = source.charAt(i);
                    if (Character.isLetterOrDigit(currentChar) || Character.isSpaceChar(currentChar)) {
                        filteredStringBuilder.append(currentChar);
                    }
                }
                return filteredStringBuilder.toString();
            }
        }
    };
    editTxMediaSearch.setFilters(new InputFilter[] { filter });

    editTxMediaSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                new AskForMediaAsyncTaks().execute(editTxMediaSearch.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editTxMediaSearch.getWindowToken(), 0);
                return true;
            }
            return false;
        }

    });

}

From source file:com.netpace.expressit.activity.UploadVideoStoryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        this.onBackPressed();
        return true;

    case R.id.menu_item_video_gallery:
        if (isValidate()) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(titleTextView.getWindowToken(), 0);

            getMediaKeyFromRemoteServer();
        }/*from w w w  .  j ava2 s  . co  m*/
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.EditFragment.java

/**
 * Sets the text of the comment being edited to the new text entered by the user,
 * sets the value of EditCommentFragment.oldText and EditCommentFragment.oldThumbnail
 * to null so that the state isn't preserved across comment edits, and returns the
 * user to their previous fragment.//from  w  w  w  .  ja  va 2s.c o  m
 * 
 * @param view The button that was pressed to call makeEdit.
 */
public void makeEdit(View view) {
    EditFragment.oldText = null;
    EditFragment.oldThumbnail = null;
    editComment.setTextPost(newTextPost.getText().toString());
    ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setMessage("Posting to Server");
    if (isThread) {
        String threadTitle = thread.getTitle();
        thread.setBodyComment(editComment);
        ThreadManager.startPost(editComment, threadTitle, editComment.getLocation(), dialog, true);
        CacheManager.getInstance().serializeThreadList(ThreadList.getThreads());
    } else {
        ThreadManager.startPost(editComment, null, editComment.getLocation(), dialog, true);
    }
    InputMethodManager inputManager = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    getFragmentManager().popBackStackImmediate();
}

From source file:org.envirocar.app.activity.LoginFragment.java

/**
 * Attempts to sign in or register the account specified by the login form.
 * If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual login attempt is made.
 *//*  w  ww . j a va 2s  . c o  m*/
private void attemptLogin() {

    // Reset errors.
    mUsernameView.setError(null);
    mPasswordView.setError(null);

    if (mAuthTask != null) {
        return;
    }

    // Store values at the time of the login attempt.
    mUsername = mUsernameView.getText().toString();
    mPassword = mPasswordView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // Check for a valid password.
    if (TextUtils.isEmpty(mPassword)) {
        mPasswordView.setError(getString(R.string.error_field_required));
        focusView = mPasswordView;
        cancel = true;
    } else if (mPassword.length() < 6) {
        mPasswordView.setError(getString(R.string.error_invalid_password));
        focusView = mPasswordView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(mUsername)) {
        mUsernameView.setError(getString(R.string.error_field_required));
        focusView = mUsernameView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt login and focus the first
        // form field with an error.
        focusView.requestFocus();
    } else {
        // hide the keyboard
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);

        // Show a progress spinner, and kick off a background task to
        // perform the user login attempt.
        mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
        showProgress(true);
        mAuthTask = new UserLoginTask();
        mAuthTask.execute((Void) null);
    }
}

From source file:com.phonegap.plugin.ChildBrowser.java

/**
 * Navigate to the new page/*  w ww.j  a v  a 2s . c o  m*/
 * 
 * @param url to load
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) this.ctx.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

    if (!url.startsWith("http") || !url.startsWith("file:")) {
        this.webview.loadUrl("http://" + url);
    } else {
        this.webview.loadUrl(url);
    }
    this.webview.requestFocus();
}