From 2f62d4aa0b4dca9ced359e1bec39ce91c35e7f73 Mon Sep 17 00:00:00 2001 From: Anna Zappone Date: Wed, 30 Jun 2021 15:56:40 +0100 Subject: [PATCH] Add landscape support Bug: 183966288 Test: locally Change-Id: Ie49eb8d81ce79634de9dac82b9933c916e156a38 --- .../layout/people_tile_small_horizontal.xml | 79 +++++++++++++++++++ packages/SystemUI/res/values/dimens.xml | 1 + .../systemui/people/PeopleSpaceUtils.java | 3 +- .../systemui/people/PeopleTileViewHelper.java | 35 +++++--- .../widget/PeopleSpaceWidgetManager.java | 4 +- .../people/PeopleTileViewHelperTest.java | 63 +++++++++++++++ 6 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 packages/SystemUI/res/layout/people_tile_small_horizontal.xml diff --git a/packages/SystemUI/res/layout/people_tile_small_horizontal.xml b/packages/SystemUI/res/layout/people_tile_small_horizontal.xml new file mode 100644 index 0000000000000..950d7ac342257 --- /dev/null +++ b/packages/SystemUI/res/layout/people_tile_small_horizontal.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 4053ac3d586f1..23d7768dd6902 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1451,6 +1451,7 @@ 12dp 6dp 136dp + 80dp 120dp 168dp 146dp diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java index 917a060f1f1de..779ab30700b16 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleSpaceUtils.java @@ -74,7 +74,8 @@ import java.util.stream.Stream; /** Utils class for People Space. */ public class PeopleSpaceUtils { /** Turns on debugging information about People Space. */ - public static final boolean DEBUG = true; + public static final boolean DEBUG = false; + public static final String PACKAGE_NAME = "package_name"; public static final String USER_ID = "user_id"; public static final String SHORTCUT_ID = "shortcut_id"; diff --git a/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java b/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java index 221bb15a0046b..cc28ce8f16836 100644 --- a/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java +++ b/packages/SystemUI/src/com/android/systemui/people/PeopleTileViewHelper.java @@ -97,7 +97,7 @@ import java.util.stream.Collectors; /** Functions that help creating the People tile layouts. */ public class PeopleTileViewHelper { /** Turns on debugging information about People Space. */ - public static final boolean DEBUG = true; + private static final boolean DEBUG = PeopleSpaceUtils.DEBUG; private static final String TAG = "PeopleTileView"; private static final int DAYS_IN_A_WEEK = 7; @@ -116,8 +116,10 @@ public class PeopleTileViewHelper { private static final int MIN_MEDIUM_VERTICAL_PADDING = 4; private static final int MAX_MEDIUM_PADDING = 16; private static final int FIXED_HEIGHT_DIMENS_FOR_MEDIUM_CONTENT_BEFORE_PADDING = 8 + 4; - private static final int FIXED_HEIGHT_DIMENS_FOR_SMALL = 6 + 4 + 8; - private static final int FIXED_WIDTH_DIMENS_FOR_SMALL = 4 + 4; + private static final int FIXED_HEIGHT_DIMENS_FOR_SMALL_VERTICAL = 6 + 4 + 8; + private static final int FIXED_WIDTH_DIMENS_FOR_SMALL_VERTICAL = 4 + 4; + private static final int FIXED_HEIGHT_DIMENS_FOR_SMALL_HORIZONTAL = 6 + 4; + private static final int FIXED_WIDTH_DIMENS_FOR_SMALL_HORIZONTAL = 8 + 8; private static final int MESSAGES_COUNT_OVERFLOW = 6; @@ -218,7 +220,7 @@ public class PeopleTileViewHelper { // Otherwise, create a list using the portrait/landscape sizes. int defaultWidth = getSizeInDp(context, R.dimen.default_width, density); - int defaultHeight = getSizeInDp(context, R.dimen.default_height, density); + int defaultHeight = getSizeInDp(context, R.dimen.default_height, density); widgetSizes = new ArrayList<>(2); int portraitWidth = options.getInt(OPTION_APPWIDGET_MIN_WIDTH, defaultWidth); @@ -405,7 +407,8 @@ public class PeopleTileViewHelper { return LAYOUT_LARGE; } // Small layout used below a certain minimum mWidth with any mHeight. - if (mWidth >= getSizeInDp(R.dimen.required_width_for_medium)) { + if (mHeight >= getSizeInDp(R.dimen.required_height_for_medium) + && mWidth >= getSizeInDp(R.dimen.required_width_for_medium)) { int spaceAvailableForPadding = mHeight - (getSizeInDp(R.dimen.avatar_size_for_medium) + 4 + getLineHeightFromResource( @@ -438,10 +441,15 @@ public class PeopleTileViewHelper { // Calculate adaptive avatar size for remaining layouts. if (layoutId == R.layout.people_tile_small) { - int avatarHeightSpace = mHeight - (FIXED_HEIGHT_DIMENS_FOR_SMALL + Math.max(18, + int avatarHeightSpace = mHeight - (FIXED_HEIGHT_DIMENS_FOR_SMALL_VERTICAL + Math.max(18, getLineHeightFromResource( R.dimen.name_text_size_for_small))); - int avatarWidthSpace = mWidth - FIXED_WIDTH_DIMENS_FOR_SMALL; + int avatarWidthSpace = mWidth - FIXED_WIDTH_DIMENS_FOR_SMALL_VERTICAL; + avatarSize = Math.min(avatarHeightSpace, avatarWidthSpace); + } + if (layoutId == R.layout.people_tile_small_horizontal) { + int avatarHeightSpace = mHeight - FIXED_HEIGHT_DIMENS_FOR_SMALL_HORIZONTAL; + int avatarWidthSpace = mWidth - FIXED_WIDTH_DIMENS_FOR_SMALL_HORIZONTAL; avatarSize = Math.min(avatarHeightSpace, avatarWidthSpace); } @@ -1024,7 +1032,7 @@ public class PeopleTileViewHelper { return R.layout.people_tile_large_empty; case LAYOUT_SMALL: default: - return R.layout.people_tile_small; + return getLayoutSmallByHeight(); } } @@ -1036,7 +1044,7 @@ public class PeopleTileViewHelper { return R.layout.people_tile_large_with_notification_content; case LAYOUT_SMALL: default: - return R.layout.people_tile_small; + return getLayoutSmallByHeight(); } } @@ -1048,10 +1056,17 @@ public class PeopleTileViewHelper { return R.layout.people_tile_large_with_status_content; case LAYOUT_SMALL: default: - return R.layout.people_tile_small; + return getLayoutSmallByHeight(); } } + private int getLayoutSmallByHeight() { + if (mHeight >= getSizeInDp(R.dimen.required_height_for_medium)) { + return R.layout.people_tile_small; + } + return R.layout.people_tile_small_horizontal; + } + /** Returns a bitmap with the user icon and package icon. */ public static Bitmap getPersonIconBitmap( Context context, PeopleSpaceTile tile, int maxAvatarSize) { diff --git a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java index 62a0df270698b..a160c1979b3bc 100644 --- a/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java +++ b/packages/SystemUI/src/com/android/systemui/people/widget/PeopleSpaceWidgetManager.java @@ -382,7 +382,7 @@ public class PeopleSpaceWidgetManager { ConversationChannel channel = mIPeopleManager.getConversation( key.getPackageName(), key.getUserId(), key.getShortcutId()); if (channel == null) { - Log.d(TAG, "Could not retrieve conversation from storage"); + if (DEBUG) Log.d(TAG, "Could not retrieve conversation from storage"); return null; } @@ -568,7 +568,7 @@ public class PeopleSpaceWidgetManager { @Nullable public Optional getAugmentedTileForExistingWidget(int widgetId, Map> notifications) { - Log.d(TAG, "Augmenting tile for existing widget: " + widgetId); + if (DEBUG) Log.d(TAG, "Augmenting tile for existing widget: " + widgetId); PeopleSpaceTile tile = getTileForExistingWidget(widgetId); if (tile == null) { if (DEBUG) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java index e4e8cf0b08022..21c592514489b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/people/PeopleTileViewHelperTest.java @@ -236,6 +236,21 @@ public class PeopleTileViewHelperTest extends SysuiTestCase { // No messages count. assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility()); + mHeight = getSizeInDp(R.dimen.required_height_for_medium) - 1; + RemoteViews smallViewHorizontal = getPeopleTileViewHelper( + tileWithLastInteraction).getViews(); + View smallResultHorizontal = smallViewHorizontal.apply(mContext, null); + + // Show name over predefined icon. + assertEquals(View.VISIBLE, smallResultHorizontal.findViewById(R.id.name).getVisibility()); + assertEquals(View.GONE, + smallResultHorizontal.findViewById(R.id.predefined_icon).getVisibility()); + // Shows person icon. + assertEquals(View.VISIBLE, + smallResultHorizontal.findViewById(R.id.person_icon).getVisibility()); + // No messages count. + assertEquals(View.GONE, + smallResultHorizontal.findViewById(R.id.messages_count).getVisibility()); mWidth = getSizeInDp(R.dimen.required_width_for_large); mHeight = getSizeInDp(R.dimen.required_height_for_large); @@ -292,6 +307,22 @@ public class PeopleTileViewHelperTest extends SysuiTestCase { // No messages count. assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility()); + mHeight = getSizeInDp(R.dimen.required_height_for_medium) - 1; + RemoteViews smallViewHorizontal = getPeopleTileViewHelper( + tileWithAvailabilityAndNewStory).getViews(); + View smallResultHorizontal = smallViewHorizontal.apply(mContext, null); + + // Show name over predefined icon. + assertEquals(View.VISIBLE, smallResultHorizontal.findViewById(R.id.name).getVisibility()); + assertEquals(View.GONE, + smallResultHorizontal.findViewById(R.id.predefined_icon).getVisibility()); + // Shows person icon. + assertEquals(View.VISIBLE, + smallResultHorizontal.findViewById(R.id.person_icon).getVisibility()); + // No messages count. + assertEquals(View.GONE, + smallResultHorizontal.findViewById(R.id.messages_count).getVisibility()); + mWidth = getSizeInDp(R.dimen.required_width_for_large); mHeight = getSizeInDp(R.dimen.required_height_for_large); RemoteViews largeView = getPeopleTileViewHelper(tileWithAvailabilityAndNewStory).getViews(); @@ -348,6 +379,22 @@ public class PeopleTileViewHelperTest extends SysuiTestCase { // No messages count. assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility()); + mHeight = getSizeInDp(R.dimen.required_height_for_medium) - 1; + RemoteViews smallViewHorizontal = getPeopleTileViewHelper( + tileWithStatusTemplate).getViews(); + View smallResultHorizontal = smallViewHorizontal.apply(mContext, null); + + // Show name over predefined icon. + assertEquals(View.GONE, smallResultHorizontal.findViewById(R.id.name).getVisibility()); + assertEquals(View.VISIBLE, + smallResultHorizontal.findViewById(R.id.predefined_icon).getVisibility()); + // Shows person icon. + assertEquals(View.VISIBLE, + smallResultHorizontal.findViewById(R.id.person_icon).getVisibility()); + // No messages count. + assertEquals(View.GONE, + smallResultHorizontal.findViewById(R.id.messages_count).getVisibility()); + mWidth = getSizeInDp(R.dimen.required_width_for_large); mHeight = getSizeInDp(R.dimen.required_height_for_large); RemoteViews largeView = getPeopleTileViewHelper(tileWithStatusTemplate).getViews(); @@ -407,6 +454,22 @@ public class PeopleTileViewHelperTest extends SysuiTestCase { // No messages count. assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility()); + mHeight = getSizeInDp(R.dimen.required_height_for_medium) - 1; + RemoteViews smallViewHorizontal = getPeopleTileViewHelper( + tileWithStatusTemplate).getViews(); + View smallResultHorizontal = smallViewHorizontal.apply(mContext, null); + + // Show name over predefined icon. + assertEquals(View.GONE, smallResultHorizontal.findViewById(R.id.name).getVisibility()); + assertEquals(View.VISIBLE, + smallResultHorizontal.findViewById(R.id.predefined_icon).getVisibility()); + // Shows person icon. + assertEquals(View.VISIBLE, + smallResultHorizontal.findViewById(R.id.person_icon).getVisibility()); + // No messages count. + assertEquals(View.GONE, + smallResultHorizontal.findViewById(R.id.messages_count).getVisibility()); + mWidth = getSizeInDp(R.dimen.required_width_for_large); mHeight = getSizeInDp(R.dimen.required_height_for_large); RemoteViews largeView = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();