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.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);
            }/* www.  java 2s .  c om*/
            fm.popBackStack();
            return true;
        } else {
            if (mDrawerToggle.onOptionsItemSelected(item)) {
                return true;
            }
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:co.carlosjimenez.android.currencyalerts.app.MainActivityFragment.java

/**
 * This method forces the soft keyboard to hide
 *//*  w  w w  . j  a  v a  2s . c om*/
private void hideIme() {
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Activity.INPUT_METHOD_SERVICE);
    //Find the currently focused view, so we can grab the correct window token from it.
    View view = mContext.getCurrentFocus();
    //If no view currently has focus, create a new one, just so we can grab a window token from it
    if (view == null) {
        view = new View(mContext);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:br.ufrgs.ufrgsmapas.libs.SearchBox.java

private void closeSearch() {
    this.materialMenu.animateState(IconState.BURGER);
    this.logo.setVisibility(View.VISIBLE);
    this.drawerLogo.setVisibility(View.VISIBLE);
    this.search.setVisibility(View.GONE);
    this.results.setVisibility(View.GONE);
    if (tint != null && rootLayout != null) {
        rootLayout.removeView(tint);/* w  w w.j  a va  2  s. c om*/
    }
    if (listener != null)
        listener.onSearchClosed();
    micStateChanged(true);
    mic.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_action_mic));
    InputMethodManager inputMethodManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(getApplicationWindowToken(), 0);
}

From source file:com.androidquery.simplefeed.activity.PostActivity.java

private void doneInput() {

    EditText edit = aq.id(R.id.edit_input).getEditText();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}

From source file:co.taqat.call.assistant.AssistantActivity.java

public void hideKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    View view = this.getCurrentFocus();
    if (imm != null && view != null) {
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//  www  . j  av  a2 s  . c  o m
}

From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    mRootView = container;// w w w.  j av a 2s.co  m
    final View view = inflater.inflate(R.layout.playlist_activity, container, false);
    mSearchView = (SearchView) view.findViewById(R.id.search);
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(final String newText) {
            mFilter = newText;
            if (newText != null && newText.isEmpty()) {
                mFilter = null;
            }
            if (mFilter != null) {
                mFilter = mFilter.toLowerCase();
            }
            mList.setDragEnabled(mFilter == null);
            update(false);
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(final String query) {
            // Hide the keyboard and give focus to the list
            final InputMethodManager imm = (InputMethodManager) mActivity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
            mList.requestFocus();
            return true;
        }
    });
    mList = (DragSortListView) view.findViewById(android.R.id.list);
    mList.requestFocus();
    mList.setDropListener(mDropListener);
    mController = new DragSortController(mList);
    mController.setDragHandleId(R.id.cover);
    mController.setRemoveEnabled(false);
    mController.setSortEnabled(true);
    mController.setDragInitMode(1);

    mList.setFloatViewManager(mController);
    mList.setOnTouchListener(mController);
    mList.setDragEnabled(true);

    refreshListColorCacheHint();
    mList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
    mList.setMultiChoiceModeListener(new MultiChoiceModeListener() {

        @Override
        public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {

            final SparseBooleanArray checkedItems = mList.getCheckedItemPositions();
            final int count = mList.getCount();
            final ListAdapter adapter = mList.getAdapter();
            final int itemId = item.getItemId();
            int j = 0;
            int[] positions = null;
            boolean result = true;

            if (itemId == R.id.menu_delete) {
                positions = new int[mList.getCheckedItemCount()];
                for (int i = 0; i < count && j < positions.length; i++) {
                    if (checkedItems.get(i)) {
                        positions[j] = ((Music) adapter.getItem(i)).getSongId();
                        j++;
                    }
                }
            } else if (itemId == R.id.menu_crop) {
                positions = new int[mList.getCount() - mList.getCheckedItemCount()];
                for (int i = 0; i < count && j < positions.length; i++) {
                    if (!checkedItems.get(i)) {
                        positions[j] = ((Music) adapter.getItem(i)).getSongId();
                        j++;
                    }
                }
            } else {
                result = false;
            }

            if (j > 0) {
                QueueControl.run(QueueControl.REMOVE_BY_ID, positions);
                mode.finish();
            }

            return result;
        }

        @Override
        public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
            final MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.mpd_queuemenu, menu);
            return true;
        }

        @Override
        public void onDestroyActionMode(final ActionMode mode) {
            mActionMode = null;
            mController.setSortEnabled(true);
        }

        @Override
        public void onItemCheckedStateChanged(final ActionMode mode, final int position, final long id,
                final boolean checked) {
            final int selectCount = mList.getCheckedItemCount();
            if (selectCount == 0) {
                mode.finish();
            }
            if (selectCount == 1) {
                mode.setTitle(R.string.actionSongSelected);
            } else {
                mode.setTitle(getString(R.string.actionSongsSelected, selectCount));
            }
        }

        @Override
        public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
            mActionMode = mode;
            mController.setSortEnabled(false);
            return false;
        }
    });

    return view;
}

From source file:com.wikitude.phonegap.WikitudePlugin.java

/**
 * add architectView to current screen/*from w w w  . jav  a2 s  . c om*/
 * @param apiKey developers's api key to use (hides watermarking/intro-animation if it matches your package-name)
 * @param filePath the url (starting with http:// for online use; starting with LOCAL_ASSETS_PATH_ROOT if oyu want to load assets within your app-assets folder)
 * @throws IOException might be thrown from ARchitect-SDK
 */
private void addArchitectView(final String apiKey, String filePath) throws IOException {
    if (this.architectView == null) {

        this.architectView = new ArchitectViewPhoneGap(this.cordova.getActivity(), new OnKeyDownListener() {

            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {
                if (WikitudePlugin.this.architectView != null && keyCode == KeyEvent.KEYCODE_BACK) {
                    WikitudePlugin.this.locationProvider.onPause();
                    removeArchitectView();
                    return true;
                }
                return false;
            }
        });

        this.architectView.setFocusableInTouchMode(true);
        this.architectView.requestFocus();

        this.locationListener = new LocationListener() {

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

            @Override
            public void onProviderDisabled(String provider) {
            }

            @Override
            public void onLocationChanged(final Location location) {
                if (location != null) {
                    WikitudePlugin.this.lastKnownLocaton = location;
                    if (WikitudePlugin.this.architectView != null) {
                        if (location.hasAltitude()) {
                            WikitudePlugin.this.architectView.setLocation(location.getLatitude(),
                                    location.getLongitude(), location.getAltitude(), location.getAccuracy());
                        } else {
                            WikitudePlugin.this.architectView.setLocation(location.getLatitude(),
                                    location.getLongitude(), location.getAccuracy());
                        }
                    }
                }
            }
        };

        /* add content view and fake initial life-cycle */
        (this.cordova.getActivity()).addContentView(this.architectView,
                new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

        /* fake life-cycle calls, because activity is already up and running */
        this.architectView.onCreate(getArchitectConfig(apiKey));
        this.architectView.onPostCreate();

        /* register self as url listener to fwd these native calls to PhoneGap */
        this.architectView.registerUrlListener(WikitudePlugin.this);

        /* load asset from local directory if prefix is used */
        if (filePath.startsWith(WikitudePlugin.LOCAL_ASSETS_PATH_ROOT)) {
            filePath = filePath.substring(WikitudePlugin.LOCAL_ASSETS_PATH_ROOT.length());
        }
        this.architectView.load(filePath);

        /* also a fake-life-cycle call (the last one before it is really shown in UI */
        this.architectView.onResume();

        this.locationProvider = new LocationProvider(this.cordova.getActivity(), this.locationListener);

        this.locationProvider.onResume();

    }

    // hide keyboard when adding AR view on top of views
    InputMethodManager inputManager = (InputMethodManager) (this.cordova.getActivity())
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow((this.cordova.getActivity()).getCurrentFocus().getWindowToken(),
            InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:com.gelakinetic.mtgfam.activities.MainActivity.java

public void hideKeyboard() {
    try {/* www  .  j a va  2  s  .c  o m*/
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getCurrentFocus().getApplicationWindowToken(), 0);
    } catch (NullPointerException e) {
        // eat it
    }
}

From source file:com.abeo.tia.noordin.ProcessCaseLoanPrincipal.java

public boolean dispatchTouchEvent(MotionEvent ev) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    return super.dispatchTouchEvent(ev);
}