Bug 1345104 - Show error when Find In Page returns no results; r=petru
authorAndrei Teslovan <andrei.teslovan@softvision.ro>
Wed, 24 Apr 2019 10:48:55 +0000
changeset 529453 29103bace2abbd31d1e27d738483f6db26d07808
parent 529452 eab0e21e5347199b24d3eaf17669c2a8efb38781
child 529454 64aa6c2339e2ccae33420744974ec95a90c9b3e1
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1345104
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1345104 - Show error when Find In Page returns no results; r=petru Differential Revision: https://phabricator.services.mozilla.com/D28609
mobile/android/app/src/main/res/drawable/ic_baseline_error.xml
mobile/android/app/src/main/res/values/colors.xml
mobile/android/base/java/org/mozilla/gecko/FindInPageBar.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/strings.xml.in
new file mode 100644
--- /dev/null
+++ b/mobile/android/app/src/main/res/drawable/ic_baseline_error.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="18dp"
+    android:height="18dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:fillColor="#000000"
+      android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
+</vector>
--- a/mobile/android/app/src/main/res/values/colors.xml
+++ b/mobile/android/app/src/main/res/values/colors.xml
@@ -271,9 +271,12 @@
     <color name="pwa_confirm_btn_normal">#E60A84FF</color>
 
     <!-- Date/Time Pickers -->
     <color name="dtp_header_background">#2B2B2B</color>
     <color name="dtp_header_text_active">#0A84FF</color>
     <color name="dtp_header_text_inactive">#B2B2B2</color>
     <color name="dtp_selection">#FFFFFF</color>
 
+    <!-- FindInPageBar -->
+    <color name="fip_text_error_background">#FF6666</color>
+
 </resources>
--- a/mobile/android/base/java/org/mozilla/gecko/FindInPageBar.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FindInPageBar.java
@@ -5,19 +5,23 @@
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.util.ActivityUtils;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
 
 import android.content.Context;
+import android.graphics.Color;
+import android.graphics.drawable.Drawable;
 import android.text.Editable;
+import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 import android.text.TextWatcher;
+import android.text.style.ForegroundColorSpan;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -131,28 +135,58 @@ public class FindInPageBar extends Linea
         }
         EventDispatcher.getInstance().unregisterUiThreadListener(this,
             "FindInPage:MatchesCountResult");
     }
 
     private void onMatchesCountResult(final int total, final int current, final int limit, final String searchString) {
         if (total == -1) {
             updateResult(Integer.toString(limit) + "+");
+            updateFindTextBackgroundColor(true);
         } else if (total > 0) {
             updateResult(Integer.toString(current) + "/" + Integer.toString(total));
+            updateFindTextBackgroundColor(true);
         } else if (TextUtils.isEmpty(searchString)) {
             updateResult("");
+            updateFindTextBackgroundColor(false);
+            updateFindTextError();
         } else {
             // We display 0/0, when there were no
             // matches found, or if matching has been turned off by setting
             // pref accessibility.typeaheadfind.matchesCountLimit to 0.
             updateResult("0/0");
         }
     }
 
+    private void updateFindTextError() {
+        if (!TextUtils.isEmpty(mFindText.getText().toString())) {
+            String errorText = getResources().getString(R.string.find_error);
+            ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.WHITE);
+            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(errorText);
+            spannableStringBuilder.setSpan(foregroundColorSpan, 0, errorText.length(), 0);
+
+            Drawable errorDrawable = getResources().getDrawable(R.drawable.ic_baseline_error);
+            errorDrawable.setBounds(0, 0, errorDrawable.getIntrinsicWidth(), errorDrawable.getIntrinsicHeight());
+
+            mFindText.setError(spannableStringBuilder, errorDrawable);
+        }
+    }
+
+    private void updateFindTextBackgroundColor(final boolean hasResults) {
+        if (TextUtils.isEmpty(mFindText.getText().toString())) {
+            mFindText.setBackgroundColor(Color.WHITE);
+        } else {
+            if (hasResults) {
+                mFindText.setBackgroundColor(Color.WHITE);
+            } else {
+                mFindText.setBackgroundColor(getResources().getColor(R.color.fip_text_error_background));
+            }
+        }
+    }
+
     private void updateResult(final String statusText) {
         mStatusText.setVisibility(statusText.isEmpty() ? View.GONE : View.VISIBLE);
         mStatusText.setText(statusText);
     }
 
     // TextWatcher implementation
 
     @Override
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -499,16 +499,20 @@ shown from Android O while a tab is bein
 
 <!-- Localization note (find_text, find_prev, find_next, find_close) : These strings are used
      as alternate text for accessibility. They are not visible in the UI. -->
 <!ENTITY find_text "Find in Page">
 <!ENTITY find_prev "Previous">
 <!ENTITY find_next "Next">
 <!ENTITY find_close "Close">
 
+<!-- Localization note (find_error) : Error message shown when there is no result for the
+     searched for text in this webpage -->
+<!ENTITY find_error "Phrase not found">
+
 <!-- Localization note (media_sending_to, media_play, media_pause, media_stop) : These strings are used
      as alternate text for accessibility. They are not visible in the UI. -->
 <!ENTITY media_sending_to "Sending to Device">
 <!ENTITY media_play "Play">
 <!ENTITY media_pause "Pause">
 <!ENTITY media_stop "Stop">
 
 <!ENTITY contextmenu_open_new_tab "Open in New Tab">
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -113,16 +113,17 @@
   <string name="desktop_mode">&desktop_mode;</string>
   <string name="page">&page;</string>
   <string name="tools">&tools;</string>
 
   <string name="find_text">&find_text;</string>
   <string name="find_prev">&find_prev;</string>
   <string name="find_next">&find_next;</string>
   <string name="find_close">&find_close;</string>
+  <string name="find_error">&find_error;</string>
 
   <string name="media_sending_to">&media_sending_to;</string>
   <string name="media_play">&media_play;</string>
   <string name="media_pause">&media_pause;</string>
   <string name="media_stop">&media_stop;</string>
 
   <string name="overlay_share_open_browser_btn_label">&overlay_share_open_browser_btn_label;</string>
   <string name="overlay_share_send_other">&overlay_share_send_other;</string>