Home | History | Annotate | Download | only in preferences
      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 
     17 package com.android.browser.preferences;
     18 
     19 import android.os.Bundle;
     20 import android.preference.Preference;
     21 import android.preference.PreferenceFragment;
     22 
     23 import com.android.browser.BrowserSettings;
     24 import com.android.browser.PreferenceKeys;
     25 import com.android.browser.R;
     26 import com.android.browser.search.SearchEngine;
     27 
     28 public class LabPreferencesFragment extends PreferenceFragment {
     29     private BrowserSettings mBrowserSettings;
     30     private Preference useInstantPref;
     31 
     32     @Override
     33     public void onCreate(Bundle savedInstanceState) {
     34         super.onCreate(savedInstanceState);
     35 
     36         mBrowserSettings = BrowserSettings.getInstance();
     37 
     38         // Load the XML preferences file
     39         addPreferencesFromResource(R.xml.lab_preferences);
     40         useInstantPref = findPreference(PreferenceKeys.PREF_USE_INSTANT_SEARCH);
     41     }
     42 
     43     @Override
     44     public void onResume() {
     45         super.onResume();
     46         if (useInstantPref != null) {
     47             useInstantPref.setEnabled(false);
     48 
     49             // Enable the "use instant" preference only if the selected
     50             // search engine is google.
     51             if (mBrowserSettings.getSearchEngine() != null) {
     52                 final String currentName = mBrowserSettings.getSearchEngine().getName();
     53                 if (SearchEngine.GOOGLE.equals(currentName)) {
     54                     useInstantPref.setEnabled(true);
     55                 }
     56             }
     57         }
     58     }
     59 
     60 }
     61