Commit 1811f49c authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

[Feed] Hook up MarginResizer for FeedNTP

Bug: 860051
Change-Id: I08b602d2f02f8e61f1539a81483d4af9ad2e0493
Reviewed-on: https://chromium-review.googlesource.com/1180505Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584546}
parent 6a178bd0
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.feed; package org.chromium.chrome.browser.feed;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
...@@ -44,6 +45,8 @@ import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegateImpl ...@@ -44,6 +45,8 @@ import org.chromium.chrome.browser.suggestions.SuggestionsNavigationDelegateImpl
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.util.ViewUtils; import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.displaystyle.HorizontalDisplayStyle;
import org.chromium.chrome.browser.widget.displaystyle.MarginResizer;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig; import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import java.util.Arrays; import java.util.Arrays;
...@@ -58,6 +61,7 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -58,6 +61,7 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
private final StreamLifecycleManager mStreamLifecycleManager; private final StreamLifecycleManager mStreamLifecycleManager;
private final Stream mStream; private final Stream mStream;
private UiConfig mUiConfig;
private FrameLayout mRootView; private FrameLayout mRootView;
private SectionHeaderView mSectionHeaderView; private SectionHeaderView mSectionHeaderView;
private FeedImageLoader mImageLoader; private FeedImageLoader mImageLoader;
...@@ -72,22 +76,15 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -72,22 +76,15 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
} }
private static class BasicStreamConfiguration implements StreamConfiguration { private static class BasicStreamConfiguration implements StreamConfiguration {
private final Resources mResources; public BasicStreamConfiguration() {}
private final int mPadding;
public BasicStreamConfiguration(Resources resources) {
mResources = resources;
mPadding = mResources.getDimensionPixelSize(
R.dimen.content_suggestions_card_modern_margin);
}
@Override @Override
public int getPaddingStart() { public int getPaddingStart() {
return mPadding; return 0;
} }
@Override @Override
public int getPaddingEnd() { public int getPaddingEnd() {
return mPadding; return 0;
} }
@Override @Override
public int getPaddingTop() { public int getPaddingTop() {
...@@ -101,18 +98,23 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -101,18 +98,23 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
private static class BasicCardConfiguration implements CardConfiguration { private static class BasicCardConfiguration implements CardConfiguration {
private final Resources mResources; private final Resources mResources;
private final UiConfig mUiConfig;
private final int mCornerRadius; private final int mCornerRadius;
private final Drawable mCardBackground; private final Drawable mCardBackground;
private final int mCardMarginBottom; private final int mCardMargin;
private final int mCardWideMargin;
public BasicCardConfiguration(Resources resources) { public BasicCardConfiguration(Resources resources, UiConfig uiConfig) {
mResources = resources; mResources = resources;
mUiConfig = uiConfig;
mCornerRadius = mResources.getDimensionPixelSize( mCornerRadius = mResources.getDimensionPixelSize(
R.dimen.content_suggestions_card_modern_corner_radius); R.dimen.content_suggestions_card_modern_corner_radius);
mCardBackground = ApiCompatibilityUtils.getDrawable( mCardBackground = ApiCompatibilityUtils.getDrawable(
mResources, R.drawable.content_card_modern_background); mResources, R.drawable.content_card_modern_background);
mCardMarginBottom = mResources.getDimensionPixelSize( mCardMargin = mResources.getDimensionPixelSize(
R.dimen.content_suggestions_card_modern_margin); R.dimen.content_suggestions_card_modern_margin);
mCardWideMargin =
mResources.getDimensionPixelSize(R.dimen.ntp_wide_card_lateral_margins);
} }
@Override @Override
...@@ -127,19 +129,21 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -127,19 +129,21 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
@Override @Override
public int getCardBottomMargin() { public int getCardBottomMargin() {
return mCardMarginBottom; return mCardMargin;
} }
@Override @Override
public int getCardStartMargin() { public int getCardStartMargin() {
// TODO(twellington): implement this method. return mUiConfig.getCurrentDisplayStyle().horizontal == HorizontalDisplayStyle.WIDE
return 0; ? mCardWideMargin
: mCardMargin;
} }
@Override @Override
public int getCardEndMargin() { public int getCardEndMargin() {
// TODO(twellington): implement this method. return mUiConfig.getCurrentDisplayStyle().horizontal == HorizontalDisplayStyle.WIDE
return 0; ? mCardWideMargin
: mCardMargin;
} }
} }
...@@ -157,6 +161,21 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -157,6 +161,21 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
public void removeOfflineStatusListener(OfflineStatusListener offlineStatusListener) {} public void removeOfflineStatusListener(OfflineStatusListener offlineStatusListener) {}
} }
/**
* Provides the additional capabilities needed for the {@link FeedNewTabPage} container view.
*/
private class RootView extends FrameLayout {
public RootView(Context context) {
super(context);
}
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mUiConfig.updateDisplayStyle();
}
}
/** /**
* Constructs a new FeedNewTabPage. * Constructs a new FeedNewTabPage.
* *
...@@ -180,8 +199,8 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -180,8 +199,8 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
FeedStreamScope streamScope = FeedStreamScope streamScope =
feedProcessScope feedProcessScope
.createFeedStreamScopeBuilder(activity, mImageLoader, actionApi, .createFeedStreamScopeBuilder(activity, mImageLoader, actionApi,
new BasicStreamConfiguration(activity.getResources()), new BasicStreamConfiguration(),
new BasicCardConfiguration(activity.getResources()), new BasicCardConfiguration(activity.getResources(), mUiConfig),
new BasicSnackbarApi(), new FeedBasicLogging(), new BasicSnackbarApi(), new FeedBasicLogging(),
new StubOfflineIndicatorApi()) new StubOfflineIndicatorApi())
.build(); .build();
...@@ -194,6 +213,12 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -194,6 +213,12 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
mSectionHeaderView = (SectionHeaderView) inflater.inflate( mSectionHeaderView = (SectionHeaderView) inflater.inflate(
R.layout.new_tab_page_snippets_expandable_header, null); R.layout.new_tab_page_snippets_expandable_header, null);
// TODO(huayinz): Add MarginResizer for sign-in promo under issue 860051 or 860043,
// depending on which one lands first.
int wideMargin = mSectionHeaderView.getResources().getDimensionPixelSize(
R.dimen.ntp_wide_card_lateral_margins);
MarginResizer.createAndAttach(mSectionHeaderView, mUiConfig, 0, wideMargin);
mMediator = new FeedNewTabPageMediator(this, mMediator = new FeedNewTabPageMediator(this,
new SnapScrollHelper(mNewTabPageManager, mNewTabPageLayout, mStream.getView())); new SnapScrollHelper(mNewTabPageManager, mNewTabPageLayout, mStream.getView()));
...@@ -209,7 +234,7 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -209,7 +234,7 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
mNewTabPageLayout.initialize(mNewTabPageManager, mTab, mTileGroupDelegate, mNewTabPageLayout.initialize(mNewTabPageManager, mTab, mTileGroupDelegate,
mSearchProviderHasLogo, mSearchProviderHasLogo,
TemplateUrlService.getInstance().isDefaultSearchEngineGoogle(), mMediator, TemplateUrlService.getInstance().isDefaultSearchEngineGoogle(), mMediator,
contextMenuManager, new UiConfig(mRootView)); contextMenuManager, mUiConfig);
mStream.getView().setBackgroundColor(Color.WHITE); mStream.getView().setBackgroundColor(Color.WHITE);
mRootView.addView(mStream.getView()); mRootView.addView(mStream.getView());
...@@ -221,10 +246,11 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate { ...@@ -221,10 +246,11 @@ public class FeedNewTabPage extends NewTabPage implements TouchEnabledDelegate {
@Override @Override
protected void initializeMainView(Context context) { protected void initializeMainView(Context context) {
int topPadding = context.getResources().getDimensionPixelOffset(R.dimen.tab_strip_height); int topPadding = context.getResources().getDimensionPixelOffset(R.dimen.tab_strip_height);
mRootView = new FrameLayout(context); mRootView = new RootView(context);
mRootView.setLayoutParams(new FrameLayout.LayoutParams( mRootView.setLayoutParams(new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
mRootView.setPadding(0, topPadding, 0, 0); mRootView.setPadding(0, topPadding, 0, 0);
mUiConfig = new UiConfig(mRootView);
} }
@Override @Override
......
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