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; |
11 import android.content.Context; | 11 import android.content.Context; |
12 import android.content.res.Resources; | 12 import android.content.res.Resources; |
13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
14 import android.support.v4.view.ViewCompat; | 14 import android.support.v4.view.ViewCompat; |
15 import android.support.v4.view.animation.FastOutLinearInInterpolator; | 15 import android.support.v4.view.animation.FastOutLinearInInterpolator; |
16 import android.support.v7.view.ContextThemeWrapper; | 16 import android.support.v7.view.ContextThemeWrapper; |
17 import android.support.v7.widget.LinearLayoutManager; | 17 import android.support.v7.widget.LinearLayoutManager; |
18 import android.support.v7.widget.RecyclerView; | 18 import android.support.v7.widget.RecyclerView; |
19 import android.support.v7.widget.helper.ItemTouchHelper; | 19 import android.support.v7.widget.helper.ItemTouchHelper; |
20 import android.util.AttributeSet; | |
20 import android.view.GestureDetector; | 21 import android.view.GestureDetector; |
21 import android.view.MotionEvent; | 22 import android.view.MotionEvent; |
22 import android.view.View; | 23 import android.view.View; |
23 import android.view.ViewGroup; | 24 import android.view.ViewGroup; |
24 import android.view.animation.Interpolator; | 25 import android.view.animation.Interpolator; |
25 import android.view.inputmethod.EditorInfo; | 26 import android.view.inputmethod.EditorInfo; |
26 import android.view.inputmethod.InputConnection; | 27 import android.view.inputmethod.InputConnection; |
27 | 28 |
28 import org.chromium.base.ApiCompatibilityUtils; | 29 import org.chromium.base.ApiCompatibilityUtils; |
29 import org.chromium.base.Callback; | 30 import org.chromium.base.Callback; |
(...skipping 17 matching lines...) Expand all Loading... | |
47 public class SuggestionsRecyclerView extends RecyclerView implements TouchDisabl eableView { | 48 public class SuggestionsRecyclerView extends RecyclerView implements TouchDisabl eableView { |
48 private static final Interpolator DISMISS_INTERPOLATOR = new FastOutLinearIn Interpolator(); | 49 private static final Interpolator DISMISS_INTERPOLATOR = new FastOutLinearIn Interpolator(); |
49 private static final int DISMISS_ANIMATION_TIME_MS = 300; | 50 private static final int DISMISS_ANIMATION_TIME_MS = 300; |
50 /** | 51 /** |
51 * A single instance of {@link ResetForDismissCallback} that can be reused a s it has no | 52 * A single instance of {@link ResetForDismissCallback} that can be reused a s it has no |
52 * state. | 53 * state. |
53 */ | 54 */ |
54 public static final NewTabPageViewHolder.PartialBindCallback RESET_FOR_DISMI SS_CALLBACK = | 55 public static final NewTabPageViewHolder.PartialBindCallback RESET_FOR_DISMI SS_CALLBACK = |
55 new ResetForDismissCallback(); | 56 new ResetForDismissCallback(); |
56 | 57 |
57 private final GestureDetector mGestureDetector; | 58 private GestureDetector mGestureDetector; |
58 private final LinearLayoutManager mLayoutManager; | 59 private LinearLayoutManager mLayoutManager; |
59 | 60 |
60 /** | 61 /** |
61 * Total height of the items being dismissed. Tracked to allow the bottom s pace to compensate | 62 * Total height of the items being dismissed. Tracked to allow the bottom s pace to compensate |
62 * for their removal animation and avoid moving the scroll position. | 63 * for their removal animation and avoid moving the scroll position. |
63 */ | 64 */ |
64 private int mCompensationHeight; | 65 private int mCompensationHeight; |
65 | 66 |
66 /** | 67 /** |
67 * Height compensation value for each item being dismissed. Since dismissals sometimes include | 68 * Height compensation value for each item being dismissed. Since dismissals sometimes include |
68 * sibling elements, and these don't get the standard treatment, we track th e total height | 69 * sibling elements, and these don't get the standard treatment, we track th e total height |
69 * associated with the element the user interacted with. | 70 * associated with the element the user interacted with. |
70 */ | 71 */ |
71 private final Map<ViewHolder, Integer> mCompensationHeightMap = new HashMap< >(); | 72 private final Map<ViewHolder, Integer> mCompensationHeightMap = new HashMap< >(); |
72 | 73 |
73 /** Whether the RecyclerView and its children should react to touch events. */ | 74 /** Whether the RecyclerView and its children should react to touch events. */ |
74 private boolean mTouchEnabled = true; | 75 private boolean mTouchEnabled = true; |
75 | 76 |
77 public SuggestionsRecyclerView(Context context, AttributeSet attrs) { | |
gone
2017/03/28 20:21:07
Put this under the other one, make the other one c
Theresa
2017/03/28 23:10:04
Done.
| |
78 super(new ContextThemeWrapper(context, R.style.NewTabPageRecyclerView), attrs); | |
79 init(); | |
80 } | |
81 | |
76 public SuggestionsRecyclerView(Context context) { | 82 public SuggestionsRecyclerView(Context context) { |
77 super(new ContextThemeWrapper(context, R.style.NewTabPageRecyclerView)); | 83 super(new ContextThemeWrapper(context, R.style.NewTabPageRecyclerView)); |
84 init(); | |
85 } | |
78 | 86 |
87 private void init() { | |
79 Resources res = getContext().getResources(); | 88 Resources res = getContext().getResources(); |
80 setBackgroundColor(ApiCompatibilityUtils.getColor(res, R.color.ntp_bg)); | 89 setBackgroundColor(ApiCompatibilityUtils.getColor(res, R.color.ntp_bg)); |
81 setLayoutParams(new LayoutParams( | 90 setLayoutParams(new LayoutParams( |
82 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATC H_PARENT)); | 91 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATC H_PARENT)); |
83 setFocusable(true); | 92 setFocusable(true); |
84 setFocusableInTouchMode(true); | 93 setFocusableInTouchMode(true); |
85 setContentDescription(res.getString(R.string.accessibility_new_tab_page) ); | 94 setContentDescription(res.getString(R.string.accessibility_new_tab_page) ); |
86 | 95 |
87 mGestureDetector = | 96 mGestureDetector = |
88 new GestureDetector(getContext(), new GestureDetector.SimpleOnGe stureListener() { | 97 new GestureDetector(getContext(), new GestureDetector.SimpleOnGe stureListener() { |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 * Callback to reset a card's properties affected by swipe to dismiss. | 365 * Callback to reset a card's properties affected by swipe to dismiss. |
357 */ | 366 */ |
358 private static class ResetForDismissCallback extends NewTabPageViewHolder.Pa rtialBindCallback { | 367 private static class ResetForDismissCallback extends NewTabPageViewHolder.Pa rtialBindCallback { |
359 @Override | 368 @Override |
360 public void onResult(NewTabPageViewHolder holder) { | 369 public void onResult(NewTabPageViewHolder holder) { |
361 assert holder instanceof CardViewHolder; | 370 assert holder instanceof CardViewHolder; |
362 ((CardViewHolder) holder).getRecyclerView().updateViewStateForDismis s(0, holder); | 371 ((CardViewHolder) holder).getRecyclerView().updateViewStateForDismis s(0, holder); |
363 } | 372 } |
364 } | 373 } |
365 } | 374 } |
OLD | NEW |