Search in sources :

Example 96 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project mosby by sockeqwe.

the class NotRetainingCountriesActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.countries_list);
    ButterKnife.bind(this);
    // Setup contentView == SwipeRefreshView
    contentView.setOnRefreshListener(this);
    // Setup recycler view
    adapter = new CountriesAdapter(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);
}
Also used : CountriesAdapter(com.hannesdorfmann.mosby3.sample.mvp.CountriesAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 97 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project mosby by sockeqwe.

the class RetainingCountriesFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstance) {
    super.onViewCreated(view, savedInstance);
    unbinder = ButterKnife.bind(this, view);
    // Setup contentView == SwipeRefreshView
    contentView.setOnRefreshListener(this);
    // Setup recycler view
    adapter = new CountriesAdapter(getActivity());
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setAdapter(adapter);
}
Also used : CountriesAdapter(com.hannesdorfmann.mosby3.sample.mvp.CountriesAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 98 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project FanLayoutManager by Cleveroad.

the class FanLayoutManager method fill.

/**
     * Method create or reuse views for recyclerView.
     *
     * @param recycler recycler from the recyclerView
     */
private void fill(RecyclerView.Recycler recycler) {
    // find center view before detach or recycle all views
    View centerView = findCurrentCenterView();
    // position for center view
    int centerViewPosition = centerView == null ? 0 : getPosition(centerView);
    // left offset for center view
    int centerViewOffset = centerView == null ? (int) (getWidth() / 2F - mSettings.getViewWidthPx() / 2F) : getDecoratedLeft(centerView);
    mViewCache.clear();
    for (int i = 0, cnt = getChildCount(); i < cnt; i++) {
        View view = getChildAt(i);
        int pos = getPosition(view);
        mViewCache.put(pos, view);
    }
    for (int i = 0; i < mViewCache.size(); i++) {
        detachView(mViewCache.valueAt(i));
    }
    // main fill logic
    if (mScrollToPosition != RecyclerView.NO_POSITION) {
        // fill views if start position not in the middle of screen (restore state)
        fillRightFromCenter(mScrollToPosition, centerViewOffset, recycler);
    } else {
        // fill views if start position in the middle of the screen
        fillRightFromCenter(centerViewPosition, centerViewOffset, recycler);
    }
    for (int i = 0; i < mViewCache.size(); i++) {
        recycler.recycleView(mViewCache.valueAt(i));
    }
    // update rotations.
    updateArcViewPositions();
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 99 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project FanLayoutManager by Cleveroad.

the class FanLayoutManager method fillRightFromCenter.

/**
     * Method draw view using center view position.
     *
     * @param centerViewPosition position of center view (anchor). This view will be in center
     * @param recycler           Recycler from the recyclerView
     */
private void fillRightFromCenter(int centerViewPosition, int centerViewOffset, RecyclerView.Recycler recycler) {
    // +++++++++++ Prepare data +++++++++++
    // left limit. need to prepare with before they will be show to user.
    int leftBorder = -(mSettings.getViewWidthPx() + (mIsCollapsed ? mSettings.getViewWidthPx() : 0));
    // right limit.
    int rightBorder = getWidth() + (mSettings.getViewWidthPx() + (mIsCollapsed ? mSettings.getViewWidthPx() : 0));
    int leftViewOffset = centerViewOffset;
    int leftViewPosition = centerViewPosition;
    // margin to draw cards in bottom
    final int baseTopMargin = Math.max(0, getHeight() - mSettings.getViewHeightPx() - mSettings.getViewWidthPx() / 4);
    int overlapDistance;
    if (mIsCollapsed) {
        // overlap distance if views are collapsed
        overlapDistance = -mSettings.getViewWidthPx() / 4;
    } else {
        // overlap distance if views aren't collapsed
        overlapDistance = mSettings.getViewWidthPx() / 4;
    }
    boolean fillRight = true;
    // specs for item views
    final int widthSpec = View.MeasureSpec.makeMeasureSpec(mSettings.getViewWidthPx(), View.MeasureSpec.EXACTLY);
    final int heightSpec = View.MeasureSpec.makeMeasureSpec(mSettings.getViewHeightPx(), View.MeasureSpec.EXACTLY);
    // if have to restore state with selected item
    boolean hasPendingStateSelectedItem = mPendingSavedState != null && mPendingSavedState.isSelected && mPendingSavedState.mCenterItemPosition != RecyclerView.NO_POSITION;
    // offset for left and right views in case we have to restore pending state with selected view.
    // this is delta distance between overlap cards state and collapse (selected card) card state
    // need to use ones for all left view and right views
    float deltaOffset = mSettings.getViewWidthPx() / 2;
    // search left position for first view
    while (leftViewOffset > leftBorder) {
        if (mIsCollapsed) {
            // offset for collapsed views
            leftViewOffset -= (mSettings.getViewWidthPx() + Math.abs(overlapDistance));
        } else {
            // offset for NOT collapsed views
            leftViewOffset -= (mSettings.getViewWidthPx() - Math.abs(overlapDistance));
        }
        leftViewPosition--;
    }
    if (leftViewPosition < 0) {
        // if theoretically position for left view is less than left view.
        if (mIsCollapsed) {
            // offset for collapsed views
            leftViewOffset += (mSettings.getViewWidthPx() + Math.abs(overlapDistance)) * Math.abs(leftViewPosition);
        } else {
            // offset for NOT collapsed views
            leftViewOffset += (mSettings.getViewWidthPx() - Math.abs(overlapDistance)) * Math.abs(leftViewPosition);
        }
        leftViewPosition = 0;
    }
    // offset for left views if we restore state and have selected item
    if (hasPendingStateSelectedItem && leftViewPosition != mPendingSavedState.mCenterItemPosition) {
        leftViewOffset += -deltaOffset;
    }
    View selectedView = null;
    while (fillRight && leftViewPosition < getItemCount()) {
        // offset for current view if we restore state and have selected item
        if (hasPendingStateSelectedItem && leftViewPosition == mPendingSavedState.mCenterItemPosition && leftViewPosition != 0) {
            leftViewOffset += deltaOffset;
        }
        // get view from local cache
        View view = mViewCache.get(leftViewPosition);
        if (view == null) {
            // get view from recycler
            view = recycler.getViewForPosition(leftViewPosition);
            // optimization for view rotation
            view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            // add vew to the recyclerView
            addView(view);
            // measuring view
            measureChildWithDecorationsAndMargin(view, widthSpec, heightSpec);
            // set offsets, with and height in the recyclerView
            layoutDecorated(view, leftViewOffset, baseTopMargin, leftViewOffset + mSettings.getViewWidthPx(), baseTopMargin + mSettings.getViewHeightPx());
        } else {
            attachView(view);
            mViewCache.remove(leftViewPosition);
        }
        view.setScaleX(1F);
        view.setScaleY(1F);
        if (mIsSelected && centerViewPosition == leftViewPosition) {
            selectedView = view;
        }
        // calculate position for next view. last position + view height - overlap between views.
        leftViewOffset = leftViewOffset + mSettings.getViewWidthPx() - overlapDistance;
        // check right border. stop loop if next view is > then right border.
        fillRight = leftViewOffset < rightBorder;
        // offset for right views if we restore state and have selected item
        if (hasPendingStateSelectedItem && leftViewPosition == mPendingSavedState.mCenterItemPosition) {
            leftViewOffset += deltaOffset;
        }
        leftViewPosition++;
    }
    // this part need to scale center selected view
    if (hasPendingStateSelectedItem) {
        //            View view = findCurrentCenterView();
        if (selectedView != null) {
            selectedView.setScaleX(mAnimationHelper.getViewScaleFactor());
            selectedView.setScaleY(mAnimationHelper.getViewScaleFactor());
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 100 with Recycler

use of android.support.v7.widget.RecyclerView.Recycler in project AndroidChromium by JackyAndroid.

the class NewTabPageRecyclerView method snapScroll.

/**
     * Snaps the scroll point of the RecyclerView to prevent the user from scrolling to midway
     * through a transition and to allow peeking card behaviour.
     */
public void snapScroll(View fakeBox, int parentScrollY, int parentHeight) {
    // Snap scroll to prevent resting in the middle of the omnibox transition.
    final int searchBoxTransitionLength = getResources().getDimensionPixelSize(R.dimen.ntp_search_box_transition_length);
    int fakeBoxUpperBound = fakeBox.getTop() + fakeBox.getPaddingTop();
    if (scrollOutOfRegion(fakeBoxUpperBound - searchBoxTransitionLength, fakeBoxUpperBound)) {
        // The snap scrolling regions should never overlap.
        return;
    }
    // Snap scroll to prevent resting in the middle of the peeking card transition
    // and to allow the peeking card to peek a bit before snapping back.
    CardViewHolder peekingCardViewHolder = findFirstCard();
    if (peekingCardViewHolder != null && isFirstItemVisible()) {
        if (!mHasSpaceForPeekingCard)
            return;
        ViewHolder firstHeaderViewHolder = findFirstHeader();
        // That one does not peek.
        if (firstHeaderViewHolder == null)
            return;
        View peekingCardView = peekingCardViewHolder.itemView;
        View headerView = firstHeaderViewHolder.itemView;
        final int peekingHeight = getResources().getDimensionPixelSize(R.dimen.snippets_padding_and_peeking_card_height);
        // |A + B - C| gives the offset of the peeking card relative to the Recycler View,
        // so scrolling to this point would put the peeking card at the top of the
        // screen. Remove the |headerView| height which gets dynamically increased with
        // scrolling.
        // |A + B - C - D| will scroll us so that the peeking card is just off the bottom
        // of the screen.
        // Finally, we get |A + B - C - D + E| because the transition starts from the
        // peeking card's resting point, which is |E| from the bottom of the screen.
        int start = // A.
        peekingCardView.getTop() + // B.
        parentScrollY - // C.
        headerView.getHeight() - // D.
        parentHeight + // E.
        peekingHeight;
        // The height of the region in which the the peeking card will snap.
        int snapScrollHeight = peekingHeight + headerView.getHeight();
        scrollOutOfRegion(start, start + snapScrollHeight, start + snapScrollHeight);
    }
}
Also used : SectionHeaderViewHolder(org.chromium.chrome.browser.ntp.snippets.SectionHeaderViewHolder) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)106 View (android.view.View)100 TextView (android.widget.TextView)19 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)15 ImageView (android.widget.ImageView)13 OrientationHelper (android.support.v7.widget.OrientationHelper)12 GridLayoutManager (android.support.v7.widget.GridLayoutManager)10 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)10 Point (android.graphics.Point)7 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 Bundle (android.os.Bundle)6 ActivityManager (android.app.ActivityManager)5 AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)5 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)5 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)5 Recycler (android.support.v7.widget.RecyclerView.Recycler)5 RecyclerListener (android.support.v7.widget.RecyclerView.RecyclerListener)5 ViewGroup (android.view.ViewGroup)5