勤能补拙,熟能生巧,宁静致远

记录工作中的点滴积累,总结成长的步伐里程。

博客园 首页 新随笔 联系 订阅 管理

Browser设置搜索引擎,在com.android.browser.preferences.GeneralPreferencesFragment中加载R.xml.general_preferences。

看看general_preferences.xml

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <PreferenceCategory android:title="@string/pref_general_title">
        <com.android.browser.preferences.NonformattingListPreference
            android:key="homepage_picker"
            android:entries="@array/pref_homepage_choices"
            android:entryValues="@array/pref_homepage_values"
            android:title="@string/pref_content_homepage" />

        <com.android.browser.search.SearchEnginePreference
       android:defaultValue="@string/default_search_engine_value"
            android:dialogTitle="@string/pref_content_search_engine"
            android:key="search_engine"
            android:summary="@string/pref_content_search_engine_summary"
            android:title="@string/pref_content_search_engine" />

SearchEnginePreference来显示引擎列表,SearchEngines.getSearchEngineInfos(context)获取引擎

  
  //SearchEngines获取引擎列表
  public
static List<SearchEngineInfo> getSearchEngineInfos(Context context) { ArrayList<SearchEngineInfo> searchEngineInfos = new ArrayList<SearchEngineInfo>(); String[] searchEngines = context.getResources().getStringArray(R.array.search_engines); for (int i = 0; i < searchEngines.length; i++) { String name = searchEngines[i]; SearchEngineInfo info = new SearchEngineInfo(context, name); searchEngineInfos.add(info); } return searchEngineInfos; }

Browser中所有的引擎列表在values/all_search_engines.xml中配置。R.array.search_engines配置要显示的引擎。

all_search_engines.xml

 

<resources>
  <string-array name="DuckDuckGo" translatable="false">
    <item>DuckDuckGo</item>
    <item>duckduckgo.com</item>
    <item>http://duckduckgo.com/favicon.ico</item>
    <item>https://duckduckgo.com/?q={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_uk" translatable="false">
    <item>Yahoo! UK &amp; Ireland</item>
    <item>uk.yahoo.com</item>
    <item>http://uk.search.yahoo.com/favicon.ico</item>
    <item>http://uk.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://uk-sayt.ff.search.yahoo.com/gossip-uk-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="yahoo_jp" translatable="false">
    <item>Yahoo! JAPAN</item>
    <item>yahoo.co.jp</item>
    <item>http://search.yahoo.co.jp/favicon.ico</item>
    <item>http://search.yahoo.co.jp/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="rambler" translatable="false">
    <item>Rambler</item>
    <item>rambler.ru</item>
    <item>http://www.rambler.ru/favicon.ico</item>
    <item>http://www.rambler.ru/srch?words={searchTerms}</item>
    <item>windows-1251</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_br" translatable="false">
    <item>Yahoo! Brasil</item>
    <item>br.yahoo.com</item>
    <item>http://br.search.yahoo.com/favicon.ico</item>
    <item>http://br.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://br-sayt.ff.search.yahoo.com/gossip-br-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="bing_zh_HK" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=zh-HK&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_el_GR" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=el-GR&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_tr_TR" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=tr-TR&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="ask_uk" translatable="false">
    <item>Ask Jeeves</item>
    <item>uk.ask.com</item>
    <item>http://uk.ask.com/favicon.ico</item>
    <item>http://uk.ask.com/web?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ss.uk.ask.com/query?q={searchTerms}&amp;li=ff</item>
  </string-array>
  <string-array name="nate" translatable="false">
    <item>&#xb124;&#xc774;&#xd2b8;&#xb2f7;&#xcef4;</item>
    <item>nate.com</item>
    <item>http://nate.search.empas.com/favicon.ico</item>
    <item>http://nate.search.empas.com/search/all.html?q={searchTerms}</item>
    <item>EUC-KR</item>
    <item></item>
  </string-array>
  <string-array name="uol" translatable="false">
    <item>UOL Busca</item>
    <item>busca.uol.com.br</item>
    <item>http://busca.uol.com.br/favicon.ico</item>
    <item>http://busca.uol.com.br/www/index.html?q={searchTerms}</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="baidu_cn" translatable="false">
    <item>&#x767e;&#x5ea6;</item>
    <item>baidu.com</item>
    <item>http://www.baidu.com/favicon.ico</item>
    <item>http://www.baidu.com/s?wd={searchTerms}</item>
    <item>GB2312</item>
    <item></item>
  </string-array>
  <string-array name="baidu" translatable="false">
    <item>Baidu</item>
    <item>baidu.com</item>
    <item>http://www.baidu.com/favicon.ico</item>
    <item>http://www.baidu.com/s?wd={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_ch" translatable="false">
    <item>Yahoo! Suche</item>
    <item>ch.yahoo.com</item>
    <item>http://ch.search.yahoo.com/favicon.ico</item>
    <item>http://ch.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="bing_nl_BE" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=nl-BE&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="yahoo_cn" translatable="false">
    <item>&#x4e2d;&#x56fd;&#x96c5;&#x864e;</item>
    <item>cn.yahoo.com</item>
    <item>http://sg.search.yahoo.com/favicon.ico</item>
    <item>http://sg.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="onet" translatable="false">
    <item>Onet.pl</item>
    <item>onet.pl</item>
    <item>http://szukaj.onet.pl/favicon.ico</item>
    <item>http://szukaj.onet.pl/query.html?qt={searchTerms}</item>
    <item>ISO-8859-2</item>
    <item></item>
  </string-array>
  <string-array name="ask_es" translatable="false">
    <item>Ask.com Espa&#x00f1;a</item>
    <item>es.ask.com</item>
    <item>http://es.ask.com/favicon.ico</item>
    <item>http://es.ask.com/web?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ss.es.ask.com/query?q={searchTerms}&amp;li=ff</item>
  </string-array>
  <string-array name="bing_cs_CZ" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=cs-CZ&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="altavista_se" translatable="false">
    <item>AltaVista</item>
    <item>se.altavista.com</item>
    <item>http://se.altavista.com/favicon.ico</item>
    <item>http://se.altavista.com/web/results?q={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="mail_ru" translatable="false">
    <item>\@MAIL.RU</item>
    <item>mail.ru</item>
    <item>http://img.go.mail.ru/favicon.ico</item>
    <item>http://go.mail.ru/search?q={searchTerms}</item>
    <item>windows-1251</item>
    <item></item>
  </string-array>
  <string-array name="hispavista" translatable="false">
    <item>hispavista</item>
    <item>hispavista.com</item>
    <item>http://buscar.hispavista.com/favicon.ico</item>
    <item>http://buscar.hispavista.com/?cadena={searchTerms}</item>
    <item>iso-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="bing_zh_CN" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=zh-CN&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="google" translatable="false">
    <item>Google</item>
    <item>google.com</item>
    <item>https://www.google.com/favicon.ico</item>
    <item>https://www.google.com/search?ie={inputEncoding}&amp;source=android-browser&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>https://www.google.com/complete/search?client=android&amp;q={searchTerms}</item>
  </string-array>
  <string-array name="bing_en_NZ" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=en-NZ&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_fr_BE" translatable="false">
    <item>Bing</item>
    <item></item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=fr-BE&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="rednano" translatable="false">
    <item>Rednano</item>
    <item>rednano.sg</item>
    <item>http://rednano.sg/favicon.ico</item>
    <item>http://rednano.sg/sfe/lwi.action?querystring={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="goo" translatable="false">
    <item>goo</item>
    <item>search.goo.ne.jp</item>
    <item>http://goo.ne.jp/favicon.ico</item>
    <item>http://search.goo.ne.jp/web.jsp?MT={searchTerms}&amp;IE={inputEncoding}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="sapo" translatable="false">
    <item>SAPO</item>
    <item>sapo.pt</item>
    <item>http://imgs.sapo.pt/images/sapo.ico</item>
    <item>http://pesquisa.sapo.pt/?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://pesquisa.sapo.pt/livesapo?q={searchTerms}</item>
  </string-array>
  <string-array name="bing_it_IT" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=it-IT&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_es_ES" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=es-ES&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="abcsok" translatable="false">
    <item>ABC S&#x00f8;k</item>
    <item>abcsok.no</item>
    <item>http://abcsok.no/favicon.ico</item>
    <item>http://abcsok.no/index.html?q={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_dk" translatable="false">
    <item>Yahoo! Danmark</item>
    <item>dk.yahoo.com</item>
    <item>http://dk.search.yahoo.com/favicon.ico</item>
    <item>http://dk.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_de" translatable="false">
    <item>Yahoo! Deutschland</item>
    <item>de.yahoo.com</item>
    <item>http://de.search.yahoo.com/favicon.ico</item>
    <item>http://de.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://de-sayt.ff.search.yahoo.com/gossip-de-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="bing_de_AT" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=de-AT&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_pl_PL" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=pl-PL&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="tut" translatable="false">
    <item>TUT.BY</item>
    <item>tut.by</item>
    <item>http://www.tut.by/favicon.ico</item>
    <item>http://search.tut.by/?query={searchTerms}</item>
    <item>windows-1251</item>
    <item></item>
  </string-array>
  <string-array name="spray" translatable="false">
    <item>Spray</item>
    <item>spray.se</item>
    <item>http://www.eniro.se/favicon.ico</item>
    <item>http://www.eniro.se/query?ax=spray&amp;search_word={searchTerms}&amp;what=web</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="wp" translatable="false">
    <item>Wirtualna Polska</item>
    <item>wp.pl</item>
    <item>http://szukaj.wp.pl/favicon.ico</item>
    <item>http://szukaj.wp.pl/szukaj.html?szukaj={searchTerms}</item>
    <item>ISO-8859-2</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_tw" translatable="false">
    <item>Yahoo!&#x5947;&#x6469;</item>
    <item>tw.yahoo.com</item>
    <item>http://tw.search.yahoo.com/favicon.ico</item>
    <item>http://tw.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="atlas_cz" translatable="false">
    <item>Atlas</item>
    <item>atlas.cz</item>
    <item>http://img.atlas.cz/favicon.ico</item>
    <item>http://search.atlas.cz/?q={searchTerms}</item>
    <item>windows-1250</item>
    <item></item>
  </string-array>
  <string-array name="bing_en_GB" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=en-GB&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="yahoo_es" translatable="false">
    <item>Yahoo! Espa&#x00f1;a</item>
    <item>es.yahoo.com</item>
    <item>http://es.search.yahoo.com/favicon.ico</item>
    <item>http://es.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://es-sayt.ff.search.yahoo.com/gossip-es-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="libero" translatable="false">
    <item>Libero</item>
    <item>libero.it</item>
    <item>http://arianna.libero.it/favicon.ico</item>
    <item>http://arianna.libero.it/search/abin/integrata.cgi?query={searchTerms}</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="bing_sv_SE" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=sv-SE&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="yahoo_nz" translatable="false">
    <item>Yahoo!Xtra</item>
    <item>nz.yahoo.com</item>
    <item>http://nz.search.yahoo.com/favicon.ico</item>
    <item>http://nz.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://aue-sayt.ff.search.yahoo.com/gossip-nz-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="terra_es" translatable="false">
    <item>Terra</item>
    <item>terra.es</item>
    <item>http://buscador.terra.es/favicon.ico</item>
    <item>http://buscador.terra.es/Default.aspx?query={searchTerms}&amp;source=Search</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_nl" translatable="false">
    <item>Yahoo! Nederland</item>
    <item>nl.yahoo.com</item>
    <item>http://nl.search.yahoo.com/favicon.ico</item>
    <item>http://nl.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_no" translatable="false">
    <item>Yahoo! Norge</item>
    <item>no.yahoo.com</item>
    <item>http://no.search.yahoo.com/favicon.ico</item>
    <item>http://no.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="daum" translatable="false">
    <item>Daum</item>
    <item>daum.net</item>
    <item>http://search.daum.net/favicon.ico</item>
    <item>http://search.daum.net/search?q={searchTerms}</item>
    <item>EUC-KR</item>
    <item>http://sug.search.daum.net/search_nsuggest?mod=fxjson&amp;q={searchTerms}</item>
  </string-array>
  <string-array name="yahoo_fr" translatable="false">
    <item>Yahoo! France</item>
    <item>fr.yahoo.com</item>
    <item>http://fr.search.yahoo.com/favicon.ico</item>
    <item>http://fr.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://fr-sayt.ff.search.yahoo.com/gossip-fr-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="ask_nl" translatable="false">
    <item>Ask.com Nederland</item>
    <item>nl.ask.com</item>
    <item>http://nl.ask.com/favicon.ico</item>
    <item>http://nl.ask.com/web?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ss.nl.ask.com/query?q={searchTerms}&amp;li=ff</item>
  </string-array>
  <string-array name="seznam" translatable="false">
    <item>Seznam</item>
    <item>seznam.cz</item>
    <item>http://1.im.cz/szn/img/favicon.ico</item>
    <item>http://search.seznam.cz/?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://suggest.fulltext.seznam.cz/?dict=fulltext_ff&amp;phrase={searchTerms}&amp;encoding={inputEncoding}&amp;response_encoding=utf-8</item>
  </string-array>
  <string-array name="centrum_cz" translatable="false">
    <item>Centrum.cz</item>
    <item>centrum.cz</item>
    <item>http://img.centrum.cz/6/vy2/o/favicon.ico</item>
    <item>http://search.centrum.cz/index.php?charset={inputEncoding}&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="eniro_se" translatable="false">
    <item>Eniro</item>
    <item>eniro.se</item>
    <item>http://eniro.se/favicon.ico</item>
    <item>http://eniro.se/query?search_word={searchTerms}&amp;what=web_local</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="kvasir" translatable="false">
    <item>Kvasir</item>
    <item>kvasir.no</item>
    <item>http://www.kvasir.no/img/favicon.ico</item>
    <item>http://www.kvasir.no/nettsok/searchResult.html?searchExpr={searchTerms}</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="yahoo" translatable="false">
    <item>Yahoo!</item>
    <item>yahoo.com</item>
    <item>http://search.yahoo.com/favicon.ico</item>
    <item>http://search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ff.search.yahoo.com/gossip?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="bing_en_IE" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=en-IE&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_pt_PT" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=pt-PT&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_de_CH" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=de-CH&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_nl_NL" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=nl-NL&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_fr_CH" translatable="false">
    <item>Bing</item>
    <item></item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=fr-CH&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_zh_TW" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=zh-TW&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_ru_RU" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=ru-RU&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_en_AU" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=en-AU&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing_da_DK" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=da-DK&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="ask_it" translatable="false">
    <item>Ask.com Italia</item>
    <item>it.ask.com</item>
    <item>http://it.ask.com/favicon.ico</item>
    <item>http://it.ask.com/web?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ss.it.ask.com/query?q={searchTerms}&amp;li=ff</item>
  </string-array>
  <string-array name="yandex_ru" translatable="false">
    <item>&#x042f;&#x043d;&#x0434;&#x0435;&#x043a;&#x0441;</item>
    <item>yandex.ru</item>
    <item>http://yandex.ru/favicon.ico</item>
    <item>http://yandex.ru/yandsearch?text={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://suggest.yandex.net/suggest-ff.cgi?part={searchTerms}</item>
  </string-array>
  <string-array name="bing_ja_JP" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=ja-JP&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="yahoo_kr" translatable="false">
    <item>&#xc57c;&#xd6c4;! &#xcf54;&#xb9ac;&#xc544;</item>
    <item>kr.yahoo.com</item>
    <item>http://kr.search.yahoo.com/favicon.ico</item>
    <item>http://kr.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://kr.atc.search.yahoo.com/atcx.php?property=main&amp;ot=fxjson&amp;ei=utf8&amp;eo=utf8&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="ask_de" translatable="false">
    <item>Ask.com Deutschland</item>
    <item>de.ask.com</item>
    <item>http://de.ask.com/favicon.ico</item>
    <item>http://de.ask.com/web?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ss.de.ask.com/query?q={searchTerms}&amp;li=ff</item>
  </string-array>
  <string-array name="yahoo_hk" translatable="false">
    <item>Yahoo! Hong Kong</item>
    <item>hk.yahoo.com</item>
    <item>http://hk.search.yahoo.com/favicon.ico</item>
    <item>http://hk.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="bing_fr_FR" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=fr-FR&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="in" translatable="false">
    <item>in.gr</item>
    <item>in.gr</item>
    <item>http://www.in.gr/favicon.ico</item>
    <item>http://find.in.gr/?qs={searchTerms}</item>
    <item>ISO-8859-7</item>
    <item></item>
  </string-array>
  <string-array name="bing_nb_NO" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=nb-NO&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="yahoo_sg" translatable="false">
    <item>Yahoo! Singapore</item>
    <item>sg.yahoo.com</item>
    <item>http://sg.search.yahoo.com/favicon.ico</item>
    <item>http://sg.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://sg-sayt.ff.search.yahoo.com/gossip-sg-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="yahoo_se" translatable="false">
    <item>Yahoo! Sverige</item>
    <item>se.yahoo.com</item>
    <item>http://se.search.yahoo.com/favicon.ico</item>
    <item>http://se.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="bing_de_DE" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=de-DE&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="search_de_CH" translatable="false">
    <item>search.ch</item>
    <item>search.ch</item>
    <item>http://www.search.ch/favicon.ico</item>
    <item>http://www.search.ch/index.de.html?q={searchTerms}</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="mynet" translatable="false">
    <item>MYNET</item>
    <item>mynet.com</item>
    <item>http://img.mynet.com/mynetfavori.ico</item>
    <item>http://arama.mynet.com/search.aspx?q={searchTerms}&amp;pg=q</item>
    <item>windows-1254</item>
    <item></item>
  </string-array>
  <string-array name="search_fr_CH" translatable="false">
    <item>search.ch</item>
    <item></item>
    <item>http://www.search.ch/favicon.ico</item>
    <item>http://www.search.ch/index.fr.html?q={searchTerms}</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="virgilio" translatable="false">
    <item>Virgilio</item>
    <item>virgilio.it</item>
    <item>http://ricerca.alice.it/favicon.ico</item>
    <item>http://ricerca.alice.it/ricerca?qs={searchTerms}</item>
    <item>ISO-8859-1</item>
    <item></item>
  </string-array>
  <string-array name="bing_en_SG" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=en-SG&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="yahoo_it" translatable="false">
    <item>Yahoo! Italia</item>
    <item>it.yahoo.com</item>
    <item>http://it.search.yahoo.com/favicon.ico</item>
    <item>http://it.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://it-sayt.ff.search.yahoo.com/gossip-it-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="yahoo_at" translatable="false">
    <item>Yahoo! Suche</item>
    <item>at.yahoo.com</item>
    <item>http://at.search.yahoo.com/favicon.ico</item>
    <item>http://at.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="yahoo_au" translatable="false">
    <item>Yahoo!7</item>
    <item>au.yahoo.com</item>
    <item>http://au.search.yahoo.com/favicon.ico</item>
    <item>http://au.search.yahoo.com/search?ei={inputEncoding}&amp;fr=crmas&amp;p={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://aue-sayt.ff.search.yahoo.com/gossip-au-sayt?output=fxjson&amp;command={searchTerms}</item>
  </string-array>
  <string-array name="bing_pt_BR" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=pt-BR&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="bing" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  <string-array name="netsprint" translatable="false">
    <item>NetSprint</item>
    <item>netsprint.pl</item>
    <item>http://netsprint.pl/favicon.ico</item>
    <item>http://www.netsprint.pl/serwis/search?q={searchTerms}</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
  <string-array name="naver" translatable="false">
    <item>&#xb124;&#xc774;&#xbc84;</item>
    <item>naver.com</item>
    <item>http://search.naver.com/favicon.ico</item>
    <item>http://search.naver.com/search.naver?ie={inputEncoding}&amp;query={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://ac.search.naver.com/autocompl?m=s&amp;ie={inputEncoding}&amp;oe=utf-8&amp;q={searchTerms}</item>
  </string-array>
  <string-array name="bing_en_ZA" translatable="false">
    <item>Bing</item>
    <item>bing.com</item>
    <item>http://www.bing.com/s/wlflag.ico</item>
    <item>http://www.bing.com/search?setmkt=en-ZA&amp;q={searchTerms}</item>
    <item>UTF-8</item>
    <item>http://api.bing.com/osjson.aspx?query={searchTerms}&amp;language={language}</item>
  </string-array>
  
<!-- add for CMCC 139 search -->
  <string-array name="cmcc_cn" translatable="false">
    <item>139&#x641C;&#x7D22;</item>
    <item>s.139.com</item>
    <item>http://s.139.com/favicon.ico</item>
    <item>http://s.139.com/search.do?q={searchTerms}&amp;category=downloadable|web|browseable&amp;tid=2123,2124,2125,2126&amp;fr=portalcustom2</item>
    <item>GB2312</item>
    <item></item>
  </string-array>

  <string-array name="cmcc" translatable="false">
    <item>139 Search</item>
    <item>s.139.com</item>
    <item>http://s.139.com/favicon.ico</item>
    <item>http://s.139.com/search.do?q={searchTerms}&amp;category=downloadable|web|browseable&amp;tid=2123,2124,2125,2126&amp;fr=portalcustom2</item>
    <item>UTF-8</item>
    <item></item>
  </string-array>
<!-- end add  -->

  <!-- Custom search engines used from overlays -->
  <string-array name="custom_search_engine_1" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_2" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_3" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_4" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_5" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_6" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_7" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_8" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_9" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_10" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_11" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_12" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_13" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_14" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_15" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_16" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_17" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_18" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_19" translatable="false">
  </string-array>
  <string-array name="custom_search_engine_20" translatable="false">
  </string-array>
</resources>
View Code

 

 

 

donottranslate-search_engines.xml中的search_engines配置,注意每种语言values下都有一个donottranslate-search_engines  都要配置,否则切换语言会导致引擎列表不一样

donottranslate-search_engines.xml
<
resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <string-array name="search_engines" translatable="false"> <item>cmcc</item> <item>baidu</item> <item>yahoo</item> <item>bing</item> </string-array> <string name="default_search_engine_value">baidu</string> </resources>

SearchEngines.getSearchEngineInfos(context)将search_engines配置的item拿到,然后去all_search_engines.xml中匹配,获取对应的SearchEngineInfo,然后显示引擎列表。

 public SearchEngineInfo(Context context, String name) throws IllegalArgumentException {
        mName = name;

        final Resources res = context.getResources();
        String packageName = R.class.getPackage().getName();
        int id_data = res.getIdentifier(name, "array", packageName);
        if(id_data == 0) {
            id_data = res.getIdentifier(name, "array", context.getPackageName());
        }
        if (id_data == 0) {
            throw new IllegalArgumentException("No resources found for " + name);
        }
        mSearchEngineData = res.getStringArray(id_data);

        if (mSearchEngineData == null) {
            throw new IllegalArgumentException("No data found for " + name);
        }
        if (mSearchEngineData.length != NUM_FIELDS) {
                throw new IllegalArgumentException(
                        name + " has invalid number of fields - " + mSearchEngineData.length);
        }
        if (TextUtils.isEmpty(mSearchEngineData[FIELD_SEARCH_URI])) {
            throw new IllegalArgumentException(name + " has an empty search URI");
        }

        // Add the current language/country information to the URIs.
        Locale locale = context.getResources().getConfiguration().locale;
        StringBuilder language = new StringBuilder(locale.getLanguage());
        if (!TextUtils.isEmpty(locale.getCountry())) {
            language.append('-');
            language.append(locale.getCountry());
        }

        String language_str = language.toString();
        mSearchEngineData[FIELD_SEARCH_URI] =
                mSearchEngineData[FIELD_SEARCH_URI].replace(PARAMETER_LANGUAGE, language_str);
        mSearchEngineData[FIELD_SUGGEST_URI] =
                mSearchEngineData[FIELD_SUGGEST_URI].replace(PARAMETER_LANGUAGE, language_str);

        // Default to UTF-8 if not specified.
        String enc = mSearchEngineData[FIELD_ENCODING];
        if (TextUtils.isEmpty(enc)) {
            enc = "UTF-8";
            mSearchEngineData[FIELD_ENCODING] = enc;
        }

        // Add the input encoding method to the URI.
        mSearchEngineData[FIELD_SEARCH_URI] =
                mSearchEngineData[FIELD_SEARCH_URI].replace(PARAMETER_INPUT_ENCODING, enc);
        mSearchEngineData[FIELD_SUGGEST_URI] =
                mSearchEngineData[FIELD_SUGGEST_URI].replace(PARAMETER_INPUT_ENCODING, enc);
    }
View Code

 

posted on 2015-04-29 18:59  ^-^antoon^-^  阅读(647)  评论(0编辑  收藏  举报