Java Code Examples for android.support.v4.view.ViewCompat#postOnAnimation()

The following examples show how to use android.support.v4.view.ViewCompat#postOnAnimation() . 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: GoogleMapsBottomSheetBehavior.java    From Google-Maps-BottomSheet with The Unlicense 6 votes vote down vote up
private void startSettlingAnimation(View child, int state) {
    int top;
    if (state == STATE_COLLAPSED) {
        top = mMaxOffset;
    } else if (state == STATE_EXPANDED) {
        top = mMinOffset;
    } else if (mHideable && state == STATE_HIDDEN) {
        top = mParentHeight;
    } else if (state == STATE_ANCHORED) {
        top = mAnchorOffset;
    } else {
        throw new IllegalArgumentException("Illegal state argument: " + state);
    }
    if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
        setStateInternal(STATE_SETTLING);
        ViewCompat.postOnAnimation(child, new SettleRunnable(child, state));
    } else {
        setStateInternal(state);
    }
}
 
Example 2
Source File: SlidingPaneLayout.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void dimChildView(View v, float mag, int fadeColor) {
    final LayoutParams lp = (LayoutParams) v.getLayoutParams();

    if (mag > 0 && fadeColor != 0) {
        final int baseAlpha = (fadeColor & 0xff000000) >>> 24;
        int imag = (int) (baseAlpha * mag);
        int color = imag << 24 | (fadeColor & 0xffffff);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) {
            ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        final DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
 
Example 3
Source File: OverScrollViewPager.java    From material-intro-screen with MIT License 6 votes vote down vote up
@Override
public void run() {
    if (startTime == -1) {
        startTime = System.currentTimeMillis();
    } else {
        long normalizedTime = (1000 * (System.currentTimeMillis() - startTime)) / duration;
        normalizedTime = Math.max(Math.min(normalizedTime, 1000), 0);

        final int deltaY = Math.round((scrollFromPosition - scrollToPosition)
                * interpolator.getInterpolation(normalizedTime / 1000f));
        currentPosition = scrollFromPosition - deltaY;

        moveOverScrollView(currentPosition);
    }

    if (scrollToPosition != currentPosition) {
        ViewCompat.postOnAnimation(OverScrollViewPager.this, this);
    }
}
 
Example 4
Source File: BottomSheetBehaviorV2.java    From paper-launcher with MIT License 5 votes vote down vote up
@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, V child, View target) {
    if (child.getTop() == mMinOffset) {
        setStateInternal(STATE_EXPANDED);
        return;
    }
    if (target != mNestedScrollingChildRef.get() || !mNestedScrolled) {
        return;
    }
    int top;
    int targetState;
    if (mLastNestedScrollDy > 0) {
        top = mMinOffset;
        targetState = STATE_EXPANDED;
    } else if (mHideable && shouldHide(child, getYVelocity())) {
        top = mParentHeight;
        targetState = STATE_HIDDEN;
    } else if (mLastNestedScrollDy == 0) {
        int currentTop = child.getTop();
        if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        } else {
            top = mMaxOffset;
            targetState = STATE_COLLAPSED;
        }
    } else {
        top = mMaxOffset;
        targetState = STATE_COLLAPSED;
    }
    if (mViewDragHelper.smoothSlideViewTo(child, child.getLeft(), top)) {
        setStateInternal(STATE_SETTLING);
        ViewCompat.postOnAnimation(child, new SettleRunnable(child, targetState));
    } else {
        setStateInternal(targetState);
    }
    mNestedScrolled = false;
}
 
Example 5
Source File: WatchMessagePictureActivity.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
protected void updateCurrentImageView(final int position) {
    View currentLayout = imageViewPager.findViewWithTag(position);
    if (currentLayout == null) {
        ViewCompat.postOnAnimation(imageViewPager, new Runnable() {

            @Override
            public void run() {
                updateCurrentImageView(position);
            }
        });
        return;
    }
    image = (BaseZoomableImageView) currentLayout.findViewById(R.id.watch_image_view);
    requestOriImage(imageMsgList.get(position));
}
 
Example 6
Source File: ClassifyView.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    if (mSelected != null && scrollIfNecessary()) {
        inScrollMode = true;
        if (mSelected != null) { //it might be lost during scrolling
            moveIfNecessary(mSelected);
        }
        removeCallbacks(mScrollRunnable);
        ViewCompat.postOnAnimation(ClassifyView.this, this);
    } else {
        inScrollMode = false;
    }
}
 
Example 7
Source File: BottomSheetBehaviorGoogleMapsLike.java    From Nibo with MIT License 5 votes vote down vote up
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
    int top;
    @State int targetState;
    if (yvel < 0) { // Moving up
        top = mMinOffset;
        targetState = STATE_EXPANDED;
    } else if (mHideable && shouldHide(releasedChild, yvel)) {
        top = mParentHeight;
        targetState = STATE_HIDDEN;
    } else if (yvel == 0.f) {
        int currentTop = releasedChild.getTop();
        if (Math.abs(currentTop - mMinOffset) < Math.abs(currentTop - mMaxOffset)) {
            top = mMinOffset;
            targetState = STATE_EXPANDED;
        } else {
            top = mMaxOffset;
            targetState = STATE_COLLAPSED;
        }
    } else {
        top = mMaxOffset;
        targetState = STATE_COLLAPSED;
    }
    if (mViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top)) {
        setStateInternal(STATE_SETTLING);
        ViewCompat.postOnAnimation(releasedChild,
                new SettleRunnable(releasedChild, targetState));
    } else {
        setStateInternal(targetState);
    }
}
 
Example 8
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
void start(int initialVelocity) {
    if (!mScroller.isFinished()) {
        mScroller.abortAnimation();
    }
    int initialY = initialVelocity < 0 ? Integer.MAX_VALUE : 0;
    mLastFlingY = initialY;
    mScroller.fling(0, initialY, 0, initialVelocity, 0, Integer.MAX_VALUE, 0,
            Integer.MAX_VALUE);
    mTouchMode = TOUCH_MODE_FLING;
    ViewCompat.postOnAnimation(ZrcAbsListView.this, this);
}
 
Example 9
Source File: ItemTouchHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if (mSelected != null && scrollIfNecessary()) {
        if (mSelected != null) { //it might be lost during scrolling
            moveIfNecessary(mSelected);
        }
        mRecyclerView.removeCallbacks(mScrollRunnable);
        ViewCompat.postOnAnimation(mRecyclerView, this);
    }
}
 
Example 10
Source File: HeaderFlingRunnable.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
public void startFling(int dy, float velocityX, float velocityY) {
    mIsScroollClose = true;
    mOverScroller.abortAnimation();
    mOverScroller.startScroll(0, (int) mChild.getTranslationY(), 0, dy, 100);
    ViewCompat.postOnAnimation(mChild, this);
    if (mOnScrollChangeListener != null) {
        mOnScrollChangeListener.onFlingStart(mChild, mTarget, velocityX, velocityY);
    }
}
 
Example 11
Source File: DirectionalViewpager.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
private void completeScroll(boolean postEvents) {
    boolean needPopulate = mScrollState == SCROLL_STATE_SETTLING;
    if (needPopulate) {
        // Done with scroll, no longer want to cache view drawing.
        setScrollingCacheEnabled(false);
        boolean wasScrolling = !mScroller.isFinished();
        if (wasScrolling) {
            mScroller.abortAnimation();
            int oldX = getScrollX();
            int oldY = getScrollY();
            int x = mScroller.getCurrX();
            int y = mScroller.getCurrY();
            if (oldX != x || oldY != y) {
                scrollTo(x, y);
                if (isHorizontal() && x != oldX) {
                    pageScrolled(x, 0);
                }
            }
        }
    }
    mPopulatePending = false;
    for (int i = 0; i < mItems.size(); i++) {
        ItemInfo ii = mItems.get(i);
        if (ii.scrolling) {
            needPopulate = true;
            ii.scrolling = false;
        }
    }
    if (needPopulate) {
        if (postEvents) {
            ViewCompat.postOnAnimation(this, mEndScrollRunnable);
        } else {
            mEndScrollRunnable.run();
        }
    }
}
 
Example 12
Source File: CoolViewPager.java    From CoolViewPager with Apache License 2.0 5 votes vote down vote up
private void completeScroll(boolean postEvents) {
    boolean needPopulate = mScrollState == SCROLL_STATE_SETTLING;
    if (needPopulate) {
        // Done with scroll, no longer want to cache view drawing.
        setScrollingCacheEnabled(false);
        boolean wasScrolling = !mScroller.isFinished();
        if (wasScrolling) {
            mScroller.abortAnimation();
            int oldX = getScrollX();
            int oldY = getScrollY();
            int x = mScroller.getCurrX();
            int y = mScroller.getCurrY();
            if (oldX != x || oldY != y) {
                scrollTo(x, y);
                if (x != oldX) {
                    pageScrolled(x);
                }
            }
        }
    }
    mPopulatePending = false;
    for (int i = 0; i < mItems.size(); i++) {
        CoolViewPager.ItemInfo ii = mItems.get(i);
        if (ii.scrolling) {
            needPopulate = true;
            ii.scrolling = false;
        }
    }
    if (needPopulate) {
        if (postEvents) {
            ViewCompat.postOnAnimation(this, mEndScrollRunnable);
        } else {
            mEndScrollRunnable.run();
        }
    }
}
 
Example 13
Source File: VerViewPager.java    From likeJDGoodsDetails with Apache License 2.0 5 votes vote down vote up
private void completeScroll(boolean postEvents) {
	boolean needPopulate = mScrollState == SCROLL_STATE_SETTLING;
	if (needPopulate) {
		// Done with scroll, no longer want to cache view drawing.
		setScrollingCacheEnabled(false);
		mScroller.abortAnimation();
		int oldX = getScrollX();
		int oldY = getScrollY();
		int x = mScroller.getCurrX();
		int y = mScroller.getCurrY();
		if (oldX != x || oldY != y) {
			scrollTo(x, y);
		}
	}
	mPopulatePending = false;
	for (int i = 0; i < mItems.size(); i++) {
		ItemInfo ii = mItems.get(i);
		if (ii.scrolling) {
			needPopulate = true;
			ii.scrolling = false;
		}
	}
	if (needPopulate) {
		if (postEvents) {
			ViewCompat.postOnAnimation(this, mEndScrollRunnable);
		} else {
			mEndScrollRunnable.run();
		}
	}
}
 
Example 14
Source File: ItemTouchHelper.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if (mSelected != null && scrollIfNecessary()) {
        if (mSelected != null) { //it might be lost during scrolling
            moveIfNecessary(mSelected);
        }
        mRecyclerView.removeCallbacks(mScrollRunnable);
        ViewCompat.postOnAnimation(mRecyclerView, this);
    }
}
 
Example 15
Source File: ViewPager.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
private void completeScroll(boolean postEvents) {
    boolean needPopulate = mScrollState == SCROLL_STATE_SETTLING;
    if (needPopulate) {
        // Done with scroll, no longer want to cache view drawing.
        setScrollingCacheEnabled(false);
        mScroller.abortAnimation();
        int oldX = getScrollX();
        int oldY = getScrollY();
        int x = mScroller.getCurrX();
        int y = mScroller.getCurrY();
        if (oldX != x || oldY != y) {
            scrollTo(x, y);
        }
    }
    mPopulatePending = false;
    for (int i=0; i<mItems.size(); i++) {
        ItemInfo ii = mItems.get(i);
        if (ii.scrolling) {
            needPopulate = true;
            ii.scrolling = false;
        }
    }
    if (needPopulate) {
        if (postEvents) {
            ViewCompat.postOnAnimation(this, mEndScrollRunnable);
        } else {
            mEndScrollRunnable.run();
        }
    }
}
 
Example 16
Source File: HeaderBehavior.java    From ticdesign with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    if (mLayout != null && mScroller != null && mScroller.computeScrollOffset()) {
        setHeaderTopBottomOffset(mParent, mLayout, mScroller.getCurrY());

        // Post ourselves so that we run on the next animation
        ViewCompat.postOnAnimation(mLayout, this);
    }
}
 
Example 17
Source File: HeaderFlingRunnable.java    From CoordinatorLayoutExample with Apache License 2.0 4 votes vote down vote up
public void scrollToClose(int headerOffset) {
    mIsScroollClose = true;
    mOverScroller.abortAnimation();
    mOverScroller.startScroll(0, (int) mChild.getTranslationY(), 0, (int) (headerOffset - mChild.getTranslationY()), 100);
    ViewCompat.postOnAnimation(mChild, this);
}
 
Example 18
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 4 votes vote down vote up
@Override
public void run() {
	switch (mTouchMode) {
	default:
		endFling();
		return;
	case TOUCH_MODE_SCROLL:
		if (mScroller.isFinished()) {
			return;
		}
	case TOUCH_MODE_RESCROLL:
	case TOUCH_MODE_FLING: {
		if (mDataChanged) {
			layoutChildren();
		}
		final Scroller scroller = mScroller;
		boolean more = scroller.computeScrollOffset();
		final int y = scroller.getCurrY();
		final int mPaddingBottom = getPaddingBottom();
		final int mPaddingTop = getPaddingTop();
		int delta = mLastFlingY - y;
		if (delta > 0) {
			mMotionPosition = mFirstPosition;
			delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop
					- 1, delta);
		} else {
			int offsetToLast = getChildCount() - 1;
			mMotionPosition = mFirstPosition + offsetToLast;
			delta = Math.max(-(getHeight() - mPaddingBottom
					- mPaddingTop - 1), delta);
		}
		final boolean atEdge = trackMotionScroll(delta, delta);
		final boolean atEnd = atEdge && (delta != 0);
		final int touchMode = mTouchMode;
		if (atEnd) {
			endFling();
			if (touchMode == TOUCH_MODE_FLING) {
				scrollToAdjustViewsUpOrDown();
			}
			break;
		}
		if (more && !atEnd) {
			mLastFlingY = y;
			ViewCompat.postOnAnimation(ZrcAbsListView.this, this);
		} else {
			endFling();
			if (touchMode == TOUCH_MODE_FLING) {
				scrollToAdjustViewsUpOrDown();
			}
		}
		break;
	}
	}
}
 
Example 19
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    switch (mTouchMode) {
    default:
        endFling();
        return;
    case TOUCH_MODE_SCROLL:
        if (mScroller.isFinished()) {
            return;
        }
    case TOUCH_MODE_RESCROLL:
    case TOUCH_MODE_FLING: {
        if (mDataChanged) {
            layoutChildren();
        }
        final Scroller scroller = mScroller;
        boolean more = scroller.computeScrollOffset();
        final int y = scroller.getCurrY();
        final int mPaddingBottom = getPaddingBottom();
        final int mPaddingTop = getPaddingTop();
        int delta = mLastFlingY - y;
        if (delta > 0) {
            mMotionPosition = mFirstPosition;
            delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop - 1, delta);
        } else {
            int offsetToLast = getChildCount() - 1;
            mMotionPosition = mFirstPosition + offsetToLast;
            delta = Math.max(-(getHeight() - mPaddingBottom - mPaddingTop - 1), delta);
        }
        final boolean atEdge = trackMotionScroll(delta, delta);
        final boolean atEnd = atEdge && (delta != 0);
        final int touchMode = mTouchMode;
        if (atEnd) {
            endFling();
            if (touchMode == TOUCH_MODE_FLING) {
                scrollToAdjustViewsUpOrDown();
            }
            break;
        }
        if (more && !atEnd) {
            mLastFlingY = y;
            ViewCompat.postOnAnimation(ZrcAbsListView.this, this);
        } else {
            endFling();
            if (touchMode == TOUCH_MODE_FLING) {
                scrollToAdjustViewsUpOrDown();
            }
        }
        break;
    }
    }
}
 
Example 20
Source File: ExtendableListView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private void postOnAnimate(Runnable runnable) {
    ViewCompat.postOnAnimation(this, runnable);
}