Java Code Examples for android.view.inputmethod.InputMethodManager#toggleSoftInput()

The following examples show how to use android.view.inputmethod.InputMethodManager#toggleSoftInput() . 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: AbstractWriteActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (smiley.isShown()) {
        removeViewWithAnim(smiley);
    } else if (!TextUtils.isEmpty(et.getText().toString()) && canShowSaveDraftDialog()) {
        SaveDraftDialog dialog = new SaveDraftDialog();
        dialog.show(getFragmentManager(), "");
    } else {

        if (BeeboApplication.getInstance().getAccountBean().equals(getCurrentAccountBean())) {
            super.onBackPressed();
        } else {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm.isActive()) {
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
            }
            Intent intent = MainTimeLineActivity.newIntent(getCurrentAccountBean());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }

    }
}
 
Example 2
Source File: SearchActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    simpleSearchView.showSearch(false);
    simpleSearchView.getSearchEditText().requestFocus();

    if (query != null) {
        simpleSearchView.getSearchEditText().setText(query);
        simpleSearchView.getSearchEditText().setSelection(query.length());
        query = null;
    }

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
}
 
Example 3
Source File: TFragment.java    From NIM_Android_UIKit with MIT License 6 votes vote down vote up
protected void showKeyboard(boolean isShow) {
    Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return;
    }

    if (isShow) {
        if (activity.getCurrentFocus() == null) {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        } else {
            imm.showSoftInput(activity.getCurrentFocus(), 0);
        }
    } else {
        if (activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }

    }
}
 
Example 4
Source File: HiddenEditText.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
  boolean focus = super.requestFocus(direction, previouslyFocusedRect);

  if (currentTextEntity != null && focus) {
    currentTextEntity.setFocused(true);
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
    if (!imm.isAcceptingText()) {
      imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
  }

  return focus;
}
 
Example 5
Source File: EditPostActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    ((Infinity) getApplication()).getAppComponent().inject(this);

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_edit_post);

    ButterKnife.bind(this);

    EventBus.getDefault().register(this);

    applyCustomTheme();

    if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
        Slidr.attach(this);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
        addOnOffsetChangedListener(appBarLayout);
    }

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mFullName = getIntent().getStringExtra(EXTRA_FULLNAME);
    mAccessToken = getIntent().getStringExtra(EXTRA_ACCESS_TOKEN);
    titleTextView.setText(getIntent().getStringExtra(EXTRA_TITLE));
    mPostContent = getIntent().getStringExtra(EXTRA_CONTENT);
    contentEditText.setText(mPostContent);

    contentEditText.requestFocus();
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm != null) {
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    }
}
 
Example 6
Source File: NetworkSettingsActivity.java    From bitseal with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If the soft keyboard is open, this method will close it. Currently only
 * works for API 16 and above. 
 */
private void closeKeyboardIfOpen()
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
		final View activityRootView = getWindow().getDecorView().getRootView();	
		final OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener()
		{
			@Override
			@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
			public void onGlobalLayout() 
			{
			    Rect rect = new Rect();
			    // rect will be populated with the coordinates of your view that area still visible.
			    activityRootView.getWindowVisibleDisplayFrame(rect);

			    int heightDiff = activityRootView.getRootView().getHeight() - (rect.bottom - rect.top);
			    if (heightDiff > 100)
			    {
			    	// If the difference is more than 100 pixels, it's probably caused by the soft keyboard being open. Now we want to close it.
					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); // Toggle the soft keyboard. 
			    }
			    
			    // Now we have to remove the OnGlobalLayoutListener, otherwise we will experience errors
			    activityRootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
			}
		};
		activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
	}
}
 
Example 7
Source File: DisplayUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Toggle keyboard If the keyboard is visible,then hidden it,if it's
 * invisible,then show it
 *
 * @param context 上下文
 */
public static void toggleKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive()) {
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
Example 8
Source File: SecurityActivity.java    From bitseal with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If the soft keyboard is open, this method will close it. Currently only
 * works for API 16 and above. 
 */
private void closeKeyboardIfOpen()
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
		final View activityRootView = getWindow().getDecorView().getRootView();	
		final OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener()
		{
			@Override
			@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
			public void onGlobalLayout() 
			{
			    Rect rect = new Rect();
			    // rect will be populated with the coordinates of your view that area still visible.
			    activityRootView.getWindowVisibleDisplayFrame(rect);

			    int heightDiff = activityRootView.getRootView().getHeight() - (rect.bottom - rect.top);
			    if (heightDiff > 100)
			    {
			    	// If the difference is more than 100 pixels, it's probably caused by the soft keyboard being open. Now we want to close it.
					InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
					imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); // Toggle the soft keyboard. 
			    }
			    
			    // Now we have to remove the OnGlobalLayoutListener, otherwise we will experience errors
			    activityRootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
			}
		};
		activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
	}
}
 
Example 9
Source File: UIView.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void showKeyboard(boolean isShow) {
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (isShow) {
        if (getCurrentFocus() == null) {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        } else {
            imm.showSoftInput(getCurrentFocus(), 0);
        }
    } else {
        if (getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
}
 
Example 10
Source File: KeyBoardUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 打开软键盘
 * @param editText {@link EditText}
 * @return {@code true} success, {@code false} fail
 */
public static boolean openKeyboard(final EditText editText) {
    if (editText != null) {
        try {
            InputMethodManager imm = AppUtils.getInputMethodManager();
            imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
            return true;
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "openKeyboard");
        }
    }
    return false;
}
 
Example 11
Source File: SearchView.java    From CustomSearchView with Apache License 2.0 5 votes vote down vote up
/**
 * 通知监听者 进行搜索操作
 * @param text
 */
private void notifyStartSearching(String text){
    if (mListener != null) {
        mListener.onSearch(etInput.getText().toString());
    }
    //隐藏软键盘
    InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
Example 12
Source File: CommonUtil.java    From Yuan-SxMusic with Apache License 2.0 5 votes vote down vote up
/**
 * EditText获取焦点并显示软键盘
 */
//弹出软键盘
public static void showKeyboard(EditText editText, Context context) {
    //其中editText为dialog中的输入框的 EditText
    if (editText != null) {
        //设置可获得焦点
        editText.setFocusable(true);
        editText.setFocusableInTouchMode(true);
        //请求获得焦点
        editText.requestFocus();
        //调用系统输入法
        InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.toggleSoftInput(0,InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
Example 13
Source File: KeyboardUtils.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
/**
 * 切换键盘显示与否状态
 */
public static void toggleSoftInput(Context context, EditText edit) {
    edit.setFocusable(true);
    edit.setFocusableInTouchMode(true);
    edit.requestFocus();
    InputMethodManager inputManager = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
 
Example 14
Source File: KeyBoardUtils.java    From zone-sdk with MIT License 4 votes vote down vote up
/**
 * 如果输入法已经显示,那么就隐藏它;如果输入法现在没显示,那么就显示它
 */
public static void toggle(Context context) {
	InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
	imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
Example 15
Source File: KeyboardUtils.java    From CoolChat with Apache License 2.0 4 votes vote down vote up
/**
 * 开关输入法
 *
 * @param currentFocusView 当前焦点view
 */
public static void toggleSoftInput(View currentFocusView) {
    InputMethodManager imm = (InputMethodManager) currentFocusView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(currentFocusView, InputMethodManager.RESULT_SHOWN);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
 
Example 16
Source File: InputMethodUtils.java    From android-common with Apache License 2.0 4 votes vote down vote up
public static void toggleSoftInput(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
 
Example 17
Source File: KeyboardUtils.java    From android-mvp-interactor-architecture with Apache License 2.0 4 votes vote down vote up
public static void toggleSoftInput(Context context) {
    InputMethodManager imm = (InputMethodManager) context
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
 
Example 18
Source File: ViewTaskActivity.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void hideKeyboard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    if (imm.isActive() && imm.isAcceptingText()) {
        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    }
}
 
Example 19
Source File: BaseUiHelper.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
public static void toggleSoftInput(Context context) {
    InputMethodManager inputmanger = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputmanger != null) {
        inputmanger.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS );
    }
}
 
Example 20
Source File: DeviceUtil.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * 控制键盘显隐,如果输入法在窗口上已经显示,则隐藏,反之则显示
 *
 * @param context
 */
public static void toggleInputKeyboard(Context context) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}