Initial search bar implementation.
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
Bug: 37477506
Test: make RunSettingsRoboTests
Change-Id: Id7477b90fbaf30eb5cac1ee244c847bddb95b3fd
diff --git a/Android.mk b/Android.mk
index 349b79c..eeaad0c 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,9 +22,10 @@
LOCAL_STATIC_ANDROID_LIBRARIES := \
android-support-v4 \
android-support-v13 \
- android-support-v7-recyclerview \
- android-support-v7-preference \
android-support-v7-appcompat \
+ android-support-v7-cardview \
+ android-support-v7-preference \
+ android-support-v7-recyclerview \
android-support-v14-preference
LOCAL_JAVA_LIBRARIES := \
diff --git a/res/layout/dashboard_header_spacer.xml b/res/layout/dashboard_header_spacer.xml
new file mode 100644
index 0000000..442ae48
--- /dev/null
+++ b/res/layout/dashboard_header_spacer.xml
@@ -0,0 +1,25 @@
+<?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:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="@dimen/search_bar_margin">
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="?android:attr/actionBarSize"/>
+</LinearLayout>
diff --git a/res/layout/settings_main_dashboard.xml b/res/layout/settings_main_dashboard.xml
index c10193c..1a3b133 100644
--- a/res/layout/settings_main_dashboard.xml
+++ b/res/layout/settings_main_dashboard.xml
@@ -18,7 +18,31 @@
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/main_content"
- android:layout_height="match_parent"
- android:layout_width="match_parent"
- />
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent">
+ <FrameLayout
+ android:id="@+id/main_content"
+ android:layout_height="match_parent"
+ android:layout_width="match_parent"/>
+ <android.support.v7.widget.CardView
+ android:id="@+id/search_bar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="@dimen/search_bar_margin"
+ app:cardCornerRadius="2dp"
+ app:cardBackgroundColor="?android:attr/colorBackground"
+ app:cardElevation="2dp">
+ <Toolbar
+ android:id="@+id/search_action_bar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="@dimen/search_bar_negative_margin"
+ android:background="?android:attr/selectableItemBackground"
+ android:navigationIcon="@drawable/ic_search_24dp"
+ android:title="@string/search_menu"
+ android:titleTextAppearance="?android:attr/subtitleTextAppearance"
+ android:titleTextColor="?android:attr/textColorHint"
+ android:theme="?android:attr/actionBarTheme"/>
+ </android.support.v7.widget.CardView>
+</FrameLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 5c6796c..ad55b62 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -139,6 +139,12 @@
<dimen name="search_suggestion_item_image_margin_start">32dp</dimen>
<dimen name="search_suggestion_item_image_margin_end">32dp</dimen>
+ <!-- The following two margins need to match, with the caveat that
+ the second should be negative. The second one ensures that the icons and text
+ align despite the additional padding caused by the search bar's card background. -->
+ <dimen name="search_bar_margin">8dp</dimen>
+ <dimen name="search_bar_negative_margin">-8dp</dimen>
+
<!-- Dimensions for Wifi Assistant Card -->
<dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
<dimen name="wifi_assistant_padding_start_end">16dp</dimen>
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index daa23d6..ca39b58 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -50,6 +50,7 @@
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.Toolbar;
import com.android.internal.util.ArrayUtils;
import com.android.settings.Settings.WifiSettingsActivity;
@@ -62,6 +63,7 @@
import com.android.settings.development.DevelopmentSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DynamicIndexableContentMonitor;
+import com.android.settings.search.SearchActivity;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.wfd.WifiDisplaySettings;
import com.android.settings.widget.SwitchBar;
@@ -75,7 +77,7 @@
public class SettingsActivity extends SettingsDrawerActivity
implements PreferenceManager.OnPreferenceTreeClickListener,
PreferenceFragment.OnPreferenceStartFragmentCallback,
- ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
+ ButtonBarHandler, FragmentManager.OnBackStackChangedListener, OnClickListener {
private static final String LOG_TAG = "Settings";
@@ -345,6 +347,14 @@
launchSettingFragment(initialFragmentName, isSubSettings, intent);
}
+ if (mIsShowingDashboard) {
+ findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
+ findViewById(R.id.action_bar).setVisibility(View.GONE);
+ Toolbar toolbar = findViewById(R.id.search_action_bar);
+ toolbar.setOnClickListener(this);
+ setActionBar(toolbar);
+ }
+
mActionBar = getActionBar();
if (mActionBar != null) {
mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
@@ -432,10 +442,10 @@
switchToFragment(initialFragmentName, initialArguments, true, false,
mInitialTitleResId, mInitialTitle, false);
} else {
- // No UP affordance if we are displaying the main Dashboard
- mDisplayHomeAsUpEnabled = false;
- // Show Search affordance
- mDisplaySearch = true;
+ // Show search icon as up affordance if we are displaying the main Dashboard
+ mDisplayHomeAsUpEnabled = true;
+ // toolbar is search affordance so don't show search
+ mDisplaySearch = false;
mInitialTitleResId = R.string.dashboard_title;
switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
@@ -940,4 +950,10 @@
return bitmap;
}
-}
\ No newline at end of file
+
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(this, SearchActivity.class);
+ startActivity(intent);
+ }
+}
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index 2e7b861..eb74690 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -15,6 +15,8 @@
*/
package com.android.settings.dashboard;
+import android.annotation.AttrRes;
+import android.annotation.ColorInt;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
@@ -54,6 +56,7 @@
private static final String STATE_CATEGORY_LIST = "category_list";
private static final String STATE_SUGGESTION_MODE = "suggestion_mode";
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
+ private static final int DONT_SET_BACKGROUND_ATTR = -1;
private final IconCache mCache;
private final Context mContext;
@@ -223,6 +226,9 @@
public void onBindViewHolder(DashboardItemHolder holder, int position) {
final int type = mDashboardData.getItemTypeByPosition(position);
switch (type) {
+ case R.layout.dashboard_header_spacer:
+ onBindHeaderSpacer(holder, position);
+ break;
case R.layout.dashboard_category:
onBindCategory(holder,
(DashboardCategory) mDashboardData.getItemEntityByPosition(position));
@@ -343,6 +349,33 @@
notifyDashboardDataChanged(prevData);
}
+ private void onBindHeaderSpacer(DashboardItemHolder holder, int position) {
+ if (mDashboardData.size() > (position + 1)) {
+ // The spacer that goes underneath the search bar needs to match the
+ // background of the first real view. That view is either a condition,
+ // a suggestion, or the dashboard item.
+ //
+ // If it's a dashboard item, set null background so it uses the parent's
+ // background like the other views. Otherwise, match the colors.
+ int nextType = mDashboardData.getItemTypeByPosition(position + 1);
+ int colorAttr = nextType == R.layout.suggestion_header
+ ? android.R.attr.colorSecondary
+ : nextType == R.layout.condition_card
+ ? android.R.attr.colorAccent
+ : DONT_SET_BACKGROUND_ATTR;
+
+ if (colorAttr != DONT_SET_BACKGROUND_ATTR) {
+ TypedArray array = holder.itemView.getContext()
+ .obtainStyledAttributes(new int[]{colorAttr});
+ @ColorInt int color = array.getColor(0, 0);
+ array.recycle();
+ holder.itemView.setBackgroundColor(color);
+ } else {
+ holder.itemView.setBackground(null);
+ }
+ }
+ }
+
@VisibleForTesting
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
.SuggestionHeaderData data) {
diff --git a/src/com/android/settings/dashboard/DashboardData.java b/src/com/android/settings/dashboard/DashboardData.java
index 0a5ff35..60d7d8d 100644
--- a/src/com/android/settings/dashboard/DashboardData.java
+++ b/src/com/android/settings/dashboard/DashboardData.java
@@ -45,7 +45,8 @@
public static final int DEFAULT_SUGGESTION_COUNT = 2;
// id namespace for different type of items.
- private static final int NS_SPACER = 0;
+ private static final int NS_HEADER_SPACER = 0;
+ private static final int NS_SPACER = 1000;
private static final int NS_ITEMS = 2000;
private static final int NS_CONDITION = 3000;
@@ -234,6 +235,9 @@
* and mIsShowingAll, mSuggestionMode flag.
*/
private void buildItemsData() {
+ // add the view that goes under the search bar
+ countItem(null, R.layout.dashboard_header_spacer, true, NS_HEADER_SPACER);
+ resetCount();
boolean hasConditions = false;
for (int i = 0; mConditions != null && i < mConditions.size(); i++) {
boolean shouldShow = mConditions.get(i).shouldShow();
diff --git a/src/com/android/settings/search/SearchFeatureProviderImpl.java b/src/com/android/settings/search/SearchFeatureProviderImpl.java
index 725a8ee..8bb57c6 100644
--- a/src/com/android/settings/search/SearchFeatureProviderImpl.java
+++ b/src/com/android/settings/search/SearchFeatureProviderImpl.java
@@ -51,13 +51,10 @@
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(new MenuItem.OnMenuItemClickListener() {
- @Override
- public boolean onMenuItemClick(MenuItem item) {
- Intent intent = new Intent(activity, SearchActivity.class);
- activity.startActivity(intent);
- return true;
- }
+ .setOnMenuItemClickListener(item -> {
+ Intent intent = new Intent(activity, SearchActivity.class);
+ activity.startActivity(intent);
+ return true;
});
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
diff --git a/tests/robotests/src/com/android/settings/SettingsActivityTest.java b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
index 2250090..75080cc 100644
--- a/tests/robotests/src/com/android/settings/SettingsActivityTest.java
+++ b/tests/robotests/src/com/android/settings/SettingsActivityTest.java
@@ -30,12 +30,14 @@
import android.app.ActivityManager;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
+import com.android.settings.search.SearchActivity;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -46,6 +48,7 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -140,4 +143,15 @@
assertThat(mActivity.mDisplaySearch).isTrue();
}
+
+ @Test
+ public void testOnClick() {
+ doReturn("com.android.settings").when(mActivity).getPackageName();
+
+ mActivity.onClick(null);
+
+ Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
+ assertThat(intent.getComponent()).isEqualTo(
+ new ComponentName("com.android.settings", SearchActivity.class.getName()));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index 365ba55..8eae8bc 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -24,17 +24,19 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.robolectric.RuntimeEnvironment.application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.graphics.drawable.ColorDrawable;
import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
+import android.widget.LinearLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
@@ -47,6 +49,7 @@
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
+import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
@@ -58,6 +61,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
@@ -113,6 +117,53 @@
}
@Test
+ public void testOnBindViewHolder_spacer_noSuggestions_noConditions() {
+ makeCategory();
+ DashboardAdapter.DashboardItemHolder holder = setupSpacer();
+
+ mDashboardAdapter.onBindViewHolder(holder, 0);
+
+ assertThat(holder.itemView.getBackground()).isNull();
+ }
+
+ @Test
+ public void testOnBindViewHolder_spacer_suggestion_noConditions() {
+ setupSuggestions(makeSuggestions("pkg1"));
+ makeCategory();
+ DashboardAdapter.DashboardItemHolder holder = setupSpacer();
+
+ mDashboardAdapter.onBindViewHolder(holder, 0);
+
+ assertThat(holder.itemView.getBackground()).isNotNull();
+ assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
+ }
+
+ @Test
+ public void testOnBindViewHolder_spacer_noSuggestion_condition() {
+ makeCondition();
+ makeCategory();
+ DashboardAdapter.DashboardItemHolder holder = setupSpacer();
+
+ mDashboardAdapter.onBindViewHolder(holder, 0);
+
+ assertThat(holder.itemView.getBackground()).isNotNull();
+ assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
+ }
+
+ @Test
+ public void testOnBindViewHolder_spacer_suggestion_condition() {
+ setupSuggestions(makeSuggestions("pkg1"));
+ makeCondition();
+ makeCategory();
+ DashboardAdapter.DashboardItemHolder holder = setupSpacer();
+
+ mDashboardAdapter.onBindViewHolder(holder, 0);
+
+ assertThat(holder.itemView.getBackground()).isNotNull();
+ assertThat(holder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
+ }
+
+ @Test
public void testSetConditions_AfterSetConditions_ExpandedConditionNull() {
mDashboardAdapter.onExpandClick(mView);
assertThat(mDashboardAdapter.mDashboardData.getExpandedCondition()).isEqualTo(mCondition);
@@ -122,7 +173,7 @@
@Test
public void testSuggestionsLogs_NotExpanded() {
- setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+ setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
verify(mFactory.metricsFeatureProvider, times(2)).action(
any(Context.class), mActionCategoryCaptor.capture(),
mActionPackageCaptor.capture());
@@ -137,7 +188,7 @@
@Test
public void testSuggestionsLogs_NotExpandedAndPaused() {
- setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+ setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onPause();
verify(mFactory.metricsFeatureProvider, times(4)).action(
any(Context.class), mActionCategoryCaptor.capture(),
@@ -154,7 +205,7 @@
@Test
public void testSuggestionsLogs_Expanded() {
- setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+ setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
@@ -173,7 +224,7 @@
@Test
public void testSuggestionsLogs_ExpandedAndPaused() {
- setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+ setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
@@ -196,7 +247,7 @@
@Test
public void testSuggestionsLogs_ExpandedAfterPause() {
- setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+ setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
@@ -221,7 +272,7 @@
@Test
public void testSuggestionsLogs_ExpandedAfterPauseAndPausedAgain() {
- setUpSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
+ setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3"));
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
@@ -250,7 +301,7 @@
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShown() {
- setUpSuggestions(makeSuggestions("pkg1"));
+ setupSuggestions(makeSuggestions("pkg1"));
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
@@ -267,7 +318,7 @@
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAndPaused() {
- setUpSuggestions(makeSuggestions("pkg1"));
+ setupSuggestions(makeSuggestions("pkg1"));
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
mSuggestionHolder.itemView.callOnClick();
@@ -286,7 +337,7 @@
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPause() {
- setUpSuggestions(makeSuggestions("pkg1"));
+ setupSuggestions(makeSuggestions("pkg1"));
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
@@ -306,7 +357,7 @@
@Test
public void testSuggestionsLogs_ExpandedWithLessThanDefaultShownAfterPauseAndPausedAgain() {
- setUpSuggestions(makeSuggestions("pkg1"));
+ setupSuggestions(makeSuggestions("pkg1"));
mDashboardAdapter.onPause();
mDashboardAdapter.onBindSuggestionHeader(
mSuggestionHolder, mSuggestionHeaderData);
@@ -330,15 +381,15 @@
public void testBindViewHolder_inflateRemoteView() {
List<Tile> packages = makeSuggestions("pkg1");
RemoteViews remoteViews = mock(RemoteViews.class);
- TextView textView = new TextView(application);
+ TextView textView = new TextView(RuntimeEnvironment.application);
doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
packages.get(0).remoteViews = remoteViews;
mDashboardAdapter.setCategoriesAndSuggestions(Collections.emptyList(), packages);
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
- new FrameLayout(application),
+ new FrameLayout(RuntimeEnvironment.application),
R.layout.suggestion_tile_card);
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
+ mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
mSuggestionHolder.itemView.performClick();
@@ -347,7 +398,8 @@
@Test
public void testBindViewHolder_primaryViewHandlesClick() {
- Context context = new ContextThemeWrapper(application, R.style.Theme_Settings);
+ Context context =
+ new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
List<Tile> packages = makeSuggestions("pkg1");
RemoteViews remoteViews = mock(RemoteViews.class);
@@ -362,7 +414,7 @@
new FrameLayout(context),
R.layout.suggestion_tile_card);
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
+ mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
mSuggestionHolder.itemView.performClick();
assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
@@ -375,7 +427,8 @@
@Test
public void testBindViewHolder_viewsClearedOnRebind() {
- Context context = new ContextThemeWrapper(application, R.style.Theme_Settings);
+ Context context =
+ new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
List<Tile> packages = makeSuggestions("pkg1");
RemoteViews remoteViews = mock(RemoteViews.class);
@@ -390,8 +443,8 @@
new FrameLayout(context),
R.layout.suggestion_tile_card);
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
- mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 1);
+ mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
+ mDashboardAdapter.onBindViewHolder(mSuggestionHolder, 2);
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
assertThat(itemView.getChildCount()).isEqualTo(1);
@@ -408,11 +461,31 @@
return suggestions;
}
- private void setUpSuggestions(List<Tile> suggestions) {
+ private void setupSuggestions(List<Tile> suggestions) {
mDashboardAdapter.setCategoriesAndSuggestions(new ArrayList<>(), suggestions);
mSuggestionHolder = mDashboardAdapter.onCreateViewHolder(
- new FrameLayout(application),
- mDashboardAdapter.getItemViewType(0));
+ new FrameLayout(RuntimeEnvironment.application),
+ mDashboardAdapter.getItemViewType(1));
}
+ private void makeCondition() {
+ final List<Condition> conditions = new ArrayList<>();
+ Condition condition = mock(Condition.class);
+ when(condition.shouldShow()).thenReturn(true);
+ conditions.add(condition);
+ mDashboardAdapter.setConditions(conditions);
+ }
+
+ private void makeCategory() {
+ List<DashboardCategory> categories = new ArrayList<>();
+ categories.add(new DashboardCategory());
+ mDashboardAdapter.setCategory(categories);
+ }
+
+ private DashboardAdapter.DashboardItemHolder setupSpacer() {
+ Context context = RuntimeEnvironment.application;
+ final View view = LayoutInflater.from(context)
+ .inflate(R.layout.dashboard_header_spacer, new LinearLayout(context), false);
+ return new DashboardAdapter.DashboardItemHolder(view);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
index abea565..8bbb15b 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardDataTest.java
@@ -112,7 +112,7 @@
public void testBuildItemsData_containsAllData() {
final DashboardData.SuggestionHeaderData data =
new DashboardData.SuggestionHeaderData(false, 1, 0);
- final Object[] expectedObjects = {mTestCondition, null, data, mTestSuggestion,
+ final Object[] expectedObjects = {null, mTestCondition, null, data, mTestSuggestion,
mDashboardCategory, mTestCategoryTile};
final int expectedSize = expectedObjects.length;
@@ -171,7 +171,7 @@
@Test
public void testDiffUtil_DataEqual_noResultData() {
List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
- testDiffUtil(mDashboardDataWithOneConditions,
+ testDiffUtil(mDashboardDataWithOneConditions,
mDashboardDataWithOneConditions, testResultData);
}
@@ -180,7 +180,7 @@
//Build testResultData
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
testResultData.add(new ListUpdateResult.ResultData(
- ListUpdateResult.ResultData.TYPE_OPERATION_INSERT, 1, 1));
+ ListUpdateResult.ResultData.TYPE_OPERATION_INSERT, 2, 1));
testDiffUtil(mDashboardDataWithOneConditions,
mDashboardDataWithTwoConditions, testResultData);
@@ -191,7 +191,7 @@
//Build testResultData
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
testResultData.add(new ListUpdateResult.ResultData(
- ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 0, 6));
+ ListUpdateResult.ResultData.TYPE_OPERATION_REMOVE, 1, 6));
testDiffUtil(mDashboardDataWithOneConditions, mDashboardDataWithNoItems, testResultData);
}
@@ -203,8 +203,8 @@
mDashboardDataWithOneConditions.getItemList(),
mDashboardDataWithOneConditions.getItemList());
- // Item in position 0 is condition card, which payload should not be null
- assertThat(callback.getChangePayload(0, 0)).isNotEqualTo(null);
+ // Item in position 1 is condition card, which payload should not be null
+ assertThat(callback.getChangePayload(1, 1)).isNotNull();
}
@Test
@@ -214,9 +214,9 @@
mDashboardDataWithOneConditions.getItemList(),
mDashboardDataWithOneConditions.getItemList());
- // Only item in position 0 is condition card, so others' payload should be null
- for (int i = 1; i < mDashboardDataWithOneConditions.getItemList().size(); i++) {
- assertThat(callback.getChangePayload(i, i)).isEqualTo(null);
+ // Position 0 is spacer, 1 is condition card, so others' payload should be null
+ for (int i = 2; i < mDashboardDataWithOneConditions.getItemList().size(); i++) {
+ assertThat(callback.getChangePayload(i, i)).isNull();
}
}
@@ -356,6 +356,11 @@
return arg2 - resultData.arg2;
}
+
+ @Override
+ public String toString() {
+ return "op:" + operation + ",arg1:" + arg1 + ",arg2:" + arg2;
+ }
}
}
}