Loading packages/SettingsLib/Spa/search/AndroidManifest.xml +5 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <!-- <!-- Copyright (C) 2025 The Android Open Source Project Copyright (C) 2025 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. you may not use this file except in compliance with the License. You may obtain a copy of the License at You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and See the License for the specific language governing permissions and limitations under the License. limitations under the License. --> --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.settingslib.spa.search"> package="com.android.settingslib.spa.search"> <uses-sdk android:minSdkVersion="31" /> <uses-sdk android:minSdkVersion="31" /> </manifest> </manifest> packages/SettingsLib/Spa/search/proto/spa_search_landing.proto +3 −0 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ syntax = "proto2"; syntax = "proto2"; package com.android.settingslib.spa.search; package com.android.settingslib.spa.search; option java_package = "com.android.settingslib.spa.search"; message SpaSearchLandingKey { message SpaSearchLandingKey { oneof page { oneof page { Loading @@ -26,6 +27,8 @@ message SpaSearchLandingKey { message SpaSearchLandingSpaPage { message SpaSearchLandingSpaPage { /** The destination of SPA page. */ /** The destination of SPA page. */ optional string destination = 1; optional string destination = 1; /** The key to highlight the item. */ optional string highlight_item_key = 2; } } message SpaSearchLandingFragment { message SpaSearchLandingFragment { Loading packages/SettingsLib/Spa/search/src/com/android/settingslib/spa/search/SearchablePage.kt +13 −1 Original line number Original line Diff line number Diff line Loading @@ -17,9 +17,21 @@ package com.android.settingslib.spa.search package com.android.settingslib.spa.search import android.content.Context import android.content.Context import com.android.settingslib.spa.framework.compose.HighlightBox interface SearchablePage { interface SearchablePage { data class SearchItem(val itemTitle: String, val keywords: String? = null) data class SearchItem( /** * The key to highlight the item in the page. * * The corresponding item in the page should be wrapped with [HighlightBox] and pass this * key to [HighlightBox]'s `highlightItemKey` parameter. When search result item is clicked, * the item with this key will be highlighted. */ val highlightItemKey: String, val itemTitle: String, val keywords: String? = null, ) /** Gets the title of the page. */ /** Gets the title of the page. */ fun getPageTitleForSearch(context: Context): String fun getPageTitleForSearch(context: Context): String Loading packages/SettingsLib/Spa/search/src/com/android/settingslib/spa/search/SpaSearchLandingActivity.kt +8 −2 Original line number Original line Diff line number Diff line Loading @@ -37,7 +37,7 @@ abstract class SpaSearchLandingActivity : Activity() { val destination = key.spaPage.destination val destination = key.spaPage.destination if (destination.isNotEmpty()) { if (destination.isNotEmpty()) { Log.d(TAG, "Launch SPA search result: ${key.spaPage}") Log.d(TAG, "Launch SPA search result: ${key.spaPage}") startSpaPage(destination) startSpaPage(destination, key.spaPage.highlightItemKey) } } } } if (key.hasFragment()) { if (key.hasFragment()) { Loading @@ -55,7 +55,13 @@ abstract class SpaSearchLandingActivity : Activity() { abstract fun isValidCall(): Boolean abstract fun isValidCall(): Boolean open fun startSpaPage(destination: String) { /** * Starts the Spa page. * * @param destination The destination of SPA page. * @param highlightItemKey The key to highlight the item. */ open fun startSpaPage(destination: String, highlightItemKey: String) { throw UnsupportedOperationException() throw UnsupportedOperationException() } } Loading packages/SettingsLib/Spa/search/src/com/android/settingslib/spa/search/SpaSearchRepository.kt +12 −8 Original line number Original line Diff line number Diff line Loading @@ -46,22 +46,26 @@ class SpaSearchRepository() { private fun SettingsPageProvider.createSpaSearchIndexablePage( private fun SettingsPageProvider.createSpaSearchIndexablePage( getPageTitleForSearch: (context: Context) -> String, getPageTitleForSearch: (context: Context) -> String, getSearchItems: (context: Context) -> List<SearchItem>, getSearchItems: (context: Context) -> List<SearchItem>, ): SpaSearchIndexablePage { ) = val searchLandingKey = SpaSearchIndexablePage(targetClass = this::class.java) { context -> SpaSearchLandingKey.newBuilder() .setSpaPage(SpaSearchLandingSpaPage.newBuilder().setDestination(name)) .build() return SpaSearchIndexablePage(targetClass = this::class.java) { context -> val pageTitle = getPageTitleForSearch(context) val pageTitle = getPageTitleForSearch(context) getSearchItems(context).map { searchItem -> getSearchItems(context).map { searchItem -> SpaSearchIndexableItem( SpaSearchIndexableItem( searchLandingKey = searchLandingKey, searchLandingKey = spaPageLandingKey(name, searchItem.highlightItemKey), pageTitle = pageTitle, pageTitle = pageTitle, itemTitle = searchItem.itemTitle, itemTitle = searchItem.itemTitle, keywords = searchItem.keywords, keywords = searchItem.keywords, ) ) } } } } } private fun spaPageLandingKey(name: String, highlightItemKey: String) = SpaSearchLandingKey.newBuilder() .setSpaPage( SpaSearchLandingSpaPage.newBuilder() .setDestination(name) .setHighlightItemKey(highlightItemKey) ) .build() } } } } Loading
packages/SettingsLib/Spa/search/AndroidManifest.xml +5 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <!-- <!-- Copyright (C) 2025 The Android Open Source Project Copyright (C) 2025 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. you may not use this file except in compliance with the License. You may obtain a copy of the License at You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and See the License for the specific language governing permissions and limitations under the License. limitations under the License. --> --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.settingslib.spa.search"> package="com.android.settingslib.spa.search"> <uses-sdk android:minSdkVersion="31" /> <uses-sdk android:minSdkVersion="31" /> </manifest> </manifest>
packages/SettingsLib/Spa/search/proto/spa_search_landing.proto +3 −0 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ syntax = "proto2"; syntax = "proto2"; package com.android.settingslib.spa.search; package com.android.settingslib.spa.search; option java_package = "com.android.settingslib.spa.search"; message SpaSearchLandingKey { message SpaSearchLandingKey { oneof page { oneof page { Loading @@ -26,6 +27,8 @@ message SpaSearchLandingKey { message SpaSearchLandingSpaPage { message SpaSearchLandingSpaPage { /** The destination of SPA page. */ /** The destination of SPA page. */ optional string destination = 1; optional string destination = 1; /** The key to highlight the item. */ optional string highlight_item_key = 2; } } message SpaSearchLandingFragment { message SpaSearchLandingFragment { Loading
packages/SettingsLib/Spa/search/src/com/android/settingslib/spa/search/SearchablePage.kt +13 −1 Original line number Original line Diff line number Diff line Loading @@ -17,9 +17,21 @@ package com.android.settingslib.spa.search package com.android.settingslib.spa.search import android.content.Context import android.content.Context import com.android.settingslib.spa.framework.compose.HighlightBox interface SearchablePage { interface SearchablePage { data class SearchItem(val itemTitle: String, val keywords: String? = null) data class SearchItem( /** * The key to highlight the item in the page. * * The corresponding item in the page should be wrapped with [HighlightBox] and pass this * key to [HighlightBox]'s `highlightItemKey` parameter. When search result item is clicked, * the item with this key will be highlighted. */ val highlightItemKey: String, val itemTitle: String, val keywords: String? = null, ) /** Gets the title of the page. */ /** Gets the title of the page. */ fun getPageTitleForSearch(context: Context): String fun getPageTitleForSearch(context: Context): String Loading
packages/SettingsLib/Spa/search/src/com/android/settingslib/spa/search/SpaSearchLandingActivity.kt +8 −2 Original line number Original line Diff line number Diff line Loading @@ -37,7 +37,7 @@ abstract class SpaSearchLandingActivity : Activity() { val destination = key.spaPage.destination val destination = key.spaPage.destination if (destination.isNotEmpty()) { if (destination.isNotEmpty()) { Log.d(TAG, "Launch SPA search result: ${key.spaPage}") Log.d(TAG, "Launch SPA search result: ${key.spaPage}") startSpaPage(destination) startSpaPage(destination, key.spaPage.highlightItemKey) } } } } if (key.hasFragment()) { if (key.hasFragment()) { Loading @@ -55,7 +55,13 @@ abstract class SpaSearchLandingActivity : Activity() { abstract fun isValidCall(): Boolean abstract fun isValidCall(): Boolean open fun startSpaPage(destination: String) { /** * Starts the Spa page. * * @param destination The destination of SPA page. * @param highlightItemKey The key to highlight the item. */ open fun startSpaPage(destination: String, highlightItemKey: String) { throw UnsupportedOperationException() throw UnsupportedOperationException() } } Loading
packages/SettingsLib/Spa/search/src/com/android/settingslib/spa/search/SpaSearchRepository.kt +12 −8 Original line number Original line Diff line number Diff line Loading @@ -46,22 +46,26 @@ class SpaSearchRepository() { private fun SettingsPageProvider.createSpaSearchIndexablePage( private fun SettingsPageProvider.createSpaSearchIndexablePage( getPageTitleForSearch: (context: Context) -> String, getPageTitleForSearch: (context: Context) -> String, getSearchItems: (context: Context) -> List<SearchItem>, getSearchItems: (context: Context) -> List<SearchItem>, ): SpaSearchIndexablePage { ) = val searchLandingKey = SpaSearchIndexablePage(targetClass = this::class.java) { context -> SpaSearchLandingKey.newBuilder() .setSpaPage(SpaSearchLandingSpaPage.newBuilder().setDestination(name)) .build() return SpaSearchIndexablePage(targetClass = this::class.java) { context -> val pageTitle = getPageTitleForSearch(context) val pageTitle = getPageTitleForSearch(context) getSearchItems(context).map { searchItem -> getSearchItems(context).map { searchItem -> SpaSearchIndexableItem( SpaSearchIndexableItem( searchLandingKey = searchLandingKey, searchLandingKey = spaPageLandingKey(name, searchItem.highlightItemKey), pageTitle = pageTitle, pageTitle = pageTitle, itemTitle = searchItem.itemTitle, itemTitle = searchItem.itemTitle, keywords = searchItem.keywords, keywords = searchItem.keywords, ) ) } } } } } private fun spaPageLandingKey(name: String, highlightItemKey: String) = SpaSearchLandingKey.newBuilder() .setSpaPage( SpaSearchLandingSpaPage.newBuilder() .setDestination(name) .setHighlightItemKey(highlightItemKey) ) .build() } } } }