Replaces the default Toolbar in SettingsActivity with one that looks
like a search bar. It uses a Toolbar inside a CardView with some custom
styling.
Since the search bar is a floating element, the new toolbar lives in the
content frame of the dashboard. A FrameLayout is used to provide the
layering that is desired.
Since the search bar is on top, an additional spacer view is added to
the list of items in the dashboard. Its color changes based on what
the first view is so that it always matches.
Adds android-support-v7-cardview as a dependency (and reorders the
other deps to be in alphabetical order).
Remaining work (in future CLs):
- remove search menu option?
- clean up initial window
- remove the line between the header and the first condition
when there's a condition
Change-Id: I627b406735c8e2280ac08f44ca32f7098621a830
Merged-In: Id7477b90fbaf30eb5cac1ee244c847bddb95b3fd
Bug: 37477506
Test: make RunSettingsRoboTests
112 lines
3.7 KiB
Java
112 lines
3.7 KiB
Java
/*
|
|
* Copyright (C) 2016 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.search2;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.support.annotation.VisibleForTesting;
|
|
import android.util.Log;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settings.applications.PackageManagerWrapperImpl;
|
|
import com.android.settings.dashboard.SiteMapManager;
|
|
import com.android.settings.search.IndexingCallback;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
/**
|
|
* FeatureProvider for the refactored search code.
|
|
*/
|
|
public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
|
|
|
private static final String TAG = "SearchFeatureProvider";
|
|
|
|
private DatabaseIndexingManager mDatabaseIndexingManager;
|
|
private SiteMapManager mSiteMapManager;
|
|
|
|
@Override
|
|
public boolean isEnabled(Context context) {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void setUpSearchMenu(Menu menu, final Activity activity) {
|
|
if (menu == null || activity == null) {
|
|
return;
|
|
}
|
|
String menuTitle = activity.getString(R.string.search_menu);
|
|
MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, menuTitle)
|
|
.setIcon(R.drawable.ic_search_24dp)
|
|
.setOnMenuItemClickListener(item -> {
|
|
Intent intent = new Intent(activity, SearchActivity.class);
|
|
activity.startActivity(intent);
|
|
return true;
|
|
});
|
|
|
|
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
}
|
|
|
|
@Override
|
|
public DatabaseResultLoader getDatabaseSearchLoader(Context context, String query) {
|
|
return new DatabaseResultLoader(context, query, getSiteMapManager());
|
|
}
|
|
|
|
@Override
|
|
public InstalledAppResultLoader getInstalledAppSearchLoader(Context context, String query) {
|
|
return new InstalledAppResultLoader(
|
|
context, new PackageManagerWrapperImpl(context.getPackageManager()), query,
|
|
getSiteMapManager());
|
|
}
|
|
|
|
@Override
|
|
public SavedQueryLoader getSavedQueryLoader(Context context) {
|
|
return new SavedQueryLoader(context);
|
|
}
|
|
|
|
@Override
|
|
public DatabaseIndexingManager getIndexingManager(Context context) {
|
|
if (mDatabaseIndexingManager == null) {
|
|
mDatabaseIndexingManager = new DatabaseIndexingManager(context.getApplicationContext(),
|
|
context.getPackageName());
|
|
}
|
|
return mDatabaseIndexingManager;
|
|
}
|
|
|
|
@Override
|
|
public boolean isIndexingComplete(Context context) {
|
|
return getIndexingManager(context).isIndexingComplete();
|
|
}
|
|
|
|
public SiteMapManager getSiteMapManager() {
|
|
if (mSiteMapManager == null) {
|
|
mSiteMapManager = new SiteMapManager();
|
|
}
|
|
return mSiteMapManager;
|
|
}
|
|
|
|
@Override
|
|
public void updateIndex(Context context, IndexingCallback callback) {
|
|
long indexStartTime = System.currentTimeMillis();
|
|
getIndexingManager(context).indexDatabase(callback);
|
|
Log.d(TAG, "IndexDatabase() took " +
|
|
(System.currentTimeMillis() - indexStartTime) + " ms");
|
|
}
|
|
}
|