android.view.inputmethod.InputMethodManager Java Examples
The following examples show how to use
android.view.inputmethod.InputMethodManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InAppBrowser.java From phonegapbootcampsite with MIT License | 6 votes |
/** * Navigate to the new page * * @param url to load */ private void navigate(final String url) { InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0); this.cordova.getActivity().runOnUiThread(new Runnable() { public void run() { if (!url.startsWith("http") && !url.startsWith("file:")) { InAppBrowser.this.inAppWebView.loadUrl("http://" + url); } else { InAppBrowser.this.inAppWebView.loadUrl(url); } InAppBrowser.this.inAppWebView.requestFocus(); } }); }
Example #2
Source File: SearchEditText.java From LiuAGeAndroid with MIT License | 6 votes |
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { pressSearch = (keyCode == KeyEvent.KEYCODE_ENTER); if (pressSearch && listener != null) { /*隐藏软键盘*/ InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0); } if (event.getAction() == KeyEvent.ACTION_UP) { pressSearch = false; listener.onSearchClick(v); } } return false; }
Example #3
Source File: ES_ExternalStorage.java From test-samples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.es_layout); inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); et_file = (EditText) findViewById(R.id.es_et_file); et_error = (EditText) findViewById(R.id.es_et_error); b_read = (Button) findViewById(R.id.es_b_read); tv_output = (TextView) findViewById(R.id.es_tv_output); et_file.setText(DEFAULT_FILE); b_read.setOnClickListener(this); }
Example #4
Source File: RestoreBackupFragment.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private void handleRestore(@NonNull Context context, @NonNull BackupUtil.BackupInfo backup) { View view = LayoutInflater.from(context).inflate(R.layout.enter_backup_passphrase_dialog, null); EditText prompt = view.findViewById(R.id.restore_passphrase_input); prompt.addTextChangedListener(new PassphraseAsYouTypeFormatter()); new AlertDialog.Builder(context) .setTitle(R.string.RegistrationActivity_enter_backup_passphrase) .setView(view) .setPositiveButton(R.string.RegistrationActivity_restore, (dialog, which) -> { InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(prompt.getWindowToken(), 0); setSpinning(restoreButton); skipRestoreButton.setVisibility(View.INVISIBLE); String passphrase = prompt.getText().toString(); restoreAsynchronously(context, backup, passphrase); }) .setNegativeButton(android.R.string.cancel, null) .show(); Log.i(TAG, "Prompt for backup passphrase shown to user."); }
Example #5
Source File: RegisterServiceActivity.java From BonjourBrowser with Apache License 2.0 | 6 votes |
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (getView() == null || actionId != EditorInfo.IME_ACTION_DONE) { return false; } switch (v.getId()) { case R.id.service_name: regTypeEditText.requestFocus(); return true; case R.id.reg_type: portEditText.requestFocus(); return true; case R.id.port: InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getView().getWindowToken(), 0); return true; } return false; }
Example #6
Source File: EditPoiFragment.java From AndroidApp with Mozilla Public License 2.0 | 6 votes |
private void closeFragment() { ((MainActivity) getActivity()).showNavigationNoFab(); getActivity() .getSupportFragmentManager() .beginTransaction() .remove(EditPoiFragment.this) .commit(); //Close keyboard // Check if no view has focus: View view = getActivity().getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
Example #7
Source File: KeyboardUtils.java From mosby with Apache License 2.0 | 6 votes |
/** * Hides the soft keyboard from screen * * @param view Usually the EditText, but in dynamically layouts you should pass the layout * instead of the EditText * @return true, if keyboard has been hidden, otherwise false (i.e. the keyboard was not displayed * on the screen or no Softkeyboard because device has hardware keyboard) */ public static boolean hideKeyboard(View view) { if (view == null) { throw new NullPointerException("View is null!"); } try { InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm == null) { return false; } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } catch (Exception e) { return false; } return true; }
Example #8
Source File: UIUtils.java From MinMinGuard with GNU General Public License v3.0 | 6 votes |
static public void restartApp(Context context, String packageName) { ActivityManager am = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE); am.killBackgroundProcesses(packageName); Intent it = context.getPackageManager().getLaunchIntentForPackage(packageName); Activity a = (Activity) context; if (it != null) { if (a.getCurrentFocus() != null) { ((InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(a.getCurrentFocus().getWindowToken(), 0); } it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(it); } else { Toast.makeText(context, context.getString(R.string.msg_app_launch_fail), Toast.LENGTH_SHORT).show(); } }
Example #9
Source File: JmeAndroidSystem.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void showSoftKeyboard(final boolean show) { view.getHandler().post(new Runnable() { @Override public void run() { InputMethodManager manager = (InputMethodManager)view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (show) { manager.showSoftInput(view, 0); } else { manager.hideSoftInputFromWindow(view.getWindowToken(), 0); } } }); }
Example #10
Source File: BaseFragment.java From RxZhihuDaily with MIT License | 6 votes |
protected void showKeyboard() { Activity activity = getActivity(); if (activity == null) { return; } InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm == null) { return; } if (activity.getCurrentFocus() == null) { imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } else { imm.showSoftInput(activity.getCurrentFocus(), 0); } }
Example #11
Source File: ActivityUtils.java From memetastic with GNU General Public License v3.0 | 6 votes |
public ActivityUtils setSoftKeyboardVisibile(boolean visible, View... editView) { final Activity activity = _activity; if (activity != null) { final View v = (editView != null && editView.length > 0) ? (editView[0]) : (activity.getCurrentFocus() != null && activity.getCurrentFocus().getWindowToken() != null ? activity.getCurrentFocus() : null); final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); if (v != null && imm != null) { Runnable r = () -> { if (visible) { v.requestFocus(); imm.showSoftInput(v, InputMethodManager.SHOW_FORCED); } else { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } }; r.run(); for (int d : new int[]{100, 350}) { v.postDelayed(r, d); } } } return this; }
Example #12
Source File: StreamFragment.java From Klyph with MIT License | 6 votes |
private void postComment() { if (sendEditText.getText().toString().length() > 0) { Bundle params = new Bundle(); params.putString("message", sendEditText.getText().toString()); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(sendEditText.getWindowToken(), 0); sendRequest(params); } else { AlertUtil.showAlert(getActivity(), R.string.error, R.string.define_comment_before_publish, R.string.ok); } }
Example #13
Source File: InputMethodService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @MainThread @Override public void hideSoftInput(int flags, ResultReceiver resultReceiver) { if (DEBUG) Log.v(TAG, "hideSoftInput()"); boolean wasVis = isInputViewShown(); mShowInputFlags = 0; mShowInputRequested = false; doHideWindow(); clearInsetOfPreviousIme(); if (resultReceiver != null) { resultReceiver.send(wasVis != isInputViewShown() ? InputMethodManager.RESULT_HIDDEN : (wasVis ? InputMethodManager.RESULT_UNCHANGED_SHOWN : InputMethodManager.RESULT_UNCHANGED_HIDDEN), null); } }
Example #14
Source File: NewsContentActivity.java From xmpp with Apache License 2.0 | 6 votes |
/** * 初始化控件 */ private void initialView() { initViewPager(); DialogView.Initial(this, "正在评论......"); imm = (InputMethodManager) getSystemService(this.INPUT_METHOD_SERVICE); mPager = (ViewPager) findViewById(R.id.news_content_vPager); mPager.setOnPageChangeListener(this); et_pinglun = (EditText) findViewById(R.id.news_content_editText_pinglun); tv_pinglun = (TextView) findViewById(R.id.news_content_text_showpinglun); tv_uppinglun = (TextView) findViewById(R.id.news_content_text_enterpinglun); tv_pinglun.setText(content.getCpinglun() + "评"); back = (LinearLayout) findViewById(R.id.news_content_back); back.setOnClickListener(this); tv_pinglun.setOnClickListener(this); tv_uppinglun.setOnClickListener(this); mPager.setAdapter(mAdapter); mPager.setCurrentItem(0); }
Example #15
Source File: EaseBaseActivity.java From Social with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); //http://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/ //理论上应该放在launcher activity,放在基类中所有集成此库的app都可以避免此问题 if(!isTaskRoot()){ Intent intent = getIntent(); String action = intent.getAction(); if(intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN)){ finish(); return; } } inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); }
Example #16
Source File: SearchBox.java From NHentai-android with GNU General Public License v3.0 | 6 votes |
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); } 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); }
Example #17
Source File: HomeActivity.java From zap-android with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //NFC mNfcAdapter = NfcAdapter.getDefaultAdapter(this); mInputMethodManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); mHandler = new Handler(); mUnlockDialog = buildUnlockDialog(); // Register observer to detect if app goes to background ProcessLifecycleOwner.get().getLifecycle().addObserver(this); // Set wallet fragment as beginning fragment mFt = getSupportFragmentManager().beginTransaction(); mCurrentFragment = new WalletFragment(); mFt.replace(R.id.mainContent, mCurrentFragment); mFt.commit(); // Setup Listener BottomNavigationView navigation = findViewById(R.id.mainNavigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); }
Example #18
Source File: AndroidUtilities.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public static void hideKeyboard(View view) { if (view == null) { return; } try { InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (!imm.isActive()) { return; } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } catch (Exception e) { FileLog.e(e); } }
Example #19
Source File: HideUtil.java From KUtils with Apache License 2.0 | 5 votes |
/** * @param mActivity * @param token */ private void hideSoftInput(Activity mActivity, IBinder token) { if (token != null) { InputMethodManager im = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE); im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS); } }
Example #20
Source File: Util.java From floatingsearchview with Apache License 2.0 | 5 votes |
public static void showSoftKeyboard(final Context context, final EditText editText) { new Handler().postDelayed(new Runnable() { @Override public void run() { InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_FORCED); } }, 100); }
Example #21
Source File: InputMethodUtil.java From SimpleProject with MIT License | 5 votes |
/** * 显示键盘 * @param context * @param view */ public static void showKeyboard(Context context, View view) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.showSoftInput(view, 0); } }
Example #22
Source File: EaseChatPrimaryMenuBase.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
/** * hide keyboard */ public void hideKeyboard() { if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (activity.getCurrentFocus() != null) inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
Example #23
Source File: KeyBoardUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 关闭软键盘 * @param activity {@link Activity} * @return {@code true} success, {@code false} fail */ public static boolean closeKeyboard(final Activity activity) { if (activity != null) { try { InputMethodManager imm = AppUtils.getInputMethodManager(); imm.hideSoftInputFromWindow(activity.getWindow().peekDecorView().getWindowToken(), 0); return true; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "closeKeyboard"); } } return false; }
Example #24
Source File: AutoCompleteTextView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void buildImeCompletions() { final ListAdapter adapter = mAdapter; if (adapter != null) { InputMethodManager imm = InputMethodManager.peekInstance(); if (imm != null) { final int count = Math.min(adapter.getCount(), 20); CompletionInfo[] completions = new CompletionInfo[count]; int realCount = 0; for (int i = 0; i < count; i++) { if (adapter.isEnabled(i)) { Object item = adapter.getItem(i); long id = adapter.getItemId(i); completions[realCount] = new CompletionInfo(id, realCount, convertSelectionToString(item)); realCount++; } } if (realCount != count) { CompletionInfo[] tmp = new CompletionInfo[realCount]; System.arraycopy(completions, 0, tmp, 0, realCount); completions = tmp; } imm.displayCompletions(this, completions); } } }
Example #25
Source File: Utils.java From LoveTalkClient with Apache License 2.0 | 5 votes |
public static void hideSoftInputView(Activity activity) { if (activity.getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { InputMethodManager manager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); View currentFocus = activity.getCurrentFocus(); if (currentFocus != null) { manager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }
Example #26
Source File: MainActivity.java From quickstart-android with Apache License 2.0 | 5 votes |
private void hideKeyboard() { View view = this.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
Example #27
Source File: PlacePickerFragment.java From android-skeleton-project with MIT License | 5 votes |
@Override public void onAttach(Activity activity) { super.onAttach(activity); if (searchBox != null) { InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(searchBox, InputMethodManager.SHOW_IMPLICIT); } }
Example #28
Source File: LoginFragment.java From aws-device-farm-sample-app-for-android with Apache License 2.0 | 5 votes |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_login, container, false); ButterKnife.inject(this,view); USERNAME = getString(R.string.login_username); PASSWORD = getString(R.string.login_password); FAIL_MESSAGE = getString(R.string.login_fail_message); SUCCESS_MESSAGE = getString(R.string.login_success_message); ALT_BUTTON_FAIL_TITLE = getString(R.string.try_login_again_button_title); ALT_BUTTON_SUCCESS_TITLE = getString(R.string.logout_button_title); imm = (InputMethodManager)getActivity().getSystemService(getActivity().getApplicationContext().INPUT_METHOD_SERVICE); return view; }
Example #29
Source File: InputMethodUtils.java From FriendBook with GNU General Public License v3.0 | 5 votes |
public static boolean hideSoftInput(View view) { InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { return imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } else { return true; } }
Example #30
Source File: BaldInputMethodService.java From BaldPhone with Apache License 2.0 | 5 votes |
public void startVoiceListening() { final InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE); if (voiceExists(imeManager)) { final IBinder token = getWindow().getWindow().getAttributes().token; imeManager.setInputMethod(token, VOICE_RECOGNITION_IMS); } }