Merge "Add basic breadcrumb on search result."
This commit is contained in:
@@ -211,7 +211,12 @@ class CursorToSearchResultConverter {
|
||||
}
|
||||
|
||||
private List<String> getBreadcrumbs(Cursor cursor) {
|
||||
return new ArrayList<>();
|
||||
final List<String> breadcrumbs = new ArrayList<>();
|
||||
final String screenTitle = cursor.getString(COLUMN_INDEX_SCREEN_TITLE);
|
||||
if (!TextUtils.isEmpty(screenTitle)) {
|
||||
breadcrumbs.add(screenTitle);
|
||||
}
|
||||
return breadcrumbs;
|
||||
}
|
||||
|
||||
/** Uses the breadcrumbs to determine the offset to the base rank.
|
||||
|
@@ -56,6 +56,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static android.provider.SearchIndexablesContract.COLUMN_INDEX_NON_INDEXABLE_KEYS_KEY_VALUE;
|
||||
@@ -279,7 +280,7 @@ public class DatabaseIndexingManager {
|
||||
* @param className the class name (typically a fragment name).
|
||||
* @param rebuild true means that you want to delete the data from the Index first.
|
||||
* @param includeInSearchResults true means that you want the bit "enabled" set so that the
|
||||
* data will be seen included into the search results
|
||||
* data will be seen included into the search results
|
||||
*/
|
||||
public void updateFromClassNameResource(String className, final boolean rebuild,
|
||||
boolean includeInSearchResults) {
|
||||
@@ -287,7 +288,7 @@ public class DatabaseIndexingManager {
|
||||
throw new IllegalArgumentException("class name cannot be null!");
|
||||
}
|
||||
final SearchIndexableResource res = SearchIndexableResources.getResourceByName(className);
|
||||
if (res == null ) {
|
||||
if (res == null) {
|
||||
Log.e(LOG_TAG, "Cannot find SearchIndexableResources for class name: " + className);
|
||||
return;
|
||||
}
|
||||
@@ -753,7 +754,7 @@ public class DatabaseIndexingManager {
|
||||
}
|
||||
|
||||
private void updateOneRowWithFilteredData(SQLiteDatabase database, DatabaseRow.Builder builder,
|
||||
String title, String summaryOn, String summaryOff,String keywords) {
|
||||
String title, String summaryOn, String summaryOff, String keywords) {
|
||||
|
||||
final String updatedTitle = DatabaseIndexingUtils.normalizeHyphen(title);
|
||||
final String updatedSummaryOn = DatabaseIndexingUtils.normalizeHyphen(summaryOn);
|
||||
@@ -783,14 +784,8 @@ public class DatabaseIndexingManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// The DocID should contains more than the title string itself (you may have two settings
|
||||
// with the same title). So we need to use a combination of the title and the screenTitle.
|
||||
StringBuilder sb = new StringBuilder(row.updatedTitle);
|
||||
sb.append(row.screenTitle);
|
||||
int docId = sb.toString().hashCode();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, docId);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DOCID, row.getDocId());
|
||||
values.put(IndexDatabaseHelper.IndexColumns.LOCALE, row.locale);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_RANK, row.rank);
|
||||
values.put(IndexDatabaseHelper.IndexColumns.DATA_TITLE, row.updatedTitle);
|
||||
@@ -919,7 +914,7 @@ public class DatabaseIndexingManager {
|
||||
}
|
||||
if (!TextUtils.isEmpty(data.className)) {
|
||||
delete(database, IndexDatabaseHelper.IndexColumns.CLASS_NAME, data.className);
|
||||
} else {
|
||||
} else {
|
||||
if (data instanceof SearchIndexableRaw) {
|
||||
final SearchIndexableRaw raw = (SearchIndexableRaw) data;
|
||||
if (!TextUtils.isEmpty(raw.title)) {
|
||||
@@ -938,7 +933,7 @@ public class DatabaseIndexingManager {
|
||||
|
||||
private int delete(SQLiteDatabase database, String columName, String value) {
|
||||
final String whereClause = columName + "=?";
|
||||
final String[] whereArgs = new String[] { value };
|
||||
final String[] whereArgs = new String[]{value};
|
||||
|
||||
return database.delete(IndexDatabaseHelper.Tables.TABLE_PREFS_INDEX, whereClause,
|
||||
whereArgs);
|
||||
@@ -993,6 +988,16 @@ public class DatabaseIndexingManager {
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the doc id for this row.
|
||||
*/
|
||||
public int getDocId() {
|
||||
// The DocID should contains more than the title string itself (you may have two
|
||||
// settings with the same title). So we need to use a combination of multiple
|
||||
// attributes from this row.
|
||||
return Objects.hash(updatedTitle, screenTitle, key, payloadType);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String mLocale;
|
||||
private String mUpdatedTitle;
|
||||
@@ -1013,7 +1018,8 @@ public class DatabaseIndexingManager {
|
||||
private boolean mEnabled;
|
||||
private String mKey;
|
||||
private int mUserId;
|
||||
@ResultPayload.PayloadType private int mPayloadType;
|
||||
@ResultPayload.PayloadType
|
||||
private int mPayloadType;
|
||||
private ResultPayload mPayload;
|
||||
|
||||
public Builder setLocale(String locale) {
|
||||
@@ -1114,7 +1120,7 @@ public class DatabaseIndexingManager {
|
||||
public Builder setPayload(ResultPayload payload) {
|
||||
mPayload = payload;
|
||||
|
||||
if(mPayload != null) {
|
||||
if (mPayload != null) {
|
||||
setPayloadType(mPayload.getType());
|
||||
}
|
||||
return this;
|
||||
@@ -1122,6 +1128,7 @@ public class DatabaseIndexingManager {
|
||||
|
||||
/**
|
||||
* Payload type is added when a Payload is added to the Builder in {setPayload}
|
||||
*
|
||||
* @param payloadType PayloadType
|
||||
* @return The Builder
|
||||
*/
|
||||
|
@@ -21,41 +21,32 @@ import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.widget.PreferenceImageView;
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* ViewHolder for Settings represented as SwitchPreferences.
|
||||
*/
|
||||
public class InlineSwitchViewHolder extends SearchViewHolder {
|
||||
public final TextView titleView;
|
||||
public final TextView summaryView;
|
||||
public final PreferenceImageView iconView;
|
||||
|
||||
public final Switch switchView;
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private final String TAG = "SwitchViewHolder";
|
||||
|
||||
public InlineSwitchViewHolder(View view, Context context) {
|
||||
super(view);
|
||||
mContext = context;
|
||||
titleView = (TextView) view.findViewById(android.R.id.title);
|
||||
summaryView = (TextView) view.findViewById(android.R.id.summary);
|
||||
iconView = (PreferenceImageView) view.findViewById(android.R.id.icon);
|
||||
switchView = (Switch) view.findViewById(R.id.switchView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBind(SearchFragment fragment, SearchResult result) {
|
||||
super.onBind(fragment, result);
|
||||
if (mContext == null) {
|
||||
return;
|
||||
}
|
||||
final InlineSwitchPayload payload = (InlineSwitchPayload) result.payload;
|
||||
switchView.setChecked(payload.getSwitchValue(mContext));
|
||||
|
||||
switchView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
@@ -63,9 +54,5 @@ public class InlineSwitchViewHolder extends SearchViewHolder {
|
||||
payload.setSwitchValue(mContext, isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
titleView.setText(result.title);
|
||||
summaryView.setText(result.summary);
|
||||
iconView.setImageDrawable(result.icon);
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,7 @@ import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.utils.AsyncLoader;
|
||||
|
||||
@@ -45,6 +46,7 @@ public class InstalledAppResultLoader extends AsyncLoader<List<SearchResult>> {
|
||||
private static final Intent LAUNCHER_PROBE = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
|
||||
private final List<String> mBreadcrumb;
|
||||
private final String mQuery;
|
||||
private final UserManager mUserManager;
|
||||
private final PackageManagerWrapper mPackageManager;
|
||||
@@ -53,6 +55,9 @@ public class InstalledAppResultLoader extends AsyncLoader<List<SearchResult>> {
|
||||
public InstalledAppResultLoader(Context context, PackageManagerWrapper pmWrapper,
|
||||
String query) {
|
||||
super(context);
|
||||
mBreadcrumb = new ArrayList<>();
|
||||
mBreadcrumb.add(context.getString(R.string.app_and_notification_dashboard_title));
|
||||
mBreadcrumb.add(context.getString(R.string.applications_settings));
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mPackageManager = pmWrapper;
|
||||
mQuery = query;
|
||||
@@ -87,6 +92,7 @@ public class InstalledAppResultLoader extends AsyncLoader<List<SearchResult>> {
|
||||
builder.addIcon(info.loadIcon(pm))
|
||||
.addTitle(info.loadLabel(pm))
|
||||
.addRank(wordDiff)
|
||||
.addBreadcrumbs(mBreadcrumb)
|
||||
.addPayload(new IntentPayload(intent));
|
||||
results.add(builder.build());
|
||||
}
|
||||
@@ -127,7 +133,7 @@ public class InstalledAppResultLoader extends AsyncLoader<List<SearchResult>> {
|
||||
* perfectly, and larger values means they are less similar.
|
||||
* <p/>
|
||||
* Example:
|
||||
* appName: Abcde, query: Abcde, Returns NAME_EXACT_MATCH
|
||||
* appName: Abcde, query: Abcde, Returns {@link #NAME_EXACT_MATCH}
|
||||
* appName: Abcde, query: ade, Returns 2
|
||||
* appName: Abcde, query: ae, Returns 3
|
||||
* appName: Abcde, query: ea, Returns NAME_NO_MATCH
|
||||
|
@@ -16,10 +16,6 @@
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* ViewHolder for intent based search results.
|
||||
@@ -27,25 +23,14 @@ import com.android.settings.R;
|
||||
*/
|
||||
public class IntentSearchViewHolder extends SearchViewHolder {
|
||||
|
||||
public final TextView titleView;
|
||||
public final TextView summaryView;
|
||||
public final ImageView iconView;
|
||||
|
||||
public IntentSearchViewHolder(View view) {
|
||||
super(view);
|
||||
titleView = (TextView) view.findViewById(android.R.id.title);
|
||||
summaryView = (TextView) view.findViewById(android.R.id.summary);
|
||||
iconView = (ImageView) view.findViewById(android.R.id.icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBind(final SearchFragment fragment, final SearchResult result) {
|
||||
titleView.setText(result.title);
|
||||
summaryView.setText(result.summary);
|
||||
iconView.setImageDrawable(result.icon);
|
||||
if (result.icon == null) {
|
||||
iconView.setBackgroundResource(R.drawable.empty_icon);
|
||||
}
|
||||
super.onBind(fragment, result);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@@ -15,8 +15,14 @@
|
||||
*/
|
||||
package com.android.settings.search2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* The ViewHolder for the Search RecyclerView.
|
||||
@@ -25,9 +31,47 @@ import android.view.View;
|
||||
*/
|
||||
public abstract class SearchViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public final TextView titleView;
|
||||
public final TextView summaryView;
|
||||
public final TextView breadcrumbView;
|
||||
public final ImageView iconView;
|
||||
|
||||
public SearchViewHolder(View view) {
|
||||
super(view);
|
||||
titleView = (TextView) view.findViewById(android.R.id.title);
|
||||
summaryView = (TextView) view.findViewById(android.R.id.summary);
|
||||
iconView = (ImageView) view.findViewById(android.R.id.icon);
|
||||
breadcrumbView = (TextView) view.findViewById(R.id.breadcrumb);
|
||||
}
|
||||
|
||||
public abstract void onBind(SearchFragment fragment, SearchResult result);
|
||||
public void onBind(SearchFragment fragment, SearchResult result) {
|
||||
titleView.setText(result.title);
|
||||
if (TextUtils.isEmpty(result.summary)) {
|
||||
summaryView.setVisibility(View.GONE);
|
||||
} else {
|
||||
summaryView.setText(result.summary);
|
||||
summaryView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
iconView.setImageDrawable(result.icon);
|
||||
if (result.icon == null) {
|
||||
iconView.setBackgroundResource(R.drawable.empty_icon);
|
||||
}
|
||||
bindBreadcrumbView(result);
|
||||
}
|
||||
|
||||
private void bindBreadcrumbView(SearchResult result) {
|
||||
if (result.breadcrumbs == null || result.breadcrumbs.isEmpty()) {
|
||||
breadcrumbView.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
final Context context = breadcrumbView.getContext();
|
||||
String breadcrumb = result.breadcrumbs.get(0);
|
||||
final int count = result.breadcrumbs.size();
|
||||
for (int i = 1; i < count; i++) {
|
||||
breadcrumb = context.getString(R.string.search_breadcrumb_connector,
|
||||
breadcrumb, result.breadcrumbs.get(i));
|
||||
}
|
||||
breadcrumbView.setText(breadcrumb);
|
||||
breadcrumbView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user