Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(628)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java

Issue 2416723002: Load live version when pulling down to reload an offline page on connected network (Closed)
Patch Set: Address one more feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java
index 45677771637fefaf3e6e47a06ad38f1d6d105bd1..6543a19062599063a3ac9df68aae16da4a9ff796 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/SwipeRefreshHandler.java
@@ -8,9 +8,9 @@ import android.content.Context;
import android.view.ViewGroup.LayoutParams;
import org.chromium.base.TraceEvent;
-import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.tab.Tab;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.OverscrollRefreshHandler;
import org.chromium.third_party.android.swiperefresh.SwipeRefreshLayout;
@@ -19,7 +19,6 @@ import org.chromium.third_party.android.swiperefresh.SwipeRefreshLayout;
* An overscroll handler implemented in terms a modified version of the Android
* compat library's SwipeRefreshLayout effect.
*/
-@JNINamespace("content")
public class SwipeRefreshHandler implements OverscrollRefreshHandler {
// Synthetic delay between the {@link #didStopRefreshing()} signal and the
// call to stop the refresh animation.
@@ -33,6 +32,9 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
// logic, rendering and animation.
private final SwipeRefreshLayout mSwipeRefreshLayout;
+ // The Tab where the swipe occurs.
+ private Tab mTab;
+
// The ContentViewCore with which the handler is associated. The handler
// will set/unset itself as the default OverscrollRefreshHandler as the
// association changes.
@@ -53,8 +55,12 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
* Simple constructor to use when creating an OverscrollRefresh instance from code.
*
* @param context The associated context.
+ * @param tab The Tab where the swipe occurs.
*/
- public SwipeRefreshHandler(Context context) {
+ public SwipeRefreshHandler(Context context, Tab tab) {
+ mTab = tab;
+ mContentViewCore = mTab.getContentViewCore();
+
mSwipeRefreshLayout = new SwipeRefreshLayout(context);
mSwipeRefreshLayout.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
@@ -62,26 +68,6 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
// SwipeRefreshLayout.LARGE layouts appear broken on JellyBean.
mSwipeRefreshLayout.setSize(SwipeRefreshLayout.DEFAULT);
mSwipeRefreshLayout.setEnabled(false);
- }
-
- /**
- * Pair the effect with a given ContentViewCore instance. If that instance is null,
- * the effect will be disabled.
- * @param contentViewCore The associated ContentViewCore instance.
- */
- public void setContentViewCore(final ContentViewCore contentViewCore) {
- if (mContentViewCore == contentViewCore) return;
-
- if (mContentViewCore != null) {
- setEnabled(false);
- cancelStopRefreshingRunnable();
- mSwipeRefreshLayout.setOnRefreshListener(null);
- mContentViewCore.setOverscrollRefreshHandler(null);
- }
-
- mContentViewCore = contentViewCore;
-
- if (mContentViewCore == null) return;
setEnabled(true);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@@ -93,11 +79,10 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
if (mAccessibilityRefreshString == null) {
int resId = R.string.accessibility_swipe_refresh;
mAccessibilityRefreshString =
- contentViewCore.getContext().getResources().getString(resId);
+ mContentViewCore.getContext().getResources().getString(resId);
}
mSwipeRefreshLayout.announceForAccessibility(mAccessibilityRefreshString);
- contentViewCore.getWebContents().getNavigationController().reloadToRefreshContent(
- true);
+ mTab.reload();
RecordUserAction.record("MobilePullGestureReload");
}
});
@@ -116,7 +101,17 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
}
});
- contentViewCore.setOverscrollRefreshHandler(this);
+ mContentViewCore.setOverscrollRefreshHandler(this);
+ }
+
+ /**
+ * Destroys and cleans up itself.
+ */
+ public void destroy() {
+ setEnabled(false);
+ cancelStopRefreshingRunnable();
+ mSwipeRefreshLayout.setOnRefreshListener(null);
+ mContentViewCore.setOverscrollRefreshHandler(null);
}
/**
@@ -192,7 +187,6 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
// with composited SurfaceView content.
private void attachSwipeRefreshLayoutIfNecessary() {
cancelDetachLayoutRunnable();
- if (mContentViewCore == null) return;
if (mSwipeRefreshLayout.getParent() == null) {
mContentViewCore.getContainerView().addView(mSwipeRefreshLayout);
}
@@ -200,7 +194,6 @@ public class SwipeRefreshHandler implements OverscrollRefreshHandler {
private void detachSwipeRefreshLayoutIfNecessary() {
cancelDetachLayoutRunnable();
- if (mContentViewCore == null) return;
if (mSwipeRefreshLayout.getParent() != null) {
mContentViewCore.getContainerView().removeView(mSwipeRefreshLayout);
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698