OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.enhancedbookmarks; |
| 6 |
| 7 import android.animation.ObjectAnimator; |
| 8 import android.content.Context; |
| 9 import android.support.v7.widget.RecyclerView; |
| 10 import android.util.AttributeSet; |
| 11 import android.view.View; |
| 12 import android.view.ViewTreeObserver.OnScrollChangedListener; |
| 13 import android.widget.RelativeLayout; |
| 14 |
| 15 import com.google.android.apps.chrome.R; |
| 16 |
| 17 import org.chromium.chrome.browser.widget.FadingShadow; |
| 18 import org.chromium.chrome.browser.widget.FadingShadowView; |
| 19 import org.chromium.components.bookmarks.BookmarkId; |
| 20 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
| 21 |
| 22 import java.util.List; |
| 23 |
| 24 /** |
| 25 * A ViewGroup that holds an {@link EnhancedBookmarkActionBar}, a {@link FadingS
hadowView}, a |
| 26 * {@link EnhancedBookmarkRecyclerView} and a {@link EnhancedBookmarkLoadingView
}. On large |
| 27 * tablet, it can be replaced by a {@link EnhancedBookmarkSearchView} with the s
ame size, located at |
| 28 * the right of the window. |
| 29 */ |
| 30 public class EnhancedBookmarkContentView extends RelativeLayout implements |
| 31 EnhancedBookmarkUIObserver { |
| 32 private static final int SHADOW_ANIMATION_DURATION_MS = 500; |
| 33 private EnhancedBookmarkDelegate mDelegate; |
| 34 private EnhancedBookmarkRecyclerView mItemsContainer; |
| 35 private EnhancedBookmarkActionBar mActionBar; |
| 36 private FadingShadowView mShadow; |
| 37 private EnhancedBookmarkLoadingView mLoadingView; |
| 38 private ObjectAnimator mShadowInAnim; |
| 39 |
| 40 private OnScrollChangedListener mScrollListener = new OnScrollChangedListene
r() { |
| 41 @Override |
| 42 public void onScrollChanged() { |
| 43 if (mShadow == null || mDelegate == null || mDelegate.isSelectionEna
bled() |
| 44 || mDelegate.isListModeEnabled()) return; |
| 45 int firstPosition = mItemsContainer.getLayoutManager() |
| 46 .findFirstCompletelyVisibleItemPosition(); |
| 47 if (firstPosition == 0 || firstPosition == RecyclerView.NO_POSITION)
{ |
| 48 if (mShadowInAnim.isStarted()) mShadowInAnim.cancel(); |
| 49 mShadow.setStrength(0); |
| 50 } else { |
| 51 if (!mShadowInAnim.isStarted() && mShadow.getStrength() < 1.0f)
{ |
| 52 mShadowInAnim.start(); |
| 53 } |
| 54 } |
| 55 } |
| 56 }; |
| 57 |
| 58 /** |
| 59 * Creates an instance of {@link EnhancedBookmarkContentView}. This construc
tor should be used |
| 60 * by the framework when inflating from XML. |
| 61 */ |
| 62 public EnhancedBookmarkContentView(Context context, AttributeSet attrs) { |
| 63 super(context, attrs); |
| 64 } |
| 65 |
| 66 @Override |
| 67 protected void onFinishInflate() { |
| 68 super.onFinishInflate(); |
| 69 mItemsContainer = (EnhancedBookmarkRecyclerView) findViewById( |
| 70 R.id.eb_items_container); |
| 71 mItemsContainer.setEmptyView(findViewById(R.id.eb_empty_view)); |
| 72 mItemsContainer.getViewTreeObserver().addOnScrollChangedListener(mScroll
Listener); |
| 73 mActionBar = (EnhancedBookmarkActionBar) findViewById(R.id.eb_action_bar
); |
| 74 mLoadingView = (EnhancedBookmarkLoadingView) findViewById(R.id.eb_initia
l_loading_view); |
| 75 mShadow = (FadingShadowView) findViewById(R.id.shadow); |
| 76 mShadow.init(getResources().getColor(R.color.enhanced_bookmark_app_bar_s
hadow_color), |
| 77 FadingShadow.POSITION_TOP); |
| 78 mShadowInAnim = ObjectAnimator.ofFloat(mShadow, "Strength", 1.0f) |
| 79 .setDuration(SHADOW_ANIMATION_DURATION_MS); |
| 80 mShadowInAnim.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE); |
| 81 } |
| 82 |
| 83 /** |
| 84 * Handles the event when user clicks back button and the UI is in selection
mode. |
| 85 * @return True if there are selected bookmarks, and the back button is proc
essed by this |
| 86 * method. False otherwise. |
| 87 */ |
| 88 public boolean onBackPressed() { |
| 89 if (mDelegate != null && mDelegate.isSelectionEnabled()) { |
| 90 mDelegate.clearSelection(); |
| 91 return true; |
| 92 } |
| 93 return false; |
| 94 } |
| 95 |
| 96 void showLoadingUi() { |
| 97 mActionBar.showLoadingUi(); |
| 98 mLoadingView.showLoadingUI(); |
| 99 } |
| 100 |
| 101 // EnhancedBookmarkDelegate implementations. |
| 102 |
| 103 @Override |
| 104 public void onEnhancedBookmarkDelegateInitialized(EnhancedBookmarkDelegate d
elegate) { |
| 105 mDelegate = delegate; |
| 106 mDelegate.addUIObserver(this); |
| 107 mItemsContainer.onEnhancedBookmarkDelegateInitialized(mDelegate); |
| 108 mActionBar.onEnhancedBookmarkDelegateInitialized(mDelegate); |
| 109 } |
| 110 |
| 111 @Override |
| 112 public void onAllBookmarksStateSet() { |
| 113 mLoadingView.hideLoadingUI(); |
| 114 } |
| 115 |
| 116 @Override |
| 117 public void onFolderStateSet(BookmarkId folder) { |
| 118 mLoadingView.hideLoadingUI(); |
| 119 } |
| 120 |
| 121 @Override |
| 122 public void onFilterStateSet(String filter) { |
| 123 mLoadingView.hideLoadingUI(); |
| 124 } |
| 125 |
| 126 @Override |
| 127 public void onSelectionStateChange(List<BookmarkId> selectedBookmarks) { |
| 128 if (!selectedBookmarks.isEmpty()) mShadow.setStrength(1.0f); |
| 129 else mScrollListener.onScrollChanged(); |
| 130 } |
| 131 |
| 132 @Override |
| 133 public void onDestroy() { |
| 134 mDelegate.removeUIObserver(this); |
| 135 } |
| 136 |
| 137 @Override |
| 138 public void onListModeChange(boolean isListModeEnabled) { |
| 139 if (EnhancedBookmarkRecyclerView.isLargeTablet(getContext())) { |
| 140 if (isListModeEnabled) mShadow.setVisibility(View.GONE); |
| 141 else mShadow.setVisibility(View.VISIBLE); |
| 142 } |
| 143 mShadow.setStrength(mDelegate.isListModeEnabled() ? 1.0f : 0.0f); |
| 144 } |
| 145 } |
OLD | NEW |