Add dynamic Preferences indexing (part 2)

- change the Index SQL model. Add a new "enabled" column.
- use that column for issuing a more restrictive search query
- change the SearchIndexProvider API to pass the "enable" state
- apply it to Bluetooth settings
- refactor the list of indexable resources (SearchIndexableResources)

Change-Id: Ic900fb27cb12a285a80d953aa1aa88f0070cd986
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
new file mode 100644
index 0000000..c65e50c
--- /dev/null
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.search;
+
+import android.provider.SearchIndexableResource;
+import com.android.settings.DateTimeSettings;
+import com.android.settings.DevelopmentSettings;
+import com.android.settings.DeviceInfoSettings;
+import com.android.settings.DisplaySettings;
+import com.android.settings.HomeSettings;
+import com.android.settings.PrivacySettings;
+import com.android.settings.R;
+import com.android.settings.SecuritySettings;
+import com.android.settings.SoundSettings;
+import com.android.settings.WallpaperTypeSettings;
+import com.android.settings.WirelessSettings;
+import com.android.settings.accessibility.AccessibilitySettings;
+import com.android.settings.bluetooth.BluetoothSettings;
+import com.android.settings.deviceinfo.Memory;
+import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.inputmethod.InputMethodAndLanguageSettings;
+import com.android.settings.location.LocationSettings;
+import com.android.settings.net.DataUsageMeteredSettings;
+import com.android.settings.print.PrintSettingsFragment;
+import com.android.settings.users.UserSettings;
+import com.android.settings.wifi.WifiSettings;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+public final class SearchIndexableResources {
+
+    private static int NO_DATA_RES_ID = 0;
+
+    private static HashMap<String, SearchIndexableResource> sResMap =
+            new HashMap<String, SearchIndexableResource>();
+
+
+    static {
+        sResMap.put(WifiSettings.class.getName(),
+                new SearchIndexableResource(1,
+                        NO_DATA_RES_ID,
+                        WifiSettings.class.getName(),
+                        R.drawable.ic_settings_wireless));
+
+        sResMap.put(BluetoothSettings.class.getName(),
+                new SearchIndexableResource(2,
+                        NO_DATA_RES_ID,
+                        BluetoothSettings.class.getName(),
+                        R.drawable.ic_settings_bluetooth2));
+
+        sResMap.put(DataUsageMeteredSettings.class.getName(),
+                new SearchIndexableResource(3, R.xml.data_usage_metered_prefs,
+                        DataUsageMeteredSettings.class.getName(),
+                        R.drawable.ic_settings_data_usage));
+
+        sResMap.put(WirelessSettings.class.getName(),
+                new SearchIndexableResource(4, R.xml.wireless_settings,
+                        WirelessSettings.class.getName(),
+                        R.drawable.empty_icon));
+
+        sResMap.put(HomeSettings.class.getName(),
+                new SearchIndexableResource(5, R.xml.home_selection,
+                        HomeSettings.class.getName(),
+                        R.drawable.ic_settings_home));
+
+        sResMap.put(SoundSettings.class.getName(),
+                new SearchIndexableResource(6, R.xml.sound_settings,
+                        SoundSettings.class.getName(),
+                        R.drawable.ic_settings_sound));
+
+        sResMap.put(DisplaySettings.class.getName(),
+                new SearchIndexableResource(7, R.xml.display_settings,
+                        DisplaySettings.class.getName(),
+                        R.drawable.ic_settings_display));
+
+        sResMap.put(WallpaperTypeSettings.class.getName(),
+                new SearchIndexableResource(7, NO_DATA_RES_ID,
+                        WallpaperTypeSettings.class.getName(),
+                        R.drawable.ic_settings_display));
+
+        sResMap.put(Memory.class.getName(),
+                new SearchIndexableResource(8, R.xml.device_info_memory,
+                        Memory.class.getName(),
+                        R.drawable.ic_settings_storage));
+
+        sResMap.put(PowerUsageSummary.class.getName(),
+                new SearchIndexableResource(9, R.xml.power_usage_summary,
+                        PowerUsageSummary.class.getName(),
+                        R.drawable.ic_settings_battery));
+
+        sResMap.put(UserSettings.class.getName(),
+                new SearchIndexableResource(10, R.xml.user_settings,
+                        UserSettings.class.getName(),
+                        R.drawable.ic_settings_multiuser));
+
+        sResMap.put(LocationSettings.class.getName(),
+                new SearchIndexableResource(11, R.xml.location_settings,
+                        LocationSettings.class.getName(),
+                        R.drawable.ic_settings_location));
+
+        sResMap.put(SecuritySettings.class.getName(),
+                new SearchIndexableResource(12, R.xml.security_settings,
+                        SecuritySettings.class.getName(),
+                        R.drawable.ic_settings_security));
+
+        sResMap.put(InputMethodAndLanguageSettings.class.getName(),
+                new SearchIndexableResource(13, R.xml.language_settings,
+                        InputMethodAndLanguageSettings.class.getName(),
+                        R.drawable.ic_settings_language));
+
+        sResMap.put(PrivacySettings.class.getName(),
+                new SearchIndexableResource(14, R.xml.privacy_settings,
+                        PrivacySettings.class.getName(),
+                        R.drawable.ic_settings_backup));
+
+        sResMap.put(DateTimeSettings.class.getName(),
+                new SearchIndexableResource(15, R.xml.date_time_prefs,
+                        DateTimeSettings.class.getName(),
+                        R.drawable.ic_settings_date_time));
+
+        sResMap.put(AccessibilitySettings.class.getName(),
+                new SearchIndexableResource(16, R.xml.accessibility_settings,
+                        AccessibilitySettings.class.getName(),
+                        R.drawable.ic_settings_accessibility));
+
+        sResMap.put(PrintSettingsFragment.class.getName(),
+                new SearchIndexableResource(17, R.xml.print_settings,
+                        PrintSettingsFragment.class.getName(),
+                        com.android.internal.R.drawable.ic_print));
+
+        sResMap.put(DevelopmentSettings.class.getName(),
+                new SearchIndexableResource(18, R.xml.development_prefs,
+                        DevelopmentSettings.class.getName(),
+                        R.drawable.ic_settings_development));
+
+        sResMap.put(DeviceInfoSettings.class.getName(),
+                new SearchIndexableResource(19, R.xml.device_info_settings,
+                        DeviceInfoSettings.class.getName(),
+                        R.drawable.ic_settings_about));
+    }
+
+    private SearchIndexableResources() {
+    }
+
+    public static int size() {
+        return sResMap.size();
+    }
+
+    public static SearchIndexableResource getResourceByName(String className) {
+        return sResMap.get(className);
+    }
+
+    public static Collection<SearchIndexableResource> values() {
+        return sResMap.values();
+    }
+}