Create RemoteViews for all supported app widget sizes
This ensures the correct size measuring for rotation and for devices with multiple screens. Fix: 183966288 Test: verified locally Change-Id: I5d2bf55ad779a535a8b69917672192018ba11dbc
This commit is contained in:
@@ -29,6 +29,7 @@ import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT;
|
||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH;
|
||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT;
|
||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH;
|
||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_SIZES;
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_PX;
|
||||
|
||||
@@ -43,7 +44,6 @@ import android.app.people.ConversationStatus;
|
||||
import android.app.people.PeopleSpaceTile;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
@@ -59,6 +59,7 @@ import android.text.TextUtils;
|
||||
import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.util.SizeF;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
@@ -85,8 +86,10 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -173,28 +176,64 @@ public class PeopleTileViewHelper {
|
||||
private Locale mLocale;
|
||||
private NumberFormat mIntegerFormat;
|
||||
|
||||
public PeopleTileViewHelper(Context context, @Nullable PeopleSpaceTile tile,
|
||||
int appWidgetId, Bundle options, PeopleTileKey key) {
|
||||
PeopleTileViewHelper(Context context, @Nullable PeopleSpaceTile tile,
|
||||
int appWidgetId, int width, int height, PeopleTileKey key) {
|
||||
mContext = context;
|
||||
mTile = tile;
|
||||
mKey = key;
|
||||
mAppWidgetId = appWidgetId;
|
||||
mDensity = mContext.getResources().getDisplayMetrics().density;
|
||||
int display = mContext.getResources().getConfiguration().orientation;
|
||||
mWidth = display == Configuration.ORIENTATION_PORTRAIT
|
||||
? options.getInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.default_width)) : options.getInt(
|
||||
OPTION_APPWIDGET_MAX_WIDTH,
|
||||
getSizeInDp(R.dimen.default_width));
|
||||
mHeight = display == Configuration.ORIENTATION_PORTRAIT ? options.getInt(
|
||||
OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.default_height))
|
||||
: options.getInt(OPTION_APPWIDGET_MIN_HEIGHT,
|
||||
getSizeInDp(R.dimen.default_height));
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mLayoutSize = getLayoutSize();
|
||||
}
|
||||
|
||||
public RemoteViews getViews() {
|
||||
/**
|
||||
* Creates a {@link RemoteViews} for the specified arguments. The RemoteViews will support all
|
||||
* the sizes present in {@code options.}.
|
||||
*/
|
||||
public static RemoteViews createRemoteViews(Context context, @Nullable PeopleSpaceTile tile,
|
||||
int appWidgetId, Bundle options, PeopleTileKey key) {
|
||||
List<SizeF> widgetSizes = getWidgetSizes(context, options);
|
||||
Map<SizeF, RemoteViews> sizeToRemoteView =
|
||||
widgetSizes
|
||||
.stream()
|
||||
.distinct()
|
||||
.collect(Collectors.toMap(
|
||||
Function.identity(),
|
||||
size -> new PeopleTileViewHelper(
|
||||
context, tile, appWidgetId,
|
||||
(int) size.getWidth(),
|
||||
(int) size.getHeight(),
|
||||
key)
|
||||
.getViews()));
|
||||
return new RemoteViews(sizeToRemoteView);
|
||||
}
|
||||
|
||||
private static List<SizeF> getWidgetSizes(Context context, Bundle options) {
|
||||
float density = context.getResources().getDisplayMetrics().density;
|
||||
List<SizeF> widgetSizes = options.getParcelableArrayList(OPTION_APPWIDGET_SIZES);
|
||||
// If the full list of sizes was provided in the options bundle, use that.
|
||||
if (widgetSizes != null && !widgetSizes.isEmpty()) return widgetSizes;
|
||||
|
||||
// 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);
|
||||
widgetSizes = new ArrayList<>(2);
|
||||
|
||||
int portraitWidth = options.getInt(OPTION_APPWIDGET_MIN_WIDTH, defaultWidth);
|
||||
int portraitHeight = options.getInt(OPTION_APPWIDGET_MAX_HEIGHT, defaultHeight);
|
||||
widgetSizes.add(new SizeF(portraitWidth, portraitHeight));
|
||||
|
||||
int landscapeWidth = options.getInt(OPTION_APPWIDGET_MAX_WIDTH, defaultWidth);
|
||||
int landscapeHeight = options.getInt(OPTION_APPWIDGET_MIN_HEIGHT, defaultHeight);
|
||||
widgetSizes.add(new SizeF(landscapeWidth, landscapeHeight));
|
||||
|
||||
return widgetSizes;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RemoteViews getViews() {
|
||||
RemoteViews viewsForTile = getViewForTile();
|
||||
int maxAvatarSize = getMaxAvatarSize(viewsForTile);
|
||||
RemoteViews views = setCommonRemoteViewsFields(viewsForTile, maxAvatarSize);
|
||||
|
||||
@@ -297,8 +297,8 @@ public class PeopleSpaceWidgetManager {
|
||||
Log.e(TAG, "Cannot update invalid widget");
|
||||
return;
|
||||
}
|
||||
RemoteViews views = new PeopleTileViewHelper(mContext, tile, appWidgetId,
|
||||
options, key).getViews();
|
||||
RemoteViews views = PeopleTileViewHelper.createRemoteViews(mContext, tile, appWidgetId,
|
||||
options, key);
|
||||
|
||||
// Tell the AppWidgetManager to perform an update on the current app widget.
|
||||
mAppWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
@@ -1031,8 +1031,8 @@ public class PeopleSpaceWidgetManager {
|
||||
Optional.empty());
|
||||
|
||||
if (DEBUG) Log.i(TAG, "Returning tile preview for shortcutId: " + shortcutId);
|
||||
return new PeopleTileViewHelper(mContext, augmentedTile, 0, options,
|
||||
new PeopleTileKey(augmentedTile)).getViews();
|
||||
return PeopleTileViewHelper.createRemoteViews(mContext, augmentedTile, 0, options,
|
||||
new PeopleTileKey(augmentedTile));
|
||||
}
|
||||
|
||||
protected final BroadcastReceiver mBaseBroadcastReceiver = new BroadcastReceiver() {
|
||||
|
||||
@@ -26,8 +26,6 @@ import static android.app.people.PeopleSpaceTile.BLOCK_CONVERSATIONS;
|
||||
import static android.app.people.PeopleSpaceTile.SHOW_CONTACTS;
|
||||
import static android.app.people.PeopleSpaceTile.SHOW_IMPORTANT_CONVERSATIONS;
|
||||
import static android.app.people.PeopleSpaceTile.SHOW_STARRED_CONTACTS;
|
||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT;
|
||||
import static android.appwidget.AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH;
|
||||
|
||||
import static com.android.systemui.people.PeopleSpaceUtils.STARRED_CONTACT;
|
||||
import static com.android.systemui.people.PeopleSpaceUtils.VALID_CONTACT;
|
||||
@@ -48,7 +46,6 @@ import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.util.DisplayMetrics;
|
||||
@@ -136,15 +133,14 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private Bundle mOptions;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private PeopleTileViewHelper mPeopleTileViewHelper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mOptions = new Bundle();
|
||||
|
||||
when(mMockContext.getString(R.string.birthday_status)).thenReturn(
|
||||
mContext.getString(R.string.birthday_status));
|
||||
when(mMockContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
@@ -159,25 +155,24 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
TextView textView = mock(TextView.class);
|
||||
when(textView.getLineHeight()).thenReturn(16);
|
||||
when(mPackageManager.getApplicationIcon(anyString())).thenReturn(null);
|
||||
mPeopleTileViewHelper = getPeopleTileViewHelper(
|
||||
PERSON_TILE, mOptions);
|
||||
|
||||
mWidth = getSizeInDp(R.dimen.default_width);
|
||||
mHeight = getSizeInDp(R.dimen.default_height);
|
||||
mPeopleTileViewHelper = getPeopleTileViewHelper(PERSON_TILE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRemoteViewsWithLastInteractionTimeUnderOneDayHidden() {
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(PERSON_TILE_WITHOUT_NOTIFICATION).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
// Not showing last interaction.
|
||||
assertEquals(View.GONE, result.findViewById(R.id.last_interaction).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION, mOptions).getViews();
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
// Not showing last interaction.
|
||||
@@ -213,8 +208,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
PeopleSpaceTile tileWithLastInteraction =
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION.toBuilder().setLastInteractionTimestamp(
|
||||
123445L).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithLastInteraction, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tileWithLastInteraction).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -230,10 +224,8 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// No status.
|
||||
assertThat((View) result.findViewById(R.id.text_content)).isNull();
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithLastInteraction, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(tileWithLastInteraction).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show name over predefined icon.
|
||||
@@ -245,12 +237,10 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithLastInteraction, mOptions).getViews();
|
||||
tileWithLastInteraction).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -275,8 +265,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
new ConversationStatus.Builder(
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION.getId(),
|
||||
ACTIVITY_GAME).build())).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithAvailabilityAndNewStory, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tileWithAvailabilityAndNewStory).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -290,10 +279,8 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// No status.
|
||||
assertThat((View) result.findViewById(R.id.text_content)).isNull();
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithAvailabilityAndNewStory, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(tileWithAvailabilityAndNewStory).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show name rather than game type.
|
||||
@@ -305,12 +292,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// No messages count.
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithAvailabilityAndNewStory, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(tileWithAvailabilityAndNewStory).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -333,8 +317,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
NEW_STORY_WITH_AVAILABILITY, new ConversationStatus.Builder(
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION.getId(),
|
||||
ACTIVITY_BIRTHDAY).build())).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithStatusTemplate, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -351,10 +334,8 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
assertEquals(statusContent.getText(), mContext.getString(R.string.birthday_status));
|
||||
assertThat(statusContent.getMaxLines()).isEqualTo(2);
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithStatusTemplate, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show icon instead of name.
|
||||
@@ -367,12 +348,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// No messages count.
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithStatusTemplate, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -397,8 +375,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
PERSON_TILE_WITHOUT_NOTIFICATION.toBuilder().setStatuses(
|
||||
Arrays.asList(GAME_STATUS,
|
||||
NEW_STORY_WITH_AVAILABILITY)).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithStatusTemplate, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -416,10 +393,8 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
assertEquals(statusContent.getText(), GAME_DESCRIPTION);
|
||||
assertThat(statusContent.getMaxLines()).isEqualTo(2);
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithStatusTemplate, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show icon instead of name.
|
||||
@@ -432,12 +407,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// No messages count.
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithStatusTemplate, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(tileWithStatusTemplate).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -466,7 +438,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
ACTIVITY_ANNIVERSARY).setDescription("Anniversary").setAvailability(
|
||||
AVAILABILITY_AVAILABLE).setIcon(mIcon).build())).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithIconInStatusTemplate, mOptions).getViews();
|
||||
tileWithIconInStatusTemplate).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
assertEquals(View.GONE, result.findViewById(R.id.subtext).getVisibility());
|
||||
@@ -482,12 +454,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
assertEquals(statusContent.getText(), "Anniversary");
|
||||
assertThat(statusContent.getMaxLines()).isEqualTo(1);
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithIconInStatusTemplate, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(tileWithIconInStatusTemplate).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
assertEquals(View.GONE, largeResult.findViewById(R.id.subtext).getVisibility());
|
||||
@@ -512,8 +481,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
PeopleSpaceTile tile = PERSON_TILE.toBuilder()
|
||||
.setIsPackageSuspended(true)
|
||||
.build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tile, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tile).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
assertEquals(result.getSourceLayoutResId(), R.layout.people_tile_suppressed_layout);
|
||||
@@ -524,8 +492,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
PeopleSpaceTile tile = PERSON_TILE.toBuilder()
|
||||
.setIsUserQuieted(true)
|
||||
.build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tile, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tile).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
assertEquals(result.getSourceLayoutResId(), R.layout.people_tile_work_profile_quiet_layout);
|
||||
@@ -536,8 +503,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
PeopleSpaceTile tileWithDndBlocking = PERSON_TILE.toBuilder()
|
||||
.setNotificationPolicyState(BLOCK_CONVERSATIONS)
|
||||
.build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesEqual(
|
||||
@@ -548,8 +514,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationPolicyState(BLOCK_CONVERSATIONS)
|
||||
.setCanBypassDnd(true)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesNotEqual(
|
||||
@@ -559,8 +524,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
tileWithDndBlocking = PERSON_TILE.toBuilder()
|
||||
.setNotificationPolicyState(SHOW_IMPORTANT_CONVERSATIONS)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesEqual(
|
||||
@@ -571,8 +535,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationPolicyState(SHOW_IMPORTANT_CONVERSATIONS)
|
||||
.setIsImportantConversation(true)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesNotEqual(
|
||||
@@ -583,8 +546,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationPolicyState(SHOW_STARRED_CONTACTS)
|
||||
.setContactAffinity(VALID_CONTACT)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesEqual(
|
||||
@@ -595,8 +557,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationPolicyState(SHOW_STARRED_CONTACTS)
|
||||
.setContactAffinity(STARRED_CONTACT)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesNotEqual(
|
||||
@@ -607,8 +568,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationPolicyState(SHOW_CONTACTS)
|
||||
.setContactAffinity(STARRED_CONTACT)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesNotEqual(
|
||||
@@ -619,8 +579,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationPolicyState(SHOW_CONTACTS)
|
||||
.setContactAffinity(VALID_CONTACT)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesNotEqual(
|
||||
@@ -630,8 +589,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
tileWithDndBlocking = PERSON_TILE.toBuilder()
|
||||
.setNotificationPolicyState(SHOW_CONTACTS)
|
||||
.build();
|
||||
views = getPeopleTileViewHelper(
|
||||
tileWithDndBlocking, mOptions).getViews();
|
||||
views = getPeopleTileViewHelper(tileWithDndBlocking).getViews();
|
||||
result = views.apply(mContext, null);
|
||||
|
||||
assertResourcesEqual(
|
||||
@@ -648,8 +606,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setNotificationCategory(CATEGORY_MISSED_CALL)
|
||||
.setNotificationContent(MISSED_CALL)
|
||||
.build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithMissedCallNotification, mOptions).getViews();
|
||||
RemoteViews views = getPeopleTileViewHelper(tileWithMissedCallNotification).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -666,10 +623,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
assertEquals(statusContent.getText(), MISSED_CALL);
|
||||
assertThat(statusContent.getMaxLines()).isEqualTo(2);
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithMissedCallNotification, mOptions).getViews();
|
||||
tileWithMissedCallNotification).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show icon instead of name.
|
||||
@@ -681,12 +637,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// No messages count.
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithMissedCallNotification, mOptions).getViews();
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(tileWithMissedCallNotification).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -712,7 +665,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setStatuses(Arrays.asList(GAME_STATUS,
|
||||
NEW_STORY_WITH_AVAILABILITY)).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -733,10 +686,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// Has a single message, no count shown.
|
||||
assertEquals(View.GONE, result.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show icon instead of name.
|
||||
@@ -750,12 +702,10 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// Has a single message, no count shown.
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -786,7 +736,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
.setStatuses(Arrays.asList(GAME_STATUS,
|
||||
NEW_STORY_WITH_AVAILABILITY)).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -810,10 +760,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// Has a single message, no count shown.
|
||||
assertEquals(View.GONE, result.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show icon instead of name.
|
||||
@@ -827,12 +776,10 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// Has a single message, no count shown.
|
||||
assertEquals(View.GONE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -867,7 +814,7 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
NEW_STORY_WITH_AVAILABILITY))
|
||||
.setMessagesCount(2).build();
|
||||
RemoteViews views = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View result = views.apply(mContext, null);
|
||||
|
||||
TextView name = (TextView) result.findViewById(R.id.name);
|
||||
@@ -887,10 +834,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// Has two messages, show count.
|
||||
assertEquals(View.VISIBLE, result.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_medium) - 1);
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_medium) - 1;
|
||||
RemoteViews smallView = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View smallResult = smallView.apply(mContext, null);
|
||||
|
||||
// Show icon instead of name.
|
||||
@@ -904,12 +850,10 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
// Has two messages, show count.
|
||||
assertEquals(View.VISIBLE, smallResult.findViewById(R.id.messages_count).getVisibility());
|
||||
|
||||
mOptions.putInt(OPTION_APPWIDGET_MIN_WIDTH,
|
||||
getSizeInDp(R.dimen.required_width_for_large));
|
||||
mOptions.putInt(OPTION_APPWIDGET_MAX_HEIGHT,
|
||||
getSizeInDp(R.dimen.required_height_for_large));
|
||||
mWidth = getSizeInDp(R.dimen.required_width_for_large);
|
||||
mHeight = getSizeInDp(R.dimen.required_height_for_large);
|
||||
RemoteViews largeView = getPeopleTileViewHelper(
|
||||
tileWithStatusAndNotification, mOptions).getViews();
|
||||
tileWithStatusAndNotification).getViews();
|
||||
View largeResult = largeView.apply(mContext, null);
|
||||
|
||||
name = (TextView) largeResult.findViewById(R.id.name);
|
||||
@@ -1083,8 +1027,9 @@ public class PeopleTileViewHelperTest extends SysuiTestCase {
|
||||
/ mContext.getResources().getDisplayMetrics().density);
|
||||
}
|
||||
|
||||
private PeopleTileViewHelper getPeopleTileViewHelper(PeopleSpaceTile tile, Bundle options) {
|
||||
return new PeopleTileViewHelper(mContext, tile, 0, options,
|
||||
private PeopleTileViewHelper getPeopleTileViewHelper(
|
||||
PeopleSpaceTile tile) {
|
||||
return new PeopleTileViewHelper(mContext, tile, 0, mWidth, mHeight,
|
||||
new PeopleTileKey(tile.getId(), 0, tile.getPackageName()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user