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