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.polyvi.xface.extension.inappbrowser.XInAppBrowser.java

/**
 * ?//from  www .  j ava2  s.  com
 * @param url
 *            ??Url
 */
private void navigate(String url) {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    if (isCompleteFormUrl(url)) {
        mWebView.loadUrl(url);
    } else {
        mWebView.loadUrl("http://" + url);
    }
    mWebView.requestFocus();
}

From source file:com.spoiledmilk.ibikecph.favorites.EditFavoriteFragment.java

public void hideKeyboard() {
    if (textFavoriteName != null) {
        InputMethodManager inputManager = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(textFavoriteName.getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }//  w  w w.ja  va 2 s .c  o  m
}

From source file:com.dhaval.mobile.plugin.ChildBrowser.java

/**
 * Navigate to the new page/*from   ww w  .  j av a2  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") && !url.startsWith("file:")) {
        this.webview.loadUrl("http://" + url);
    } else {
        this.webview.loadUrl(url);
    }
    this.webview.requestFocus();
}

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

/**
 * Attempts to sign in or register the account specified by the register
 * form. If there are form errors (invalid email, missing fields, etc.), the
 * errors are presented and no actual register attempt is made.
 *//*  www.  ja va  2  s.c  o  m*/
public void attemptRegister() {
    // Reset errors.
    mUsernameView.setError(null);
    mEmailView.setError(null);
    mPasswordView.setError(null);
    mPasswordConfirmView.setError(null);

    if (mAuthTask != null) {
        return;
    }

    // Store values at the time of the register attempt.
    mUsername = mUsernameView.getText().toString();
    mEmail = mEmailView.getText().toString();
    mPassword = mPasswordView.getText().toString();
    mPasswordConfirm = mPasswordConfirmView.getText().toString();

    boolean cancel = false;
    View focusView = null;

    // TODO fiddle around with order of checks

    // 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 if the password confirm is empty
    if (TextUtils.isEmpty(mPasswordConfirm)) {
        mPasswordConfirmView.setError(getString(R.string.error_field_required));
        focusView = mPasswordConfirmView;
        cancel = true;
    }

    // Check for a valid email address.
    if (TextUtils.isEmpty(mEmail)) {
        mEmailView.setError(getString(R.string.error_field_required));
        focusView = mEmailView;
        cancel = true;
    } else if (!mEmail.matches(
            "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")) {
        mEmailView.setError(getString(R.string.error_invalid_email));
        focusView = mEmailView;
        cancel = true;
    }

    // check for valid username
    if (TextUtils.isEmpty(mUsername)) {
        mUsernameView.setError(getString(R.string.error_field_required));
        focusView = mUsernameView;
        cancel = true;
    } else if (mUsername.length() < 6) {
        mUsernameView.setError(getString(R.string.error_invalid_username));
        focusView = mUsernameView;
        cancel = true;
    }

    // check if passwords match
    if (!mPassword.equals(mPasswordConfirm)) {
        mPasswordConfirmView.setError(getString(R.string.error_passwords_not_matching));
        focusView = mPasswordConfirmView;
        cancel = true;
    }

    if (cancel) {
        // There was an error; don't attempt register 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 register attempt.
        mRegisterStatusMessageView.setText(R.string.register_progress_signing_in);
        showProgress(true);
        mAuthTask = new UserRegisterTask();
        mAuthTask.execute((Void) null);
    }
}

From source file:com.pentacog.mctracker.MCServerTrackerActivity.java

/**
 * @see android.app.Activity#onPause()//from  w  w w  .j  a  v  a2  s  .c om
 */
@Override
protected void onPause() {
    InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (mgr.isActive(getListView())) {
        mgr.hideSoftInputFromWindow(getListView().getWindowToken(), 0);
    }
    super.onPause();
}

From source file:com.accia77.mockey.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();//ww w  . j a v  a2s .  co m

    // load slide menu items
    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

    // nav drawer icons from resources
    navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

    navDrawerItems = new ArrayList<NavDrawerItem>();

    // adding nav drawer items to array
    // Home
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[IDX_NAVDRAWER_HOME],
            navMenuIcons.getResourceId(IDX_NAVDRAWER_HOME, -1)));

    // Add new quote
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[IDX_NAVDRAWER_ADD_QUOTE],
            navMenuIcons.getResourceId(IDX_NAVDRAWER_ADD_QUOTE, -1)));
    // Manage quotes
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[IDX_NAVDRAWER_MANAGE_QUOTES],
            navMenuIcons.getResourceId(IDX_NAVDRAWER_MANAGE_QUOTES, -1)));
    // Options
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[IDX_NAVDRAWER_SETTINGS],
            navMenuIcons.getResourceId(IDX_NAVDRAWER_SETTINGS, -1)));
    // Help
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[IDX_NAVDRAWER_HELP],
            navMenuIcons.getResourceId(IDX_NAVDRAWER_HELP, -1)));

    // Recycle the typed array
    navMenuIcons.recycle();

    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

    // setting the nav drawer list adapter
    adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
    mDrawerList.setAdapter(adapter);

    // enabling action bar app icon and behaving it as toggle button
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, // nav menu toggle icon
            R.string.app_name, // nav drawer open - description for
            // accessibility
            R.string.app_name // nav drawer close - description for
                              // accessibility
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);

            // calling onPrepareOptionsMenu() to show action bar icons
            // invalidateOptionsMenu();
            supportInvalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            // Close soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) MainActivity.this
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), 0);

            getSupportActionBar().setTitle(mDrawerTitle);

            // calling onPrepareOptionsMenu() to hide action bar icons
            // invalidateOptionsMenu();
            supportInvalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        // If this is the first start of the app or of a new update, show the help screen 
        sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

        bAutoLoadHelpScreen = sharedPrefs.getBoolean("autoLoadHelpScreen", true);

        iAppVersion = sharedPrefs.getInt("appVersion", 0);

        //TODO: a better way to check for the app version is definitely needed here...
        if (bAutoLoadHelpScreen || iAppVersion != 6) {
            displayView(IDX_NAVDRAWER_HELP);

            // Set the autoLoadHelpScreen and appVersion to the current values
            // in order to avoid showing the help screen all the times
            Editor editor = sharedPrefs.edit();
            editor.putBoolean("autoLoadHelpScreen", false);
            editor.putInt("appVersion", 6);
            editor.commit();
        } else
            displayView(IDX_NAVDRAWER_HOME);
    }

    m_doShowAddNewQuoteAction = true;
}

From source file:com.appnexus.opensdkapp.MainActivity.java

@Override
public void onPageSelected(int arg0) {
    Clog.v(Constants.BASE_LOG_TAG, "page selected: " + arg0);
    this.tabHost.setCurrentTab(arg0);

    DebugFragment debugFrag = (DebugFragment) pagerAdapter.getItem(TABS.DEBUG.ordinal());
    if (debugFrag != null)
        debugFrag.refresh();/*from   w  ww  .ja v  a 2 s .c  o  m*/
    else
        Clog.e(Constants.BASE_LOG_TAG, "DebugFragment object was null");

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(tabHost.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.android.printspooler.widget.PrintContentView.java

private void ensureImeClosedAndInputFocusCleared() {
    View focused = findFocus();//from  w  w w.  j a  v a  2s .c o  m

    if (focused != null && focused.isFocused()) {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive(focused)) {
            imm.hideSoftInputFromWindow(getWindowToken(), 0);
        }
        focused.clearFocus();
    }
}

From source file:prince.app.ccm.Fragment_Log.java

public void addFocusListener(EditText xT) {
    xT.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override/*from  www  .ja v  a2s. c  o  m*/
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }

            else {
                getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            }

        }
    });
}

From source file:bbct.android.common.activity.BaseballCardDetails.java

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.card_details, container, false);
    ButterKnife.bind(this, view);
    final Activity activity = Objects.requireNonNull(getActivity());
    String cardDetailsTitle = this.getString(R.string.card_details_title);
    String title = this.getString(R.string.bbct_title, cardDetailsTitle);
    activity.setTitle(title);//  w  w w  .  j a v  a  2s .com

    brandText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            Log.d(TAG, "onKey() in Brand TextView");
            Log.d(TAG, "keyCode = " + keyCode);

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) {
                Log.d(TAG, "focus on Year");
                yearText.requestFocus();
                return true;
            }

            return false;
        }
    });

    playerNameText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            Log.d(TAG, "onKey() in Player Name TextView");
            Log.d(TAG, "keyCode = " + keyCode);

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) {
                Log.d(TAG, "focus on Team");
                teamText.requestFocus();
                return true;
            }

            return false;
        }
    });

    teamText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            Log.d(TAG, "onKey() in Team TextView");
            Log.d(TAG, "keyCode = " + keyCode);

            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) {
                Log.d(TAG, "hide keyboard");
                InputMethodManager imm = Objects.requireNonNull(
                        (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE));
                imm.hideSoftInputFromWindow(teamText.getWindowToken(), 0);
                playerPositionSpinner.requestFocus();
                return true;
            }

            return false;
        }
    });

    createAdapters(activity);
    populateTextEdits();

    return view;
}