Code example for EditText

Methods: getWindowToken, hasFocus

0
     * Remove the soft keyboard from the screen. 
     */ 
    private void hideSoftInput() { 
        InputMethodManager imm = (InputMethodManager)
                mBrowserActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    } 
 
    private void disableButtons() { 
        mPrevButton.setEnabled(false);
        mNextButton.setEnabled(false);
        mPrevButton.setFocusable(false);
        mNextButton.setFocusable(false);
    } 
 
    /* package */ void setWebView(WebView webview) {
        mWebView = webview;
    } 
 
    /* package */ FindDialog(BrowserActivity context) {
        super(context, R.style.FindDialogTheme);
        mBrowserActivity = context;
        setCanceledOnTouchOutside(true);
    } 
 
    /* package */ void onConfigurationChanged(Configuration newConfig) {
        // FIXME: Would like to call mWebView.findAll again, so that the 
        // matches would refresh, but the new picture has not yet been 
        // created, so it is too soon. 
        mEditText.getText().clear();
    } 
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        Window theWindow = getWindow();
        theWindow.setGravity(Gravity.BOTTOM|Gravity.FILL_HORIZONTAL);
 
        setContentView(R.layout.browser_find);
 
        theWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
 
        mEditText = (EditText) findViewById(R.id.edit);
         
        View button = findViewById(R.id.next);
        button.setOnClickListener(mFindListener);
        mNextButton = button;
         
        button = findViewById(R.id.previous);
        button.setOnClickListener(mFindPreviousListener);
        mPrevButton = button;
         
        button = findViewById(R.id.done);
        button.setOnClickListener(mFindCancelListener);
         
        mMatches = (TextView) findViewById(R.id.matches);
        mMatchesView = findViewById(R.id.matches_view);
        disableButtons(); 
        theWindow.setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    } 
     
    public void dismiss() { 
        super.dismiss(); 
        mBrowserActivity.closeFind();
        mWebView.clearMatches();
    } 
 
    @Override 
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
                && event.getAction() == KeyEvent.ACTION_UP
                && mEditText.hasFocus()) {
            findNext(); 
            return true; 
        } 
        return super.dispatchKeyEvent(event);
    }