Home | History | Annotate | Download | only in google
      1 /*
      2  * Copyright (C) 2009 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.quicksearchbox.google;
     18 
     19 import com.android.quicksearchbox.R;
     20 import com.android.quicksearchbox.SearchSettings;
     21 
     22 import android.os.Bundle;
     23 import android.preference.CheckBoxPreference;
     24 import android.preference.Preference;
     25 import android.preference.PreferenceActivity;
     26 import android.preference.PreferenceScreen;
     27 import android.preference.Preference.OnPreferenceClickListener;
     28 
     29 /**
     30  * Activity for setting Google search preferences.
     31  */
     32 public class GoogleSettings extends PreferenceActivity implements OnPreferenceClickListener {
     33 
     34     private static final String SHOW_WEB_SUGGESTIONS_PREF = "show_web_suggestions";
     35 
     36     private CheckBoxPreference mShowWebSuggestionsPreference;
     37 
     38     @Override
     39     protected void onCreate(Bundle savedInstanceState) {
     40         super.onCreate(savedInstanceState);
     41         addPreferencesFromResource(R.xml.google_preferences);
     42         mShowWebSuggestionsPreference = (CheckBoxPreference)
     43                 findPreference(SHOW_WEB_SUGGESTIONS_PREF);
     44         mShowWebSuggestionsPreference.setOnPreferenceClickListener(this);
     45         updateShowWebSuggestionsPreference();
     46     }
     47 
     48     /**
     49      * Updates the "show web suggestions" preference from the value in system settings.
     50      */
     51     private void updateShowWebSuggestionsPreference() {
     52         boolean showWebSuggestions = SearchSettings.getShowWebSuggestions(this);
     53         mShowWebSuggestionsPreference.setChecked(showWebSuggestions);
     54     }
     55 
     56     /**
     57      * Stores the "show web suggestions" preference to the system settings.
     58      */
     59     private void storeShowWebSuggestionsPreference() {
     60         boolean showWebSuggestions = mShowWebSuggestionsPreference.isChecked();
     61         SearchSettings.setShowWebSuggestions(this, showWebSuggestions);
     62     }
     63 
     64     public boolean onPreferenceClick(Preference preference) {
     65         if (preference == mShowWebSuggestionsPreference) {
     66             storeShowWebSuggestionsPreference();
     67             return true;
     68         }
     69         return false;
     70     }
     71 
     72 }
     73