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

The following examples show how to use android.view.inputmethod.InputMethodManager#hideSoftInputFromWindow() . 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 reacteu-app with MIT License 6 votes vote down vote up
/**
 * 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: VenvyKeyboardMapper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 6 votes vote down vote up
public LuaValue hideKeyboard(U target, Varargs varargs) {
    View view = target.getView();
    if (view == null) {
        return this;
    }
    Context context = view.getContext();
    if (context instanceof Activity) {
        View v = ((Activity) context).getCurrentFocus();
        if (v != null) {
            IBinder token = v.getWindowToken();
            if (token != null) {
                InputMethodManager im = (InputMethodManager) context.getSystemService
                        (Context.INPUT_METHOD_SERVICE);
                im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    }
    return this;
}
 
Example 3
Source File: KeyboardUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Hide the soft input.
 *
 * @param view The view.
 */
public static void hideSoftInput(@NonNull final View view) {
    InputMethodManager imm =
            (InputMethodManager) Utils.getApp().getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) return;
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
 
Example 4
Source File: DateWidget.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setFocus(Context context) {
    // Hide the soft keyboard if it's showing.
    InputMethodManager inputManager =
            (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(this.getWindowToken(), 0);
}
 
Example 5
Source File: KeyBoardUtil.java    From FriendCircle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 隐藏软键盘
 */
public static void close(View view) {
    try {
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 6
Source File: Utils.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used to hide a keyboard after a user has
 * finished typing the url.
 */
public static void hideKeyboard(Activity activity,
                                IBinder windowToken) {
    InputMethodManager mgr =
        (InputMethodManager) activity.getSystemService
        (Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(windowToken, 0);
}
 
Example 7
Source File: MakeCommentDialog.java    From Broadsheet.ie-Android with MIT License 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (!validate()) {
        return;
    }

    SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString("email", email.getText().toString());
    editor.putString("commenterName", commenterName.getText().toString());
    editor.putString("commenterUrl", commenterUrl.getText().toString());
    editor.commit();

    MakeCommentRequest makeCommentRequest = new MakeCommentRequest();
    makeCommentRequest.setPostId(postId);
    makeCommentRequest.setEmail(email.getText().toString());
    makeCommentRequest.setCommentUrl(commenterUrl.getText().toString());
    makeCommentRequest.setCommentName(commenterName.getText().toString());
    makeCommentRequest.setCommentBody(commentBody.getText().toString());
    makeCommentRequest.setCommentId(commentId);

    v.setEnabled(false);

    email.clearFocus();
    commenterName.clearFocus();
    commenterUrl.clearFocus();
    commentBody.clearFocus();

    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(commentBody.getWindowToken(), 0);

    ((BaseFragmentActivity) getActivity()).onPreExecute(getResources().getString(R.string.posting_comment));

    spiceManager.execute(makeCommentRequest, new MakeCommentListener());
}
 
Example 8
Source File: SoftKeyboardUtil.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Hides the soft keyboard.
 *
 * @param activity The reference of the activity displaying the keyboard.
 */
public static void hide(@NonNull final Activity activity) {
    final InputMethodManager iManager = (InputMethodManager) activity.
            getSystemService(Context.INPUT_METHOD_SERVICE);
    final View view = activity.getCurrentFocus();
    if (view != null && iManager != null) {
        iManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
 
Example 9
Source File: Utils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 关闭软键盘
 */
public static void closeSoftKeyboard(Context context) {
    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null && ((Activity) context).getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus()
                .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
Example 10
Source File: CordovaWebView.java    From IoTgo_Android_App with MIT License 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if(boundKeyCodes.contains(keyCode))
    {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');");
                return true;
        }
        // If volumeup key
        else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');");
                return true;
        }
        else
        {
            return super.onKeyDown(keyCode, event);
        }
    }
    else if(keyCode == KeyEvent.KEYCODE_BACK)
    {
        return !(this.startOfHistory()) || isButtonPlumbedToJs(KeyEvent.KEYCODE_BACK);
    }
    else if(keyCode == KeyEvent.KEYCODE_MENU)
    {
        //How did we get here?  Is there a childView?
        View childView = this.getFocusedChild();
        if(childView != null)
        {
            //Make sure we close the keyboard if it's present
            InputMethodManager imm = (InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(childView.getWindowToken(), 0);
            cordova.getActivity().openOptionsMenu();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 11
Source File: EditTextSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnTrigger(ClearFocusEvent.class)
static void clearFocus(
    ComponentContext c, @State AtomicReference<EditTextWithEventHandlers> mountedView) {
  EditTextWithEventHandlers eventHandler = mountedView.get();
  if (eventHandler != null) {
    eventHandler.clearFocus();
    InputMethodManager imm =
        (InputMethodManager) c.getAndroidContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(eventHandler.getWindowToken(), 0);
  }
}
 
Example 12
Source File: AddTaskFragment.java    From mvp-helpers with MIT License 5 votes vote down vote up
public void onFocusChange(View view, boolean isFocused) {
    switch (view.getId()) {
        case R.id.startDateEditText:
        case R.id.dueDateEditText:

            if (isFocused) {
                final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }

            break;
    }
}
 
Example 13
Source File: GroupInfoFragment.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    InputMethodManager inputMethodManager =
            (InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE);
    if (getActivity().getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(
                getActivity().getCurrentFocus().getWindowToken(), 0);
    }
}
 
Example 14
Source File: EditTextView.java    From EditTextView with MIT License 4 votes vote down vote up
private void hideKeyboard(){
    if(ettEditText != null && !isInEditMode()) {
        InputMethodManager imm = (InputMethodManager) getContext().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(ettEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
}
 
Example 15
Source File: EditorView.java    From Nimbus with GNU General Public License v3.0 4 votes vote down vote up
public void hideKeyBoard() {
    InputMethodManager imm = (InputMethodManager) getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(lastEditText.getWindowToken(), 0);
}
 
Example 16
Source File: EmergencyFragment.java    From Saude-no-Mapa with MIT License 4 votes vote down vote up
@Override
public void dismissKeyboard() {
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
}
 
Example 17
Source File: ViewHelper.java    From WanAndroid with GNU General Public License v3.0 4 votes vote down vote up
public static void hideKeyboard(@NonNull View view) {
    InputMethodManager inputManager = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
 
Example 18
Source File: BaseRegistrationFragment.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
protected static void hideKeyboard(@NonNull Context context, @NonNull View view) {
  InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
 
Example 19
Source File: BaseInnerPage.java    From Paginize with MIT License 4 votes vote down vote up
@Override
public void onDestroy() {
  InputMethodManager imm = (InputMethodManager) getContext()
      .getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
}
 
Example 20
Source File: ParentFragmentCleanArch.java    From CleanArchitecturePlugin with Apache License 2.0 4 votes vote down vote up
public void hideKeyboard(Context context, IBinder windowToken) {
    InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(windowToken, 0);
}