Bug 950698 - Change the text for the tip for adding more search providers from Settings->Customize->Search settings. r=bnicholson, a=sledru
☠☠ backed out by d2180eeda96b ☠ ☠
authorChenxia Liu <liuche@mozilla.com>
Mon, 24 Feb 2014 10:34:07 -0500
changeset 182971 1ed9ed99b7635bd7bbbc6f24a60f409b72868d06
parent 182970 638b67508a3e70764c4afc2e1c366ce6cf54729f
child 182972 0a57931de08293195a0d161bda7bb2a480f7e438
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson, sledru
bugs950698
milestone29.0a2
Bug 950698 - Change the text for the tip for adding more search providers from Settings->Customize->Search settings. r=bnicholson, a=sledru
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/moz.build
mobile/android/base/preferences/ModifiableHintPreference.java
mobile/android/base/resources/layout/preference_search_tip.xml
mobile/android/base/resources/xml-v11/preferences_search.xml
mobile/android/base/resources/xml/preferences_search.xml
mobile/android/base/strings.xml.in
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -71,20 +71,22 @@
 <!ENTITY pref_category_privacy_short "Privacy">
 <!ENTITY pref_category_vendor "&vendorShortName;">
 <!ENTITY pref_category_datareporting "Data choices">
 <!ENTITY pref_category_installed_search_engines "Installed search engines">
 <!ENTITY pref_category_add_search_providers "Add more search providers">
 <!ENTITY pref_category_search_restore_defaults "Restore search engines">
 <!ENTITY pref_search_restore_defaults "Restore defaults">
 <!ENTITY pref_search_restore_defaults_summary "Restore defaults">
-<!-- Localization note (pref_search_tip) : "TIP" as in "hint", "clue" etc. Displayed as an
+<!-- Localization note (pref_search_hint) : "TIP" as in "hint", "clue" etc. Displayed as an
      advisory message on the customise search providers settings page explaining how to add new
-     search providers.-->
-<!ENTITY pref_search_tip "TIP: Add any website to your list of search providers by long-pressing on its search field.">
+     search providers.
+     The &formatI; in the string will be replaced by a small image of the icon described, and can be moved to wherever
+     it is applicable. -->
+<!ENTITY pref_search_hint "TIP: Add any website to your list of search providers by long-pressing on its search field and then tapping the &formatI; icon.">
 <!ENTITY pref_category_devtools "Developer tools">
 <!ENTITY pref_developer_remotedebugging "Remote debugging">
 <!ENTITY pref_developer_remotedebugging_docs "Learn more">
 <!ENTITY pref_remember_signons "Remember passwords">
 
 <!ENTITY pref_category_home "Home">
 <!ENTITY pref_category_home_panels "Panels">
 
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -276,16 +276,17 @@ gbjar.sources += [
     'preferences/AndroidImport.java',
     'preferences/AndroidImportPreference.java',
     'preferences/CustomListCategory.java',
     'preferences/CustomListPreference.java',
     'preferences/FontSizePreference.java',
     'preferences/GeckoPreferenceFragment.java',
     'preferences/GeckoPreferences.java',
     'preferences/LinkPreference.java',
+    'preferences/ModifiableHintPreference.java',
     'preferences/MultiChoicePreference.java',
     'preferences/PanelsPreference.java',
     'preferences/PanelsPreferenceCategory.java',
     'preferences/PrivateDataPreference.java',
     'preferences/SearchEnginePreference.java',
     'preferences/SearchPreferenceCategory.java',
     'preferences/SyncPreference.java',
     'PrefsHelper.java',
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/preferences/ModifiableHintPreference.java
@@ -0,0 +1,67 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.preferences;
+
+import org.mozilla.gecko.R;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.preference.Preference;
+import android.text.Spanned;
+import android.text.SpannableStringBuilder;
+import android.text.style.ImageSpan;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+class ModifiableHintPreference extends Preference {
+    private static final String LOGTAG = "ModifiableHintPref";
+    private final Context mContext;
+
+    private final String MATCH_STRING = "%I";
+    private final int RESID_TEXT_VIEW = R.id.label_search_hint;
+    private final int RESID_DRAWABLE = R.drawable.ab_add_search_engine;
+    private final double SCALE_FACTOR = 0.5;
+
+    public ModifiableHintPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        mContext = context;
+    }
+
+    public ModifiableHintPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+        mContext = context;
+    }
+
+    @Override
+    protected View onCreateView(ViewGroup parent) {
+        View thisView = super.onCreateView(parent);
+        configurePreferenceView(thisView);
+        return thisView;
+    }
+
+    private void configurePreferenceView(View view) {
+        TextView textView = (TextView) view.findViewById(RESID_TEXT_VIEW);
+        String searchHint = textView.getText().toString();
+
+        // Use an ImageSpan to include the "add search" icon in the Tip.
+        int imageSpanIndex = searchHint.indexOf(MATCH_STRING);
+        if (imageSpanIndex != -1) {
+            // Scale the resource.
+            Drawable drawable = mContext.getResources().getDrawable(RESID_DRAWABLE);
+            drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * SCALE_FACTOR),
+                               (int) (drawable.getIntrinsicHeight() * SCALE_FACTOR));
+
+            ImageSpan searchIcon = new ImageSpan(drawable);
+            final SpannableStringBuilder hintBuilder = new SpannableStringBuilder(searchHint);
+
+            // Insert the image.
+            hintBuilder.setSpan(searchIcon, imageSpanIndex, imageSpanIndex + MATCH_STRING.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+            textView.setText(hintBuilder, TextView.BufferType.SPANNABLE);
+        }
+    }
+}
--- a/mobile/android/base/resources/layout/preference_search_tip.xml
+++ b/mobile/android/base/resources/layout/preference_search_tip.xml
@@ -4,34 +4,28 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:orientation="horizontal"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:paddingRight="?android:attr/scrollbarSize">
 
-    <RelativeLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:gravity="right"
-        android:layout_marginLeft="15dip"
-        android:layout_marginRight="6dip"
-        android:layout_marginTop="5dip"
-        android:layout_marginBottom="6dip"
-        android:paddingRight="6dip"
-        android:layout_weight="1">
-
-        <TextView android:layout_height="wrap_content"
-                  android:layout_width="wrap_content"
-                  android:paddingTop="8dp"
-                  android:paddingBottom="8dp"
-                  android:text="@string/pref_search_tip"/>
-
-    </RelativeLayout>
+    <TextView android:id="@+id/label_search_hint"
+              android:layout_height="wrap_content"
+              android:layout_width="wrap_content"
+              android:text="@string/pref_search_hint"
+              android:layout_marginTop="5dip"
+              android:layout_marginBottom="6dip"
+              android:layout_marginLeft="15dip"
+              android:layout_marginRight="6dip"
+              android:paddingTop="8dp"
+              android:paddingBottom="8dp"
+              android:paddingRight="6dip"
+              android:layout_weight="1"/>
 
     <ImageView android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:paddingRight="8dp"
                android:paddingTop="12dip"
                android:src="@drawable/tip_addsearch"/>
 
 </LinearLayout>
--- a/mobile/android/base/resources/xml-v11/preferences_search.xml
+++ b/mobile/android/base/resources/xml-v11/preferences_search.xml
@@ -13,15 +13,16 @@
                         android:defaultValue="false"
                         android:persistent="false" />
 
     <org.mozilla.gecko.preferences.SearchPreferenceCategory
                         android:title="@string/pref_category_installed_search_engines"/>
 
     <PreferenceCategory android:title="@string/pref_category_add_search_providers">
 
-        <Preference android:layout="@layout/preference_search_tip"
+        <org.mozilla.gecko.preferences.ModifiableHintPreference
+                    android:layout="@layout/preference_search_tip"
                     android:enabled="false"
                     android:selectable="false"/>
 
     </PreferenceCategory>
 
 </PreferenceScreen>
--- a/mobile/android/base/resources/xml/preferences_search.xml
+++ b/mobile/android/base/resources/xml/preferences_search.xml
@@ -20,15 +20,16 @@
 
         <Preference android:key="android.not_a_preference.search.restore_defaults"
                     android:title="@string/pref_search_restore_defaults_summary" />
 
     </PreferenceCategory>
 
     <PreferenceCategory android:title="@string/pref_category_add_search_providers">
 
-        <Preference android:layout="@layout/preference_search_tip"
+        <org.mozilla.gecko.preferences.ModifiableHintPreference
+                    android:layout="@layout/preference_search_tip"
                     android:enabled="false"
                     android:selectable="false"/>
 
     </PreferenceCategory>
 
 </PreferenceScreen>
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -5,16 +5,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!DOCTYPE resources [
 #includesubst @BRANDPATH@
 #includesubst @STRINGSPATH@
 #includesubst @SYNCSTRINGSPATH@
 
 <!-- C-style format strings. -->
+<!ENTITY formatI "&#037;I">
 <!ENTITY formatS "&#037;s">
 <!ENTITY formatS1 "&#037;1&#036;s">
 <!ENTITY formatS2 "&#037;2&#036;s">
 <!ENTITY formatS3 "&#037;3&#036;s">
 <!ENTITY formatD "&#037;d">
 ]>
 
 #includesubst @BOOKMARKSPATH@
@@ -98,17 +99,17 @@
   <string name="pref_category_privacy_short">&pref_category_privacy_short;</string>
   <string name="pref_category_vendor">&pref_category_vendor;</string>
   <string name="pref_category_datareporting">&pref_category_datareporting;</string>
   <string name="pref_category_installed_search_engines">&pref_category_installed_search_engines;</string>
   <string name="pref_category_add_search_providers">&pref_category_add_search_providers;</string>
   <string name="pref_category_search_restore_defaults">&pref_category_search_restore_defaults;</string>
   <string name="pref_search_restore_defaults">&pref_search_restore_defaults;</string>
   <string name="pref_search_restore_defaults_summary">&pref_search_restore_defaults_summary;</string>
-  <string name="pref_search_tip">&pref_search_tip;</string>
+  <string name="pref_search_hint">&pref_search_hint;</string>
 
   <string name="pref_category_devtools">&pref_category_devtools;</string>
   <string name="pref_developer_remotedebugging">&pref_developer_remotedebugging;</string>
   <string name="pref_developer_remotedebugging_docs">&pref_developer_remotedebugging_docs;</string>
 
   <string name="pref_category_home">&pref_category_home;</string>
   <string name="pref_category_home_panels">&pref_category_home_panels;</string>