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; 21d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reckimport android.graphics.Point; 22d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reckimport android.graphics.Rect; 23fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Editable; 24fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Selection; 25fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Spannable; 26fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.TextWatcher; 27fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.ActionMode; 28fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.LayoutInflater; 29fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.Menu; 30fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.MenuItem; 31fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.View; 32fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.inputmethod.InputMethodManager; 33fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reckimport android.widget.EditText; 34fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reckimport android.widget.TextView; 35fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 36fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsclass FindActionModeCallback implements ActionMode.Callback, TextWatcher, 377e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount View.OnClickListener { 38fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private View mCustomView; 39fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private EditText mEditText; 40fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private TextView mMatches; 413c90952036a5ff7ddb2946c643f1a0bf1c31d53aJonathan Dixon private WebViewClassic mWebView; 42fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private InputMethodManager mInput; 43fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private Resources mResources; 44fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private boolean mMatchesFound; 45fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private int mNumberOfMatches; 4647d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease private int mActiveMatchIndex; 4705919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins private ActionMode mActionMode; 48fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 49fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins FindActionModeCallback(Context context) { 50fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mCustomView = LayoutInflater.from(context).inflate( 51fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.layout.webview_find, null); 52fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mEditText = (EditText) mCustomView.findViewById( 53fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.id.edit); 547e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount mEditText.setCustomSelectionActionModeCallback(new NoAction()); 557014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins mEditText.setOnClickListener(this); 56fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins setText(""); 57fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches = (TextView) mCustomView.findViewById( 58fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.id.matches); 59fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mInput = (InputMethodManager) 60fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins context.getSystemService(Context.INPUT_METHOD_SERVICE); 61fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mResources = context.getResources(); 62fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 63fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 6405919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins void finish() { 6505919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins mActionMode.finish(); 6605919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins } 6705919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins 68fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 69fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Place text in the text field so it can be searched for. Need to press 70fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * the find next or find previous button to find all of the matches. 71fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 72fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins void setText(String text) { 73fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mEditText.setText(text); 74fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Spannable span = (Spannable) mEditText.getText(); 75fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int length = span.length(); 76fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Ideally, we would like to set the selection to the whole field, 77fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // but this brings up the Text selection CAB, which dismisses this 78fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // one. 79fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Selection.setSelection(span, length, length); 80fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Necessary each time we set the text, so that this will watch 81fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // changes to it. 82fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 83fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = false; 84fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 85fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 86fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 87fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Set the WebView to search. Must be non null, and set before calling 88fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * startActionMode. 89fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 903c90952036a5ff7ddb2946c643f1a0bf1c31d53aJonathan Dixon void setWebView(WebViewClassic webView) { 91fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (null == webView) { 92fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins throw new AssertionError("WebView supplied to " 93fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins + "FindActionModeCallback cannot be null"); 94fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 95fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView = webView; 96fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 97fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 98fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 99fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Move the highlight to the next match. 100fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * @param next If true, find the next match further down in the document. 101fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * If false, find the previous match, up in the document. 102fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 103fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private void findNext(boolean next) { 104fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (mWebView == null) { 105fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins throw new AssertionError( 106fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins "No WebView for FindActionModeCallback::findNext"); 107fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 1087014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins if (!mMatchesFound) { 1097014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins findAll(); 1107014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins return; 1117014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins } 1127014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins if (0 == mNumberOfMatches) { 1137014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins // There are no matches, so moving to the next match will not do 1147014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins // anything. 1157014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins return; 1167014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins } 117fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView.findNext(next); 1187014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins updateMatchesString(); 119fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 120fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 121fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 122fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Highlight all the instances of the string from mEditText in mWebView. 123fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 124fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins void findAll() { 125fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (mWebView == null) { 126fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins throw new AssertionError( 127fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins "No WebView for FindActionModeCallback::findAll"); 128fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 129fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins CharSequence find = mEditText.getText(); 130fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (0 == find.length()) { 131fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView.clearMatches(); 132fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches.setVisibility(View.GONE); 133fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = false; 134abeb6a791501151308d06db6aebb438e16c1a784Victoria Lease mWebView.findAll(null); 135fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } else { 136fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = true; 13747d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setVisibility(View.INVISIBLE); 13847d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mNumberOfMatches = 0; 139abeb6a791501151308d06db6aebb438e16c1a784Victoria Lease mWebView.findAllAsync(find.toString()); 140fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 141fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 142fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 143571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins public void showSoftInput() { 14418cf9a7828f0b50daf967e22f0c5308b68d2919aLeon Scroggins mInput.startGettingWindowFocus(mEditText.getRootView()); 14518cf9a7828f0b50daf967e22f0c5308b68d2919aLeon Scroggins mInput.focusIn(mEditText); 146571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins mInput.showSoftInput(mEditText, 0); 147571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins } 148571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins 1490b8413bbeb528c854e28c5ba1550239867da5c2eVictoria Lease public void updateMatchCount(int matchIndex, int matchCount, boolean isEmptyFind) { 1500b8413bbeb528c854e28c5ba1550239867da5c2eVictoria Lease if (!isEmptyFind) { 15147d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mNumberOfMatches = matchCount; 15247d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mActiveMatchIndex = matchIndex; 15347d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease updateMatchesString(); 15447d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } else { 15547d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setVisibility(View.INVISIBLE); 15647d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mNumberOfMatches = 0; 15747d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } 15847d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } 15947d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease 160fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 161fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Update the string which tells the user how many matches were found, and 162fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * which match is currently highlighted. 163fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 164fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private void updateMatchesString() { 16547d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease if (mNumberOfMatches == 0) { 16647d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setText(com.android.internal.R.string.no_matches); 16747d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } else { 16847d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setText(mResources.getQuantityString( 169fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.plurals.matches_found, mNumberOfMatches, 17047d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mActiveMatchIndex + 1, mNumberOfMatches)); 17147d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } 17247d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setVisibility(View.VISIBLE); 173fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 174fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 1757014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins // OnClickListener implementation 1767014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins 1777014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins @Override 1787014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins public void onClick(View v) { 1797014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins findNext(true); 1807014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins } 1817014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins 182fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // ActionMode.Callback implementation 183fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 184fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 185fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public boolean onCreateActionMode(ActionMode mode, Menu menu) { 186f8419a0299680ed580975b0fcb758990b4367db8Adam Powell if (!mode.isUiFocusable()) { 187f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // If the action mode we're running in is not focusable the user 188f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // will not be able to type into the find on page field. This 189f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // should only come up when we're running in a dialog which is 190f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // already less than ideal; disable the option for now. 191f8419a0299680ed580975b0fcb758990b4367db8Adam Powell return false; 192f8419a0299680ed580975b0fcb758990b4367db8Adam Powell } 193f8419a0299680ed580975b0fcb758990b4367db8Adam Powell 194fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mode.setCustomView(mCustomView); 195fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_find, 196fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins menu); 19705919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins mActionMode = mode; 198fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Editable edit = mEditText.getText(); 199fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Selection.setSelection(edit, edit.length()); 200fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches.setVisibility(View.GONE); 201fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = false; 202fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches.setText("0"); 203fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mEditText.requestFocus(); 204fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return true; 205fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 206fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 207fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 208fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void onDestroyActionMode(ActionMode mode) { 209fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck mActionMode = null; 210fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView.notifyFindDialogDismissed(); 2113c90952036a5ff7ddb2946c643f1a0bf1c31d53aJonathan Dixon mInput.hideSoftInputFromWindow(mWebView.getWebView().getWindowToken(), 0); 212fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 213fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 214fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 215fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 216fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return false; 217fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 218fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 219fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 220fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 221261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins if (mWebView == null) { 222261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins throw new AssertionError( 223261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins "No WebView for FindActionModeCallback::onActionItemClicked"); 224261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins } 2253c90952036a5ff7ddb2946c643f1a0bf1c31d53aJonathan Dixon mInput.hideSoftInputFromWindow(mWebView.getWebView().getWindowToken(), 0); 226fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins switch(item.getItemId()) { 227fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins case com.android.internal.R.id.find_prev: 228fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins findNext(false); 229fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins break; 230fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins case com.android.internal.R.id.find_next: 231fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins findNext(true); 232fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins break; 233fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins default: 234fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return false; 235fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 236fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return true; 237fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 238fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 239fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // TextWatcher implementation 240fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 241fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 242fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void beforeTextChanged(CharSequence s, 243fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int start, 244fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int count, 245fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int after) { 246fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Does nothing. Needed to implement TextWatcher. 247fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 248fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 249fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 250fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void onTextChanged(CharSequence s, 251fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int start, 252fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int before, 253fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int count) { 254fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins findAll(); 255fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 256fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 257fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 258fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void afterTextChanged(Editable s) { 259fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Does nothing. Needed to implement TextWatcher. 260fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 261fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 262d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck private Rect mGlobalVisibleRect = new Rect(); 263d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck private Point mGlobalVisibleOffset = new Point(); 264d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck public int getActionModeGlobalBottom() { 265fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck if (mActionMode == null) { 266fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck return 0; 267fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck } 268d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck View view = (View) mCustomView.getParent(); 269d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck if (view == null) { 270d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck view = mCustomView; 271d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck } 272d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck view.getGlobalVisibleRect(mGlobalVisibleRect, mGlobalVisibleOffset); 273d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck return mGlobalVisibleRect.bottom; 274fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck } 275fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck 2767e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public static class NoAction implements ActionMode.Callback { 2777e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 2787e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public boolean onCreateActionMode(ActionMode mode, Menu menu) { 2797e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount return false; 2807e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 2817e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount 2827e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 2837e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 2847e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount return false; 2857e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 2867e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount 2877e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 2887e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 2897e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount return false; 2907e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 2917e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount 2927e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 2937e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public void onDestroyActionMode(ActionMode mode) { 2947e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 2957e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 296fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins} 297