Home | History | Annotate | Download | only in search
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.browser.search;
     17 
     18 import com.android.browser.R;
     19 
     20 import android.app.SearchManager;
     21 import android.content.ComponentName;
     22 import android.content.Context;
     23 import android.content.pm.ActivityInfo;
     24 import android.content.pm.PackageManager;
     25 import android.content.res.Resources;
     26 import android.preference.ListPreference;
     27 import android.util.AttributeSet;
     28 import android.util.Log;
     29 
     30 import java.util.ArrayList;
     31 
     32 class SearchEnginePreference extends ListPreference {
     33 
     34     private static final String TAG = "SearchEnginePreference";
     35 
     36     public SearchEnginePreference(Context context, AttributeSet attrs) {
     37         super(context, attrs);
     38 
     39         ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>();
     40         ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
     41 
     42         SearchEngine defaultSearchEngine = SearchEngines.getDefaultSearchEngine(context);
     43         String defaultSearchEngineName = null;
     44         if (defaultSearchEngine != null) {
     45             defaultSearchEngineName = defaultSearchEngine.getName();
     46             entryValues.add(defaultSearchEngineName);
     47             entries.add(defaultSearchEngine.getLabel());
     48         }
     49         for (SearchEngineInfo searchEngineInfo : SearchEngines.getSearchEngineInfos(context)) {
     50             String name = searchEngineInfo.getName();
     51             // Skip entry with same name as default provider
     52             if (!name.equals(defaultSearchEngineName)) {
     53                 entryValues.add(name);
     54                 entries.add(searchEngineInfo.getLabel());
     55             }
     56         }
     57 
     58         setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
     59         setEntries(entries.toArray(new CharSequence[entries.size()]));
     60     }
     61 
     62 }
     63