Example usage for android.view View getWindowToken

List of usage examples for android.view View getWindowToken

Introduction

In this page you can find the example usage for android.view View getWindowToken.

Prototype

public IBinder getWindowToken() 

Source Link

Document

Retrieve a unique token identifying the window this view is attached to.

Usage

From source file:com.duy.pascal.ui.editor.BaseEditorActivity.java

protected void closeKeyBoard() {
    // Central system API to the overall input method framework (IMF) architecture
    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    View currentFocus = getCurrentFocus();
    if (currentFocus != null) {
        // Base interface for a remotable object
        IBinder windowToken = currentFocus.getWindowToken();

        // Hide type
        int hideType = InputMethodManager.HIDE_NOT_ALWAYS;

        // Hide the KeyBoard
        if (inputManager != null) {
            inputManager.hideSoftInputFromWindow(windowToken, hideType);
        }//from   www  . j  a v  a2  s  .  co  m
    }
}

From source file:com.taobao.weex.extend.module.actionsheet.WXActionSheet.java

@Nullable
@Override/*from w  w  w .  j  a v a  2s .  c  o m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable 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);
        }
    }

    actionSheetView = createRoot();
    decor = (ViewGroup) getActivity().getWindow().getDecorView();

    attachItems();

    decor.addView(actionSheetView);

    backgroundLayer.startAnimation(createAlphaInAnimation());
    sheetContainer.startAnimation(createTranslationInAnimation());
    return super.onCreateView(inflater, container, savedInstanceState);
}

From source file:com.darly.im.ui.CCPActivityBase.java

/**
 * hide input method./*from  www  .  ja  va 2  s  . c om*/
 */
public void hideSoftKeyboard(View view) {
    if (view == null) {
        return;
    }

    InputMethodManager inputMethodManager = (InputMethodManager) mActionBarActivity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        IBinder localIBinder = view.getWindowToken();
        if (localIBinder != null)
            inputMethodManager.hideSoftInputFromWindow(localIBinder, 0);
    }
}

From source file:com.ericsun.duom.Framework.Activity.BaseActivity.java

protected void closeKeyBoard() {
    View view = findViewById(rootViewId);
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) ct.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*  w  w w .jav a 2 s . c  o  m*/
}

From source file:jp.mau.twappremover.MainActivity.java

/** ?? */
private void setButton() {
    Button btn = (Button) findViewById(R.id.activity_main_btn_submit);
    btn.setOnClickListener(new OnClickListener() {
        @Override//from w  w w  .  j a  v  a  2  s.  c  o  m
        public void onClick(View v) {
            reset();
            // ???
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            if (_id.getText().length() < 1 || _pass.getText().length() < 1) {
                // ???????
            } else {
                //                ?
                loginTask();
            }
        }
    });
}

From source file:com.mikhaellopez.saveinsta.activity.MainActivity.java

private void closeKeyboard() {
    // Check if no view has focus:
    View view = getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*  ww w. j a va2  s .c o  m*/
}

From source file:org.cvasilak.jboss.mobile.app.fragments.AttributeEditorFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.save) {

        View v = getActivity().getCurrentFocus();

        // handle the case where an editext has focus
        // and user clicks 'Save'.
        // update local model and hide the soft keyboard
        if (v != null && (v instanceof EditText)) {
            EditText text = (EditText) v;

            onValueChanged(text.getTag().toString(), text.getText().toString());

            // hide the keyboard now
            InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }/*from  w ww .  j  av  a2s. c o m*/

        save();

        return (true);
    }

    return (super.onOptionsItemSelected(item));
}

From source file:org.deviceconnect.android.deviceplugin.hue.activity.fragment.HueFragment04.java

/**
 * Edit serial.//from   w ww.  j  a  v  a 2s.c  om
 */
private void editSerial() {
    final EditText editText = new EditText(getActivity());
    editText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                InputMethodManager inputMethodManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.frag04_serial_number_title)
            .setMessage(R.string.frag04_serial_number_message).setView(editText)
            .setPositiveButton(R.string.frag04_serial_ok, new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int whichButton) {
                    String serial = editText.getText().toString();
                    searchLightManually(serial);
                }
            }).setNegativeButton(R.string.frag04_serial_cancel, new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int whichButton) {
                }
            }).show();
    final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    positiveButton.setEnabled(false);

    // Input limit of the serial number
    InputFilter inputFilter = new InputFilter() {
        @Override
        public CharSequence filter(final CharSequence source, final int start, final int end,
                final Spanned dest, final int dstart, final int dend) {
            if (source.toString().matches("[0-9a-fA-F]+")) {
                return source;
            } else {
                return "";
            }
        }
    };
    InputFilter[] filters = new InputFilter[] { inputFilter, new InputFilter.LengthFilter(6) };
    editText.setFilters(filters);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) {
        }

        @Override
        public void onTextChanged(final CharSequence s, final int start, final int before, final int count) {
            positiveButton.setEnabled(editText.length() == 6);
        }

        @Override
        public void afterTextChanged(final Editable s) {
        }
    });
    editText.setHint(R.string.frag04_serial_number_hint);
}

From source file:com.ruesga.rview.wizard.WizardActivity.java

private void closeKeyboardIfNeeded() {
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from  w w  w .  j a  va2 s . c o  m
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogItemEditFragment.java

private void showAttachments() {
    // Hide keyboard
    View view = getActivity().getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }//  ww  w. ja  v  a2  s  . c  o m
        // If we don't delay this, bottom sheet might position itself over the
        // former keyboard position, which is then gone
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
            }
        }, 200);
    } else {
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
    }
}