App header cleanup

- Refactor the entity header layout to use LinearLayout and add id to
  content area
- Remove now unused AppHeader class
- Make entire icon+text area clickable and link to app info page
  Refactor the binding logic from bindButton to its own method.
- Remove unused MultiLinePreference

Fix: 62705377
Test: make RunSettingsRoboTests

Change-Id: I6db554695410e71b669f6fdba29d98fedc3364b9
This commit is contained in:
Fan Zhang
2017-06-30 13:14:02 -07:00
parent 08da5d84c0
commit 75bee9bf98
14 changed files with 137 additions and 224 deletions

View File

@@ -25,13 +25,12 @@ import android.support.v7.preference.PreferenceScreen;
import android.util.ArraySet;
import android.view.View;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.applications.PackageManagerWrapper;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settings.widget.EntityHeaderController.ActionType;
import com.android.settingslib.AppItem;
import org.junit.After;
@@ -46,6 +45,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -96,7 +96,7 @@ public class AppDataUsageTest {
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
verify(mHeaderController).setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE);
verify(mHeaderController).setHasAppInfoLink(false);
}
@Test
@@ -119,6 +119,7 @@ public class AppDataUsageTest {
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
when(mHeaderController.setUid(fakeUserId)).thenReturn(mHeaderController);
when(mHeaderController.setHasAppInfoLink(anyBoolean())).thenReturn(mHeaderController);
doReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS))
.when(mFragment)
@@ -128,7 +129,7 @@ public class AppDataUsageTest {
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
verify(mHeaderController)
.setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE);
.setHasAppInfoLink(true);
verify(mHeaderController)
.setUid(fakeUserId);
}

View File

@@ -53,6 +53,7 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -182,14 +183,17 @@ public class EntityHeaderControllerTest {
}
@Test
public void bindButton_noAppInfo_shouldNotShowButton() {
public void bindButton_noAppInfo_shouldNotAttachClickListener() {
final View appLinks = mLayoutInflater
.inflate(R.layout.settings_entity_header, null /* root */);
final Activity activity = mock(Activity.class);
when(mFragment.getActivity()).thenReturn(activity);
mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
mController.setPackageName(null)
.setHasAppInfoLink(true)
.setButtonActions(
EntityHeaderController.ActionType.ACTION_APP_INFO,
EntityHeaderController.ActionType.ACTION_NONE,
EntityHeaderController.ActionType.ACTION_NONE);
mController.done(mActivity);
@@ -197,45 +201,32 @@ public class EntityHeaderControllerTest {
.isEqualTo(View.GONE);
assertThat(appLinks.findViewById(android.R.id.button2).getVisibility())
.isEqualTo(View.GONE);
appLinks.findViewById(R.id.entity_header_content).performClick();
verify(mFragment, never()).getActivity();
verify(activity, never()).startActivity(any(Intent.class));
}
@Test
public void bindButton_hasAppInfo_shouldShowButton() {
public void bindButton_hasAppInfo_shouldAttachClickListener() {
final View appLinks = mLayoutInflater
.inflate(R.layout.settings_entity_header, null /* root */);
when(mFragment.getActivity()).thenReturn(mock(Activity.class));
mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
mController.setPackageName("123")
.setUid(UserHandle.USER_SYSTEM)
.setButtonActions(
EntityHeaderController.ActionType.ACTION_APP_INFO,
EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
mController.done(mActivity);
assertThat(appLinks.findViewById(android.R.id.button1).getVisibility())
.isEqualTo(View.VISIBLE);
assertThat(appLinks.findViewById(android.R.id.button2).getVisibility())
.isEqualTo(View.GONE);
}
@Test
public void bindButton_hasAppInfo_shouldHaveContentDescription() {
final View appLinks = mLayoutInflater
.inflate(R.layout.settings_entity_header, null /* root */);
when(mFragment.getActivity()).thenReturn(mock(Activity.class));
final Activity activity = mock(Activity.class);
when(mFragment.getActivity()).thenReturn(activity);
when(mContext.getString(eq(R.string.application_info_label))).thenReturn("App Info");
mController = EntityHeaderController.newInstance(mActivity, mFragment, appLinks);
mController.setPackageName("123")
.setUid(UserHandle.USER_SYSTEM)
.setHasAppInfoLink(true)
.setButtonActions(
EntityHeaderController.ActionType.ACTION_APP_INFO,
EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
EntityHeaderController.ActionType.ACTION_NONE);
mController.done(mActivity);
assertThat(appLinks.findViewById(android.R.id.button1).getContentDescription().toString())
.isEqualTo("App info");
appLinks.findViewById(R.id.entity_header_content).performClick();
verify(activity).startActivityForResultAsUser(
any(Intent.class), anyInt(), any(UserHandle.class));
}
@Test