@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); finish(); break; case R.id.menu_enable_ori_comment: if (enableCommentOri.isChecked()) { enableCommentOri.setChecked(false); } else { enableCommentOri.setChecked(true); } break; case R.id.menu_enable_repost: if (enableRepost.isChecked()) { enableRepost.setChecked(false); } else { enableRepost.setChecked(true); } break; case R.id.menu_at: Intent intent = new Intent(WriteCommentActivity.this, AtUserActivity.class); intent.putExtra("token", token); startActivityForResult(intent, AT_USER); break; } return true; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { InputMethodManager imm = (InputMethodManager) AddCitiyActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { imm.hideSoftInputFromWindow( AddCitiyActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } // Insert City info MyCitiesForecastManager.requestMyCitiesForecastSummary( defaultHotCityList[position], new Callback<MyCitiesForecastSummaryResult, Error>() { @Override public void success(MyCitiesForecastSummaryResult result) { LogUtil.d(TAG, "requestMyForecastSummary success"); LogUtil.d(TAG, StringUtil.toJson(result)); finish(); } @Override public void failure(Error error) { LogUtil.d(TAG, "requestForecastSummary failure"); LogUtil.d(TAG, StringUtil.toJson(error)); } }); }
// check if soft keyboard is open public static void softKeyboardIsOpen(Solo solo) throws Exception { InputMethodManager imm = (InputMethodManager) solo.getCurrentActivity().getSystemService(Context.INPUT_METHOD_SERVICE); junit.framework.Assert.assertTrue("Keyboard is inactive.", imm.isActive()); }
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; switch (item.getItemId()) { case android.R.id.home: savaDraft(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); intent = new Intent(this, MainTimeLineActivity.class); intent.putExtra("account", getAccount()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); break; case R.id.menu_emoticon: EmotionsGridDialog dialog = new EmotionsGridDialog(); dialog.show(getFragmentManager(), ""); break; case R.id.menu_topic: String ori = content.getText().toString(); String topicTag = "##"; content.setText(ori + topicTag); content.setSelection(content.getText().toString().length() - 1); break; case R.id.menu_at: intent = new Intent(WriteWeiboActivity.this, AtUserActivity.class); intent.putExtra("token", token); startActivityForResult(intent, AT_USER); break; } return true; }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.home: InfoSearchActivity.this.finish(); break; case R.id.zjzx_zixun: intent = new Intent(this, InformationMainActivity.class); startActivity(intent); break; case R.id.info_search_button: if (searchEdittext.getText().toString().equals("")) { Toast.makeText(InfoSearchActivity.this, "搜索内容不能为空", Toast.LENGTH_LONG).show(); } else { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 } imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); refreshListData(); } break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.feedback); // TravelApplication.getInstance().addActivity(this); ActivityMange.getInstance().addActivity(this); contentEditText = (EditText) findViewById(R.id.feedback_content); contactEditText = (EditText) findViewById(R.id.feedback_contact); contactTipsTextView = (TextView) findViewById(R.id.feedback_contact_tips); ViewGroup feedbackGroup = (ViewGroup) findViewById(R.id.feedback_group); ImageButton submit = (ImageButton) findViewById(R.id.submit); submit.setOnClickListener(submitOnClickListener); feedbackGroup.setOnClickListener(feedbackGroupOnClickListener); InputMethodManager imm = (InputMethodManager) feedbackGroup.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow(feedbackGroup.getApplicationWindowToken(), 0); } token = TravelApplication.getInstance().getToken(); if (token != null && !token.equals("")) { contactEditText.setVisibility(View.GONE); contactTipsTextView.setVisibility(View.GONE); } }
// 隐藏虚拟键盘 public static void HideKeyboard(View v) { InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0); } }
/** * @Title: isInputMethodActive @Description: 输入法是否弹出 * * @param context * @param view * @return boolean */ public static boolean isInputMethodActive(Context context, View view) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { return imm.isActive(view); } return false; }
public boolean onTouchEvent(android.view.MotionEvent event) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager.isActive()) { inputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); } return true; }
public static boolean isKeyboardShowed(View view) { if (view == null) { return false; } InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); return inputManager.isActive(view); }
private void resetKeyboard() { Context context = AndroidPersistentContext.getInstance().getContext(); InputMethodManager imm = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE); if (imm.isActive()) { TeleNavDelegate.getInstance() .callAppNativeFeature(TeleNavDelegate.FEATURE_UPDATE_WINDOW_SOFT_INPUT_MODE, null); } }
/* * 关闭键盘 */ public static void closeKeyBoard(Context context) { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } }
/* * 隐藏键盘 */ public static void hideSolftInput(Context context, View v) { if (v == null) { return; } InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow(v.getWindowToken(), 0); } }
// 隐藏键盘 private void hintKb() { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 // imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, // InputMethodManager.HIDE_NOT_ALWAYS);// // 关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的 imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0); } }
// 隐藏软键盘 protected void hideSoftInputKeyboard() { InputMethodManager inputMethodManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); View focusView = getActivity().getCurrentFocus(); if (focusView != null) { IBinder binder = focusView.getWindowToken(); if (binder != null && inputMethodManager.isActive()) { inputMethodManager.hideSoftInputFromWindow(binder, 0); } } }
void updateInputState() { InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (mYearEnabled && inputMethodManager.isActive(mYearSpinnerInput)) { mYearSpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else if (mMonthEnabled && inputMethodManager.isActive(mMonthSpinnerInput)) { mMonthSpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else if (mDayEnabled && inputMethodManager.isActive(mDaySpinnerInput)) { mDaySpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else if (mHourEnabled && inputMethodManager.isActive(mHourSpinnerInput)) { mHourSpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else if (mMinuteEnabled && inputMethodManager.isActive(mMinuteSpinnerInput)) { mMinuteSpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } }
public static void hideKeyboard(View view) { if (view == null) { return; } InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (!imm.isActive()) { return; } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }
@Override public void onNothingSelected(AdapterView<?> parent) { InputMethodManager imm = (InputMethodManager) AddCitiyActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { imm.hideSoftInputFromWindow( AddCitiyActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
private void updateInputState() { // Make sure that if the user changes the value and the IME is active // for one of the inputs if this widget, the IME is closed. If the user // changed the value via the IME and there is a next input the IME will // be shown, otherwise the user chose another means of changing the // value and having the IME up makes no sense. Context context = getContext(); InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { if (inputMethodManager.isActive(mYearSpinnerInput)) { mYearSpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else if (inputMethodManager.isActive(mMonthSpinnerInput)) { mMonthSpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } else if (inputMethodManager.isActive(mDaySpinnerInput)) { mDaySpinnerInput.clearFocus(); inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0); } } }
/* * (non-Javadoc) * * @see com.aviary.android.feather.effects.AbstractEffectPanel#onDeactivate() */ @Override public void onDeactivate() { super.onDeactivate(); endEditView(topHv); endEditView(bottomHv); if (mImageView != null) { ((ImageViewDrawableOverlay) mImageView).setOnDrawableEventListener(null); ((ImageViewDrawableOverlay) mImageView).setOnLayoutListener(null); } if (editTopButton != null) editTopButton.setOnClickListener(null); if (editBottomButton != null) editBottomButton.setOnClickListener(null); if (clearButtonTop != null) clearButtonTop.setOnClickListener(null); if (clearButtonBottom != null) clearButtonBottom.setOnClickListener(null); if (mInputManager.isActive(editTopText)) mInputManager.hideSoftInputFromWindow(editTopText.getWindowToken(), 0); if (mInputManager.isActive(editBottomText)) mInputManager.hideSoftInputFromWindow(editBottomText.getWindowToken(), 0); }
@Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Insert City info. LogUtil.i(TAG, "Insert City info"); InputMethodManager imm = (InputMethodManager) AddCitiyActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { imm.hideSoftInputFromWindow( AddCitiyActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { /* 隐藏软键盘 */ InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager.isActive()) { inputMethodManager.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0); } String mKeyWord = et_search.getText().toString().trim(); if (!TextUtils.isEmpty(mKeyWord)) { if ("二手房".equals(mPosition.getText().toString().trim())) { newStartInterface(RentActivity.class, "two", mKeyWord); mListTwo.add(0, mKeyWord); for (int x = 0; x < mListTwo.size(); x++) { for (int y = x + 1; y < mListTwo.size(); y++) { if (mListTwo.get(x).equals(mListTwo.get(y))) { one = y; } } } if (one > -1) { mListTwo.remove(one); } setAdapterTwo(); } else { newStartInterface(RetalActivity.class, "one", mKeyWord); mListOne.add(0, mKeyWord); for (int x = 0; x < mListOne.size(); x++) { for (int y = x + 1; y < mListOne.size(); y++) { if (mListOne.get(x).equals(mListOne.get(y))) { record = y; } } } if (record > -1) { mListOne.remove(record); } setAdapterOne(); } } else { Toast.makeText(context, "没有关键字匹配", Toast.LENGTH_SHORT).show(); } return true; } return false; }
protected void hideGUIListMenu() { if (mGuiMenu != null && mGuiMenu.getVisibility() == View.VISIBLE) { mGuiMenu.setVisibility(View.GONE); mGuiMenu.startAnimation(mOutAnimation2Left); if (!mTabletVersion) { mGuiFooter.setVisibility(View.VISIBLE); mPager.setVisibility(View.VISIBLE); mPager.startAnimation(mInAnimationFromRight); } mMenuShown = false; InputMethodManager im = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (im != null && im.isActive()) { im.hideSoftInputFromWindow(mGuiMenu.getWindowToken(), 0); } } }
@Override protected void onRestart() { mAdapter.notifyDataSetChanged(); // 关闭软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // 得到InputMethodManager的实例 if (imm.isActive()) { // 如果开启 imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); // 关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的 } robotName = MyApplication.getString(HttpUtils.ROBOT_NIKE_NAME, "小黄鸭"); title.setText(robotName); str = "您还记得大明湖畔的" + robotName + "吗?就是我喽," + "人称江湖百晓生,熟知段子、新闻、天气、列车、菜谱、航班、百度百科,很高兴为您服务!"; mAdapter.changeFirstItem(str); super.onRestart(); }
/** * hideKeyboard * * @return */ private boolean hideKeyboard() { if (mIMM.isActive(mCreateRoom)) { mIMM.hideSoftInputFromWindow( this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); mIMM.restartInput(mCreateRoom); // mIMM.hideSoftInputFromWindow(mCreateRoom.getWindowToken(), 0); mCreateRoom.setVisibility(View.GONE); mRoomCancel.setVisibility(View.GONE); mGetRoom.setVisibility(View.VISIBLE); return true; } return false; }
/** * 选择获取图片方式 * * @param activity 所在Activity * @param hangView 挂载的View * @param takePicturePath 将图片保存到的位置 */ @Override public void selectGetImageWay( final Activity activity, View hangView, final String takePicturePath) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.hideSoftInputFromWindow(hangView.getWindowToken(), 0); } final SelectPicPopupWindow menuWindow = new SelectPicPopupWindow(activity); menuWindow.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { menuWindow.dismiss(); switch (v.getId()) { case R.id.btn_take_photo: // 跳转相机拍照 String sdStatus = Environment.getExternalStorageState(); if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { Utils.toastMessage( activity, context.getString(R.string.error_can_not_find_sdcard)); return; } Intent intentTakenPic = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // 指定调用相机拍照后的照片存储的路径 intentTakenPic.putExtra( MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(takePicturePath))); activity.startActivityForResult(intentTakenPic, ReqCode.CAMERA); break; case R.id.btn_pick_photo: Intent intentPickPic = new Intent(Intent.ACTION_PICK, null); intentPickPic.setDataAndType( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_CONTENT_TYPE); activity.startActivityForResult(intentPickPic, ReqCode.ALBUM); break; default: break; } } }); // show the choose window menuWindow.showAtLocation(hangView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); }
// displays either the system or the extended keyboard or non of them private void showKeyboard(boolean showSystemKeyboard, boolean showExtendedKeyboard) { // no matter what we are doing ... hide the zoom controls // TODO: this is not working correctly as hiding the keyboard issues a onScrollChange // notification showing the control again ... uiHandler.removeMessages(UIHandler.HIDE_ZOOMCONTROLS); if (zoomControls.getVisibility() == View.VISIBLE) zoomControls.hide(); InputMethodManager mgr; if (showSystemKeyboard) { // hide extended keyboard keyboardView.setVisibility(View.GONE); // show system keyboard mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (!mgr.isActive(sessionView)) Log.e(TAG, "Failed to show system keyboard: SessionView is not the active view!"); mgr.showSoftInput(sessionView, 0); // show modifiers keyboard modifiersKeyboardView.setVisibility(View.VISIBLE); } else if (showExtendedKeyboard) { // hide system keyboard mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(sessionView.getWindowToken(), 0); // show extended keyboard keyboardView.setKeyboard(specialkeysKeyboard); keyboardView.setVisibility(View.VISIBLE); modifiersKeyboardView.setVisibility(View.VISIBLE); } else { // hide both mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mgr.hideSoftInputFromWindow(sessionView.getWindowToken(), 0); keyboardView.setVisibility(View.GONE); modifiersKeyboardView.setVisibility(View.GONE); // clear any active key modifiers) keyboardMapper.clearlAllModifiers(); } sysKeyboardVisible = showSystemKeyboard; extKeyboardVisible = showExtendedKeyboard; }
@Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); if (itemId == android.R.id.home) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) { imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS); } finish(); } else if (itemId == R.id.menu_at) { Intent intent = AtUserActivity.atUserIntent(this, BeeboApplication.getInstance().getAccessTokenHack()); intent.putExtra(Constants.TOKEN, token); startActivityForResult(intent, AT_USER); } else if (itemId == R.id.menu_clear) { clearContentMenu(); } return true; }
@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); } } Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, TAKE_PICTURE); return super.onCreateView(inflater, container, savedInstanceState); }
/** * End edit text. * * @param view the view */ private void endEditText(final DrawableHighlightView view) { mLogger.info("endEditText", view); mEditTextWatcher.view = null; EditText editText = null; if (view == topHv) editText = editTopText; else if (view == bottomHv) editText = editBottomText; if (editText != null) { editText.removeTextChangedListener(mEditTextWatcher); if (mInputManager.isActive(editText)) { mInputManager.hideSoftInputFromWindow(editText.getWindowToken(), 0); } editText.clearFocus(); } // this will send the focus to the bottom panel // but also creating a bad visual effect // mOptionView.requestFocus(); }