| OLD | NEW |
| 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; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // The ContentViewCore with which the handler is associated. The handler | 36 // The ContentViewCore with which the handler is associated. The handler |
| 37 // will set/unset itself as the default OverscrollRefreshHandler as the | 37 // will set/unset itself as the default OverscrollRefreshHandler as the |
| 38 // association changes. | 38 // association changes. |
| 39 private ContentViewCore mContentViewCore; | 39 private ContentViewCore mContentViewCore; |
| 40 | 40 |
| 41 // Async runnable for ending the refresh animation after the page first | 41 // Async runnable for ending the refresh animation after the page first |
| 42 // loads a frame. This is used to provide a reasonable minimum animation tim
e. | 42 // loads a frame. This is used to provide a reasonable minimum animation tim
e. |
| 43 private Runnable mStopRefreshingRunnable; | 43 private Runnable mStopRefreshingRunnable; |
| 44 | 44 |
| 45 // Handles removing the layout from the view hierarchy. This is posted to e
nsure it does not |
| 46 // conflict with pending Android draws. |
| 47 private Runnable mDetachLayoutRunnable; |
| 48 |
| 45 // Accessibility utterance used to indicate refresh activation. | 49 // Accessibility utterance used to indicate refresh activation. |
| 46 private String mAccessibilityRefreshString; | 50 private String mAccessibilityRefreshString; |
| 47 | 51 |
| 48 /** | 52 /** |
| 49 * Simple constructor to use when creating an OverscrollRefresh instance fro
m code. | 53 * Simple constructor to use when creating an OverscrollRefresh instance fro
m code. |
| 50 * | 54 * |
| 51 * @param context The associated context. | 55 * @param context The associated context. |
| 52 */ | 56 */ |
| 53 public SwipeRefreshHandler(Context context) { | 57 public SwipeRefreshHandler(Context context) { |
| 54 mSwipeRefreshLayout = new SwipeRefreshLayout(context); | 58 mSwipeRefreshLayout = new SwipeRefreshLayout(context); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 97 } |
| 94 mSwipeRefreshLayout.announceForAccessibility(mAccessibilityRefre
shString); | 98 mSwipeRefreshLayout.announceForAccessibility(mAccessibilityRefre
shString); |
| 95 contentViewCore.getWebContents().getNavigationController().reloa
dToRefreshContent( | 99 contentViewCore.getWebContents().getNavigationController().reloa
dToRefreshContent( |
| 96 true); | 100 true); |
| 97 RecordUserAction.record("MobilePullGestureReload"); | 101 RecordUserAction.record("MobilePullGestureReload"); |
| 98 } | 102 } |
| 99 }); | 103 }); |
| 100 mSwipeRefreshLayout.setOnResetListener(new SwipeRefreshLayout.OnResetLis
tener() { | 104 mSwipeRefreshLayout.setOnResetListener(new SwipeRefreshLayout.OnResetLis
tener() { |
| 101 @Override | 105 @Override |
| 102 public void onReset() { | 106 public void onReset() { |
| 103 detachSwipeRefreshLayoutIfNecessary(); | 107 if (mDetachLayoutRunnable != null) return; |
| 108 mDetachLayoutRunnable = new Runnable() { |
| 109 @Override |
| 110 public void run() { |
| 111 mDetachLayoutRunnable = null; |
| 112 detachSwipeRefreshLayoutIfNecessary(); |
| 113 } |
| 114 }; |
| 115 mSwipeRefreshLayout.post(mDetachLayoutRunnable); |
| 104 } | 116 } |
| 105 }); | 117 }); |
| 106 | 118 |
| 107 contentViewCore.setOverscrollRefreshHandler(this); | 119 contentViewCore.setOverscrollRefreshHandler(this); |
| 108 } | 120 } |
| 109 | 121 |
| 110 /** | 122 /** |
| 111 * Notify the SwipeRefreshLayout that a refresh action has completed. | 123 * Notify the SwipeRefreshLayout that a refresh action has completed. |
| 112 * Defer the notification by a reasonable minimum to ensure sufficient | 124 * Defer the notification by a reasonable minimum to ensure sufficient |
| 113 * visiblity of the animation. | 125 * visiblity of the animation. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 mSwipeRefreshLayout.setEnabled(enabled); | 162 mSwipeRefreshLayout.setEnabled(enabled); |
| 151 if (!enabled) reset(); | 163 if (!enabled) reset(); |
| 152 } | 164 } |
| 153 | 165 |
| 154 private void cancelStopRefreshingRunnable() { | 166 private void cancelStopRefreshingRunnable() { |
| 155 if (mStopRefreshingRunnable != null) { | 167 if (mStopRefreshingRunnable != null) { |
| 156 mSwipeRefreshLayout.removeCallbacks(mStopRefreshingRunnable); | 168 mSwipeRefreshLayout.removeCallbacks(mStopRefreshingRunnable); |
| 157 } | 169 } |
| 158 } | 170 } |
| 159 | 171 |
| 172 private void cancelDetachLayoutRunnable() { |
| 173 if (mDetachLayoutRunnable != null) { |
| 174 mSwipeRefreshLayout.removeCallbacks(mDetachLayoutRunnable); |
| 175 mDetachLayoutRunnable = null; |
| 176 } |
| 177 } |
| 178 |
| 160 private Runnable getStopRefreshingRunnable() { | 179 private Runnable getStopRefreshingRunnable() { |
| 161 if (mStopRefreshingRunnable == null) { | 180 if (mStopRefreshingRunnable == null) { |
| 162 mStopRefreshingRunnable = new Runnable() { | 181 mStopRefreshingRunnable = new Runnable() { |
| 163 @Override | 182 @Override |
| 164 public void run() { | 183 public void run() { |
| 165 mSwipeRefreshLayout.setRefreshing(false); | 184 mSwipeRefreshLayout.setRefreshing(false); |
| 166 } | 185 } |
| 167 }; | 186 }; |
| 168 } | 187 } |
| 169 return mStopRefreshingRunnable; | 188 return mStopRefreshingRunnable; |
| 170 } | 189 } |
| 171 | 190 |
| 172 // The animation view is attached/detached on-demand to minimize overlap | 191 // The animation view is attached/detached on-demand to minimize overlap |
| 173 // with composited SurfaceView content. | 192 // with composited SurfaceView content. |
| 174 private void attachSwipeRefreshLayoutIfNecessary() { | 193 private void attachSwipeRefreshLayoutIfNecessary() { |
| 194 cancelDetachLayoutRunnable(); |
| 175 if (mContentViewCore == null) return; | 195 if (mContentViewCore == null) return; |
| 176 if (mSwipeRefreshLayout.getParent() == null) { | 196 if (mSwipeRefreshLayout.getParent() == null) { |
| 177 mContentViewCore.getContainerView().addView(mSwipeRefreshLayout); | 197 mContentViewCore.getContainerView().addView(mSwipeRefreshLayout); |
| 178 } | 198 } |
| 179 } | 199 } |
| 180 | 200 |
| 181 private void detachSwipeRefreshLayoutIfNecessary() { | 201 private void detachSwipeRefreshLayoutIfNecessary() { |
| 202 cancelDetachLayoutRunnable(); |
| 182 if (mContentViewCore == null) return; | 203 if (mContentViewCore == null) return; |
| 183 if (mSwipeRefreshLayout.getParent() != null) { | 204 if (mSwipeRefreshLayout.getParent() != null) { |
| 184 mContentViewCore.getContainerView().removeView(mSwipeRefreshLayout); | 205 mContentViewCore.getContainerView().removeView(mSwipeRefreshLayout); |
| 185 } | 206 } |
| 186 } | 207 } |
| 187 } | 208 } |
| OLD | NEW |