android.support.v7.widget.RecyclerView.OnScrollListener Java Examples

The following examples show how to use android.support.v7.widget.RecyclerView.OnScrollListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelectableListLayout.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the RecyclerView.
 *
 * @param adapter The adapter that provides a binding from an app-specific data set to views
 *                that are displayed within the RecyclerView.
 * @return The RecyclerView itself.
 */
public RecyclerView initializeRecyclerView(Adapter<RecyclerView.ViewHolder> adapter) {
    mAdapter = adapter;
    mAdapter.registerAdapterDataObserver(mAdapterObserver);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            setToolbarShadowVisibility();
        }
    });

    mItemAnimator = mRecyclerView.getItemAnimator();

    return mRecyclerView;
}
 
Example #2
Source File: IPauseOnScrollRecycler.java    From android-Stupid-Adapter with Apache License 2.0 6 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
	super.onScrollStateChanged(recyclerView, newState);
	switch (newState) {
	case android.widget.AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
		adapter.onResume();
		break;
	case android.widget.AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
		// adapter.pause();
		adapter.onResume();
		break;
	case android.widget.AbsListView.OnScrollListener.SCROLL_STATE_FLING:
		adapter.onPause();
		break;
	}
	if (listener2 != null)
		listener2.onScrollStateChanged(recyclerView, newState);

}
 
Example #3
Source File: RecyclerRefreshLayout.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * 获取ListView对象
 */
protected void getRefreshView() {
    int childs = getChildCount();
    if (childs > 0) {
        View childView = getChildAt(0);
        if (childView instanceof RecyclerView) {
            mRecyclerView = (RecyclerView) childView;
            // 设置滚动监听器给ListView, 使得滚动的情况下也可以自动加载
            mRecyclerView.setOnScrollListener(mScrollListener);
            mRecyclerView.setOnScrollListener(new OnScrollListener() {
            });
        }
    }
}
 
Example #4
Source File: ConversationFragment.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private void initializeResources() {
  this.recipients     = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
  this.threadId       = this.getActivity().getIntent().getLongExtra("thread_id", -1);
  this.lastSeen       = this.getActivity().getIntent().getLongExtra(ConversationActivity.LAST_SEEN_EXTRA, -1);
  this.firstLoad      = true;

  OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
  list.addOnScrollListener(scrollListener);
}
 
Example #5
Source File: SearchFragment.java    From umeng_community_android with MIT License 4 votes vote down vote up
/**
 * 添加相关用户显示</br>
 * 
 * @param users
 */
@Override
public void showRelativeUserView(List<CommUser> users) {
    mAdapter.getDataSource().clear();
    if (users == null || users.size() == 0) {
        mMoreView.setVisibility(View.GONE);
        // invalidate
        mAdapter.notifyDataSetChanged();
        return;
    }
    int itemWidth = mAdapter.computeWidth();
    LayoutParams params = mRecyclerView.getLayoutParams();
    if (users.size() > 4) {
        mMoreView.setVisibility(View.VISIBLE);
        params.width = (SearchUsersAdapter.MAX_SHOW_NUM - 1) * itemWidth;
    } else {
        params.width = users.size() * itemWidth;
        mMoreView.setVisibility(View.GONE);
    }
    mRecyclerView.setLayoutParams(params);
    mRecyclerView.invalidate();
    mAdapter.getDataSource().addAll(users);
    mAdapter.notifyDataSetChanged();
    AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
    alphaAnimation.setDuration(400);
    alphaAnimation.setFillAfter(true);
    LayoutAnimationController layoutAnimationController = new LayoutAnimationController(
            alphaAnimation, 0.4f);
    mRecyclerView.setLayoutAnimation(layoutAnimationController);

    mRecyclerView.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            int visibleItemCount = mLinearLayoutManager.getChildCount();
            int totalItemCount = mLinearLayoutManager.getItemCount();
            int pastVisiblesItems = mLinearLayoutManager.findFirstVisibleItemPosition();

            if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                ((SearchPresenter) mPresenter).loadMoreUser();
            }
        }
    });
}
 
Example #6
Source File: SuggestionsBottomSheetContent.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public SuggestionsBottomSheetContent(final ChromeActivity activity, final BottomSheet sheet,
        TabModelSelector tabModelSelector, SnackbarManager snackbarManager) {
    Profile profile = Profile.getLastUsedProfile();
    SuggestionsNavigationDelegate navigationDelegate =
            new SuggestionsNavigationDelegateImpl(activity, profile, sheet, tabModelSelector);
    mTileGroupDelegate = new TileGroupDelegateImpl(
            activity, profile, tabModelSelector, navigationDelegate, snackbarManager);
    mSuggestionsUiDelegate = createSuggestionsDelegate(
            profile, navigationDelegate, sheet, activity.getReferencePool());

    mView = LayoutInflater.from(activity).inflate(
            R.layout.suggestions_bottom_sheet_content, null);
    mRecyclerView = (SuggestionsRecyclerView) mView.findViewById(R.id.recycler_view);

    TouchEnabledDelegate touchEnabledDelegate = new TouchEnabledDelegate() {
        @Override
        public void setTouchEnabled(boolean enabled) {
            activity.getBottomSheet().setTouchEnabled(enabled);
        }
    };
    mContextMenuManager =
            new ContextMenuManager(activity, navigationDelegate, touchEnabledDelegate);
    activity.getWindowAndroid().addContextMenuCloseListener(mContextMenuManager);
    mSuggestionsUiDelegate.addDestructionObserver(new DestructionObserver() {
        @Override
        public void onDestroy() {
            activity.getWindowAndroid().removeContextMenuCloseListener(mContextMenuManager);
        }
    });

    UiConfig uiConfig = new UiConfig(mRecyclerView);

    final NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsUiDelegate,
            /* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getForProfile(profile),
            mContextMenuManager, mTileGroupDelegate);
    mRecyclerView.init(uiConfig, mContextMenuManager, adapter);

    mBottomSheetObserver = new SuggestionsSheetVisibilityChangeObserver(this, activity) {
        @Override
        public void onSheetOpened() {
            mRecyclerView.scrollToPosition(0);
            adapter.refreshSuggestions();
            mSuggestionsUiDelegate.getEventReporter().onSurfaceOpened();
            mRecyclerView.getScrollEventReporter().reset();

            if (ChromeFeatureList.isEnabled(
                        ChromeFeatureList.CONTEXTUAL_SUGGESTIONS_CAROUSEL)
                    && sheet.getActiveTab() != null) {
                updateContextualSuggestions(sheet.getActiveTab().getUrl());
            }

            super.onSheetOpened();
        }

        @Override
        public void onContentShown() {
            SuggestionsMetrics.recordSurfaceVisible();
        }

        @Override
        public void onContentHidden() {
            SuggestionsMetrics.recordSurfaceHidden();
        }

        @Override
        public void onContentStateChanged(@BottomSheet.SheetState int contentState) {
            if (contentState == BottomSheet.SHEET_STATE_HALF) {
                SuggestionsMetrics.recordSurfaceHalfVisible();
            } else if (contentState == BottomSheet.SHEET_STATE_FULL) {
                SuggestionsMetrics.recordSurfaceFullyVisible();
            }
        }
    };

    mShadowView = (FadingShadowView) mView.findViewById(R.id.shadow);
    mShadowView.init(
            ApiCompatibilityUtils.getColor(mView.getResources(), R.color.toolbar_shadow_color),
            FadingShadow.POSITION_TOP);

    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            boolean shadowVisible = mRecyclerView.canScrollVertically(-1);
            mShadowView.setVisibility(shadowVisible ? View.VISIBLE : View.GONE);
        }
    });

    final LocationBar locationBar = (LocationBar) sheet.findViewById(R.id.location_bar);
    mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        @SuppressLint("ClickableViewAccessibility")
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (locationBar != null && locationBar.isUrlBarFocused()) {
                locationBar.setUrlBarFocus(false);
            }

            // Never intercept the touch event.
            return false;
        }
    });
}
 
Example #7
Source File: HistoryManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new HistoryManager.
 * @param activity The Activity associated with the HistoryManager.
 * @param isSeparateActivity Whether the history UI will be shown in a separate activity than
 *                           the main Chrome activity.
 * @param snackbarManager The {@link SnackbarManager} used to display snackbars.
 */
@SuppressWarnings("unchecked") // mSelectableListLayout
public HistoryManager(
        Activity activity, boolean isSeparateActivity, SnackbarManager snackbarManager) {
    mActivity = activity;
    mIsSeparateActivity = isSeparateActivity;
    mSnackbarManager = snackbarManager;

    mSelectionDelegate = new SelectionDelegate<>();
    mSelectionDelegate.addObserver(this);
    mHistoryAdapter = new HistoryAdapter(mSelectionDelegate, this,
            sProviderForTests != null ? sProviderForTests : new BrowsingHistoryBridge());

    // 1. Create SelectableListLayout.
    mSelectableListLayout =
            (SelectableListLayout<HistoryItem>) LayoutInflater.from(activity).inflate(
                    R.layout.history_main, null);

    // 2. Initialize RecyclerView.
    mRecyclerView = mSelectableListLayout.initializeRecyclerView(mHistoryAdapter);

    // 3. Initialize toolbar.
    mToolbar = (HistoryManagerToolbar) mSelectableListLayout.initializeToolbar(
            R.layout.history_toolbar, mSelectionDelegate, R.string.menu_history, null,
            R.id.normal_menu_group, R.id.selection_mode_menu_group,
            R.color.default_primary_color, this);
    mToolbar.setManager(this);
    mToolbar.initializeSearchView(this, R.string.history_manager_search, R.id.search_menu_id);

    // 4. Width constrain the SelectableListLayout.
    mSelectableListLayout.configureWideDisplayStyle();

    // 5. Initialize empty view.
    mEmptyView = mSelectableListLayout.initializeEmptyView(
            VectorDrawableCompat.create(
                    mActivity.getResources(), R.drawable.history_big, mActivity.getTheme()),
            R.string.history_manager_empty, R.string.history_manager_no_results);

    // 6. Create large icon bridge.
    mLargeIconBridge = new LargeIconBridge(Profile.getLastUsedProfile().getOriginalProfile());
    ActivityManager activityManager = ((ActivityManager) ContextUtils
            .getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
    int maxSize = Math.min((activityManager.getMemoryClass() / 4) * MEGABYTES_TO_BYTES,
            FAVICON_MAX_CACHE_SIZE_BYTES);
    mLargeIconBridge.createCache(maxSize);

    // 7. Initialize the adapter to load items.
    mHistoryAdapter.initialize();

    // 8. Add scroll listener to page in more items when necessary.
    mRecyclerView.addOnScrollListener(new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (!mHistoryAdapter.canLoadMoreItems()) return;

            // Load more items if the scroll position is close to the bottom of the list.
            LinearLayoutManager layoutManager =
                    (LinearLayoutManager) recyclerView.getLayoutManager();
            if (layoutManager.findLastVisibleItemPosition()
                    > (mHistoryAdapter.getItemCount() - 25)) {
                mHistoryAdapter.loadMoreItems();
                recordUserActionWithOptionalSearch("LoadMoreOnScroll");
            }
        }});

    // 9. Listen to changes in sign in state.
    SigninManager.get(mActivity).addSignInStateObserver(this);

    recordUserAction("Show");
}
 
Example #8
Source File: XRecylerAdapter.java    From android-Stupid-Adapter with Apache License 2.0 4 votes vote down vote up
public IPauseOnScrollRecycler getOnScrollListener(OnScrollListener l) {
	return new IPauseOnScrollRecycler(this, l);
}
 
Example #9
Source File: IPauseOnScrollRecycler.java    From android-Stupid-Adapter with Apache License 2.0 4 votes vote down vote up
public IPauseOnScrollRecycler(IXPauseListener adapter,
		OnScrollListener listener) {
	this.adapter = adapter;
	this.listener2 = listener;
}
 
Example #10
Source File: JazzyRecyclerViewScrollListener.java    From JazzyListView with Apache License 2.0 4 votes vote down vote up
public void setOnScrollListener(OnScrollListener l) {
    // hijack the scroll listener setter and have this list also notify the additional listener
    mAdditionalOnScrollListener = l;
}
 
Example #11
Source File: RecyclerRefreshLayout.java    From umeng_community_android with MIT License 2 votes vote down vote up
/**
 * 使外部可以监听到listview的滚动
 * 
 * @param listener
 */
public void addOnScrollListener(OnScrollListener listener) {
    mListViewOnScrollListener = listener;
}