Merge "Add basic breadcrumb on search result."
This commit is contained in:
26
res/layout/search_breadcrumb_view.xml
Normal file
26
res/layout/search_breadcrumb_view.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 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.
|
||||
-->
|
||||
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/breadcrumb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:ellipsize="marquee"/>
|
33
res/layout/search_icon_view.xml
Normal file
33
res/layout/search_icon_view.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2017 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.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="60dp"
|
||||
android:gravity="center_horizontal|top"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:scaleType="fitCenter"/>
|
||||
</LinearLayout>
|
@@ -19,36 +19,20 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="60dp"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="48dp"
|
||||
android:maxHeight="48dp"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/search_icon_view"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
@@ -62,20 +46,18 @@
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLength="60"
|
||||
android:maxLines="10"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<include layout="@layout/search_breadcrumb_view"/>
|
||||
</LinearLayout>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end|center_vertical"
|
||||
android:paddingStart="16dp"
|
||||
android:orientation="vertical"/>
|
||||
android:gravity="top"
|
||||
android:paddingStart="16dp"/>
|
||||
</LinearLayout>
|
@@ -19,36 +19,20 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="60dp"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="48dp"
|
||||
android:maxHeight="48dp"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/search_icon_view"/>
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
@@ -62,11 +46,11 @@
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="10"/>
|
||||
android:maxLines="3"
|
||||
android:ellipsize="marquee"/>
|
||||
|
||||
</RelativeLayout>
|
||||
<include layout="@layout/search_breadcrumb_view"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
@@ -5947,6 +5947,10 @@
|
||||
<string name="search_menu">Search settings</string>
|
||||
<!-- Text used as a search hint into the search box -->
|
||||
<string name="query_hint_text">Search settings</string>
|
||||
<!-- Search breadcrumb connector symbol -->
|
||||
<string name="search_breadcrumb_connector" translatable="false">
|
||||
<xliff:g name="first_item">%1$s</xliff:g> > <xliff:g name="second_item">%2$s</xliff:g>
|
||||
</string>
|
||||
|
||||
<!-- Text used to identify the search query suggestions / recent searches -->
|
||||
<string name="search_recents_queries_label">Recent searches</string>
|
||||
|
@@ -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;
|
||||
@@ -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);
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
}
|
||||
}
|
@@ -196,7 +196,7 @@ public class DatabaseIndexingManagerTest {
|
||||
@Test
|
||||
public void testNullResource_NothingInserted() {
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, null /* searchIndexableResource */,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(0);
|
||||
}
|
||||
@@ -205,7 +205,7 @@ public class DatabaseIndexingManagerTest {
|
||||
public void testAddResource_RowsInserted() {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(6);
|
||||
}
|
||||
@@ -214,7 +214,7 @@ public class DatabaseIndexingManagerTest {
|
||||
public void testAddResourceHeader_RowsMatch() {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.application_settings);
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
|
||||
cursor.moveToPosition(1);
|
||||
@@ -267,25 +267,27 @@ public class DatabaseIndexingManagerTest {
|
||||
public void testAddResourceCustomSetting_RowsMatch() {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.gesture_settings);
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
cursor.moveToPosition(0);
|
||||
new HashMap<>());
|
||||
final String prefTitle =
|
||||
mContext.getString(R.string.fingerprint_swipe_for_notifications_title);
|
||||
final String prefSummary =
|
||||
mContext.getString(R.string.fingerprint_swipe_for_notifications_summary);
|
||||
Cursor cursor = mDb.rawQuery(
|
||||
"SELECT * FROM prefs_index where data_title='" + prefTitle + "'", null);
|
||||
cursor.moveToFirst();
|
||||
|
||||
// Locale
|
||||
assertThat(cursor.getString(0)).isEqualTo(localeStr);
|
||||
// Data Rank
|
||||
assertThat(cursor.getInt(1)).isEqualTo(rank);
|
||||
// Data Title
|
||||
assertThat(cursor.getString(2)).isEqualTo("Swipe for notifications");
|
||||
assertThat(cursor.getString(2)).isEqualTo(prefTitle);
|
||||
// Normalized Title
|
||||
assertThat(cursor.getString(3)).isEqualTo("swipe for notifications");
|
||||
assertThat(cursor.getString(3)).isEqualTo(prefTitle.toLowerCase());
|
||||
// Summary On
|
||||
assertThat(cursor.getString(4)).isEqualTo("To check your notifications, " +
|
||||
"swipe down on the fingerprint sensor on the back of your phone.");
|
||||
assertThat(cursor.getString(4)).isEqualTo(prefSummary);
|
||||
// Summary On Normalized
|
||||
assertThat(cursor.getString(5)).isEqualTo("to check your notifications, " +
|
||||
"swipe down on the fingerprint sensor on the back of your phone.");
|
||||
assertThat(cursor.getString(5)).isEqualTo(prefSummary.toLowerCase());
|
||||
// Summary Off - only on for checkbox preferences
|
||||
assertThat(cursor.getString(6)).isEmpty();
|
||||
// Summary off normalized - only on for checkbox preferences
|
||||
@@ -295,7 +297,8 @@ public class DatabaseIndexingManagerTest {
|
||||
// Keywords
|
||||
assertThat(cursor.getString(9)).isEmpty();
|
||||
// Screen Title
|
||||
assertThat(cursor.getString(10)).isEqualTo("Gestures");
|
||||
assertThat(cursor.getString(10)).isEqualTo(
|
||||
mContext.getString(R.string.gesture_preference_title));
|
||||
// Class Name
|
||||
assertThat(cursor.getString(11)).isEqualTo(className);
|
||||
// Icon
|
||||
@@ -322,7 +325,7 @@ public class DatabaseIndexingManagerTest {
|
||||
public void testAddResourceCheckboxPreference_RowsMatch() {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.application_settings);
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
|
||||
/* Should return 6 results, with the following titles:
|
||||
* Advanced Settings, Apps, Manage Apps, Preferred install location, Running Services
|
||||
@@ -377,7 +380,7 @@ public class DatabaseIndexingManagerTest {
|
||||
public void testAddResourceListPreference_RowsMatch() {
|
||||
SearchIndexableResource resource = getFakeResource(R.xml.application_settings);
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
|
||||
cursor.moveToPosition(3);
|
||||
@@ -436,7 +439,7 @@ public class DatabaseIndexingManagerTest {
|
||||
resource.className = "com.android.settings.display.ScreenZoomSettings";
|
||||
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(1);
|
||||
}
|
||||
@@ -448,7 +451,7 @@ public class DatabaseIndexingManagerTest {
|
||||
resource.className = "com.android.settings.display.ScreenZoomSettings";
|
||||
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
cursor.moveToPosition(0);
|
||||
|
||||
@@ -504,7 +507,7 @@ public class DatabaseIndexingManagerTest {
|
||||
resource.className = "com.android.settings.LegalSettings";
|
||||
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
|
||||
assertThat(cursor.getCount()).isEqualTo(2);
|
||||
}
|
||||
@@ -516,7 +519,7 @@ public class DatabaseIndexingManagerTest {
|
||||
resource.className = "com.android.settings.LegalSettings";
|
||||
|
||||
mManager.indexOneSearchIndexableData(mDb, localeStr, resource,
|
||||
new HashMap<String, List<String>>());
|
||||
new HashMap<>());
|
||||
Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index ORDER BY data_title", null);
|
||||
cursor.moveToPosition(0);
|
||||
|
||||
|
@@ -41,6 +41,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -73,6 +74,7 @@ public class IntentSearchViewHolderTest {
|
||||
assertThat(mHolder.titleView).isNotNull();
|
||||
assertThat(mHolder.summaryView).isNotNull();
|
||||
assertThat(mHolder.iconView).isNotNull();
|
||||
assertThat(mHolder.breadcrumbView).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,11 +86,43 @@ public class IntentSearchViewHolderTest {
|
||||
assertThat(mHolder.titleView.getText()).isEqualTo(TITLE);
|
||||
assertThat(mHolder.summaryView.getText()).isEqualTo(SUMMARY);
|
||||
assertThat(mHolder.iconView.getDrawable()).isEqualTo(mIcon);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mHolder.breadcrumbView.getVisibility()).isEqualTo(View.GONE);
|
||||
|
||||
verify(mFragment).onSearchResultClicked();
|
||||
verify(mFragment).startActivity(any(Intent.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_emptySummary_hideSummaryView() {
|
||||
final SearchResult result = new Builder().addTitle(TITLE)
|
||||
.addRank(1)
|
||||
.addPayload(new IntentPayload(null))
|
||||
.addIcon(mIcon)
|
||||
.build();
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
assertThat(mHolder.summaryView.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindViewElements_withBreadcrumb_shouldFormatBreadcrumb() {
|
||||
final List<String> breadcrumbs = new ArrayList<>();
|
||||
breadcrumbs.add("a");
|
||||
breadcrumbs.add("b");
|
||||
breadcrumbs.add("c");
|
||||
final SearchResult result = new Builder().addTitle(TITLE)
|
||||
.addRank(1)
|
||||
.addPayload(new IntentPayload(null))
|
||||
.addBreadcrumbs(breadcrumbs)
|
||||
.addIcon(mIcon)
|
||||
.build();
|
||||
|
||||
mHolder.onBind(mFragment, result);
|
||||
assertThat(mHolder.breadcrumbView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(mHolder.breadcrumbView.getText()).isEqualTo("a > b > c");
|
||||
}
|
||||
|
||||
private SearchResult getSearchResult() {
|
||||
Builder builder = new Builder();
|
||||
builder.addTitle(TITLE)
|
||||
|
Reference in New Issue
Block a user