Loading src/com/android/settings/bluetooth/BluetoothSettings.java +3 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem private final IntentFilter mIntentFilter; // For Search private static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth"; // accessed from inner class (not private to avoid thunks) FooterPreference mMyDevicePreference; Loading Loading @@ -567,6 +569,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem SearchIndexableRaw data = new SearchIndexableRaw(context); data.title = res.getString(R.string.bluetooth_settings); data.screenTitle = res.getString(R.string.bluetooth_settings); data.key = DATA_KEY_REFERENCE; result.add(data); // Add cached paired BT devices Loading src/com/android/settings/search2/CursorToSearchResultConverter.java +39 −8 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.android.settings.Utils; import com.android.settings.dashboard.SiteMapManager; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; Loading Loading @@ -77,6 +78,22 @@ class CursorToSearchResultConverter { private final Set<String> mKeys; private final int LONG_TITLE_LENGTH = 20; private static final String[] whiteList = { "main_toggle_wifi", "main_toggle_bluetooth", "toggle_airplane", "tether_settings", "battery_saver", "toggle_nfc", "restrict_background", "data_usage_enable", "button_roaming_key", }; private static final Set<String> prioritySettings = new HashSet(Arrays.asList(whiteList)); public CursorToSearchResultConverter(Context context, String queryText) { mContext = context; mKeys = new HashSet<>(); Loading Loading @@ -135,7 +152,7 @@ class CursorToSearchResultConverter { } final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor); final int rank = getRank(breadcrumbs, baseRank); final int rank = getRank(title, breadcrumbs, baseRank, key); final SearchResult.Builder builder = new SearchResult.Builder(); builder.addTitle(title) Loading Loading @@ -225,18 +242,32 @@ class CursorToSearchResultConverter { } /** Uses the breadcrumbs to determine the offset to the base rank. * There are two checks * A) If the query matches the highest level menu title * B) If the query matches a subsequent menu title * There are three checks * A) If the result is prioritized and the highest base level * B) If the query matches the highest level menu title * C) If the query matches a subsequent menu title * D) Is the title longer than 20 * * If the query matches A and B, the offset is 0. * If the query matches A only, the offset is 1. * If the query matches neither A nor B, the offset is 2. * If the query matches A, set it to TOP_RANK * If the query matches B and C, the offset is 0. * If the query matches C only, the offset is 1. * If the query matches neither B nor C, the offset is 2. * If the query matches D, the offset is 2 * @param title of the result. * @param crumbs from the Information Architecture * @param baseRank of the result. Lower if it's a better result. * @return */ private int getRank(List<String> crumbs, int baseRank) { private int getRank(String title, List<String> crumbs, int baseRank, String key) { // The result can only be prioritized if it is a top ranked result. if (prioritySettings.contains(key) && baseRank < DatabaseResultLoader.BASE_RANKS[1]) { return SearchResult.TOP_RANK; } if (title.length() > LONG_TITLE_LENGTH) { return baseRank + 2; } return baseRank; } } src/com/android/settings/search2/DatabaseResultLoader.java +1 −1 Original line number Diff line number Diff line Loading @@ -97,7 +97,7 @@ public class DatabaseResultLoader extends AsyncLoader<List<? extends SearchResul * If the query only matches keywords or entries, the best rank it can be is 9 * */ private static final int[] BASE_RANKS = {1, 3, 7, 9}; public static final int[] BASE_RANKS = {1, 3, 7, 9}; private final String mQueryText; private final Context mContext; Loading src/com/android/settings/search2/SearchResult.java +7 −2 Original line number Diff line number Diff line Loading @@ -27,10 +27,15 @@ import java.util.Objects; public class SearchResult implements Comparable<SearchResult> { /** * Defines the max rank for a search result to be considered as ranked. Results with ranks * Defines the lowest rank for a search result to be considered as ranked. Results with ranks * higher than this have no guarantee for sorting order. */ public static final int MAX_RANK = 10; public static final int BOTTOM_RANK = 10; /** * Defines the highest rank for a search result. Used for special search results only. */ public static final int TOP_RANK = 0; /** * The title of the result and main text displayed. Loading src/com/android/settings/search2/SearchResultsAdapter.java +4 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import static com.android.settings.search2.SearchResult.MAX_RANK; import static com.android.settings.search2.SearchResult.TOP_RANK; import static com.android.settings.search2.SearchResult.BOTTOM_RANK; public class SearchResultsAdapter extends Adapter<SearchViewHolder> { Loading Loading @@ -117,9 +118,9 @@ public class SearchResultsAdapter extends Adapter<SearchViewHolder> { int dbIndex = 0; int appIndex = 0; int rank = 1; int rank = TOP_RANK; while (rank <= MAX_RANK) { while (rank <= BOTTOM_RANK) { while ((dbIndex < dbSize) && (databaseResults.get(dbIndex).rank == rank)) { results.add(databaseResults.get(dbIndex++)); } Loading Loading
src/com/android/settings/bluetooth/BluetoothSettings.java +3 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,8 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem private final IntentFilter mIntentFilter; // For Search private static final String DATA_KEY_REFERENCE = "main_toggle_bluetooth"; // accessed from inner class (not private to avoid thunks) FooterPreference mMyDevicePreference; Loading Loading @@ -567,6 +569,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem SearchIndexableRaw data = new SearchIndexableRaw(context); data.title = res.getString(R.string.bluetooth_settings); data.screenTitle = res.getString(R.string.bluetooth_settings); data.key = DATA_KEY_REFERENCE; result.add(data); // Add cached paired BT devices Loading
src/com/android/settings/search2/CursorToSearchResultConverter.java +39 −8 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import com.android.settings.Utils; import com.android.settings.dashboard.SiteMapManager; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; Loading Loading @@ -77,6 +78,22 @@ class CursorToSearchResultConverter { private final Set<String> mKeys; private final int LONG_TITLE_LENGTH = 20; private static final String[] whiteList = { "main_toggle_wifi", "main_toggle_bluetooth", "toggle_airplane", "tether_settings", "battery_saver", "toggle_nfc", "restrict_background", "data_usage_enable", "button_roaming_key", }; private static final Set<String> prioritySettings = new HashSet(Arrays.asList(whiteList)); public CursorToSearchResultConverter(Context context, String queryText) { mContext = context; mKeys = new HashSet<>(); Loading Loading @@ -135,7 +152,7 @@ class CursorToSearchResultConverter { } final List<String> breadcrumbs = getBreadcrumbs(sitemapManager, cursor); final int rank = getRank(breadcrumbs, baseRank); final int rank = getRank(title, breadcrumbs, baseRank, key); final SearchResult.Builder builder = new SearchResult.Builder(); builder.addTitle(title) Loading Loading @@ -225,18 +242,32 @@ class CursorToSearchResultConverter { } /** Uses the breadcrumbs to determine the offset to the base rank. * There are two checks * A) If the query matches the highest level menu title * B) If the query matches a subsequent menu title * There are three checks * A) If the result is prioritized and the highest base level * B) If the query matches the highest level menu title * C) If the query matches a subsequent menu title * D) Is the title longer than 20 * * If the query matches A and B, the offset is 0. * If the query matches A only, the offset is 1. * If the query matches neither A nor B, the offset is 2. * If the query matches A, set it to TOP_RANK * If the query matches B and C, the offset is 0. * If the query matches C only, the offset is 1. * If the query matches neither B nor C, the offset is 2. * If the query matches D, the offset is 2 * @param title of the result. * @param crumbs from the Information Architecture * @param baseRank of the result. Lower if it's a better result. * @return */ private int getRank(List<String> crumbs, int baseRank) { private int getRank(String title, List<String> crumbs, int baseRank, String key) { // The result can only be prioritized if it is a top ranked result. if (prioritySettings.contains(key) && baseRank < DatabaseResultLoader.BASE_RANKS[1]) { return SearchResult.TOP_RANK; } if (title.length() > LONG_TITLE_LENGTH) { return baseRank + 2; } return baseRank; } }
src/com/android/settings/search2/DatabaseResultLoader.java +1 −1 Original line number Diff line number Diff line Loading @@ -97,7 +97,7 @@ public class DatabaseResultLoader extends AsyncLoader<List<? extends SearchResul * If the query only matches keywords or entries, the best rank it can be is 9 * */ private static final int[] BASE_RANKS = {1, 3, 7, 9}; public static final int[] BASE_RANKS = {1, 3, 7, 9}; private final String mQueryText; private final Context mContext; Loading
src/com/android/settings/search2/SearchResult.java +7 −2 Original line number Diff line number Diff line Loading @@ -27,10 +27,15 @@ import java.util.Objects; public class SearchResult implements Comparable<SearchResult> { /** * Defines the max rank for a search result to be considered as ranked. Results with ranks * Defines the lowest rank for a search result to be considered as ranked. Results with ranks * higher than this have no guarantee for sorting order. */ public static final int MAX_RANK = 10; public static final int BOTTOM_RANK = 10; /** * Defines the highest rank for a search result. Used for special search results only. */ public static final int TOP_RANK = 0; /** * The title of the result and main text displayed. Loading
src/com/android/settings/search2/SearchResultsAdapter.java +4 −3 Original line number Diff line number Diff line Loading @@ -32,7 +32,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import static com.android.settings.search2.SearchResult.MAX_RANK; import static com.android.settings.search2.SearchResult.TOP_RANK; import static com.android.settings.search2.SearchResult.BOTTOM_RANK; public class SearchResultsAdapter extends Adapter<SearchViewHolder> { Loading Loading @@ -117,9 +118,9 @@ public class SearchResultsAdapter extends Adapter<SearchViewHolder> { int dbIndex = 0; int appIndex = 0; int rank = 1; int rank = TOP_RANK; while (rank <= MAX_RANK) { while (rank <= BOTTOM_RANK) { while ((dbIndex < dbSize) && (databaseResults.get(dbIndex).rank == rank)) { results.add(databaseResults.get(dbIndex++)); } Loading