Improve the details shown about the matches.
Show "i of n" rather than just the number of matches. Also use a
separate string for 'zero' matches, since getQuantityString does
not work for quantity '0'.
Bug 2663680
Depends on changes to frameworks/base and external/webkit.
Change-Id: I4f2f096a4bc78e0c274993f42061cec85aeec745
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 18a2144..a30a399 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -50,17 +50,16 @@
<!-- Label for a confirm button. Used in multiple contexts. -->
<string name="ok">OK</string>
- <!-- Displayed on the Find dialog to display the number of matches
- found in the current page. -->
+ <!-- Displayed on the Find dialog when there are no matches -->
+ <string name="no_matches">No matches</string>
+
+ <!-- Displayed on the Find dialog to display the index of the highlighted
+ match and total number of matches found in the current page. -->
<plurals name="matches_found">
- <!-- Case of no matches -->
- <item quantity="zero">No matches</item>
<!-- Case of one match -->
<item quantity="one">1 match</item>
- <!-- Case of "few" (two) matches -->
- <item quantity="few"><xliff:g id="number" example="2">%d</xliff:g> matches</item>
- <!-- Case of several matches -->
- <item quantity="other"><xliff:g id="number" example="137">%d</xliff:g> matches</item>
+ <!-- Case of multiple total matches -->
+ <item quantity="other"><xliff:g id="index" example="2">%d</xliff:g> of <xliff:g id="total" example="137">%d</xliff:g></item>
</plurals>
<!-- Displayed on the title bar while the page is loading -->
diff --git a/src/com/android/browser/FindDialog.java b/src/com/android/browser/FindDialog.java
index 9646952..bcd5bb7 100644
--- a/src/com/android/browser/FindDialog.java
+++ b/src/com/android/browser/FindDialog.java
@@ -48,6 +48,7 @@
// (or the text needs to be changed) before WebView.findAll can be called.
// Once it has been called, enter should move to the next match.
private boolean mMatchesFound;
+ private int mNumberOfMatches;
private View.OnClickListener mFindListener = new View.OnClickListener() {
public void onClick(View v) {
findNext();
@@ -68,6 +69,7 @@
throw new AssertionError("No WebView for FindDialog::onClick");
}
mWebView.findNext(false);
+ updateMatchesString();
hideSoftInput();
}
};
@@ -175,6 +177,7 @@
throw new AssertionError("No WebView for FindDialog::findNext");
}
mWebView.findNext(true);
+ updateMatchesString();
hideSoftInput();
}
@@ -182,12 +185,13 @@
// In case the matches view is showing from a previous search
mMatchesView.setVisibility(View.INVISIBLE);
mMatchesFound = false;
+ // This text is only here to ensure that mMatches has a height.
+ mMatches.setText("0");
mEditText.requestFocus();
Spannable span = (Spannable) mEditText.getText();
int length = span.length();
Selection.setSelection(span, 0, length);
span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
- setMatchesFound(0);
disableButtons();
startAnimation(AnimationUtils.loadAnimation(mBrowserActivity,
R.anim.find_dialog_enter));
@@ -207,14 +211,14 @@
int start,
int before,
int count) {
- if (mWebView == null) {
- throw new AssertionError(
- "No WebView for FindDialog::onTextChanged");
- }
findAll();
}
private void findAll() {
+ if (mWebView == null) {
+ throw new AssertionError(
+ "No WebView for FindDialog::findAll");
+ }
CharSequence find = mEditText.getText();
if (0 == find.length()) {
disableButtons();
@@ -228,7 +232,10 @@
if (found < 2) {
disableButtons();
if (found == 0) {
- setMatchesFound(0);
+ // Cannot use getQuantityString, which ignores the "zero"
+ // quantity.
+ mMatches.setText(mBrowserActivity.getResources().getString(
+ R.string.no_matches));
}
} else {
mPrevButton.setFocusable(true);
@@ -240,8 +247,16 @@
}
private void setMatchesFound(int found) {
+ mNumberOfMatches = found;
+ updateMatchesString();
+ }
+
+ private void updateMatchesString() {
+ // Note: updateMatchesString is only called by methods that have already
+ // checked mWebView for null.
String template = mBrowserActivity.getResources().
- getQuantityString(R.plurals.matches_found, found, found);
+ getQuantityString(R.plurals.matches_found, mNumberOfMatches,
+ mWebView.findIndex() + 1, mNumberOfMatches);
mMatches.setText(template);
}