| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
| 6 | 6 |
| 7 import android.animation.Animator; | 7 import android.animation.Animator; |
| 8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
| 9 import android.animation.AnimatorSet; | 9 import android.animation.AnimatorSet; |
| 10 import android.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 import android.view.View; | 24 import android.view.View; |
| 25 import android.view.ViewGroup; | 25 import android.view.ViewGroup; |
| 26 import android.view.animation.Interpolator; | 26 import android.view.animation.Interpolator; |
| 27 import android.view.inputmethod.EditorInfo; | 27 import android.view.inputmethod.EditorInfo; |
| 28 import android.view.inputmethod.InputConnection; | 28 import android.view.inputmethod.InputConnection; |
| 29 | 29 |
| 30 import org.chromium.base.ApiCompatibilityUtils; | 30 import org.chromium.base.ApiCompatibilityUtils; |
| 31 import org.chromium.base.Callback; | 31 import org.chromium.base.Callback; |
| 32 import org.chromium.chrome.R; | 32 import org.chromium.chrome.R; |
| 33 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 33 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
| 34 import org.chromium.chrome.browser.ntp.ContextMenuManager.TouchDisableableView; | |
| 35 import org.chromium.chrome.browser.ntp.cards.CardViewHolder; | 34 import org.chromium.chrome.browser.ntp.cards.CardViewHolder; |
| 36 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; | 35 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
| 37 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; | 36 import org.chromium.chrome.browser.ntp.cards.NewTabPageViewHolder; |
| 38 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; | 37 import org.chromium.chrome.browser.widget.displaystyle.UiConfig; |
| 39 | 38 |
| 40 import java.util.ArrayList; | 39 import java.util.ArrayList; |
| 41 import java.util.Collections; | 40 import java.util.Collections; |
| 42 import java.util.HashMap; | 41 import java.util.HashMap; |
| 43 import java.util.List; | 42 import java.util.List; |
| 44 import java.util.Map; | 43 import java.util.Map; |
| 45 import java.util.Set; | 44 import java.util.Set; |
| 46 | 45 |
| 47 /** | 46 /** |
| 48 * Simple wrapper on top of a RecyclerView that will acquire focus when tapped.
Ensures the | 47 * Simple wrapper on top of a RecyclerView that will acquire focus when tapped.
Ensures the |
| 49 * New Tab page receives focus when clicked. | 48 * New Tab page receives focus when clicked. |
| 50 */ | 49 */ |
| 51 public class SuggestionsRecyclerView extends RecyclerView implements TouchDisabl
eableView { | 50 public class SuggestionsRecyclerView extends RecyclerView { |
| 52 private static final Interpolator DISMISS_INTERPOLATOR = new FastOutLinearIn
Interpolator(); | 51 private static final Interpolator DISMISS_INTERPOLATOR = new FastOutLinearIn
Interpolator(); |
| 53 private static final int DISMISS_ANIMATION_TIME_MS = 300; | 52 private static final int DISMISS_ANIMATION_TIME_MS = 300; |
| 54 /** | 53 /** |
| 55 * A single instance of {@link ResetForDismissCallback} that can be reused a
s it has no | 54 * A single instance of {@link ResetForDismissCallback} that can be reused a
s it has no |
| 56 * state. | 55 * state. |
| 57 */ | 56 */ |
| 58 public static final NewTabPageViewHolder.PartialBindCallback RESET_FOR_DISMI
SS_CALLBACK = | 57 public static final NewTabPageViewHolder.PartialBindCallback RESET_FOR_DISMI
SS_CALLBACK = |
| 59 new ResetForDismissCallback(); | 58 new ResetForDismissCallback(); |
| 60 | 59 |
| 61 private final GestureDetector mGestureDetector; | 60 private final GestureDetector mGestureDetector; |
| 62 private final LinearLayoutManager mLayoutManager; | 61 private final LinearLayoutManager mLayoutManager; |
| 63 | 62 |
| 64 /** | 63 /** |
| 65 * Total height of the items being dismissed. Tracked to allow the bottom s
pace to compensate | 64 * Total height of the items being dismissed. Tracked to allow the bottom s
pace to compensate |
| 66 * for their removal animation and avoid moving the scroll position. | 65 * for their removal animation and avoid moving the scroll position. |
| 67 */ | 66 */ |
| 68 private int mCompensationHeight; | 67 private int mCompensationHeight; |
| 69 | 68 |
| 70 /** | 69 /** |
| 71 * Height compensation value for each item being dismissed. Since dismissals
sometimes include | 70 * Height compensation value for each item being dismissed. Since dismissals
sometimes include |
| 72 * sibling elements, and these don't get the standard treatment, we track th
e total height | 71 * sibling elements, and these don't get the standard treatment, we track th
e total height |
| 73 * associated with the element the user interacted with. | 72 * associated with the element the user interacted with. |
| 74 */ | 73 */ |
| 75 private final Map<ViewHolder, Integer> mCompensationHeightMap = new HashMap<
>(); | 74 private final Map<ViewHolder, Integer> mCompensationHeightMap = new HashMap<
>(); |
| 76 | 75 |
| 77 /** Whether the RecyclerView and its children should react to touch events.
*/ | 76 /** |
| 77 * Whether the {@link SuggestionsRecyclerView} and its children should react
to touch events. |
| 78 */ |
| 78 private boolean mTouchEnabled = true; | 79 private boolean mTouchEnabled = true; |
| 79 | 80 |
| 80 /** The ui config for this view. */ | 81 /** The ui config for this view. */ |
| 81 private UiConfig mUiConfig; | 82 private UiConfig mUiConfig; |
| 82 | 83 |
| 83 /** The context menu manager for this view. */ | 84 /** The context menu manager for this view. */ |
| 84 private ContextMenuManager mContextMenuManager; | 85 private ContextMenuManager mContextMenuManager; |
| 85 | 86 |
| 86 public SuggestionsRecyclerView(Context context) { | 87 public SuggestionsRecyclerView(Context context) { |
| 87 this(context, null); | 88 this(context, null); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 112 setHasFixedSize(true); | 113 setHasFixedSize(true); |
| 113 | 114 |
| 114 ItemTouchHelper helper = new ItemTouchHelper(new ItemTouchCallbacks()); | 115 ItemTouchHelper helper = new ItemTouchHelper(new ItemTouchCallbacks()); |
| 115 helper.attachToRecyclerView(this); | 116 helper.attachToRecyclerView(this); |
| 116 } | 117 } |
| 117 | 118 |
| 118 public boolean isFirstItemVisible() { | 119 public boolean isFirstItemVisible() { |
| 119 return mLayoutManager.findFirstVisibleItemPosition() == 0; | 120 return mLayoutManager.findFirstVisibleItemPosition() == 0; |
| 120 } | 121 } |
| 121 | 122 |
| 123 /** |
| 124 * Sets whether the {@link SuggestionsRecyclerView} and its children should
react to touch |
| 125 * events. |
| 126 */ |
| 127 public void setTouchEnabled(boolean enabled) { |
| 128 mTouchEnabled = enabled; |
| 129 } |
| 130 |
| 122 @Override | 131 @Override |
| 123 public boolean onInterceptTouchEvent(MotionEvent ev) { | 132 public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 124 mGestureDetector.onTouchEvent(ev); | 133 mGestureDetector.onTouchEvent(ev); |
| 125 if (!mTouchEnabled) return true; | 134 if (!mTouchEnabled) return true; |
| 126 return super.onInterceptTouchEvent(ev); | 135 return super.onInterceptTouchEvent(ev); |
| 127 } | 136 } |
| 128 | 137 |
| 129 @Override | 138 @Override |
| 130 public void setTouchEnabled(boolean enabled) { | |
| 131 mTouchEnabled = enabled; | |
| 132 } | |
| 133 | |
| 134 @Override | |
| 135 public boolean onTouchEvent(MotionEvent ev) { | 139 public boolean onTouchEvent(MotionEvent ev) { |
| 136 if (!mTouchEnabled) return false; | 140 if (!mTouchEnabled) return false; |
| 137 | 141 |
| 138 // Action down would already have been handled in onInterceptTouchEvent | 142 // Action down would already have been handled in onInterceptTouchEvent |
| 139 if (ev.getActionMasked() != MotionEvent.ACTION_DOWN) { | 143 if (ev.getActionMasked() != MotionEvent.ACTION_DOWN) { |
| 140 mGestureDetector.onTouchEvent(ev); | 144 mGestureDetector.onTouchEvent(ev); |
| 141 } | 145 } |
| 142 return super.onTouchEvent(ev); | 146 return super.onTouchEvent(ev); |
| 143 } | 147 } |
| 144 | 148 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 * Callback to reset a card's properties affected by swipe to dismiss. | 396 * Callback to reset a card's properties affected by swipe to dismiss. |
| 393 */ | 397 */ |
| 394 private static class ResetForDismissCallback extends NewTabPageViewHolder.Pa
rtialBindCallback { | 398 private static class ResetForDismissCallback extends NewTabPageViewHolder.Pa
rtialBindCallback { |
| 395 @Override | 399 @Override |
| 396 public void onResult(NewTabPageViewHolder holder) { | 400 public void onResult(NewTabPageViewHolder holder) { |
| 397 assert holder instanceof CardViewHolder; | 401 assert holder instanceof CardViewHolder; |
| 398 ((CardViewHolder) holder).getRecyclerView().updateViewStateForDismis
s(0, holder); | 402 ((CardViewHolder) holder).getRecyclerView().updateViewStateForDismis
s(0, holder); |
| 399 } | 403 } |
| 400 } | 404 } |
| 401 } | 405 } |
| OLD | NEW |