<!-- App snippet with buttons -->
<ImageView
android:id="@android:id/icon"
- android:layout_marginTop="16dp"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="fitXY"
<style name="AppHeader">
<item name="android:background">@color/card_background_grey</item>
<item name="android:gravity">center_horizontal</item>
+ <item name="android:paddingTop">16dp</item>
<item name="android:paddingStart">16dp</item>
<item name="android:paddingEnd">16dp</item>
- <item name="android:paddingBottom">16dp</item>
+ <item name="android:paddingBottom">8dp</item>
</style>
<style name="TextAppearance.AppHeaderTitle"
package com.android.settings.applications;
+import android.annotation.IdRes;
+import android.annotation.UserIdInt;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
+import android.os.UserHandle;
import android.support.annotation.IntDef;
import android.text.TextUtils;
import android.util.Log;
+import android.view.LayoutInflater;
import android.view.View;
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.settingslib.applications.ApplicationsState;
public class AppHeaderController {
- @IntDef({ActionType.ACTION_APP_INFO,
+ @IntDef({ActionType.ACTION_NONE,
+ ActionType.ACTION_APP_INFO,
ActionType.ACTION_APP_PREFERENCE,
ActionType.ACTION_STORE_DEEP_LINK,
ActionType.ACTION_NOTIF_PREFERENCE})
@Retention(RetentionPolicy.SOURCE)
- @interface ActionType {
- int ACTION_APP_INFO = 0;
- int ACTION_STORE_DEEP_LINK = 1;
- int ACTION_APP_PREFERENCE = 2;
- int ACTION_NOTIF_PREFERENCE = 3;
+ public @interface ActionType {
+ int ACTION_NONE = 0;
+ int ACTION_APP_INFO = 1;
+ int ACTION_STORE_DEEP_LINK = 2;
+ int ACTION_APP_PREFERENCE = 3;
+ int ACTION_NOTIF_PREFERENCE = 4;
}
private static final String TAG = "AppDetailFeature";
private final Context mContext;
+ private final Fragment mFragment;
+ private final View mAppHeader;
- public AppHeaderController(Context context) {
+ private Drawable mIcon;
+ private CharSequence mLabel;
+ private CharSequence mSummary;
+ private String mPackageName;
+ private Intent mAppNotifPrefIntent;
+ @UserIdInt
+ private int mUid = UserHandle.USER_NULL;
+ @ActionType
+ private int mLeftAction;
+ @ActionType
+ private int mRightAction;
+
+ public AppHeaderController(Context context, Fragment fragment, View appHeader) {
mContext = context;
+ mFragment = fragment;
+ if (appHeader != null) {
+ mAppHeader = appHeader;
+ } else {
+ mAppHeader = LayoutInflater.from(mContext)
+ .inflate(R.layout.app_details, null /* root */);
+ }
+ }
+
+ public AppHeaderController setIcon(Drawable icon) {
+ if (icon != null) {
+ mIcon = icon.getConstantState().newDrawable(mContext.getResources());
+ }
+ return this;
+ }
+
+ public AppHeaderController setIcon(ApplicationsState.AppEntry appEntry) {
+ if (appEntry.icon != null) {
+ mIcon = appEntry.icon.getConstantState().newDrawable(mContext.getResources());
+ }
+ return this;
+ }
+
+ public AppHeaderController setLabel(CharSequence label) {
+ mLabel = label;
+ return this;
+ }
+
+ public AppHeaderController setLabel(ApplicationsState.AppEntry appEntry) {
+ mLabel = appEntry.label;
+ return this;
+ }
+
+ public AppHeaderController setSummary(CharSequence summary) {
+ mSummary = summary;
+ return this;
+ }
+
+ public AppHeaderController setSummary(PackageInfo packageInfo) {
+ if (packageInfo != null) {
+ mSummary = packageInfo.versionName;
+ }
+ return this;
+ }
+
+ public AppHeaderController setButtonActions(@ActionType int leftAction,
+ @ActionType int rightAction) {
+ mLeftAction = leftAction;
+ mRightAction = rightAction;
+ return this;
}
- public void bindAppHeader(View appSnippet, PackageInfo packageInfo,
- ApplicationsState.AppEntry appEntry) {
+ public AppHeaderController setPackageName(String packageName) {
+ mPackageName = packageName;
+ return this;
+ }
+
+ public AppHeaderController setUid(int uid) {
+ mUid = uid;
+ return this;
+ }
+
+ public AppHeaderController setAppNotifPrefIntent(Intent appNotifPrefIntent) {
+ mAppNotifPrefIntent = appNotifPrefIntent;
+ return this;
+ }
+
+ /**
+ * Binds app header view and data from {@code PackageInfo} and {@code AppEntry}.
+ */
+ public void bindAppHeader(PackageInfo packageInfo, ApplicationsState.AppEntry appEntry) {
final String versionName = packageInfo == null ? null : packageInfo.versionName;
- final Resources res = appSnippet.getResources();
+ final Resources res = mAppHeader.getResources();
// Set Icon
- final ImageView iconView = (ImageView) appSnippet.findViewById(android.R.id.icon);
+ final ImageView iconView = (ImageView) mAppHeader.findViewById(android.R.id.icon);
if (appEntry.icon != null) {
iconView.setImageDrawable(appEntry.icon.getConstantState().newDrawable(res));
}
// Set application name.
- final TextView labelView = (TextView) appSnippet.findViewById(android.R.id.title);
+ final TextView labelView = (TextView) mAppHeader.findViewById(android.R.id.title);
labelView.setText(appEntry.label);
// Version number of application
- final TextView appVersion = (TextView) appSnippet.findViewById(android.R.id.summary);
+ final TextView appVersion = (TextView) mAppHeader.findViewById(android.R.id.summary);
if (!TextUtils.isEmpty(versionName)) {
appVersion.setSelected(true);
}
}
- public void bindAppHeaderButtons(Fragment fragment, View appLinkButtons, String packageName,
- @ActionType int leftAction, @ActionType int rightAction) {
- ImageButton leftButton = (ImageButton) appLinkButtons.findViewById(R.id.left_button);
- ImageButton rightButton = (ImageButton) appLinkButtons.findViewById(R.id.right_button);
+ /**
+ * Done mutating appheader, rebinds everything.
+ */
+ public View done() {
+ return done(true);
+ }
- bindAppDetailButton(fragment, packageName, leftButton, leftAction);
- bindAppDetailButton(fragment, packageName, rightButton, rightAction);
+ /**
+ * Done mutating appheader, rebinds everything (optionally skip rebinding buttons).
+ */
+ public View done(boolean rebindActions) {
+ ImageView iconView = (ImageView) mAppHeader.findViewById(android.R.id.icon);
+ if (iconView != null) {
+ iconView.setImageDrawable(mIcon);
+ }
+ setText(android.R.id.title, mLabel);
+ setText(android.R.id.summary, mSummary);
+ if (rebindActions) {
+ bindAppHeaderButtons();
+ }
+ return mAppHeader;
}
- private void bindAppDetailButton(Fragment fragment, String packageName,
- ImageButton button, @ActionType int action) {
+ /**
+ * Only binds app header with button actions.
+ */
+ public void bindAppHeaderButtons() {
+ ImageButton leftButton = (ImageButton) mAppHeader.findViewById(R.id.left_button);
+ ImageButton rightButton = (ImageButton) mAppHeader.findViewById(R.id.right_button);
+
+ bindButton(leftButton, mLeftAction);
+ bindButton(rightButton, mRightAction);
+ }
+
+ private void bindButton(ImageButton button, @ActionType int action) {
if (button == null) {
return;
}
switch (action) {
case ActionType.ACTION_APP_INFO: {
- if (packageName == null || packageName.equals(Utils.OS_PKG)) {
+ if (mPackageName == null || mPackageName.equals(Utils.OS_PKG)
+ || mUid == UserHandle.USER_NULL
+ || !AppHeader.includeAppInfo(mFragment)) {
button.setVisibility(View.GONE);
} else {
- // TODO
button.setImageResource(com.android.settings.R.drawable.ic_info);
+ button.setOnClickListener(v -> AppInfoBase.startAppInfoFragment(
+ InstalledAppDetails.class, R.string.application_info_label,
+ mPackageName, mUid, mFragment, 0));
button.setVisibility(View.VISIBLE);
}
return;
}
case ActionType.ACTION_STORE_DEEP_LINK: {
final Intent intent = new Intent(Intent.ACTION_SHOW_APP_INFO)
- .setPackage(getInstallerPackageName(mContext, packageName));
+ .setPackage(getInstallerPackageName(mContext, mPackageName));
final Intent result = resolveIntent(intent);
if (result == null) {
button.setVisibility(View.GONE);
} else {
- result.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
+ result.putExtra(Intent.EXTRA_PACKAGE_NAME, mPackageName);
button.setImageResource(R.drawable.ic_sim_sd);
- button.setOnClickListener(v -> fragment.startActivity(intent));
+ button.setOnClickListener(v -> mFragment.startActivity(intent));
button.setVisibility(View.VISIBLE);
}
return;
}
case ActionType.ACTION_NOTIF_PREFERENCE: {
- // TODO
+ if (mAppNotifPrefIntent == null) {
+ button.setVisibility(View.GONE);
+ } else {
+ button.setOnClickListener(v -> mFragment.startActivity(mAppNotifPrefIntent));
+ button.setVisibility(View.VISIBLE);
+ }
return;
}
case ActionType.ACTION_APP_PREFERENCE: {
final Intent intent = resolveIntent(
- new Intent(Intent.ACTION_APPLICATION_PREFERENCES).setPackage(packageName));
+ new Intent(Intent.ACTION_APPLICATION_PREFERENCES).setPackage(mPackageName));
if (intent == null) {
button.setVisibility(View.GONE);
return;
}
- button.setOnClickListener(v -> fragment.startActivity(intent));
+ button.setOnClickListener(v -> mFragment.startActivity(intent));
button.setVisibility(View.VISIBLE);
return;
}
+ case ActionType.ACTION_NONE: {
+ button.setVisibility(View.GONE);
+ return;
+ }
}
}
}
return null;
}
-}
+
+ private void setText(@IdRes int id, CharSequence text) {
+ TextView textView = (TextView) mAppHeader.findViewById(id);
+ if (textView != null) {
+ textView.setText(text);
+ textView.setVisibility(TextUtils.isEmpty(text) ? View.GONE : View.VISIBLE);
+ }
+ }
+}
\ No newline at end of file
package com.android.settings.applications;
+import android.app.Fragment;
+import android.view.View;
+
public interface ApplicationFeatureProvider {
- AppHeaderController getAppHeaderController();
+ /**
+ * Returns a new {@link AppHeaderController} instance to customize app header.
+ */
+ AppHeaderController newAppHeaderController(Fragment fragment, View appHeader);
}
package com.android.settings.applications;
+import android.app.Fragment;
import android.content.Context;
+import android.view.View;
public class ApplicationFeatureProviderImpl implements ApplicationFeatureProvider {
private final Context mContext;
- private AppHeaderController mAppHeaderController;
-
public ApplicationFeatureProviderImpl(Context context) {
mContext = context.getApplicationContext();
}
- @Override
- public AppHeaderController getAppHeaderController() {
- if (mAppHeaderController == null) {
- mAppHeaderController = new AppHeaderController(mContext);
- }
- return mAppHeaderController;
+ public AppHeaderController newAppHeaderController(Fragment fragment, View appHeader) {
+ return new AppHeaderController(mContext, fragment, appHeader);
}
}
private final HashSet<String> mHomePackages = new HashSet<>();
private DashboardFeatureProvider mDashboardFeatureProvider;
- private AppHeaderController mAppHeaderController;
private boolean mInitialized;
private boolean mShowUninstalled;
final Activity activity = getActivity();
mDashboardFeatureProvider =
FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
- mAppHeaderController = FeatureFactory.getFactory(activity)
- .getApplicationFeatureProvider(activity).getAppHeaderController();
setHasOptionsMenu(true);
addPreferencesFromResource(mDashboardFeatureProvider.isEnabled()
if (!mDashboardFeatureProvider.isEnabled()) {
handleHeader();
} else {
+ final Activity activity = getActivity();
mHeader = (LayoutPreference) findPreference(KEY_HEADER);
- mAppHeaderController.bindAppHeaderButtons(
- this,
- mHeader.findViewById(R.id.app_detail_links),
- mPackageName,
- AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE);
+ FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, mHeader.findViewById(R.id.app_snippet))
+ .setPackageName(mPackageName)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
+ AppHeaderController.ActionType.ACTION_APP_PREFERENCE)
+ .bindAppHeaderButtons();
prepareUninstallAndStop();
}
final View appSnippet = mHeader.findViewById(R.id.app_snippet);
mState.ensureIcon(mAppEntry);
if (mDashboardFeatureProvider.isEnabled()) {
- mAppHeaderController.bindAppHeader(appSnippet, pkgInfo, mAppEntry);
+ final Activity activity = getActivity();
+ FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this, appSnippet)
+ .setLabel(mAppEntry)
+ .setIcon(mAppEntry)
+ .setSummary(pkgInfo)
+ .done(false /* rebindActions */);
} else {
setupAppSnippet(appSnippet, mAppEntry.label, mAppEntry.icon,
pkgInfo != null ? pkgInfo.versionName : null);
package com.android.settings.notification;
+import android.app.Activity;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.pm.ApplicationInfo;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
+import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.util.ArrayMap;
import android.util.Log;
+import android.view.View;
import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.Utils;
+import com.android.settings.applications.AppHeaderController;
import com.android.settings.applications.AppInfoBase;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.notification.NotificationBackend.AppRow;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.RestrictedSwitchPreference;
-
import java.util.List;
/** These settings are per app, so should not be returned in global search results. */
.addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
private static final String KEY_CHANNELS = "channels";
+
+ private DashboardFeatureProvider mDashboardFeatureProvider;
private PreferenceCategory mChannels;
- List<NotificationChannel> mChannelList;
+ private List<NotificationChannel> mChannelList;
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mAppRow == null) return;
- AppHeader.createAppHeader(this, mAppRow.icon, mAppRow.label, mAppRow.pkg, mAppRow.uid,
- mAppRow.settingsIntent);
+ if (!mDashboardFeatureProvider.isEnabled()) {
+ AppHeader.createAppHeader(this, mAppRow.icon, mAppRow.label, mAppRow.pkg, mAppRow.uid,
+ mAppRow.settingsIntent);
+ }
}
@Override
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ final Activity activity = getActivity();
+ mDashboardFeatureProvider =
+ FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
addPreferencesFromResource(R.xml.app_notification_settings);
+
mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
mPriority =
(RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BYPASS_DND);
}
updateDependents(mAppRow.appImportance);
}
+ if (mDashboardFeatureProvider.isEnabled()) {
+ final AppHeaderController appHeaderController = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this /* fragment */, null /* appHeader */);
+ final View appHeader = appHeaderController.setIcon(mAppRow.icon)
+ .setLabel(mAppRow.label)
+ .setPackageName(mAppRow.pkg)
+ .setUid(mAppRow.uid)
+ .setAppNotifPrefIntent(mAppRow.settingsIntent)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE)
+ .done();
+ final Preference appHeaderPref = new LayoutPreference(getPrefContext(), appHeader);
+ appHeaderPref.setOrder(0);
+ getPreferenceScreen().addPreference(appHeaderPref);
+ }
}
@Override
import com.android.settings.AppHeader;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
+import com.android.settings.applications.AppHeaderController;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.dashboard.DashboardFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
+import android.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.service.notification.NotificationListenerService.Ranking;
import android.support.v7.preference.Preference;
+import android.view.View;
public class ChannelNotificationSettings extends NotificationSettingsBase {
protected static final String KEY_LIGHTS = "lights";
protected RestrictedSwitchPreference mLights;
protected RestrictedSwitchPreference mVibrate;
protected DefaultNotificationTonePreference mRingtone;
+
+ private DashboardFeatureProvider mDashboardFeatureProvider;
private int mMaxImportance;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mAppRow == null || mChannel == null) return;
- AppHeader.createAppHeader(
- this, mAppRow.icon, mChannel.getName(), mAppRow.pkg, mAppRow.uid);
+ if (!mDashboardFeatureProvider.isEnabled()) {
+ AppHeader.createAppHeader(
+ this, mAppRow.icon, mChannel.getName(), mAppRow.pkg, mAppRow.uid);
+ }
}
@Override
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ final Activity activity = getActivity();
+ mDashboardFeatureProvider =
+ FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
addPreferencesFromResource(R.xml.channel_notification_settings);
mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
mChannel.getImportance() == NotificationManager.IMPORTANCE_NONE,
mMaxImportance);
}
+ if (mDashboardFeatureProvider.isEnabled()) {
+ final AppHeaderController appHeaderController = FeatureFactory.getFactory(activity)
+ .getApplicationFeatureProvider(activity)
+ .newAppHeaderController(this /* fragment */, null /* appHeader */);
+ final View appHeader = appHeaderController.setIcon(mAppRow.icon)
+ .setLabel(mAppRow.label)
+ .setSummary(mChannel.getName())
+ .setPackageName(mAppRow.pkg)
+ .setUid(mAppRow.uid)
+ .setButtonActions(AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NONE)
+ .done();
+ final Preference appHeaderPref = new LayoutPreference(getPrefContext(), appHeader);
+ appHeaderPref.setOrder(0);
+ getPreferenceScreen().addPreference(appHeaderPref);
+ }
}
@Override
package com.android.settings.applications;
+import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
+import android.os.UserHandle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
private ApplicationsState.AppEntry mAppEntry;
@Mock
private Fragment mFragment;
+ @Mock
+ private View mAppHeader;
private Context mShadowContext;
private LayoutInflater mLayoutInflater;
mLayoutInflater = LayoutInflater.from(mShadowContext);
mInfo = new PackageInfo();
mInfo.versionName = "1234";
- mController = new AppHeaderController(mContext);
+ }
+
+ @Test
+ public void testBuildView_constructedWithoutView_shouldCreateNewView() {
+ mController = new AppHeaderController(mShadowContext, mFragment, null);
+ View view = mController.done();
+
+ assertThat(view).isNotNull();
+ }
+
+ @Test
+ public void testBuildView_constructedWithView_shouldReturnSameView() {
+ View inputView = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
+ mController = new AppHeaderController(mShadowContext, mFragment, inputView);
+ View view = mController.done();
+
+ assertThat(view).isSameAs(inputView);
}
@Test
final View appHeader = mLayoutInflater.inflate(R.layout.app_details, null /* root */);
final TextView label = (TextView) appHeader.findViewById(android.R.id.title);
final TextView version = (TextView) appHeader.findViewById(android.R.id.summary);
- label.setText(testString);
- label.setText(testString);
- mController.bindAppHeader(appHeader, mInfo, mAppEntry);
+ mController = new AppHeaderController(mShadowContext, mFragment, appHeader);
+ mController.setLabel(testString);
+ mController.setSummary(testString);
+ mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
+ mController.done();
- assertThat(label.getText()).isNotEqualTo(testString);
- assertThat(version.getText())
- .isEqualTo(mShadowContext.getString(R.string.version_text, mInfo.versionName));
+ assertThat(label.getText()).isEqualTo(testString);
+ assertThat(version.getText()).isEqualTo(testString);
}
@Test
.inflate(R.layout.app_details, null /* root */);
when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
.thenReturn(info);
- mController.bindAppHeaderButtons(mFragment, appLinks,
- mShadowContext.getPackageName(),
+
+ mController = new AppHeaderController(mContext, mFragment, appLinks);
+ mController.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE);
+ AppHeaderController.ActionType.ACTION_NONE);
+ mController.done();
+
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.VISIBLE);
assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
- .isEqualTo(View.VISIBLE);
+ .isEqualTo(View.GONE);
try {
appLinks.findViewById(R.id.left_button).performClick();
} catch (Exception e) {
.inflate(R.layout.app_details, null /* root */);
when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
.thenReturn(null);
- mController.bindAppHeaderButtons(mFragment, appLinks,
- mShadowContext.getPackageName(),
+
+ mController = new AppHeaderController(mContext, mFragment, appLinks);
+ mController.setButtonActions(
AppHeaderController.ActionType.ACTION_APP_PREFERENCE,
- AppHeaderController.ActionType.ACTION_APP_PREFERENCE);
+ AppHeaderController.ActionType.ACTION_NONE);
+ mController.done();
+
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
.inflate(R.layout.app_details, null /* root */);
when(mContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
.thenReturn(null);
- mController.bindAppHeaderButtons(mFragment, appLinks,
- mShadowContext.getPackageName(),
+
+ mController = new AppHeaderController(mContext, mFragment, appLinks);
+ mController.setButtonActions(
AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK,
- AppHeaderController.ActionType.ACTION_STORE_DEEP_LINK);
+ AppHeaderController.ActionType.ACTION_NONE);
+ mController.done();
+
+ assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
+ .isEqualTo(View.GONE);
+ assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
+ .isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void bindButton_noAppInfo_shouldNotShowButton() {
+ final View appLinks = mLayoutInflater
+ .inflate(R.layout.app_details, null /* root */);
+
+ mController = new AppHeaderController(mContext, mFragment, appLinks);
+ mController.setPackageName(null)
+ .setButtonActions(
+ AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NONE);
+ mController.done();
+
assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
.isEqualTo(View.GONE);
assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
.isEqualTo(View.GONE);
}
+
+ @Test
+ public void bindButton_hasAppInfo_shouldShowButton() {
+ final View appLinks = mLayoutInflater
+ .inflate(R.layout.app_details, null /* root */);
+ when(mFragment.getActivity()).thenReturn(mock(Activity.class));
+
+ mController = new AppHeaderController(mContext, mFragment, appLinks);
+ mController.setPackageName("123")
+ .setUid(UserHandle.USER_SYSTEM)
+ .setButtonActions(
+ AppHeaderController.ActionType.ACTION_APP_INFO,
+ AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE);
+ mController.done();
+
+ assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
+ .isEqualTo(View.VISIBLE);
+ assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
+ .isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void bindButton_hasAppNotifIntent_shouldShowButton() {
+ final View appLinks = mLayoutInflater
+ .inflate(R.layout.app_details, null /* root */);
+
+ mController = new AppHeaderController(mContext, mFragment, appLinks);
+ mController.setAppNotifPrefIntent(new Intent())
+ .setButtonActions(
+ AppHeaderController.ActionType.ACTION_NOTIF_PREFERENCE,
+ AppHeaderController.ActionType.ACTION_NONE);
+ mController.done();
+
+ assertThat(appLinks.findViewById(R.id.left_button).getVisibility())
+ .isEqualTo(View.VISIBLE);
+ assertThat(appLinks.findViewById(R.id.right_button).getVisibility())
+ .isEqualTo(View.GONE);
+ }
}