FileDocCategorySizeDatePackage
FindDialog.javaAPI DocAndroid 1.5 API7465Wed May 06 22:42:42 BST 2009com.android.browser

FindDialog

public class FindDialog extends android.app.Dialog implements android.text.TextWatcher

Fields Summary
private android.webkit.WebView
mWebView
private android.widget.TextView
mMatches
private BrowserActivity
mBrowserActivity
private android.view.View
mOk
private android.widget.EditText
mEditText
private android.view.View
mNextButton
private android.view.View
mPrevButton
private android.view.View
mMatchesView
private View.OnClickListener
mFindListener
private View.OnClickListener
mFindCancelListener
private View.OnClickListener
mFindPreviousListener
Constructors Summary
FindDialog(BrowserActivity context)

        super(context, R.style.FindDialogTheme);
        mBrowserActivity = context;
        setCanceledOnTouchOutside(true);
    
Methods Summary
public voidafterTextChanged(android.text.Editable s)

    
public voidbeforeTextChanged(java.lang.CharSequence s, int start, int count, int after)

    
private voiddisableButtons()

        mPrevButton.setEnabled(false);
        mNextButton.setEnabled(false);
        mPrevButton.setFocusable(false);
        mNextButton.setFocusable(false);
    
public voiddismiss()

        super.dismiss();
        mBrowserActivity.closeFind();
        mWebView.clearMatches();
    
public booleandispatchKeyEvent(android.view.KeyEvent event)

        int code = event.getKeyCode();
        boolean up = event.getAction() == KeyEvent.ACTION_UP;
        switch (code) {
            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_ENTER:
                if (!mEditText.hasFocus()) {
                    break;
                }
                if (up) {
                    findNext();
                }
                return true;
            default:
                break;
        }
        return super.dispatchKeyEvent(event);
    
private voidfindNext()

        if (mWebView == null) {
            throw new AssertionError("No WebView for FindDialog::findNext");
        }
        mWebView.findNext(true);
        hideSoftInput();
    
private voidhideSoftInput()


    /*
     * Remove the soft keyboard from the screen.
     */
       
        InputMethodManager imm = (InputMethodManager)
                mBrowserActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
    
voidonConfigurationChanged(android.content.res.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();
    
protected voidonCreate(android.os.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);
        mOk = button;
        
        mMatches = (TextView) findViewById(R.id.matches);
        mMatchesView = findViewById(R.id.matches_view);
        disableButtons();
        theWindow.setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    
public voidonTextChanged(java.lang.CharSequence s, int start, int before, int count)

        if (mWebView == null) {
            throw new AssertionError(
                    "No WebView for FindDialog::onTextChanged");
        }
        CharSequence find = mEditText.getText();
        if (0 == find.length()) {
            disableButtons();
            mWebView.clearMatches();
            mMatchesView.setVisibility(View.INVISIBLE);
        } else {
            mMatchesView.setVisibility(View.VISIBLE);
            int found = mWebView.findAll(find.toString());
            setMatchesFound(found);
            if (found < 2) {
                disableButtons();
                if (found == 0) {
                    setMatchesFound(0);
                }
            } else {
                mPrevButton.setFocusable(true);
                mNextButton.setFocusable(true);
                mPrevButton.setEnabled(true);
                mNextButton.setEnabled(true);
            }
        }
    
private voidsetMatchesFound(int found)

        String template = mBrowserActivity.getResources().
                getQuantityString(R.plurals.matches_found, found, found);

        mMatches.setText(template);
    
voidsetWebView(android.webkit.WebView webview)

        mWebView = webview;
    
public voidshow()

        super.show();
        mEditText.requestFocus();
        mEditText.setText("");
        Spannable span = (Spannable) mEditText.getText();
        span.setSpan(this, 0, span.length(), 
                     Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        setMatchesFound(0);
        disableButtons();