Example usage for android.view View getWindowToken

List of usage examples for android.view View getWindowToken

Introduction

In this page you can find the example usage for android.view View getWindowToken.

Prototype

public IBinder getWindowToken() 

Source Link

Document

Retrieve a unique token identifying the window this view is attached to.

Usage

From source file:nl.thehyve.transmartclient.MainActivity.java

private void hideKeyboard() {
    View view = getCurrentFocus();
    if (view != null) {
        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//  ww  w  . j av a  2s.  c  o  m
}

From source file:org.dharmaseed.android.NavigationActivity.java

@Override
public void onFocusChange(View v, boolean hasFocus) {
    Log.i("focusChange", hasFocus + "");
    if (hasFocus) {
        ((EditText) v).setCursorVisible(true);
    } else {/*from  w  w  w  .  j av a  2 s  .com*/
        ((EditText) v).setCursorVisible(false);
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
}

From source file:org.mozilla.gecko.AwesomeBarTabs.java

private void hideSoftInput(View view) {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);

    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

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

private void hideKeyboard() {
    View view = getCurrentFocus();
    if (view != null) {
        ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }//from w w w  .  j  a  v a 2 s .c om
}

From source file:com.itude.mobile.mobbl.core.controller.MBViewManager.java

public void hideSoftKeyBoard(View triggeringView) {
    InputMethodManager imm = (InputMethodManager) triggeringView.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(triggeringView.getWindowToken(), 0);
}

From source file:org.wheelmap.android.fragment.POIDetailEditableFragment.java

public void closeKeyboard() {
    View view = getView().findFocus();
    if (view == null || !(view instanceof EditText)) {
        return;/*  www  .ja va  2  s . c om*/
    }

    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

}

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/*  www.j a  v  a  2  s. com*/
        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.androzic.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action buttons
    switch (item.getItemId()) {
    case android.R.id.home:
        FragmentManager fm = getSupportFragmentManager();
        if (fm.getBackStackEntryCount() > 0) {
            View v = getCurrentFocus();
            if (v != null) {
                // Hide keyboard
                final InputMethodManager imm = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }/*from  ww w  . ja  v a 2s .  c  o m*/
            fm.popBackStack();
            return true;
        } else {
            if (mDrawerToggle.onOptionsItemSelected(item)) {
                return true;
            }
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.example.emachine.FXcalcActivity.java

private void hideKeyboard() {
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this
                .getSystemService(Context.INPUT_METHOD_SERVICE);

        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }/*  w ww.  j a  va  2  s.  c  om*/
}

From source file:ru.tinkoff.acquiring.sdk.EnterCardFragment.java

private void hideSoftKeyboard() {
    View view = getActivity().getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from   w w  w  .j a v a  2  s  . c om*/
}