OSDN Git Service

App header cleanup
authorFan Zhang <zhfan@google.com>
Fri, 30 Jun 2017 20:14:02 +0000 (13:14 -0700)
committerFan Zhang <zhfan@google.com>
Thu, 6 Jul 2017 20:23:38 +0000 (13:23 -0700)
- 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

14 files changed:
res/layout-sw320dp/settings_entity_header.xml
res/layout/settings_entity_header.xml
src/com/android/settings/AppHeader.java [deleted file]
src/com/android/settings/MultiLinePreference.java [deleted file]
src/com/android/settings/applications/AppInfoWithHeader.java
src/com/android/settings/applications/InstalledAppDetails.java
src/com/android/settings/applications/ProcessStatsBase.java
src/com/android/settings/applications/ProcessStatsDetail.java
src/com/android/settings/datausage/AppDataUsage.java
src/com/android/settings/notification/AppNotificationSettings.java
src/com/android/settings/notification/ChannelNotificationSettings.java
src/com/android/settings/widget/EntityHeaderController.java
tests/robotests/src/com/android/settings/datausage/AppDataUsageTest.java
tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java

index 5096250..6240cc1 100644 (file)
   -->
 
 <!-- Entity header -->
-<RelativeLayout
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/entity_header"
     style="@style/EntityHeader"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:paddingStart="@dimen/preference_no_icon_padding_start"
     android:paddingTop="24dp"
     android:paddingBottom="24dp">
 
-    <ImageView
-        android:id="@+id/entity_header_icon"
-        android:layout_width="48dp"
-        android:layout_height="48dp"
-        android:scaleType="fitXY"
-        android:layout_gravity="center_horizontal"
-        android:antialias="true" />
+    <LinearLayout
+        android:id="@+id/entity_header_content"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:background="?android:attr/selectableItemBackground"
+        android:orientation="horizontal"
+        android:paddingStart="56dp">
+
+        <ImageView
+            android:id="@+id/entity_header_icon"
+            android:layout_width="48dp"
+            android:layout_height="48dp"
+            android:scaleType="fitXY"
+            android:layout_gravity="center_horizontal"
+            android:antialias="true" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingStart="16dp"
+            android:paddingEnd="16dp"
+            android:orientation="vertical">
+
+            <TextView
+                android:id="@+id/entity_header_title"
+                style="@style/TextAppearance.EntityHeaderTitle"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:singleLine="false"
+                android:ellipsize="marquee"
+                android:gravity="start"
+                android:textDirection="locale"
+                android:paddingTop="8dp" />
+
+            <TextView
+                android:id="@+id/install_type"
+                android:visibility="gone"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="start"
+                android:singleLine="true"
+                android:ellipsize="marquee"
+                android:textAppearance="@android:style/TextAppearance.Material.Body1"
+                android:textColor="?android:attr/textColorSecondary" />
+
+            <TextView
+                android:id="@+id/entity_header_summary"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="start"
+                android:singleLine="true"
+                android:ellipsize="marquee"
+                android:textAppearance="@android:style/TextAppearance.Material.Body1"
+                android:textColor="?android:attr/textColorSecondary" />
+
+        </LinearLayout>
+    </LinearLayout>
 
     <LinearLayout
         android:id="@+id/entity_header_links"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
-        android:layout_alignParentEnd="true"
         android:orientation="vertical">
 
         <ImageButton
 
     </LinearLayout>
 
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_toEndOf="@id/entity_header_icon"
-        android:layout_toStartOf="@id/entity_header_links"
-        android:paddingStart="16dp"
-        android:paddingEnd="16dp"
-        android:orientation="vertical">
-
-        <TextView
-            android:id="@+id/entity_header_title"
-            style="@style/TextAppearance.EntityHeaderTitle"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:singleLine="false"
-            android:ellipsize="marquee"
-            android:gravity="start"
-            android:textDirection="locale"
-            android:paddingTop="8dp" />
-
-        <TextView
-            android:id="@+id/install_type"
-            android:visibility="gone"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:gravity="start"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:textAppearance="@android:style/TextAppearance.Material.Body1"
-            android:textColor="?android:attr/textColorSecondary" />
-
-        <TextView
-            android:id="@+id/entity_header_summary"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:gravity="start"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:textAppearance="@android:style/TextAppearance.Material.Body1"
-            android:textColor="?android:attr/textColorSecondary" />
-
-    </LinearLayout>
-
-</RelativeLayout>
\ No newline at end of file
+</LinearLayout>
\ No newline at end of file
index 61a718c..6254d7a 100644 (file)
     android:orientation="horizontal">
 
     <LinearLayout
+        android:id="@+id/entity_header_content"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
+        android:background="?android:attr/selectableItemBackground"
         android:orientation="vertical">
 
         <ImageView
diff --git a/src/com/android/settings/AppHeader.java b/src/com/android/settings/AppHeader.java
deleted file mode 100644 (file)
index 45902d8..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2015 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;
-
-import android.app.Fragment;
-import android.content.Intent;
-import android.os.Bundle;
-
-public class AppHeader {
-
-    public static final String EXTRA_HIDE_INFO_BUTTON = "hideInfoButton";
-    // constant value that can be used to check return code from sub activity.
-    private static final int INSTALLED_APP_DETAILS = 1;
-
-    public static boolean includeAppInfo(final Fragment fragment) {
-        Bundle args = fragment.getArguments();
-        boolean showInfo = true;
-        if (args != null && args.getBoolean(EXTRA_HIDE_INFO_BUTTON, false)) {
-            showInfo = false;
-        }
-        Intent intent = fragment.getActivity().getIntent();
-        if (intent != null && intent.getBooleanExtra(EXTRA_HIDE_INFO_BUTTON, false)) {
-            showInfo = false;
-        }
-        return showInfo;
-    }
-}
diff --git a/src/com/android/settings/MultiLinePreference.java b/src/com/android/settings/MultiLinePreference.java
deleted file mode 100644 (file)
index fff6b24..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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;
-
-import android.content.Context;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceViewHolder;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.TextView;
-
-public class MultiLinePreference extends Preference {
-
-    public MultiLinePreference(Context ctx, AttributeSet attrs, int defStyle) {
-        super(ctx, attrs, defStyle);
-    }
-
-    public MultiLinePreference(Context ctx, AttributeSet attrs) {
-        super(ctx, attrs);
-    }
-
-    public MultiLinePreference(Context ctx) {
-        super(ctx);
-    }
-
-    @Override
-    public void onBindViewHolder(PreferenceViewHolder view) {
-        super.onBindViewHolder(view);
-
-        TextView textView = (TextView) view.findViewById(android.R.id.title);
-        if (textView != null) {
-            textView.setSingleLine(false);
-        }
-    }
-}
index 95877e9..3df81c7 100644 (file)
@@ -51,7 +51,8 @@ public abstract class AppInfoWithHeader extends AppInfoBase {
                 .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
                 .setPackageName(mPackageName)
                 .setUid(mPackageInfo.applicationInfo.uid)
-                .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+                .setHasAppInfoLink(true)
+                .setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE)
                 .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
index b3aacb2..d12fcf8 100755 (executable)
@@ -69,7 +69,6 @@ import android.widget.Button;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.os.BatterySipper;
 import com.android.internal.os.BatteryStatsHelper;
-import com.android.settings.AppHeader;
 import com.android.settings.DeviceAdminAdd;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
@@ -145,7 +144,7 @@ public class InstalledAppDetails extends AppInfoBase
     private static final int DLG_FORCE_STOP = DLG_BASE + 1;
     private static final int DLG_DISABLE = DLG_BASE + 2;
     private static final int DLG_SPECIAL_DISABLE = DLG_BASE + 3;
-
+    private static final String EXTRA_HIDE_INFO_BUTTON = "hideInfoButton";
     private static final String KEY_HEADER = "header_view";
     private static final String KEY_INSTANT_APP_BUTTONS = "instant_app_buttons";
     private static final String KEY_ACTION_BUTTONS = "action_buttons";
@@ -445,6 +444,7 @@ public class InstalledAppDetails extends AppInfoBase
         EntityHeaderController.newInstance(activity, this, mHeader.findViewById(R.id.entity_header))
                 .setRecyclerView(getListView(), getLifecycle())
                 .setPackageName(mPackageName)
+                .setHasAppInfoLink(false)
                 .setButtonActions(EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
                         EntityHeaderController.ActionType.ACTION_NONE)
                 .styleActionBar(activity)
@@ -935,7 +935,7 @@ public class InstalledAppDetails extends AppInfoBase
         // start new activity to manage app permissions
         Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS);
         intent.putExtra(Intent.EXTRA_PACKAGE_NAME, mAppEntry.info.packageName);
-        intent.putExtra(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
+        intent.putExtra(EXTRA_HIDE_INFO_BUTTON, true);
         try {
             getActivity().startActivityForResult(intent, SUB_INFO_FRAGMENT);
         } catch (ActivityNotFoundException e) {
@@ -953,7 +953,6 @@ public class InstalledAppDetails extends AppInfoBase
         Bundle args = new Bundle();
         args.putString(ARG_PACKAGE_NAME, appEntry.info.packageName);
         args.putInt(ARG_PACKAGE_UID, appEntry.info.uid);
-        args.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
 
         SettingsActivity sa = (SettingsActivity) caller.getActivity();
         sa.startPreferencePanel(caller, fragment.getName(), args, -1, title, caller,
index 7aa3cc7..3f66789 100644 (file)
@@ -24,7 +24,6 @@ import android.widget.ArrayAdapter;
 import android.widget.Spinner;
 
 import com.android.internal.app.procstats.ProcessStats;
-import com.android.settings.AppHeader;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
@@ -138,7 +137,6 @@ public abstract class ProcessStatsBase extends SettingsPreferenceFragment
         args.putDouble(ProcessStatsDetail.EXTRA_MAX_MEMORY_USAGE,
                 memInfo.usedWeight * memInfo.weightToRam);
         args.putDouble(ProcessStatsDetail.EXTRA_TOTAL_SCALE, memInfo.totalScale);
-        args.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, !includeAppInfo);
         activity.startPreferencePanel(null, ProcessStatsDetail.class.getName(), args,
                 R.string.memory_usage, null, null, 0);
     }
index b9c3826..af35298 100644 (file)
@@ -137,7 +137,8 @@ public class ProcessStatsDetail extends SettingsPreferenceFragment {
                 .setUid(mApp.mUiTargetApp != null
                         ? mApp.mUiTargetApp.uid
                         : UserHandle.USER_NULL)
-                .setButtonActions(ActionType.ACTION_APP_INFO, ActionType.ACTION_NONE)
+                .setHasAppInfoLink(true)
+                .setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE)
                 .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
index d9643f2..222693d 100644 (file)
@@ -338,9 +338,8 @@ public class AppDataUsage extends DataUsageBase implements Preference.OnPreferen
                 .newInstance(activity, this, null /* header */)
                 .setRecyclerView(getListView(), getLifecycle())
                 .setUid(uid)
-                .setButtonActions(showInfoButton
-                                ? EntityHeaderController.ActionType.ACTION_APP_INFO
-                                : EntityHeaderController.ActionType.ACTION_NONE,
+                .setHasAppInfoLink(showInfoButton)
+                .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
                         EntityHeaderController.ActionType.ACTION_NONE)
                 .setIcon(mIcon)
                 .setLabel(mLabel)
index 5cac0bb..78a0a74 100644 (file)
@@ -34,7 +34,6 @@ import android.view.View;
 import android.widget.Switch;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.AppHeader;
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.applications.AppInfoBase;
@@ -137,6 +136,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
                 .setLabel(mAppRow.label)
                 .setPackageName(mAppRow.pkg)
                 .setUid(mAppRow.uid)
+                .setHasAppInfoLink(true)
                 .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
                         EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
                 .done(activity, getPrefContext());
@@ -219,7 +219,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
         channelPref.setSummary(getImportanceSummary(channel));
         Bundle channelArgs = new Bundle();
         channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
-        channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
         channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
         channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
         Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
index c873c07..fa6c8ee 100644 (file)
@@ -36,7 +36,6 @@ import android.view.View;
 import android.widget.Switch;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.AppHeader;
 import com.android.settings.R;
 import com.android.settings.RingtonePreference;
 import com.android.settings.Utils;
@@ -146,8 +145,9 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
                 .setSummary(mAppRow.label)
                 .setPackageName(mAppRow.pkg)
                 .setUid(mAppRow.uid)
-                .setButtonActions(EntityHeaderController.ActionType.ACTION_APP_INFO,
-                        EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
+                .setButtonActions(EntityHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
+                        EntityHeaderController.ActionType.ACTION_NONE)
+                .setHasAppInfoLink(true)
                 .done(activity, getPrefContext());
         getPreferenceScreen().addPreference(pref);
     }
@@ -283,7 +283,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
         mImportance = findPreference(KEY_IMPORTANCE);
         Bundle channelArgs = new Bundle();
         channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
-        channelArgs.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
         channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
         channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
         mImportance.setEnabled(mSuspendedAppsAdmin == null && isChannelConfigurable(mChannel));
index 8f64920..f2fca7c 100644 (file)
@@ -39,7 +39,6 @@ import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.TextView;
 
-import com.android.settings.AppHeader;
 import com.android.settings.R;
 import com.android.settings.Utils;
 import com.android.settings.applications.AppInfoBase;
@@ -59,15 +58,13 @@ import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION
 public class EntityHeaderController {
 
     @IntDef({ActionType.ACTION_NONE,
-            ActionType.ACTION_APP_INFO,
             ActionType.ACTION_APP_PREFERENCE,
             ActionType.ACTION_NOTIF_PREFERENCE})
     @Retention(RetentionPolicy.SOURCE)
     public @interface ActionType {
         int ACTION_NONE = 0;
-        int ACTION_APP_INFO = 1;
-        int ACTION_APP_PREFERENCE = 2;
-        int ACTION_NOTIF_PREFERENCE = 3;
+        int ACTION_APP_PREFERENCE = 1;
+        int ACTION_NOTIF_PREFERENCE = 2;
     }
 
     public static final String PREF_KEY_APP_HEADER = "pref_app_header";
@@ -94,6 +91,8 @@ public class EntityHeaderController {
     @ActionType
     private int mAction2;
 
+    private boolean mHasAppInfoLink;
+
     private boolean mIsInstantApp;
 
     /**
@@ -177,6 +176,11 @@ public class EntityHeaderController {
         return this;
     }
 
+    public EntityHeaderController setHasAppInfoLink(boolean hasAppInfoLink) {
+        mHasAppInfoLink = hasAppInfoLink;
+        return this;
+    }
+
     public EntityHeaderController setButtonActions(@ActionType int action1,
             @ActionType int action2) {
         mAction1 = action1;
@@ -243,14 +247,40 @@ public class EntityHeaderController {
      * Only binds entity header with button actions.
      */
     public EntityHeaderController bindHeaderButtons() {
-        ImageButton button1 = mHeader.findViewById(android.R.id.button1);
-        ImageButton button2 = mHeader.findViewById(android.R.id.button2);
-
+        final View entityHeaderContent = mHeader.findViewById(R.id.entity_header_content);
+        final ImageButton button1 = mHeader.findViewById(android.R.id.button1);
+        final ImageButton button2 = mHeader.findViewById(android.R.id.button2);
+        bindAppInfoLink(entityHeaderContent);
         bindButton(button1, mAction1);
         bindButton(button2, mAction2);
         return this;
     }
 
+    private void bindAppInfoLink(View entityHeaderContent) {
+        if (!mHasAppInfoLink) {
+            // Caller didn't ask for app link, skip.
+            return;
+        }
+        if (entityHeaderContent == null
+                || mPackageName == null
+                || mPackageName.equals(Utils.OS_PKG)
+                || mUid == UserHandle.USER_NULL) {
+            Log.w(TAG, "Missing ingredients to build app info link, skip");
+            return;
+        }
+        entityHeaderContent.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                AppInfoBase.startAppInfoFragment(
+                        InstalledAppDetails.class, R.string.application_info_label,
+                        mPackageName, mUid, mFragment, 0 /* request */,
+                        mMetricsCategory);
+
+            }
+        });
+        return;
+    }
+
     public EntityHeaderController styleActionBar(Activity activity) {
         if (activity == null) {
             Log.w(TAG, "No activity, cannot style actionbar.");
@@ -284,29 +314,6 @@ public class EntityHeaderController {
             return;
         }
         switch (action) {
-            case ActionType.ACTION_APP_INFO: {
-                if (mPackageName == null || mPackageName.equals(Utils.OS_PKG)
-                        || mUid == UserHandle.USER_NULL
-                        || !AppHeader.includeAppInfo(mFragment)) {
-                    button.setVisibility(View.GONE);
-                } else {
-                    button.setContentDescription(
-                            mAppContext.getString(R.string.application_info_label));
-                    button.setImageResource(com.android.settings.R.drawable.ic_info);
-                    button.setOnClickListener(new View.OnClickListener() {
-                        @Override
-                        public void onClick(View v) {
-                            AppInfoBase.startAppInfoFragment(
-                                    InstalledAppDetails.class, R.string.application_info_label,
-                                    mPackageName, mUid, mFragment, 0 /* request */,
-                                    mMetricsCategory);
-
-                        }
-                    });
-                    button.setVisibility(View.VISIBLE);
-                }
-                return;
-            }
             case ActionType.ACTION_NOTIF_PREFERENCE: {
                 if (mAppNotifPrefIntent == null) {
                     button.setVisibility(View.GONE);
index 05efa9f..637962b 100644 (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);
     }
index 4294dcf..fc6071e 100644 (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);
-    }
-
-    @Test
-    public void bindButton_hasAppInfo_shouldShowButton() {
-        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);
+        appLinks.findViewById(R.id.entity_header_content).performClick();
+        verify(mFragment, never()).getActivity();
+        verify(activity, never()).startActivity(any(Intent.class));
     }
 
     @Test
-    public void bindButton_hasAppInfo_shouldHaveContentDescription() {
+    public void bindButton_hasAppInfo_shouldAttachClickListener() {
         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