FindActionModeCallback.java revision 7014b12873068f109f58b9d0ad4116fd8d4bf22f
1fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins/*
2fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Copyright (C) 2010 The Android Open Source Project
3fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins *
4fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Licensed under the Apache License, Version 2.0 (the "License");
5fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * you may not use this file except in compliance with the License.
6fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * You may obtain a copy of the License at
7fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins *
8fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins *      http://www.apache.org/licenses/LICENSE-2.0
9fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins *
10fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Unless required by applicable law or agreed to in writing, software
11fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * distributed under the License is distributed on an "AS IS" BASIS,
12fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * See the License for the specific language governing permissions and
14fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * limitations under the License.
15fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */
16fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
17fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginspackage android.webkit;
18fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
19fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.content.Context;
20fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.content.res.Resources;
21fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Editable;
22fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Selection;
23fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Spannable;
24fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.TextWatcher;
25fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.webkit.WebView;
26fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.widget.EditText;
27fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.widget.TextView;
28fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.ActionMode;
29fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.LayoutInflater;
30fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.Menu;
31fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.MenuInflater;
32fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.MenuItem;
33fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.View;
34fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.inputmethod.InputMethodManager;
35fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
36fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsclass FindActionModeCallback implements ActionMode.Callback, TextWatcher,
377014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        View.OnLongClickListener, View.OnClickListener {
38fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private View mCustomView;
39fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private EditText mEditText;
40fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private TextView mMatches;
41fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private WebView mWebView;
42fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private InputMethodManager mInput;
43fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private Resources mResources;
44fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private boolean mMatchesFound;
45fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private int mNumberOfMatches;
4605919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins    private ActionMode mActionMode;
47fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
48fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    FindActionModeCallback(Context context) {
49fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mCustomView = LayoutInflater.from(context).inflate(
50fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                com.android.internal.R.layout.webview_find, null);
51fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mEditText = (EditText) mCustomView.findViewById(
52fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                com.android.internal.R.id.edit);
53fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // Override long click so that select ActionMode is not opened, which
54fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // would exit find ActionMode.
55fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mEditText.setOnLongClickListener(this);
567014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        mEditText.setOnClickListener(this);
57fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        setText("");
58fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mMatches = (TextView) mCustomView.findViewById(
59fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                com.android.internal.R.id.matches);
60fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mInput = (InputMethodManager)
61fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                context.getSystemService(Context.INPUT_METHOD_SERVICE);
62fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mResources = context.getResources();
63fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
64fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
6505919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins    void finish() {
6605919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins        mActionMode.finish();
6705919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins    }
6805919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins
69fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    /*
70fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * Place text in the text field so it can be searched for.  Need to press
71fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * the find next or find previous button to find all of the matches.
72fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     */
73fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    void setText(String text) {
74fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mEditText.setText(text);
75fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        Spannable span = (Spannable) mEditText.getText();
76fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        int length = span.length();
77fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // Ideally, we would like to set the selection to the whole field,
78fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // but this brings up the Text selection CAB, which dismisses this
79fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // one.
80fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        Selection.setSelection(span, length, length);
81fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // Necessary each time we set the text, so that this will watch
82fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // changes to it.
83fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
84fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mMatchesFound = false;
85fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
86fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
87fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    /*
88fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * Set the WebView to search.  Must be non null, and set before calling
89fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * startActionMode.
90fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     */
91fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    void setWebView(WebView webView) {
92fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        if (null == webView) {
93fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            throw new AssertionError("WebView supplied to "
94fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                    + "FindActionModeCallback cannot be null");
95fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        }
96fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mWebView = webView;
97fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
98fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
99fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    /*
100fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * Move the highlight to the next match.
101fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * @param next If true, find the next match further down in the document.
102fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     *             If false, find the previous match, up in the document.
103fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     */
104fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private void findNext(boolean next) {
105fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        if (mWebView == null) {
106fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            throw new AssertionError(
107fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                    "No WebView for FindActionModeCallback::findNext");
108fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        }
1097014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        if (!mMatchesFound) {
1107014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins            findAll();
1117014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins            return;
1127014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        }
1137014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        if (0 == mNumberOfMatches) {
1147014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins            // There are no matches, so moving to the next match will not do
1157014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins            // anything.
1167014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins            return;
1177014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        }
118fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mWebView.findNext(next);
1197014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        updateMatchesString();
120fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
121fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
122fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    /*
123fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * Highlight all the instances of the string from mEditText in mWebView.
124fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     */
125fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    void findAll() {
126fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        if (mWebView == null) {
127fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            throw new AssertionError(
128fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                    "No WebView for FindActionModeCallback::findAll");
129fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        }
130fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        CharSequence find = mEditText.getText();
131fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        if (0 == find.length()) {
132fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            mWebView.clearMatches();
133fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            mMatches.setVisibility(View.GONE);
134fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            mMatchesFound = false;
135fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        } else {
136fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            mMatchesFound = true;
137fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            mMatches.setVisibility(View.VISIBLE);
138fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            mNumberOfMatches = mWebView.findAll(find.toString());
139fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            if (0 == mNumberOfMatches) {
140fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                mMatches.setText(mResources.getString(
141fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                        com.android.internal.R.string.no_matches));
142fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            } else {
143fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                updateMatchesString();
144fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            }
145fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        }
146fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
147fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
148571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins    public void showSoftInput() {
14918cf9a7828f0b50daf967e22f0c5308b68d2919aLeon Scroggins        mInput.startGettingWindowFocus(mEditText.getRootView());
15018cf9a7828f0b50daf967e22f0c5308b68d2919aLeon Scroggins        mInput.focusIn(mEditText);
151571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins        mInput.showSoftInput(mEditText, 0);
152571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins    }
153571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins
154fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    /*
155fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * Update the string which tells the user how many matches were found, and
156fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     * which match is currently highlighted.
15773254be0ddfc075521a63a069c6c30d200dca557Leon Scroggins     * Not to be called when mNumberOfMatches is 0.
158fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins     */
159fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    private void updateMatchesString() {
160fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        String template = mResources.getQuantityString(
161fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                com.android.internal.R.plurals.matches_found, mNumberOfMatches,
162fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                mWebView.findIndex() + 1, mNumberOfMatches);
163fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
164fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mMatches.setText(template);
165fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
166fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
167fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    // OnLongClickListener implementation
168fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
169fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
170fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public boolean onLongClick(View v) { return true; }
171fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
1727014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins    // OnClickListener implementation
1737014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins
1747014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins    @Override
1757014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins    public void onClick(View v) {
1767014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins        findNext(true);
1777014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins    }
1787014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins
179fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    // ActionMode.Callback implementation
180fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
181fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
182fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
183fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mode.setCustomView(mCustomView);
184fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_find,
185fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                menu);
18605919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins        mActionMode = mode;
187fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        Editable edit = mEditText.getText();
188fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        Selection.setSelection(edit, edit.length());
189fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mMatches.setVisibility(View.GONE);
190fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mMatchesFound = false;
191fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mMatches.setText("0");
192fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mEditText.requestFocus();
193fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        return true;
194fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
195fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
196fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
197fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public void onDestroyActionMode(ActionMode mode) {
198fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mWebView.notifyFindDialogDismissed();
199fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
200fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
201fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
202fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
203fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
204fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        return false;
205fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
206fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
207fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
208fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
209261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins        if (mWebView == null) {
210261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins            throw new AssertionError(
211261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins                    "No WebView for FindActionModeCallback::onActionItemClicked");
212261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins        }
213261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins        mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
214fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        switch(item.getItemId()) {
215fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            case com.android.internal.R.id.find_prev:
216fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                findNext(false);
217fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                break;
218fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            case com.android.internal.R.id.find_next:
219fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                findNext(true);
220fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                break;
221fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins            default:
222fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                return false;
223fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        }
224fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        return true;
225fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
226fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
227fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    // TextWatcher implementation
228fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
229fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
230fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public void beforeTextChanged(CharSequence s,
231fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                                  int start,
232fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                                  int count,
233fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                                  int after) {
234fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // Does nothing.  Needed to implement TextWatcher.
235fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
236fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
237fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
238fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public void onTextChanged(CharSequence s,
239fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                              int start,
240fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                              int before,
241fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins                              int count) {
242fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        findAll();
243fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
244fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
245fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    @Override
246fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    public void afterTextChanged(Editable s) {
247fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins        // Does nothing.  Needed to implement TextWatcher.
248fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins    }
249fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins
250fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins}
251