Commit bc79e00a authored by spdonghao's avatar spdonghao Committed by Commit Bot

[Instant Start] Remove borders of Feed placeholder.

Bug: 1111824
Change-Id: I4f3766703802d94a371e2b57f30af198b01e3bfc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2344945Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Commit-Queue: Hao Dong <spdonghao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799809}
parent 212ec49e
...@@ -27,7 +27,6 @@ android_resources("java_resources") { ...@@ -27,7 +27,6 @@ android_resources("java_resources") {
"java/res/drawable-xxhdpi/ic_home.png", "java/res/drawable-xxhdpi/ic_home.png",
"java/res/drawable-xxxhdpi/ic_explore.png", "java/res/drawable-xxxhdpi/ic_explore.png",
"java/res/drawable-xxxhdpi/ic_home.png", "java/res/drawable-xxxhdpi/ic_home.png",
"java/res/drawable/hairline_border_card_background_light.xml",
"java/res/layout/feed_loading_layout.xml", "java/res/layout/feed_loading_layout.xml",
"java/res/layout/ss_bottom_bar_layout.xml", "java/res/layout/ss_bottom_bar_layout.xml",
"java/res/layout/ss_explore_button.xml", "java/res/layout/ss_explore_button.xml",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@color/default_bg_color" />
<stroke android:width="1dp" android:color="@color/feed_placeholder_color"/>
<corners android:radius="@dimen/default_rounded_corner_radius" />
</shape>
...@@ -30,7 +30,7 @@ import org.chromium.components.browser_ui.widget.displaystyle.ViewResizer; ...@@ -30,7 +30,7 @@ import org.chromium.components.browser_ui.widget.displaystyle.ViewResizer;
*/ */
public class FeedLoadingLayout extends LinearLayout { public class FeedLoadingLayout extends LinearLayout {
private static final int CARD_MARGIN_DP = 12; private static final int CARD_MARGIN_DP = 12;
private static final int CARD_PADDING_DP = 15; private static final int CARD_TOP_PADDING_DP = 15;
private static final int IMAGE_PLACEHOLDER_BOTTOM_PADDING_DP = 72; private static final int IMAGE_PLACEHOLDER_BOTTOM_PADDING_DP = 72;
private static final int IMAGE_PLACEHOLDER_BOTTOM_PADDING_DENSE_DP = 48; private static final int IMAGE_PLACEHOLDER_BOTTOM_PADDING_DENSE_DP = 48;
private static final int IMAGE_PLACEHOLDER_SIZE_DP = 92; private static final int IMAGE_PLACEHOLDER_SIZE_DP = 92;
...@@ -117,7 +117,6 @@ public class FeedLoadingLayout extends LinearLayout { ...@@ -117,7 +117,6 @@ public class FeedLoadingLayout extends LinearLayout {
LinearLayout parent, boolean isSmallCard, ViewGroup.LayoutParams lp) { LinearLayout parent, boolean isSmallCard, ViewGroup.LayoutParams lp) {
LinearLayout container = new LinearLayout(mContext); LinearLayout container = new LinearLayout(mContext);
container.setLayoutParams(lp); container.setLayoutParams(lp);
container.setBackgroundResource(R.drawable.hairline_border_card_background_light);
container.setOrientation(isSmallCard ? HORIZONTAL : VERTICAL); container.setOrientation(isSmallCard ? HORIZONTAL : VERTICAL);
ImageView imagePlaceholder = getImagePlaceholder(isSmallCard); ImageView imagePlaceholder = getImagePlaceholder(isSmallCard);
ImageView textPlaceholder = getTextPlaceholder(isSmallCard); ImageView textPlaceholder = getTextPlaceholder(isSmallCard);
...@@ -130,37 +129,35 @@ public class FeedLoadingLayout extends LinearLayout { ...@@ -130,37 +129,35 @@ public class FeedLoadingLayout extends LinearLayout {
LinearLayout.LayoutParams imagePlaceholderLp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams imagePlaceholderLp = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ImageView imagePlaceholder = new ImageView(mContext); ImageView imagePlaceholder = new ImageView(mContext);
int imageRadius = mResources.getDimensionPixelSize(R.dimen.default_rounded_corner_radius); imagePlaceholder.setImageDrawable(
imagePlaceholder.setImageDrawable(isSmallCard ? getSmallImageDrawable(imageRadius) isSmallCard ? getSmallImageDrawable() : getLargeImageDrawable());
: getLargeImageDrawable(imageRadius));
imagePlaceholder.setLayoutParams(imagePlaceholderLp); imagePlaceholder.setLayoutParams(imagePlaceholderLp);
imagePlaceholder.setScaleType(ImageView.ScaleType.FIT_XY); imagePlaceholder.setScaleType(ImageView.ScaleType.FIT_XY);
return imagePlaceholder; return imagePlaceholder;
} }
private LayerDrawable getSmallImageDrawable(int imageRadius) { private LayerDrawable getSmallImageDrawable() {
int imageSize = dpToPx(IMAGE_PLACEHOLDER_SIZE_DP); int imageSize = dpToPx(IMAGE_PLACEHOLDER_SIZE_DP);
int padding = dpToPx(CARD_PADDING_DP); int top = dpToPx(CARD_TOP_PADDING_DP);
GradientDrawable[] placeholder = getRectangles(1, imageSize, imageSize, imageRadius, false); GradientDrawable[] placeholder = getRectangles(1, imageSize, imageSize);
LayerDrawable layerDrawable = new LayerDrawable(placeholder); LayerDrawable layerDrawable = new LayerDrawable(placeholder);
layerDrawable.setLayerInset(0, 0, padding, padding, layerDrawable.setLayerInset(0, 0, top, 0,
mIsFirstCardDense ? dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DENSE_DP) mIsFirstCardDense ? dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DENSE_DP)
: dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DP)); : dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DP));
return layerDrawable; return layerDrawable;
} }
private LayerDrawable getLargeImageDrawable(int imageRadius) { private LayerDrawable getLargeImageDrawable() {
GradientDrawable[] placeholder = getRectangles(1, dpToPx(mScreenWidthDp) - mPaddingPx * 2, GradientDrawable[] placeholder = getRectangles(
dpToPx(LARGE_IMAGE_HEIGHT_DP), imageRadius, true); 1, dpToPx(mScreenWidthDp) - mPaddingPx * 2, dpToPx(LARGE_IMAGE_HEIGHT_DP));
return new LayerDrawable(placeholder); return new LayerDrawable(placeholder);
} }
private ImageView getTextPlaceholder(boolean isSmallCard) { private ImageView getTextPlaceholder(boolean isSmallCard) {
int top = dpToPx(CARD_PADDING_DP); int top = dpToPx(CARD_TOP_PADDING_DP);
int left = top / 2; int left = top / 2;
int height = dpToPx(TEXT_PLACEHOLDER_HEIGHT_DP); int height = dpToPx(TEXT_PLACEHOLDER_HEIGHT_DP);
int width = dpToPx(mScreenWidthDp) - mPaddingPx * 2; int width = dpToPx(mScreenWidthDp) - mPaddingPx * 2;
int radius = dpToPx(TEXT_PLACEHOLDER_RADIUS_DP);
int contentHeight = dpToPx(TEXT_CONTENT_HEIGHT_DP); int contentHeight = dpToPx(TEXT_CONTENT_HEIGHT_DP);
LinearLayout.LayoutParams textPlaceholderLp = isSmallCard LinearLayout.LayoutParams textPlaceholderLp = isSmallCard
...@@ -169,10 +166,10 @@ public class FeedLoadingLayout extends LinearLayout { ...@@ -169,10 +166,10 @@ public class FeedLoadingLayout extends LinearLayout {
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LayerDrawable layerDrawable = isSmallCard LayerDrawable layerDrawable = isSmallCard
? getSmallTextDrawable(top, left, ? getSmallTextDrawable(top,
width - dpToPx(IMAGE_PLACEHOLDER_SIZE_DP) - dpToPx(CARD_PADDING_DP), height, width - dpToPx(IMAGE_PLACEHOLDER_SIZE_DP) - dpToPx(CARD_TOP_PADDING_DP),
radius, contentHeight) height, contentHeight)
: getLargeTextDrawable(top, left, width, height, radius, contentHeight + 2 * top); : getLargeTextDrawable(top, left, width, height, contentHeight + 2 * top);
ImageView textPlaceholder = new ImageView(mContext); ImageView textPlaceholder = new ImageView(mContext);
textPlaceholder.setImageDrawable(layerDrawable); textPlaceholder.setImageDrawable(layerDrawable);
...@@ -181,28 +178,27 @@ public class FeedLoadingLayout extends LinearLayout { ...@@ -181,28 +178,27 @@ public class FeedLoadingLayout extends LinearLayout {
return textPlaceholder; return textPlaceholder;
} }
private LayerDrawable getSmallTextDrawable( private LayerDrawable getSmallTextDrawable(int top, int width, int height, int contentHeight) {
int top, int left, int width, int height, int radius, int contentHeight) { GradientDrawable[] placeholders = getRectangles(4, width, height);
GradientDrawable[] placeholders = getRectangles(4, width, height, radius, false); int cardHeight = dpToPx(IMAGE_PLACEHOLDER_SIZE_DP) + dpToPx(CARD_TOP_PADDING_DP)
int cardHeight = dpToPx(IMAGE_PLACEHOLDER_SIZE_DP) + dpToPx(CARD_PADDING_DP)
+ (mIsFirstCardDense ? dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DENSE_DP) + (mIsFirstCardDense ? dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DENSE_DP)
: dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DP)); : dpToPx(IMAGE_PLACEHOLDER_BOTTOM_PADDING_DP));
LayerDrawable layerDrawable = new LayerDrawable(placeholders); LayerDrawable layerDrawable = new LayerDrawable(placeholders);
// Title Placeholder // Title Placeholder
layerDrawable.setLayerInset(0, left, top, top, cardHeight - top - height); layerDrawable.setLayerInset(0, 0, top, top, cardHeight - top - height);
// Content Placeholder // Content Placeholder
layerDrawable.setLayerInset(1, left, (contentHeight - height) / 2 + top, top, layerDrawable.setLayerInset(1, 0, (contentHeight - height) / 2 + top, top,
cardHeight - top - (height + contentHeight) / 2); cardHeight - top - (height + contentHeight) / 2);
layerDrawable.setLayerInset( layerDrawable.setLayerInset(
2, left, top + contentHeight - height, top, cardHeight - top - contentHeight); 2, 0, top + contentHeight - height, top, cardHeight - top - contentHeight);
// Publisher Placeholder // Publisher Placeholder
layerDrawable.setLayerInset(3, left, cardHeight - top - height, top * 7, top); layerDrawable.setLayerInset(3, 0, cardHeight - top - height, top * 7, top);
return layerDrawable; return layerDrawable;
} }
private LayerDrawable getLargeTextDrawable( private LayerDrawable getLargeTextDrawable(
int top, int left, int width, int height, int radius, int contentHeight) { int top, int left, int width, int height, int contentHeight) {
GradientDrawable[] placeholders = getRectangles(3, width, height, radius, false); GradientDrawable[] placeholders = getRectangles(3, width, height);
LayerDrawable layerDrawable = new LayerDrawable(placeholders); LayerDrawable layerDrawable = new LayerDrawable(placeholders);
layerDrawable.setLayerInset(0, left, top, top, contentHeight - top - height); layerDrawable.setLayerInset(0, left, top, top, contentHeight - top - height);
layerDrawable.setLayerInset( layerDrawable.setLayerInset(
...@@ -211,19 +207,14 @@ public class FeedLoadingLayout extends LinearLayout { ...@@ -211,19 +207,14 @@ public class FeedLoadingLayout extends LinearLayout {
return layerDrawable; return layerDrawable;
} }
private GradientDrawable[] getRectangles( private GradientDrawable[] getRectangles(int num, int width, int height) {
int num, int width, int height, int radius, boolean setBottomRadius) {
GradientDrawable[] placeholders = new GradientDrawable[num]; GradientDrawable[] placeholders = new GradientDrawable[num];
int radius = dpToPx(TEXT_PLACEHOLDER_RADIUS_DP);
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
placeholders[i] = new GradientDrawable(); placeholders[i] = new GradientDrawable();
placeholders[i].setShape(GradientDrawable.RECTANGLE); placeholders[i].setShape(GradientDrawable.RECTANGLE);
placeholders[i].setSize(width, height); placeholders[i].setSize(width, height);
if (setBottomRadius) { placeholders[i].setCornerRadius(radius);
placeholders[i].setCornerRadii(
new float[] {radius, radius, radius, radius, 0, 0, 0, 0});
} else {
placeholders[i].setCornerRadius(radius);
}
placeholders[i].setColor(mResources.getColor(R.color.feed_placeholder_color)); placeholders[i].setColor(mResources.getColor(R.color.feed_placeholder_color));
} }
return placeholders; return placeholders;
......
...@@ -665,7 +665,7 @@ public class InstantStartTest { ...@@ -665,7 +665,7 @@ public class InstantStartTest {
ViewUtils.onViewWaiting(AllOf.allOf(withId(R.id.single_tab_view), isDisplayed())); ViewUtils.onViewWaiting(AllOf.allOf(withId(R.id.single_tab_view), isDisplayed()));
ChromeRenderTestRule.sanitize(surface); ChromeRenderTestRule.sanitize(surface);
// TODO(crbug.com/1065314): fix favicon. // TODO(crbug.com/1065314): fix favicon.
mRenderTestRule.render(surface, "singlePane_singleTab_noMV2"); mRenderTestRule.render(surface, "singlePane_singleTab_noMV3");
// Initializes native. // Initializes native.
startAndWaitNativeInitialization(); startAndWaitNativeInitialization();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment