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 19451e338c51e8c45efc0d21536dfae6f78f6d5e06Ignacio Sollaimport android.annotation.SystemApi; 20fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.content.Context; 21fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.content.res.Resources; 22d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reckimport android.graphics.Point; 23d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reckimport android.graphics.Rect; 24fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Editable; 25fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Selection; 26fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.Spannable; 27fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.text.TextWatcher; 28fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.ActionMode; 29fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.LayoutInflater; 30fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.Menu; 31fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.MenuItem; 32fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.View; 33fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scrogginsimport android.view.inputmethod.InputMethodManager; 34fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reckimport android.widget.EditText; 35fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reckimport android.widget.TextView; 36fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 3752c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch/** 3852c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch * @hide 3952c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch */ 40451e338c51e8c45efc0d21536dfae6f78f6d5e06Ignacio Solla@SystemApi 4152c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdochpublic class FindActionModeCallback implements ActionMode.Callback, TextWatcher, 4252c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch View.OnClickListener, WebView.FindListener { 43fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private View mCustomView; 44fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private EditText mEditText; 45fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private TextView mMatches; 4652c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch private WebView mWebView; 47fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private InputMethodManager mInput; 48fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private Resources mResources; 49fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private boolean mMatchesFound; 50fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private int mNumberOfMatches; 5147d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease private int mActiveMatchIndex; 5205919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins private ActionMode mActionMode; 53fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 5452c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch public FindActionModeCallback(Context context) { 55fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mCustomView = LayoutInflater.from(context).inflate( 56fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.layout.webview_find, null); 57fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mEditText = (EditText) mCustomView.findViewById( 58fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.id.edit); 597e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount mEditText.setCustomSelectionActionModeCallback(new NoAction()); 607014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins mEditText.setOnClickListener(this); 61fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins setText(""); 62fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches = (TextView) mCustomView.findViewById( 63fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.id.matches); 64fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mInput = (InputMethodManager) 65fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins context.getSystemService(Context.INPUT_METHOD_SERVICE); 66fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mResources = context.getResources(); 67fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 68fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 6952c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch public void finish() { 7005919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins mActionMode.finish(); 7105919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins } 7205919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins 73fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 74fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Place text in the text field so it can be searched for. Need to press 75fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * the find next or find previous button to find all of the matches. 76fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 7752c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch public void setText(String text) { 78fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mEditText.setText(text); 79fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Spannable span = (Spannable) mEditText.getText(); 80fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int length = span.length(); 81fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Ideally, we would like to set the selection to the whole field, 82fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // but this brings up the Text selection CAB, which dismisses this 83fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // one. 84fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Selection.setSelection(span, length, length); 85fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Necessary each time we set the text, so that this will watch 86fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // changes to it. 87fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE); 88fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = false; 89fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 90fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 91fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 9252c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch * Set the WebView to search. Must be non null. 93fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 9452c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch public void setWebView(WebView webView) { 95fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (null == webView) { 96fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins throw new AssertionError("WebView supplied to " 97fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins + "FindActionModeCallback cannot be null"); 98fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 99fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView = webView; 10052c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch mWebView.setFindDialogFindListener(this); 10152c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch } 10252c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch 10352c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch @Override 10452c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, 10552c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch boolean isDoneCounting) { 10652c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch if (isDoneCounting) { 10752c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch updateMatchCount(activeMatchOrdinal, numberOfMatches, numberOfMatches == 0); 10852c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch } 109fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 110fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 111fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 112fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Move the highlight to the next match. 113fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * @param next If true, find the next match further down in the document. 114fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * If false, find the previous match, up in the document. 115fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 116fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private void findNext(boolean next) { 117fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (mWebView == null) { 118fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins throw new AssertionError( 119fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins "No WebView for FindActionModeCallback::findNext"); 120fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 1217014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins if (!mMatchesFound) { 1227014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins findAll(); 1237014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins return; 1247014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins } 1257014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins if (0 == mNumberOfMatches) { 1267014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins // There are no matches, so moving to the next match will not do 1277014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins // anything. 1287014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins return; 1297014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins } 130fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView.findNext(next); 1317014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins updateMatchesString(); 132fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 133fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 134fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 135fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Highlight all the instances of the string from mEditText in mWebView. 136fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 13752c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch public void findAll() { 138fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (mWebView == null) { 139fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins throw new AssertionError( 140fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins "No WebView for FindActionModeCallback::findAll"); 141fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 142fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins CharSequence find = mEditText.getText(); 143fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins if (0 == find.length()) { 144fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView.clearMatches(); 145fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches.setVisibility(View.GONE); 146fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = false; 147abeb6a791501151308d06db6aebb438e16c1a784Victoria Lease mWebView.findAll(null); 148fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } else { 149fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = true; 15047d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setVisibility(View.INVISIBLE); 15147d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mNumberOfMatches = 0; 152abeb6a791501151308d06db6aebb438e16c1a784Victoria Lease mWebView.findAllAsync(find.toString()); 153fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 154fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 155fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 156571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins public void showSoftInput() { 1575f05965f546fa42750f1a8314f8a2da01fd6bfb4Yohei Yukawa if (mEditText.requestFocus()) { 1585f05965f546fa42750f1a8314f8a2da01fd6bfb4Yohei Yukawa mInput.showSoftInput(mEditText, 0); 1595f05965f546fa42750f1a8314f8a2da01fd6bfb4Yohei Yukawa } 160571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins } 161571354fd29db3e4855e2f179c2c6ad47f4eefd77Leon Scroggins 1620b8413bbeb528c854e28c5ba1550239867da5c2eVictoria Lease public void updateMatchCount(int matchIndex, int matchCount, boolean isEmptyFind) { 1630b8413bbeb528c854e28c5ba1550239867da5c2eVictoria Lease if (!isEmptyFind) { 16447d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mNumberOfMatches = matchCount; 16547d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mActiveMatchIndex = matchIndex; 16647d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease updateMatchesString(); 16747d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } else { 1681c15b8d896229b11e13134c52579a5c9fac4d5f6Stefan Wysocki mMatches.setVisibility(View.GONE); 16947d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mNumberOfMatches = 0; 17047d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } 17147d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } 17247d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease 173fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins /* 174fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * Update the string which tells the user how many matches were found, and 175fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins * which match is currently highlighted. 176fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins */ 177fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins private void updateMatchesString() { 17847d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease if (mNumberOfMatches == 0) { 17947d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setText(com.android.internal.R.string.no_matches); 18047d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } else { 18147d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setText(mResources.getQuantityString( 182fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins com.android.internal.R.plurals.matches_found, mNumberOfMatches, 18347d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mActiveMatchIndex + 1, mNumberOfMatches)); 18447d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease } 18547d0ee9766fb972f49d5116d2d7d3a23b5321211Victoria Lease mMatches.setVisibility(View.VISIBLE); 186fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 187fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 1887014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins // OnClickListener implementation 1897014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins 1907014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins @Override 1917014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins public void onClick(View v) { 1927014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins findNext(true); 1937014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins } 1947014b12873068f109f58b9d0ad4116fd8d4bf22fLeon Scroggins 195fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // ActionMode.Callback implementation 196fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 197fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 198fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public boolean onCreateActionMode(ActionMode mode, Menu menu) { 199f8419a0299680ed580975b0fcb758990b4367db8Adam Powell if (!mode.isUiFocusable()) { 200f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // If the action mode we're running in is not focusable the user 201f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // will not be able to type into the find on page field. This 202f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // should only come up when we're running in a dialog which is 203f8419a0299680ed580975b0fcb758990b4367db8Adam Powell // already less than ideal; disable the option for now. 204f8419a0299680ed580975b0fcb758990b4367db8Adam Powell return false; 205f8419a0299680ed580975b0fcb758990b4367db8Adam Powell } 206f8419a0299680ed580975b0fcb758990b4367db8Adam Powell 207fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mode.setCustomView(mCustomView); 208fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mode.getMenuInflater().inflate(com.android.internal.R.menu.webview_find, 209fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins menu); 21005919f2133f8af89ab69c3a39aa34c6a32e78f05Leon Scroggins mActionMode = mode; 211fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Editable edit = mEditText.getText(); 212fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins Selection.setSelection(edit, edit.length()); 213fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches.setVisibility(View.GONE); 214fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatchesFound = false; 215fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mMatches.setText("0"); 216fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mEditText.requestFocus(); 217fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return true; 218fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 219fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 220fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 221fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void onDestroyActionMode(ActionMode mode) { 222fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck mActionMode = null; 223fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins mWebView.notifyFindDialogDismissed(); 22452c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch mWebView.setFindDialogFindListener(null); 22552c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); 226fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 227fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 228fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 229fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 230fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return false; 231fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 232fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 233fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 234fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 235261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins if (mWebView == null) { 236261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins throw new AssertionError( 237261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins "No WebView for FindActionModeCallback::onActionItemClicked"); 238261f42d64dbd6d59af8ffecb315169b747167cc1Leon Scroggins } 23952c9f7f95083a9d041b9261522e929073cb52fd5Ben Murdoch mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); 240fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins switch(item.getItemId()) { 241fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins case com.android.internal.R.id.find_prev: 242fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins findNext(false); 243fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins break; 244fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins case com.android.internal.R.id.find_next: 245fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins findNext(true); 246fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins break; 247fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins default: 248fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return false; 249fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 250fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins return true; 251fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 252fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 253fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // TextWatcher implementation 254fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 255fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 256fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void beforeTextChanged(CharSequence s, 257fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int start, 258fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int count, 259fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int after) { 260fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Does nothing. Needed to implement TextWatcher. 261fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 262fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 263fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 264fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void onTextChanged(CharSequence s, 265fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int start, 266fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int before, 267fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins int count) { 268fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins findAll(); 269fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 270fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 271fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins @Override 272fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins public void afterTextChanged(Editable s) { 273fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins // Does nothing. Needed to implement TextWatcher. 274fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins } 275fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins 276d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck private Rect mGlobalVisibleRect = new Rect(); 277d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck private Point mGlobalVisibleOffset = new Point(); 278d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck public int getActionModeGlobalBottom() { 279fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck if (mActionMode == null) { 280fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck return 0; 281fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck } 282d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck View view = (View) mCustomView.getParent(); 283d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck if (view == null) { 284d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck view = mCustomView; 285d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck } 286d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck view.getGlobalVisibleRect(mGlobalVisibleRect, mGlobalVisibleOffset); 287d6ac727234b9be45c3df4021dc83584e9849c00aJohn Reck return mGlobalVisibleRect.bottom; 288fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck } 289fffce6fe99f7ae80f448790371b8c0fa90277d1aJohn Reck 2907e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public static class NoAction implements ActionMode.Callback { 2917e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 2927e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public boolean onCreateActionMode(ActionMode mode, Menu menu) { 2937e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount return false; 2947e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 2957e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount 2967e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 2977e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 2987e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount return false; 2997e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 3007e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount 3017e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 3027e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 3037e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount return false; 3047e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 3057e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount 3067e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount @Override 3077e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount public void onDestroyActionMode(ActionMode mode) { 3087e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 3097e9f62ef486af98ce6fbb3e2918a45c68c0b551fGeorge Mount } 310fe026bdd3c0fd7543ceaf0732aeb824cfddb5b23Leon Scroggins} 311