Commit 3d5cd91a authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

Update the pull to refresh indicator colors

Bug: 935773
Change-Id: I291481ce839123e749d5959d413f41ac3560168c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1554291Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarBecky Zhou <huayinz@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#649178}
parent 233cf722
...@@ -17,6 +17,7 @@ import org.chromium.chrome.R; ...@@ -17,6 +17,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory; import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.gesturenav.NavigationHandler; import org.chromium.chrome.browser.gesturenav.NavigationHandler;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabWebContentsUserData; import org.chromium.chrome.browser.tab.TabWebContentsUserData;
import org.chromium.components.feature_engagement.EventConstants; import org.chromium.components.feature_engagement.EventConstants;
...@@ -55,6 +56,8 @@ public class SwipeRefreshHandler ...@@ -55,6 +56,8 @@ public class SwipeRefreshHandler
// The Tab where the swipe occurs. // The Tab where the swipe occurs.
private Tab mTab; private Tab mTab;
private EmptyTabObserver mTabObserver;
// The container view the SwipeRefreshHandler instance is currently // The container view the SwipeRefreshHandler instance is currently
// associated with. // associated with.
private ViewGroup mContainerView; private ViewGroup mContainerView;
...@@ -95,15 +98,29 @@ public class SwipeRefreshHandler ...@@ -95,15 +98,29 @@ public class SwipeRefreshHandler
private SwipeRefreshHandler(Tab tab) { private SwipeRefreshHandler(Tab tab) {
super(tab); super(tab);
mTab = tab; mTab = tab;
mTabObserver = new EmptyTabObserver() {
@Override
public void onActivityAttachmentChanged(Tab tab, boolean isAttached) {
if (!isAttached && mSwipeRefreshLayout != null) {
cancelStopRefreshingRunnable();
detachSwipeRefreshLayoutIfNecessary();
mSwipeRefreshLayout.setOnRefreshListener(null);
mSwipeRefreshLayout.setOnResetListener(null);
mSwipeRefreshLayout = null;
}
}
};
mTab.addObserver(mTabObserver);
mNavigationEnabled = mNavigationEnabled =
ChromeFeatureList.isEnabled(ChromeFeatureList.OVERSCROLL_HISTORY_NAVIGATION); ChromeFeatureList.isEnabled(ChromeFeatureList.OVERSCROLL_HISTORY_NAVIGATION);
} }
private void initSwipeRefreshLayout() { private void initSwipeRefreshLayout(final Context context) {
final Context context = mTab.getThemedApplicationContext();
mSwipeRefreshLayout = new SwipeRefreshLayout(context); mSwipeRefreshLayout = new SwipeRefreshLayout(context);
mSwipeRefreshLayout.setLayoutParams( mSwipeRefreshLayout.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(
R.color.default_bg_color_elev_2);
mSwipeRefreshLayout.setColorSchemeResources(R.color.light_active_color); mSwipeRefreshLayout.setColorSchemeResources(R.color.light_active_color);
if (mContainerView != null) mSwipeRefreshLayout.setEnabled(true); if (mContainerView != null) mSwipeRefreshLayout.setEnabled(true);
...@@ -174,7 +191,7 @@ public class SwipeRefreshHandler ...@@ -174,7 +191,7 @@ public class SwipeRefreshHandler
mSwipeType = type; mSwipeType = type;
if (type == OverscrollAction.PULL_TO_REFRESH) { if (type == OverscrollAction.PULL_TO_REFRESH) {
if (mSwipeRefreshLayout == null) initSwipeRefreshLayout(); if (mSwipeRefreshLayout == null) initSwipeRefreshLayout(mTab.getContext());
attachSwipeRefreshLayoutIfNecessary(); attachSwipeRefreshLayoutIfNecessary();
return mSwipeRefreshLayout.start(); return mSwipeRefreshLayout.start();
} else if (type == OverscrollAction.HISTORY_NAVIGATION && mNavigationEnabled) { } else if (type == OverscrollAction.HISTORY_NAVIGATION && mNavigationEnabled) {
...@@ -244,7 +261,11 @@ public class SwipeRefreshHandler ...@@ -244,7 +261,11 @@ public class SwipeRefreshHandler
private Runnable getStopRefreshingRunnable() { private Runnable getStopRefreshingRunnable() {
if (mStopRefreshingRunnable == null) { if (mStopRefreshingRunnable == null) {
mStopRefreshingRunnable = () -> mSwipeRefreshLayout.setRefreshing(false); mStopRefreshingRunnable = () -> {
if (mSwipeRefreshLayout != null) {
mSwipeRefreshLayout.setRefreshing(false);
}
};
} }
return mStopRefreshingRunnable; return mStopRefreshingRunnable;
} }
......
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