List of usage examples for android.view.inputmethod InputMethodManager hideSoftInputFromWindow
public boolean hideSoftInputFromWindow(IBinder windowToken, int flags)
From source file:co.beem.project.beem.ui.wizard.AccountConfigureFragment.java
public void hideKeyboard() { if (getActivity().getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0); }// ww w .ja v a2s .com }
From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { // Set background color and drawable. view.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.transparent)); view.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.search_background)); final SearchBar searchBar = (SearchBar) view.findViewById(R.id.lb_search_bar); if (searchBar != null) { // Set the left margin of the search bar. ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) searchBar .getLayoutParams();//from w w w. ja va 2 s. c om layoutParams.setMarginStart((int) getResources().getDimension(R.dimen.search_bar_margin_left)); searchBar.setLayoutParams(layoutParams); // Move the search bar items next to the search icon. RelativeLayout searchBarItems = (RelativeLayout) searchBar.findViewById(R.id.lb_search_bar_items); if (searchBarItems != null) { RelativeLayout.LayoutParams searchBarItemsLayoutParams = (RelativeLayout.LayoutParams) searchBarItems .getLayoutParams(); searchBarItemsLayoutParams.setMarginStart( (int) getResources().getDimension(R.dimen.search_bar_items_margin_left)); searchBarItems.setLayoutParams(searchBarItemsLayoutParams); // Set the search bar items background selector. searchBarItems.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.search_edit_text_bg_color_selector)); } // Set speech orb icon. mSpeechOrbView = (SpeechOrbView) searchBar.findViewById(R.id.lb_search_bar_speech_orb); if (mSpeechOrbView != null) { mSpeechOrbView.setOrbIcon(ContextCompat.getDrawable(getActivity(), R.drawable.search_icon)); } final SearchEditText searchEditText = (SearchEditText) searchBar .findViewById(R.id.lb_search_text_editor); if (searchEditText != null) { mSearchEditText = searchEditText; // Handle keyboard being dismissed to prevent focus going to SearchOrb // If user presses back from keyboard, you don't get KeyboardDismissListener // so handle that here. searchEditText.setOnEditorActionListener((textView, actionId, keyEvent) -> { // Track search if keyboard is closed with IME_ACTION_PREVIOUS or // if IME_ACTION_SEARCH occurs. if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_PREVIOUS) { if (mQuery != null) { AnalyticsHelper.trackSearchQuery(mQuery); } } if (actionId == EditorInfo.IME_ACTION_PREVIOUS) { // Prevent highlighting SearchOrb mSpeechOrbView.setFocusable(false); mSpeechOrbView.clearFocus(); // If there are results allow first result to be selected if (mHasResults) { mSearchEditText.clearFocus(); } // Hide keyboard since we are handling the action if (isAdded()) { // Ensure we are added before calling getActivity InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); if (inputManager != null) { inputManager.hideSoftInputFromWindow( getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } else { Log.e(TAG, "Cannot find activity, can't dismiss keyboard"); // Couldn't handle action. // Will expose other focus issues potentially. return false; } // No more processing of this action. return true; } // Someone else needs to handle this action. return false; }); // Override the dismiss listener to get around keyboard issue where dismissing // keyboard takes user into first search result's // content_details_activity_layout page. searchEditText.setOnKeyboardDismissListener(() -> { // If search returns results, focus on the first item in the result list. // If search doesn't have results, this will focus on searchEditText again. mSpeechOrbView.setFocusable(false); mSpeechOrbView.clearFocus(); // We don't need to clearFocus on SearchEditText here, the first // result will be selected already. }); } } } return view; }
From source file:com.citrus.sdk.CitrusActivity.java
private void showPrompt() { final AlertDialog.Builder alert = new AlertDialog.Builder(mContext); String message = null;/* w w w . jav a 2 s . c om*/ String title = null; if (passwordPromptShown) { message = "Incorrect Password."; title = "Please Enter Password Again."; } else { message = "Please Enter Your Password For Citrus Account."; title = "Enter Password"; } String positiveButtonText = "Pay"; alert.setTitle(title); alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(mContext); alert.setView(input); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String password = input.getText().toString(); input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); if (!TextUtils.isEmpty(password)) { mPaymentWebview .loadUrl("javascript:(function() { " + "document.getElementById('password').value='" + password + "';" + "document.getElementById(\"verify\").submit();" + "}) ()"); input.clearFocus(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0); String emailId = mCitrusClient.getUserEmailId(); getCookie(emailId, password); dialog.dismiss(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { onBackPressed(); } }); input.requestFocus(); alert.show(); }
From source file:com.soomla.example.ExampleSocialActivity.java
private void hideSoftKeyboard() { if (getCurrentFocus() != null && getCurrentFocus() instanceof EditText) { EditText edtCurrentFocusText = (EditText) getCurrentFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edtCurrentFocusText.getWindowToken(), 0); }/*from w ww . j a va 2 s. c om*/ }
From source file:org.exoplatform.shareextension.ShareActivity.java
private void hideSoftKeyboard() { InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(ComposeFragment.getFragment().getEditText().getWindowToken(), 0); }
From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { View focusView = getActivity().getCurrentFocus(); if (focusView != null) { imm.hideSoftInputFromWindow(focusView.getWindowToken(), 0); }//from ww w.j a v a 2 s . co m } mAttrs = readAttribute(); mView = createView(); mGroup = (ViewGroup) getActivity().getWindow().getDecorView(); createItems(); mGroup.addView(mView); mBg.startAnimation(createAlphaInAnimation()); mPanel.startAnimation(createTranslationInAnimation()); return super.onCreateView(inflater, container, savedInstanceState); }
From source file:com.codeim.coxin.LoginActivity.java
private void hideSoftInput(IBinder token) { if (token != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mUsernameEdit.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }//from w w w . ja va2 s .c om }
From source file:de.geeksfactory.opacclient.frontend.OpacActivity.java
protected void setupDrawer() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawerLayout != null) { hasDrawer = true;// ww w . j a v a 2 s . c o m drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ drawerLayout, /* DrawerLayout object */ R.drawable.ic_navigation_drawer, /* * nav drawer icon to replace 'Up' * caret */ R.string.drawer_open, /* "open drawer" description */ R.string.drawer_close /* "close drawer" description */ ) { /** * Called when a drawer has settled in a completely closed * state. */ @Override public void onDrawerClosed(View view) { super.onDrawerClosed(view); getSupportActionBar().setTitle(mTitle); } /** Called when a drawer has settled in a completely open state. */ @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); getSupportActionBar().setTitle(app.getResources().getString(R.string.app_name)); if (getCurrentFocus() != null) { InputMethodManager imm = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); } } }; // Set the drawer toggle as the DrawerListener drawerLayout.setDrawerListener(drawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); drawerList = (ListView) findViewById(R.id.drawer_list); navAdapter = new NavigationAdapter(this); drawerList.setAdapter(navAdapter); navAdapter.addSeperatorItem(getString(R.string.nav_hl_library)); navAdapter.addTextItemWithIcon(getString(R.string.nav_search), R.drawable.ic_action_search, "search"); navAdapter.addTextItemWithIcon(getString(R.string.nav_account), R.drawable.ic_action_account, "account"); navAdapter.addTextItemWithIcon(getString(R.string.nav_starred), R.drawable.ic_action_star_1, "starred"); navAdapter.addTextItemWithIcon(getString(R.string.nav_info), R.drawable.ic_action_info, "info"); aData.open(); accounts = aData.getAllAccounts(); if (accounts.size() > 1) { navAdapter.addSeperatorItem(getString(R.string.nav_hl_accountlist)); long tolerance = Long.decode(sp.getString("notification_warning", "367200000")); int selected = -1; for (final Account account : accounts) { Library library; try { library = ((OpacClient) getApplication()).getLibrary(account.getLibrary()); int expiring = aData.getExpiring(account, tolerance); String expiringText = ""; if (expiring > 0) { expiringText = String.valueOf(expiring); } if (getString(R.string.default_account_name).equals(account.getLabel())) { navAdapter.addLibraryItem(library.getCity(), library.getTitle(), expiringText, account.getId()); } else { navAdapter.addLibraryItem(account.getLabel(), library.getCity() + " " + library.getTitle(), expiringText, account.getId()); } if (account.getId() == app.getAccount().getId()) { selected = navAdapter.getCount() - 1; } } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } } if (selected > 0) { drawerList.setItemChecked(selected, true); } } navAdapter.addSeperatorItem(getString(R.string.nav_hl_other)); navAdapter.addTextItemWithIcon(getString(R.string.nav_settings), R.drawable.ic_action_settings, "settings"); navAdapter.addTextItemWithIcon(getString(R.string.nav_about), R.drawable.ic_action_help, "about"); drawerList.setOnItemClickListener(new DrawerItemClickListener()); if (!sp.getBoolean("version2.0.0-introduced", false) && app.getSlidingMenuEnabled()) { final Handler handler = new Handler(); // Just show the menu to explain that is there if people start // version 2 for the first time. // We need a handler because if we just put this in onCreate // nothing // happens. I don't have any idea, why. handler.postDelayed(new Runnable() { @Override public void run() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(OpacActivity.this); drawerLayout.openDrawer(drawerList); sp.edit().putBoolean("version2.0.0-introduced", true).commit(); } }, 500); } } }
From source file:org.ohmage.auth.AuthenticatorActivity.java
private void hideKeyboard() { if (getCurrentFocus() != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); }//from ww w. ja v a2 s .com }
From source file:com.freecast.LudoCast.MainActivity.java
@Override public boolean onTouchEvent(android.view.MotionEvent event) { InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); editText.setCursorVisible(false);/*w w w . j ava 2s .com*/ return imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); }