• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.quicksearchbox.preferences;
17 
18 import com.android.quicksearchbox.QsbApplication;
19 import com.android.quicksearchbox.R;
20 
21 import android.preference.PreferenceActivity;
22 import android.util.Log;
23 import android.view.Menu;
24 
25 import java.util.List;
26 
27 /**
28  * Activity for setting global search preferences.
29  */
30 public class SearchSettingsActivity extends PreferenceActivity {
31     private static final String TAG = "QSB.SearchSettingsActivity";
32     private static final boolean DBG = false;
33 
34     private static final String CLEAR_SHORTCUTS_FRAGMENT = DeviceSearchFragment.class.getName();
35 
36     private static final String ACTIVITY_HELP_CONTEXT = "settings";
37 
38     /**
39      * Populate the activity with the top-level headers.
40      */
41     @Override
onBuildHeaders(List<Header> target)42     public void onBuildHeaders(List<Header> target) {
43         loadHeadersFromResource(R.xml.preferences_headers, target);
44         onHeadersBuilt(target);
45     }
46 
47     @Override
onCreateOptionsMenu(Menu menu)48     public boolean onCreateOptionsMenu(Menu menu) {
49         super.onCreateOptionsMenu(menu);
50         getQsbApplication().getHelp().addHelpMenuItem(menu, ACTIVITY_HELP_CONTEXT, true);
51         return true;
52     }
53 
getQsbApplication()54     protected QsbApplication getQsbApplication() {
55         return QsbApplication.get(this);
56     }
57 
58     /**
59      * Get the name of the fragment that contains only a 'clear shortcuts' preference, and hence
60      * can be removed if zero-query shortcuts are disabled. Returns null if no such fragment exists.
61      */
getShortcutsOnlyFragment()62     protected String getShortcutsOnlyFragment() {
63         return CLEAR_SHORTCUTS_FRAGMENT;
64     }
65 
onHeadersBuilt(List<Header> target)66     protected void onHeadersBuilt(List<Header> target) {
67         String shortcutsFragment = getShortcutsOnlyFragment();
68         if (shortcutsFragment == null) return;
69         if (DBG) Log.d(TAG, "onHeadersBuilt shortcutsFragment=" + shortcutsFragment);
70         if (!QsbApplication.get(this).getConfig().showShortcutsForZeroQuery()) {
71             // remove 'clear shortcuts'
72             for (int i = 0; i < target.size(); ++i) {
73                 String fragment = target.get(i).fragment;
74                 if (DBG) Log.d(TAG, "fragment " + i + ": " + fragment);
75                 if (shortcutsFragment.equals(fragment)) {
76                     target.remove(i);
77                     break;
78                 }
79             }
80         }
81     }
82 
83 }
84