Search in sources :

Example 26 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project UltimateAndroid by cymcsg.

the class StaticGridLayoutManager method onLayoutChildren.

/*
     * This method is your initial call from the framework. You will receive it when you
     * need to start laying out the initial set of views. This method will not be called
     * repeatedly, so don't rely on it to continually process changes during user
     * interaction.
     *
     * This method will be called when the data set in the adapter changes, so it can be
     * used to update a layout based on a new item count.
     */
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
    //We have nothing to show for an empty data set but clear any existing views
    if (getItemCount() == 0) {
        detachAndScrapAttachedViews(recycler);
        return;
    }
    //Make the grid as square as possible, column count is root of the data set
    mTotalColumnCount = (int) Math.round(Math.sqrt(getItemCount()));
    if (getChildCount() == 0) {
        //First or empty layout
        //Scrap measure one child
        View scrap = recycler.getViewForPosition(0);
        addView(scrap);
        measureChildWithMargins(scrap, 0, 0);
        /*
             * We make some assumptions in this code based on every child
             * view being the same size (i.e. a uniform grid). This allows
             * us to compute the following values up front because they
             * won't change.
             */
        mDecoratedChildWidth = getDecoratedMeasuredWidth(scrap);
        mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);
        detachAndScrapView(scrap, recycler);
    }
    //Always update the visible row/column counts
    updateWindowSizing();
    int childLeft;
    int childTop;
    if (getChildCount() == 0) {
        //First or empty layout
        /*
             * Reset the visible and scroll positions
             */
        mFirstVisiblePosition = 0;
        childLeft = childTop = 0;
    } else if (getVisibleChildCount() > getItemCount()) {
        //Data set is too small to scroll fully, just reset position
        mFirstVisiblePosition = 0;
        childLeft = childTop = 0;
    } else {
        //Adapter data set changes
        /*
             * Keep the existing initial position, and save off
             * the current scrolled offset.
             */
        final View topChild = getChildAt(0);
        if (mForceClearOffsets) {
            childLeft = childTop = 0;
            mForceClearOffsets = false;
        } else {
            childLeft = getDecoratedLeft(topChild);
            childTop = getDecoratedTop(topChild);
        }
        /*
             * Adjust the visible position if out of bounds in the
             * new layout. This occurs when the new item count in an adapter
             * is much smaller than it was before, and you are scrolled to
             * a location where no items would exist.
             */
        int lastVisiblePosition = positionOfIndex(getVisibleChildCount() - 1);
        if (lastVisiblePosition >= getItemCount()) {
            lastVisiblePosition = (getItemCount() - 1);
            int lastColumn = mVisibleColumnCount - 1;
            int lastRow = mVisibleRowCount - 1;
            //Adjust to align the last position in the bottom-right
            mFirstVisiblePosition = Math.max(lastVisiblePosition - lastColumn - (lastRow * getTotalColumnCount()), 0);
            childLeft = getHorizontalSpace() - (mDecoratedChildWidth * mVisibleColumnCount);
            childTop = getVerticalSpace() - (mDecoratedChildHeight * mVisibleRowCount);
            // This happens on data sets too small to scroll in a direction.
            if (getFirstVisibleRow() == 0) {
                childTop = Math.min(childTop, 0);
            }
            if (getFirstVisibleColumn() == 0) {
                childLeft = Math.min(childLeft, 0);
            }
        }
    }
    //Clear all attached views into the recycle bin
    detachAndScrapAttachedViews(recycler);
    //Fill the grid for the initial layout of views
    fillGrid(DIRECTION_NONE, childLeft, childTop, recycler);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 27 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project UltimateAndroid by cymcsg.

the class ScaleInOutItemAnimator method animateAddImpl.

protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    ViewCompat.animate(view).cancel();
    ViewCompat.animate(view).scaleX(mOriginalScaleX).scaleY(mOriginalScaleY).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationCancel(View view) {
            ViewCompat.setScaleX(view, mOriginalScaleX);
            ViewCompat.setScaleY(view, mOriginalScaleY);
        }

        @Override
        public void onAnimationEnd(View view) {
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
    mAddAnimations.add(holder);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 28 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project UltimateAndroid by cymcsg.

the class SlideInOutBottomItemAnimator method animateRemoveImpl.

protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    ViewCompat.animate(view).cancel();
    ViewCompat.animate(view).setDuration(getRemoveDuration()).translationY(+mDeltaY).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationEnd(View view) {
            ViewCompat.setTranslationY(view, +mDeltaY);
            dispatchRemoveFinished(holder);
            mRemoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
    mRemoveAnimations.add(holder);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 29 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project UltimateAndroid by cymcsg.

the class SlideInOutBottomItemAnimator method animateAddImpl.

protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    ViewCompat.animate(view).cancel();
    ViewCompat.animate(view).translationY(0).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationCancel(View view) {
            ViewCompat.setTranslationY(view, 0);
        }

        @Override
        public void onAnimationEnd(View view) {
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
    mAddAnimations.add(holder);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 30 with START

use of android.support.v7.widget.helper.ItemTouchHelper.START in project UltimateAndroid by cymcsg.

the class SlideInOutRightItemAnimator method animateAddImpl.

protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    ViewCompat.animate(view).cancel();
    ViewCompat.animate(view).translationX(0).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationCancel(View view) {
            ViewCompat.setTranslationX(view, 0);
        }

        @Override
        public void onAnimationEnd(View view) {
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
    mAddAnimations.add(holder);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)367 RecyclerView (android.support.v7.widget.RecyclerView)271 TextView (android.widget.TextView)175 Intent (android.content.Intent)109 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)84 Toolbar (android.support.v7.widget.Toolbar)77 TextWatcher (android.text.TextWatcher)77 Editable (android.text.Editable)76 ImageView (android.widget.ImageView)76 ArrayList (java.util.ArrayList)68 Bundle (android.os.Bundle)48 DialogInterface (android.content.DialogInterface)47 AlertDialog (android.support.v7.app.AlertDialog)47 AdapterView (android.widget.AdapterView)46 EditText (android.widget.EditText)42 SuppressLint (android.annotation.SuppressLint)39 Button (android.widget.Button)39 ActionBar (android.support.v7.app.ActionBar)34 List (java.util.List)34 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)33