Merge "Add landscape support" into sc-dev

This commit is contained in:
Anna Zappone
2021-07-01 14:01:10 +00:00
committed by Android (Google) Code Review
6 changed files with 172 additions and 13 deletions

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2021 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.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:theme="@android:style/Theme.DeviceDefault.DayNight"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@android:id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@drawable/people_space_tile_view_card"
android:clipToOutline="true"
android:orientation="horizontal"
android:paddingHorizontal="8dp"
android:paddingTop="4dp"
android:paddingBottom="6dp">
<ImageView
android:id="@+id/person_icon"
android:layout_gravity="start|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingEnd="4dp"/>
<ImageView
android:id="@+id/predefined_icon"
android:layout_weight="1"
android:tint="?android:attr/textColorSecondary"
android:layout_gravity="start|center_vertical"
android:layout_width="18dp"
android:layout_height="18dp" />
<TextView
android:id="@+id/messages_count"
android:layout_weight="1"
android:layout_gravity="start|center_vertical"
android:gravity="center"
android:paddingHorizontal="8dp"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Notification.Title"
android:textColor="?androidprv:attr/textColorOnAccent"
android:background="@drawable/people_space_messages_count_background"
android:textSize="@dimen/name_text_size_for_small"
android:maxLines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<TextView
android:id="@+id/name"
android:layout_weight="1"
android:layout_gravity="start|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Notification.Title"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/name_text_size_for_small" />
</LinearLayout>
</FrameLayout>

View File

@@ -1457,6 +1457,7 @@
<dimen name="people_space_messages_count_radius">12dp</dimen>
<dimen name="people_space_widget_background_padding">6dp</dimen>
<dimen name="required_width_for_medium">136dp</dimen>
<dimen name="required_height_for_medium">80dp</dimen>
<dimen name="required_width_for_large">120dp</dimen>
<dimen name="required_height_for_large">168dp</dimen>
<dimen name="default_width">146dp</dimen>

View File

@@ -75,7 +75,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";

View File

@@ -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;
@@ -220,7 +222,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);
@@ -404,7 +406,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(
@@ -437,10 +440,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);
}
@@ -1033,7 +1041,7 @@ public class PeopleTileViewHelper {
return R.layout.people_tile_large_empty;
case LAYOUT_SMALL:
default:
return R.layout.people_tile_small;
return getLayoutSmallByHeight();
}
}
@@ -1045,7 +1053,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();
}
}
@@ -1057,10 +1065,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) {

View File

@@ -399,7 +399,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;
}
@@ -586,7 +586,7 @@ public class PeopleSpaceWidgetManager {
@Nullable
public Optional<PeopleSpaceTile> getAugmentedTileForExistingWidget(int widgetId,
Map<PeopleTileKey, Set<NotificationEntry>> 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) {

View File

@@ -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();