diff options
author | Android Build Role Account android-build-prod <android-build-team-robot@google.com> | 2021-03-25 10:06:25 +0000 |
---|---|---|
committer | Android Build Role Account android-build-prod <android-build-team-robot@google.com> | 2021-03-25 10:06:25 +0000 |
commit | b8ef2c22b6eef1aef03bcd4a4059cc62ac721e9f (patch) | |
tree | 95cf443f54ffd146ee5821792c331662ff06c22c | |
parent | d1e57d2805a668faaff0b5165456f81aa6abb13d (diff) | |
parent | 2f8c0c1d4080fc772ed3d32b281560bd2b59955a (diff) |
Snap for 7234866 from 2f8c0c1d4080fc772ed3d32b281560bd2b59955a to s-keystone-qcom-release
Change-Id: I950610cc2e62f4270891a4e853e32552b6b169a9
16 files changed, 25 insertions, 1163 deletions
@@ -29,17 +29,14 @@ license { ], } -android_app { - name: "SettingsIntelligence", - optimize: { - proguard_flags_files: ["proguard.cfg"], - }, +android_library { + name: "SettingsIntelligence-core", sdk_version: "system_current", - product_specific: true, - privileged: true, - required: ["privapp_whitelist_com.android.settings.intelligence"], + srcs: [ + "src/**/*.java", + "proto/**/*.proto", + ], - libs: ["android.car-stubs"], static_libs: [ "androidx.legacy_legacy-support-v4", "androidx.legacy_legacy-support-v13", @@ -48,14 +45,22 @@ android_app { "androidx.preference_preference", "androidx.recyclerview_recyclerview", "androidx.legacy_legacy-preference-v14", - "car-ui-lib", - ], - resource_dirs: ["res"], - srcs: [ - "src/**/*.java", - "proto/**/*.proto", ], proto: { type: "nano", }, } + +android_app { + name: "SettingsIntelligence", + optimize: { + proguard_flags_files: ["proguard.cfg"], + }, + sdk_version: "system_current", + product_specific: true, + privileged: true, + required: ["privapp_whitelist_com.android.settings.intelligence"], + + static_libs: ["SettingsIntelligence-core"], + resource_dirs: [], +} @@ -2,7 +2,7 @@ # Android auto rlagos@google.com # OWNER for SUW related code -ericberglund@google.com # OWNER for Car Settings related code +alexstetson@google.com # OWNER for Car Settings related code # TV Settings leifhendrik@google.com diff --git a/res/values/themes.xml b/res/values/themes.xml index c0453b1..66868de 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -23,6 +23,4 @@ <item name="android:windowNoTitle">true</item> <item name="android:windowSoftInputMode">adjustPan</item> </style> - - <style name="Theme.CarSettings" parent="@style/Theme.CarUi.WithToolbar"/> </resources>
\ No newline at end of file diff --git a/res/xml/car_search_fragment.xml b/res/xml/car_search_fragment.xml deleted file mode 100644 index 201c60a..0000000 --- a/res/xml/car_search_fragment.xml +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - ~ Copyright (C) 2020 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. - --> - -<PreferenceScreen - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:settings="http://schemas.android.com/apk/res-auto" - android:title="@string/app_name_settings_intelligence"/> diff --git a/src/com/android/settings/intelligence/search/SearchActivity.java b/src/com/android/settings/intelligence/search/SearchActivity.java index 229c926..28e1783 100644 --- a/src/com/android/settings/intelligence/search/SearchActivity.java +++ b/src/com/android/settings/intelligence/search/SearchActivity.java @@ -17,36 +17,26 @@ package com.android.settings.intelligence.search; -import androidx.fragment.app.FragmentActivity; +import android.os.Bundle; + import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.view.WindowManager; - import com.android.settings.intelligence.R; -import com.android.settings.intelligence.search.car.CarSearchFragment; public class SearchActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { - if (isAutomotive()) { - // Automotive relies on a different theme. Apply before calling super so that - // fragments are restored properly on configuration changes. - setTheme(R.style.Theme_CarSettings); - } super.onCreate(savedInstanceState); setContentView(R.layout.search_main); FragmentManager fragmentManager = getSupportFragmentManager(); Fragment fragment = fragmentManager.findFragmentById(R.id.main_content); if (fragment == null) { - fragment = isAutomotive() ? - new CarSearchFragment() : new SearchFragment(); fragmentManager.beginTransaction() - .add(R.id.main_content, fragment) + .add(R.id.main_content, new SearchFragment()) .commit(); } } @@ -56,8 +46,4 @@ public class SearchActivity extends FragmentActivity { finish(); return true; } - - private boolean isAutomotive() { - return getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); - } } diff --git a/src/com/android/settings/intelligence/search/car/CarFeatureFactoryImpl.java b/src/com/android/settings/intelligence/search/car/CarFeatureFactoryImpl.java deleted file mode 100644 index 452ab27..0000000 --- a/src/com/android/settings/intelligence/search/car/CarFeatureFactoryImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.car; - -import androidx.annotation.Keep; - -import com.android.settings.intelligence.overlay.FeatureFactoryImpl; -import com.android.settings.intelligence.search.SearchFeatureProvider; - -/** - * FeatureFactory implementation for car settings search. - */ -@Keep -public class CarFeatureFactoryImpl extends FeatureFactoryImpl { - @Override - public SearchFeatureProvider searchFeatureProvider() { - if (mSearchFeatureProvider == null) { - mSearchFeatureProvider = new CarSearchFeatureProviderImpl(); - } - return mSearchFeatureProvider; - } -} diff --git a/src/com/android/settings/intelligence/search/car/CarIntentSearchViewHolder.java b/src/com/android/settings/intelligence/search/car/CarIntentSearchViewHolder.java deleted file mode 100644 index a8353cd..0000000 --- a/src/com/android/settings/intelligence/search/car/CarIntentSearchViewHolder.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.car; - -import android.content.pm.PackageManager; -import android.text.TextUtils; -import android.view.View; - -import com.android.settings.intelligence.R; -import com.android.settings.intelligence.search.AppSearchResult; -import com.android.settings.intelligence.search.SearchResult; - -/** - * ViewHolder for intent based search results. - */ -public class CarIntentSearchViewHolder extends CarSearchViewHolder { - - public CarIntentSearchViewHolder(View view) { - super(view); - } - - @Override - public void onBind(CarSearchFragment fragment, SearchResult result) { - mTitle.setText(result.title); - if (result instanceof AppSearchResult) { - AppSearchResult appResult = (AppSearchResult) result; - PackageManager pm = fragment.getActivity().getPackageManager(); - mIcon.setImageDrawable(appResult.info.loadIcon(pm)); - } else { - mIcon.setImageDrawable(result.icon); - } - bindBreadcrumbView(result); - - itemView.setOnClickListener(v -> fragment.onSearchResultClicked(result)); - } - - private void bindBreadcrumbView(SearchResult result) { - if (result.breadcrumbs == null || result.breadcrumbs.isEmpty()) { - mSummary.setVisibility(View.GONE); - return; - } - String breadcrumb = result.breadcrumbs.get(0); - int count = result.breadcrumbs.size(); - for (int i = 1; i < count; i++) { - breadcrumb = mContext.getString(R.string.search_breadcrumb_connector, - breadcrumb, result.breadcrumbs.get(i)); - } - if (breadcrumb == null || TextUtils.isEmpty(breadcrumb.trim())) { - mSummary.setVisibility(View.GONE); - } else { - mSummary.setText(breadcrumb); - mSummary.setVisibility(View.VISIBLE); - } - } -} diff --git a/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java b/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java deleted file mode 100644 index 2491cbd..0000000 --- a/src/com/android/settings/intelligence/search/car/CarSearchFeatureProviderImpl.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.car; - -import android.content.Context; -import android.text.TextUtils; -import android.util.Log; -import android.util.Pair; -import android.view.View; - -import com.android.settings.intelligence.search.SearchFeatureProvider; -import com.android.settings.intelligence.search.SearchFragment; -import com.android.settings.intelligence.search.SearchResult; -import com.android.settings.intelligence.search.SearchResultLoader; -import com.android.settings.intelligence.search.indexing.DatabaseIndexingManager; -import com.android.settings.intelligence.search.indexing.IndexData; -import com.android.settings.intelligence.search.indexing.IndexingCallback; -import com.android.settings.intelligence.search.indexing.car.CarDatabaseIndexingManager; -import com.android.settings.intelligence.search.query.DatabaseResultTask; -import com.android.settings.intelligence.search.query.InstalledAppResultTask; -import com.android.settings.intelligence.search.query.SearchQueryTask; -import com.android.settings.intelligence.search.savedqueries.SavedQueryLoader; -import com.android.settings.intelligence.search.sitemap.SiteMapManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.FutureTask; - -/** - * SearchFeatureProvider for car settings search. - */ -public class CarSearchFeatureProviderImpl implements SearchFeatureProvider { - private static final String TAG = "CarSearchFeatureProvider"; - private static final long SMART_SEARCH_RANKING_TIMEOUT = 300L; - - private CarDatabaseIndexingManager mDatabaseIndexingManager; - private ExecutorService mExecutorService; - private SiteMapManager mSiteMapManager; - - @Override - public SearchResultLoader getSearchResultLoader(Context context, String query) { - return new SearchResultLoader(context, cleanQuery(query)); - } - - @Override - public List<SearchQueryTask> getSearchQueryTasks(Context context, String query) { - List<SearchQueryTask> tasks = new ArrayList<>(); - String cleanQuery = cleanQuery(query); - tasks.add(DatabaseResultTask.newTask(context, getSiteMapManager(), cleanQuery)); - tasks.add(InstalledAppResultTask.newTask(context, getSiteMapManager(), cleanQuery)); - return tasks; - } - - @Override - public SavedQueryLoader getSavedQueryLoader(Context context) { - return new SavedQueryLoader(context); - } - - @Override - public DatabaseIndexingManager getIndexingManager(Context context) { - if (mDatabaseIndexingManager == null) { - mDatabaseIndexingManager = new CarDatabaseIndexingManager( - context.getApplicationContext()); - } - return mDatabaseIndexingManager; - } - - @Override - public SiteMapManager getSiteMapManager() { - if (mSiteMapManager == null) { - mSiteMapManager = new SiteMapManager(); - } - return mSiteMapManager; - } - - @Override - public boolean isIndexingComplete(Context context) { - return getIndexingManager(context).isIndexingComplete(); - } - - @Override - public void initFeedbackButton() { - } - - @Override - public void showFeedbackButton(SearchFragment fragment, View root) { - } - - @Override - public void hideFeedbackButton(View root) { - } - - @Override - public void searchResultClicked(Context context, String query, SearchResult searchResult) { - } - - @Override - public boolean isSmartSearchRankingEnabled(Context context) { - return false; - } - - @Override - public long smartSearchRankingTimeoutMs(Context context) { - return SMART_SEARCH_RANKING_TIMEOUT; - } - - @Override - public void searchRankingWarmup(Context context) { - } - - @Override - public FutureTask<List<Pair<String, Float>>> getRankerTask(Context context, String query) { - return null; - } - - @Override - public void updateIndexAsync(Context context, IndexingCallback callback) { - if (DEBUG) { - Log.d(TAG, "updating index async"); - } - getIndexingManager(context).indexDatabase(callback); - } - - @Override - public ExecutorService getExecutorService() { - if (mExecutorService == null) { - mExecutorService = Executors.newCachedThreadPool(); - } - return mExecutorService; - } - - /** - * A generic method to make the query suitable for searching the database. - * - * @return the cleaned query string - */ - private String cleanQuery(String query) { - if (TextUtils.isEmpty(query)) { - return null; - } - if (Locale.getDefault().equals(Locale.JAPAN)) { - query = IndexData.normalizeJapaneseString(query); - } - return query.trim(); - } -} diff --git a/src/com/android/settings/intelligence/search/car/CarSearchFragment.java b/src/com/android/settings/intelligence/search/car/CarSearchFragment.java deleted file mode 100644 index 702be42..0000000 --- a/src/com/android/settings/intelligence/search/car/CarSearchFragment.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.car; - -import static com.android.car.ui.core.CarUi.requireInsets; -import static com.android.car.ui.core.CarUi.requireToolbar; -import static com.android.car.ui.utils.CarUiUtils.drawableToBitmap; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -import androidx.annotation.NonNull; -import androidx.loader.app.LoaderManager; -import androidx.loader.content.Loader; -import androidx.recyclerview.widget.RecyclerView; - -import com.android.car.ui.imewidescreen.CarUiImeSearchListItem; -import com.android.car.ui.preference.PreferenceFragment; -import com.android.car.ui.recyclerview.CarUiContentListItem; -import com.android.car.ui.toolbar.MenuItem; -import com.android.car.ui.toolbar.Toolbar; -import com.android.car.ui.toolbar.ToolbarController; -import com.android.settings.intelligence.R; -import com.android.settings.intelligence.overlay.FeatureFactory; -import com.android.settings.intelligence.search.AppSearchResult; -import com.android.settings.intelligence.search.SearchCommon; -import com.android.settings.intelligence.search.SearchFeatureProvider; -import com.android.settings.intelligence.search.SearchResult; -import com.android.settings.intelligence.search.indexing.IndexingCallback; -import com.android.settings.intelligence.search.savedqueries.car.CarSavedQueryController; -import com.android.settings.intelligence.search.savedqueries.car.CarSavedQueryViewHolder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Search fragment for car settings. - */ -public class CarSearchFragment extends PreferenceFragment implements - LoaderManager.LoaderCallbacks<List<? extends SearchResult>>, IndexingCallback { - private static final String TAG = "CarSearchFragment"; - private static final int REQUEST_CODE_NO_OP = 0; - - private SearchFeatureProvider mSearchFeatureProvider; - - private ToolbarController mToolbar; - private RecyclerView mRecyclerView; - - private String mQuery; - private boolean mShowingSavedQuery; - - private CarSearchResultsAdapter mSearchAdapter; - private CarSavedQueryController mSavedQueryController; - - private final RecyclerView.OnScrollListener mScrollListener = - new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (dy != 0) { - hideKeyboard(); - } - } - }; - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - setPreferencesFromResource(R.xml.car_search_fragment, rootKey); - } - - protected ToolbarController getToolbar() { - return requireToolbar(requireActivity()); - } - - protected List<MenuItem> getToolbarMenuItems() { - return null; - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - mSearchFeatureProvider = FeatureFactory.get(context).searchFeatureProvider(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - if (savedInstanceState != null) { - mQuery = savedInstanceState.getString(SearchCommon.STATE_QUERY); - mShowingSavedQuery = savedInstanceState.getBoolean( - SearchCommon.STATE_SHOWING_SAVED_QUERY); - } else { - mShowingSavedQuery = true; - } - - LoaderManager loaderManager = getLoaderManager(); - mSearchAdapter = new CarSearchResultsAdapter(/* fragment= */ this); - mToolbar = getToolbar(); - mSavedQueryController = new CarSavedQueryController( - getContext(), loaderManager, mSearchAdapter, mToolbar, this); - mSearchFeatureProvider.updateIndexAsync(getContext(), /* indexingCallback= */ this); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - if (mToolbar != null) { - List<MenuItem> items = getToolbarMenuItems(); - mToolbar.setTitle(getPreferenceScreen().getTitle()); - mToolbar.setMenuItems(items); - mToolbar.setNavButtonMode(Toolbar.NavButtonMode.BACK); - mToolbar.setState(Toolbar.State.SUBPAGE); - mToolbar.setState(Toolbar.State.SEARCH); - mToolbar.setSearchHint(R.string.abc_search_hint); - mToolbar.registerOnSearchListener(this::onQueryTextChange); - mToolbar.registerOnSearchCompletedListener(this::onSearchComplete); - mToolbar.setShowMenuItemsWhileSearching(true); - mToolbar.setSearchQuery(mQuery); - } - mRecyclerView = getListView(); - if (mRecyclerView != null) { - mRecyclerView.setAdapter(mSearchAdapter); - mRecyclerView.addOnScrollListener(mScrollListener); - } - } - - @Override - public void onStart() { - super.onStart(); - onCarUiInsetsChanged(requireInsets(requireActivity())); - } - - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putString(SearchCommon.STATE_QUERY, mQuery); - outState.putBoolean(SearchCommon.STATE_SHOWING_SAVED_QUERY, mShowingSavedQuery); - } - - private void onQueryTextChange(String query) { - if (TextUtils.equals(query, mQuery)) { - return; - } - boolean isEmptyQuery = TextUtils.isEmpty(query); - - mQuery = query; - - // If indexing is not finished, register the query text, but don't search. - if (!mSearchFeatureProvider.isIndexingComplete(getActivity())) { - mToolbar.getProgressBar().setVisible(!isEmptyQuery); - return; - } - - if (isEmptyQuery) { - LoaderManager loaderManager = getLoaderManager(); - loaderManager.destroyLoader(SearchCommon.SearchLoaderId.SEARCH_RESULT); - mShowingSavedQuery = true; - mSavedQueryController.loadSavedQueries(); - } else { - restartLoaders(); - } - } - - private void onSearchComplete() { - if (!TextUtils.isEmpty(mQuery)) { - mSavedQueryController.saveQuery(mQuery); - } - } - - /** - * Gets called when a saved query is clicked. - */ - public void onSavedQueryClicked(CharSequence query) { - String queryString = query.toString(); - mToolbar.setSearchQuery(queryString); - onQueryTextChange(queryString); - } - - @Override - public Loader<List<? extends SearchResult>> onCreateLoader(int id, Bundle args) { - Activity activity = getActivity(); - - if (id == SearchCommon.SearchLoaderId.SEARCH_RESULT) { - return mSearchFeatureProvider.getSearchResultLoader(activity, mQuery); - } - return null; - } - - @Override - public void onLoadFinished(Loader<List<? extends SearchResult>> loader, - List<? extends SearchResult> data) { - - if (mToolbar.canShowSearchResultItems()) { - List<CarUiImeSearchListItem> searchItems = new ArrayList<>(); - for (SearchResult result : data) { - CarUiImeSearchListItem item = new CarUiImeSearchListItem( - CarUiContentListItem.Action.ICON); - item.setTitle(result.title); - if (result.breadcrumbs != null && !result.breadcrumbs.isEmpty()) { - item.setBody(getBreadcrumb(result)); - } - - if (result instanceof AppSearchResult) { - AppSearchResult appResult = (AppSearchResult) result; - PackageManager pm = getActivity().getPackageManager(); - Drawable drawable = appResult.info.loadIcon(pm); - Bitmap bm = drawableToBitmap(drawable); - BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bm); - item.setIcon(bitmapDrawable); - } else if (result.icon != null) { - Bitmap bm = drawableToBitmap(result.icon); - BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bm); - item.setIcon(bitmapDrawable); - } - item.setOnItemClickedListener(v -> onSearchResultClicked(result)); - - searchItems.add(item); - } - mToolbar.setSearchResultItems(searchItems); - } - - mSearchAdapter.postSearchResults(data); - mRecyclerView.scrollToPosition(0); - } - - private String getBreadcrumb(SearchResult result) { - String breadcrumb = result.breadcrumbs.get(0); - int count = result.breadcrumbs.size(); - for (int i = 1; i < count; i++) { - breadcrumb = getContext().getString(R.string.search_breadcrumb_connector, - breadcrumb, result.breadcrumbs.get(i)); - } - - return breadcrumb; - } - - /** - * Gets called when a search result is clicked. - */ - protected void onSearchResultClicked(SearchResult result) { - mSearchFeatureProvider.searchResultClicked(getContext(), mQuery, result); - mSavedQueryController.saveQuery(mQuery); - - Intent intent = result.payload.getIntent(); - if (result instanceof AppSearchResult) { - getActivity().startActivity(intent); - } else { - PackageManager pm = getActivity().getPackageManager(); - List<ResolveInfo> info = pm.queryIntentActivities(intent, /* flags= */ 0); - if (info != null && !info.isEmpty()) { - startActivityForResult(intent, REQUEST_CODE_NO_OP); - } else { - Log.e(TAG, "Cannot launch search result, title: " - + result.title + ", " + intent); - } - } - } - - @Override - public void onLoaderReset(Loader<List<? extends SearchResult>> loader) { - } - - /** - * Gets called when Indexing is completed. - */ - @Override - public void onIndexingFinished() { - if (getActivity() == null) { - return; - } - mToolbar.getProgressBar().setVisible(false); - if (mShowingSavedQuery) { - mSavedQueryController.loadSavedQueries(); - } else { - LoaderManager loaderManager = getLoaderManager(); - loaderManager.initLoader(SearchCommon.SearchLoaderId.SEARCH_RESULT, - /* args= */ null, /* callback= */ this); - } - requery(); - } - - private void requery() { - if (TextUtils.isEmpty(mQuery)) { - return; - } - String query = mQuery; - mQuery = ""; - onQueryTextChange(query); - } - - private void restartLoaders() { - mShowingSavedQuery = false; - LoaderManager loaderManager = getLoaderManager(); - loaderManager.restartLoader(SearchCommon.SearchLoaderId.SEARCH_RESULT, - /* args= */ null, /* callback= */ this); - } - - private void hideKeyboard() { - Activity activity = getActivity(); - if (activity != null) { - View view = activity.getCurrentFocus(); - InputMethodManager imm = (InputMethodManager) - activity.getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm.isActive(view)) { - imm.hideSoftInputFromWindow(view.getWindowToken(), /* flags= */ 0); - } - } - - if (mRecyclerView != null) { - mRecyclerView.requestFocus(); - } - } -} diff --git a/src/com/android/settings/intelligence/search/car/CarSearchResultsAdapter.java b/src/com/android/settings/intelligence/search/car/CarSearchResultsAdapter.java deleted file mode 100644 index be35482..0000000 --- a/src/com/android/settings/intelligence/search/car/CarSearchResultsAdapter.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.car; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import androidx.recyclerview.widget.DiffUtil; -import androidx.recyclerview.widget.RecyclerView; - -import com.android.settings.intelligence.R; -import com.android.settings.intelligence.search.ResultPayload; -import com.android.settings.intelligence.search.SearchResult; -import com.android.settings.intelligence.search.SearchResultDiffCallback; -import com.android.settings.intelligence.search.savedqueries.car.CarSavedQueryViewHolder; - -import java.util.ArrayList; -import java.util.List; - -/** - * RecyclerView Adapter for the car search results RecyclerView. - * The adapter uses the CarSearchViewHolder for its view contents. - */ -public class CarSearchResultsAdapter extends RecyclerView.Adapter<CarSearchViewHolder> { - - private final CarSearchFragment mFragment; - private final List<SearchResult> mSearchResults; - - public CarSearchResultsAdapter(CarSearchFragment fragment) { - mFragment = fragment; - mSearchResults = new ArrayList<>(); - - setHasStableIds(true); - } - - @Override - public CarSearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - Context context = parent.getContext(); - LayoutInflater inflater = LayoutInflater.from(context); - View view; - switch (viewType) { - case ResultPayload.PayloadType.INTENT: - view = inflater.inflate(R.layout.car_ui_preference, parent, - /* attachToRoot= */ false); - return new CarIntentSearchViewHolder(view); - case ResultPayload.PayloadType.SAVED_QUERY: - view = inflater.inflate(R.layout.car_ui_preference, parent, - /* attachToRoot= */ false); - return new CarSavedQueryViewHolder(view); - default: - return null; - } - } - - @Override - public void onBindViewHolder(CarSearchViewHolder holder, int position) { - holder.onBind(mFragment, mSearchResults.get(position)); - } - - @Override - public long getItemId(int position) { - return mSearchResults.get(position).hashCode(); - } - - @Override - public int getItemViewType(int position) { - return mSearchResults.get(position).viewType; - } - - @Override - public int getItemCount() { - return mSearchResults.size(); - } - - protected void postSearchResults(List<? extends SearchResult> newSearchResults) { - DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff( - new SearchResultDiffCallback(mSearchResults, newSearchResults)); - mSearchResults.clear(); - mSearchResults.addAll(newSearchResults); - diffResult.dispatchUpdatesTo(/* adapter= */ this); - } - - /** - * Displays recent searched queries. - */ - public void displaySavedQuery(List<? extends SearchResult> data) { - clearResults(); - mSearchResults.addAll(data); - notifyDataSetChanged(); - } - - /** - * Clear current search results. - */ - public void clearResults() { - mSearchResults.clear(); - notifyDataSetChanged(); - } - - /** - * Get current search results. - */ - public List<SearchResult> getSearchResults() { - return mSearchResults; - } -} diff --git a/src/com/android/settings/intelligence/search/car/CarSearchViewHolder.java b/src/com/android/settings/intelligence/search/car/CarSearchViewHolder.java deleted file mode 100644 index 2657d9a..0000000 --- a/src/com/android/settings/intelligence/search/car/CarSearchViewHolder.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.car; - -import android.content.Context; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.recyclerview.widget.RecyclerView; - -import com.android.settings.intelligence.search.SearchResult; - -/** The ViewHolder for the car search RecyclerView. - * There are multiple search result types with different UI requirements, such as Intent results - * and saved query results. - */ -public abstract class CarSearchViewHolder extends RecyclerView.ViewHolder { - protected Context mContext; - protected ImageView mIcon; - protected TextView mTitle; - protected TextView mSummary; - - public CarSearchViewHolder(View view) { - super(view); - mContext = view.getContext(); - mIcon = view.findViewById(android.R.id.icon); - mTitle = view.findViewById(android.R.id.title); - mSummary = view.findViewById(android.R.id.summary); - } - - /** - * Update the ViewHolder data when bound. - */ - public abstract void onBind(CarSearchFragment fragment, SearchResult result); -} diff --git a/src/com/android/settings/intelligence/search/indexing/car/CarDatabaseIndexingManager.java b/src/com/android/settings/intelligence/search/indexing/car/CarDatabaseIndexingManager.java deleted file mode 100644 index 3026e82..0000000 --- a/src/com/android/settings/intelligence/search/indexing/car/CarDatabaseIndexingManager.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.indexing.car; - -import android.content.Context; - -import com.android.settings.intelligence.search.indexing.DatabaseIndexingManager; -import com.android.settings.intelligence.search.indexing.IndexDataConverter; -import com.android.settings.intelligence.search.indexing.PreIndexData; - -/** - * Car extension to {@link DatabaseIndexingManager} to use {@link CarIndexDataConverter} for - * converting {@link PreIndexData} into {@link CarIndexData}. - */ -public class CarDatabaseIndexingManager extends DatabaseIndexingManager { - - public CarDatabaseIndexingManager(Context context) { - super(context); - } - - @Override - protected IndexDataConverter getIndexDataConverter(Context context) { - return new CarIndexDataConverter(context); - } -} diff --git a/src/com/android/settings/intelligence/search/indexing/car/CarIndexData.java b/src/com/android/settings/intelligence/search/indexing/car/CarIndexData.java deleted file mode 100644 index a57d003..0000000 --- a/src/com/android/settings/intelligence/search/indexing/car/CarIndexData.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.indexing.car; - -import android.content.Context; -import android.content.Intent; - -import com.android.settings.intelligence.search.indexing.DatabaseIndexingUtils; -import com.android.settings.intelligence.search.indexing.IndexData; - -/** - * Car data class representing a single row in the Setting Search results database. - */ -public class CarIndexData extends IndexData { - - public CarIndexData(IndexData.Builder builder) { - super(builder); - } - - /** - * Builder class for {@link CarIndexData}, extending {@link IndexData.Builder}, which replaces - * all intents with direct search intents, since CarSettings doesn't support - * SearchResultTrampolineIntents. - */ - public static class Builder extends IndexData.Builder { - @Override - protected Intent buildIntent(Context context) { - return DatabaseIndexingUtils.buildDirectSearchResultIntent(getIntentAction(), - getIntentTargetPackage(), getIntentTargetClass(), getKey()); - } - } -}
\ No newline at end of file diff --git a/src/com/android/settings/intelligence/search/indexing/car/CarIndexDataConverter.java b/src/com/android/settings/intelligence/search/indexing/car/CarIndexDataConverter.java deleted file mode 100644 index 11f35cb..0000000 --- a/src/com/android/settings/intelligence/search/indexing/car/CarIndexDataConverter.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.indexing.car; - -import android.content.Context; - -import com.android.settings.intelligence.search.indexing.IndexData; -import com.android.settings.intelligence.search.indexing.IndexDataConverter; -import com.android.settings.intelligence.search.indexing.PreIndexData; - -/** - * Car helper class to convert {@link PreIndexData} to {@link CarIndexData}. - */ -public class CarIndexDataConverter extends IndexDataConverter { - - public CarIndexDataConverter(Context context) { - super(context); - } - - @Override - protected IndexData.Builder getIndexDataBuilder() { - return new CarIndexData.Builder(); - } -} diff --git a/src/com/android/settings/intelligence/search/savedqueries/car/CarSavedQueryController.java b/src/com/android/settings/intelligence/search/savedqueries/car/CarSavedQueryController.java deleted file mode 100644 index 4c9a458..0000000 --- a/src/com/android/settings/intelligence/search/savedqueries/car/CarSavedQueryController.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.savedqueries.car; - -import android.content.Context; -import android.os.Bundle; -import android.util.Log; -import android.view.MenuItem; - -import androidx.annotation.NonNull; -import androidx.loader.app.LoaderManager; -import androidx.loader.content.Loader; - -import com.android.car.ui.imewidescreen.CarUiImeSearchListItem; -import com.android.car.ui.recyclerview.CarUiContentListItem; -import com.android.car.ui.toolbar.ToolbarController; -import com.android.settings.intelligence.R; -import com.android.settings.intelligence.overlay.FeatureFactory; -import com.android.settings.intelligence.search.SearchCommon; -import com.android.settings.intelligence.search.SearchFeatureProvider; -import com.android.settings.intelligence.search.SearchResult; -import com.android.settings.intelligence.search.car.CarSearchFragment; -import com.android.settings.intelligence.search.car.CarSearchResultsAdapter; -import com.android.settings.intelligence.search.savedqueries.SavedQueryRecorder; -import com.android.settings.intelligence.search.savedqueries.SavedQueryRemover; - -import java.util.ArrayList; -import java.util.List; - -/** - * Helper class for managing saved queries. - */ -public class CarSavedQueryController implements LoaderManager.LoaderCallbacks, - MenuItem.OnMenuItemClickListener { - - private static final String ARG_QUERY = "remove_query"; - private static final String TAG = "CarSearchSavedQueryCtrl"; - - private static final int MENU_SEARCH_HISTORY = 1000; - - private final Context mContext; - private final LoaderManager mLoaderManager; - private final SearchFeatureProvider mSearchFeatureProvider; - private final CarSearchResultsAdapter mResultAdapter; - private ToolbarController mToolbar; - private CarSearchFragment mFragment; - - public CarSavedQueryController(Context context, LoaderManager loaderManager, - CarSearchResultsAdapter resultsAdapter, @NonNull ToolbarController toolbar, - CarSearchFragment fragment) { - mContext = context; - mLoaderManager = loaderManager; - mResultAdapter = resultsAdapter; - mSearchFeatureProvider = FeatureFactory.get(context) - .searchFeatureProvider(); - mToolbar = toolbar; - mFragment = fragment; - } - - @Override - public Loader onCreateLoader(int id, Bundle args) { - switch (id) { - case SearchCommon.SearchLoaderId.SAVE_QUERY_TASK: - return new SavedQueryRecorder(mContext, args.getString(ARG_QUERY)); - case SearchCommon.SearchLoaderId.REMOVE_QUERY_TASK: - return new SavedQueryRemover(mContext); - case SearchCommon.SearchLoaderId.SAVED_QUERIES: - return mSearchFeatureProvider.getSavedQueryLoader(mContext); - } - return null; - } - - @Override - public void onLoadFinished(Loader loader, Object data) { - switch (loader.getId()) { - case SearchCommon.SearchLoaderId.REMOVE_QUERY_TASK: - mLoaderManager.restartLoader(SearchCommon.SearchLoaderId.SAVED_QUERIES, - /* args= */ null, /* callback= */ this); - break; - case SearchCommon.SearchLoaderId.SAVED_QUERIES: - if (SearchFeatureProvider.DEBUG) { - Log.d(TAG, "Saved queries loaded"); - } - List<SearchResult> results = (List<SearchResult>) data; - if (mToolbar.canShowSearchResultItems()) { - List<CarUiImeSearchListItem> searchItems = new ArrayList<>(); - for (SearchResult result : results) { - CarUiImeSearchListItem item = new CarUiImeSearchListItem( - CarUiContentListItem.Action.ICON); - item.setTitle(result.title); - item.setIconResId(R.drawable.ic_restore); - item.setOnItemClickedListener( - v -> mFragment.onSavedQueryClicked(result.title)); - - searchItems.add(item); - } - mToolbar.setSearchResultItems(searchItems); - } - - mResultAdapter.displaySavedQuery(results); - break; - } - } - - @Override - public void onLoaderReset(Loader loader) { - } - - @Override - public boolean onMenuItemClick(MenuItem item) { - if (item.getItemId() != MENU_SEARCH_HISTORY) { - return false; - } - removeQueries(); - return true; - } - - /** - * Save a query to the DB. - */ - public void saveQuery(String query) { - Bundle args = new Bundle(); - args.putString(ARG_QUERY, query); - mLoaderManager.restartLoader(SearchCommon.SearchLoaderId.SAVE_QUERY_TASK, args, - /* callback= */ this); - } - - /** - * Remove all saved queries from the DB. - */ - public void removeQueries() { - Bundle args = new Bundle(); - mLoaderManager.restartLoader(SearchCommon.SearchLoaderId.REMOVE_QUERY_TASK, args, - /* callback= */ this); - } - - /** - * Load the saved queries from the DB. - */ - public void loadSavedQueries() { - if (SearchFeatureProvider.DEBUG) { - Log.d(TAG, "loading saved queries"); - } - mLoaderManager.restartLoader(SearchCommon.SearchLoaderId.SAVED_QUERIES, - /* args= */ null, /* callback= */ this); - } -}
\ No newline at end of file diff --git a/src/com/android/settings/intelligence/search/savedqueries/car/CarSavedQueryViewHolder.java b/src/com/android/settings/intelligence/search/savedqueries/car/CarSavedQueryViewHolder.java deleted file mode 100644 index 12051a8..0000000 --- a/src/com/android/settings/intelligence/search/savedqueries/car/CarSavedQueryViewHolder.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2020 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.intelligence.search.savedqueries.car; - -import android.view.View; - -import com.android.settings.intelligence.R; -import com.android.settings.intelligence.search.car.CarSearchFragment; -import com.android.settings.intelligence.search.car.CarSearchViewHolder; -import com.android.settings.intelligence.search.SearchResult; - -/** - * ViewHolder for saved queries from past searches. - */ -public class CarSavedQueryViewHolder extends CarSearchViewHolder { - - public CarSavedQueryViewHolder(View view) { - super(view); - } - - @Override - public void onBind(CarSearchFragment fragment, SearchResult result) { - mTitle.setText(result.title); - mIcon.setImageResource(R.drawable.ic_restore); - mSummary.setVisibility(View.GONE); - itemView.setOnClickListener(v -> { - fragment.onSavedQueryClicked(result.title); - }); - } -} |