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

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

Issue 2235533002: Revert "Changed NavigationController access to through tab in Java code" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.view.ViewGroup.LayoutParams; 8 import android.view.ViewGroup.LayoutParams;
9 9
10 import org.chromium.base.TraceEvent; 10 import org.chromium.base.TraceEvent;
11 import org.chromium.base.annotations.JNINamespace; 11 import org.chromium.base.annotations.JNINamespace;
12 import org.chromium.base.metrics.RecordUserAction; 12 import org.chromium.base.metrics.RecordUserAction;
13 import org.chromium.chrome.R; 13 import org.chromium.chrome.R;
14 import org.chromium.chrome.browser.navigation.NavigationHandler;
15 import org.chromium.content.browser.ContentViewCore; 14 import org.chromium.content.browser.ContentViewCore;
16 import org.chromium.content.browser.OverscrollRefreshHandler; 15 import org.chromium.content.browser.OverscrollRefreshHandler;
17 import org.chromium.third_party.android.swiperefresh.SwipeRefreshLayout; 16 import org.chromium.third_party.android.swiperefresh.SwipeRefreshLayout;
18 17
19 /** 18 /**
20 * An overscroll handler implemented in terms a modified version of the Android 19 * An overscroll handler implemented in terms a modified version of the Android
21 * compat library's SwipeRefreshLayout effect. 20 * compat library's SwipeRefreshLayout effect.
22 */ 21 */
23 @JNINamespace("content") 22 @JNINamespace("content")
24 public class SwipeRefreshHandler implements OverscrollRefreshHandler { 23 public class SwipeRefreshHandler implements OverscrollRefreshHandler {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // SwipeRefreshLayout.LARGE layouts appear broken on JellyBean. 62 // SwipeRefreshLayout.LARGE layouts appear broken on JellyBean.
64 mSwipeRefreshLayout.setSize(SwipeRefreshLayout.DEFAULT); 63 mSwipeRefreshLayout.setSize(SwipeRefreshLayout.DEFAULT);
65 mSwipeRefreshLayout.setEnabled(false); 64 mSwipeRefreshLayout.setEnabled(false);
66 } 65 }
67 66
68 /** 67 /**
69 * Pair the effect with a given ContentViewCore instance. If that instance i s null, 68 * Pair the effect with a given ContentViewCore instance. If that instance i s null,
70 * the effect will be disabled. 69 * the effect will be disabled.
71 * @param contentViewCore The associated ContentViewCore instance. 70 * @param contentViewCore The associated ContentViewCore instance.
72 */ 71 */
73 public void setContentViewCore(final ContentViewCore contentViewCore, 72 public void setContentViewCore(final ContentViewCore contentViewCore) {
74 final NavigationHandler navigationHandler) {
75 if (mContentViewCore == contentViewCore) return; 73 if (mContentViewCore == contentViewCore) return;
76 74
77 if (mContentViewCore != null) { 75 if (mContentViewCore != null) {
78 setEnabled(false); 76 setEnabled(false);
79 cancelStopRefreshingRunnable(); 77 cancelStopRefreshingRunnable();
80 mSwipeRefreshLayout.setOnRefreshListener(null); 78 mSwipeRefreshLayout.setOnRefreshListener(null);
81 mContentViewCore.setOverscrollRefreshHandler(null); 79 mContentViewCore.setOverscrollRefreshHandler(null);
82 } 80 }
83 81
84 mContentViewCore = contentViewCore; 82 mContentViewCore = contentViewCore;
85 83
86 if (mContentViewCore == null) return; 84 if (mContentViewCore == null) return;
87 85
88 setEnabled(true); 86 setEnabled(true);
89 mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefres hListener() { 87 mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefres hListener() {
90 @Override 88 @Override
91 public void onRefresh() { 89 public void onRefresh() {
92 cancelStopRefreshingRunnable(); 90 cancelStopRefreshingRunnable();
93 mSwipeRefreshLayout.postDelayed( 91 mSwipeRefreshLayout.postDelayed(
94 getStopRefreshingRunnable(), MAX_REFRESH_ANIMATION_DURAT ION_MS); 92 getStopRefreshingRunnable(), MAX_REFRESH_ANIMATION_DURAT ION_MS);
95 if (mAccessibilityRefreshString == null) { 93 if (mAccessibilityRefreshString == null) {
96 int resId = R.string.accessibility_swipe_refresh; 94 int resId = R.string.accessibility_swipe_refresh;
97 mAccessibilityRefreshString = 95 mAccessibilityRefreshString =
98 contentViewCore.getContext().getResources().getStrin g(resId); 96 contentViewCore.getContext().getResources().getStrin g(resId);
99 } 97 }
100 mSwipeRefreshLayout.announceForAccessibility(mAccessibilityRefre shString); 98 mSwipeRefreshLayout.announceForAccessibility(mAccessibilityRefre shString);
101 navigationHandler.reloadToRefreshContent(true); 99 contentViewCore.getWebContents().getNavigationController().reloa dToRefreshContent(
100 true);
102 RecordUserAction.record("MobilePullGestureReload"); 101 RecordUserAction.record("MobilePullGestureReload");
103 } 102 }
104 }); 103 });
105 mSwipeRefreshLayout.setOnResetListener(new SwipeRefreshLayout.OnResetLis tener() { 104 mSwipeRefreshLayout.setOnResetListener(new SwipeRefreshLayout.OnResetLis tener() {
106 @Override 105 @Override
107 public void onReset() { 106 public void onReset() {
108 if (mDetachLayoutRunnable != null) return; 107 if (mDetachLayoutRunnable != null) return;
109 mDetachLayoutRunnable = new Runnable() { 108 mDetachLayoutRunnable = new Runnable() {
110 @Override 109 @Override
111 public void run() { 110 public void run() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 199 }
201 200
202 private void detachSwipeRefreshLayoutIfNecessary() { 201 private void detachSwipeRefreshLayoutIfNecessary() {
203 cancelDetachLayoutRunnable(); 202 cancelDetachLayoutRunnable();
204 if (mContentViewCore == null) return; 203 if (mContentViewCore == null) return;
205 if (mSwipeRefreshLayout.getParent() != null) { 204 if (mSwipeRefreshLayout.getParent() != null) {
206 mContentViewCore.getContainerView().removeView(mSwipeRefreshLayout); 205 mContentViewCore.getContainerView().removeView(mSwipeRefreshLayout);
207 } 206 }
208 } 207 }
209 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698