Bug 950698 - Change the text for the tip for adding more search providers from Settings->Customize->Search settings. r=bnicholson

This commit is contained in:
Chenxia Liu 2014-02-20 13:11:25 -08:00
parent 8f99df4908
commit 3aebafa54c
8 changed files with 91 additions and 24 deletions

View File

@ -76,10 +76,12 @@
<!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">

View File

@ -284,6 +284,7 @@ gbjar.sources += [
'preferences/GeckoPreferenceFragment.java',
'preferences/GeckoPreferences.java',
'preferences/LinkPreference.java',
'preferences/ModifiableHintPreference.java',
'preferences/MultiChoicePreference.java',
'preferences/PanelsPreference.java',
'preferences/PanelsPreferenceCategory.java',

View File

@ -58,6 +58,7 @@ import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;

View File

@ -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);
}
}
}

View File

@ -9,24 +9,18 @@
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"

View File

@ -18,7 +18,8 @@
<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"/>

View File

@ -25,7 +25,8 @@
<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"/>

View File

@ -105,7 +105,7 @@
<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>