Search in sources :

Example 6 with EdgeEffect

use of android.widget.EdgeEffect in project platform_frameworks_base by android.

the class ViewPager method performDrag.

private boolean performDrag(float x) {
    boolean needsInvalidate = false;
    final int width = getPaddedWidth();
    final float deltaX = mLastMotionX - x;
    mLastMotionX = x;
    final EdgeEffect startEdge;
    final EdgeEffect endEdge;
    if (isLayoutRtl()) {
        startEdge = mRightEdge;
        endEdge = mLeftEdge;
    } else {
        startEdge = mLeftEdge;
        endEdge = mRightEdge;
    }
    // Translate scroll to relative coordinates.
    final float nextScrollX = getScrollX() + deltaX;
    final float scrollStart;
    if (isLayoutRtl()) {
        scrollStart = MAX_SCROLL_X - nextScrollX;
    } else {
        scrollStart = nextScrollX;
    }
    final float startBound;
    final ItemInfo startItem = mItems.get(0);
    final boolean startAbsolute = startItem.position == 0;
    if (startAbsolute) {
        startBound = startItem.offset * width;
    } else {
        startBound = width * mFirstOffset;
    }
    final float endBound;
    final ItemInfo endItem = mItems.get(mItems.size() - 1);
    final boolean endAbsolute = endItem.position == mAdapter.getCount() - 1;
    if (endAbsolute) {
        endBound = endItem.offset * width;
    } else {
        endBound = width * mLastOffset;
    }
    final float clampedScrollStart;
    if (scrollStart < startBound) {
        if (startAbsolute) {
            final float over = startBound - scrollStart;
            startEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = startBound;
    } else if (scrollStart > endBound) {
        if (endAbsolute) {
            final float over = scrollStart - endBound;
            endEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = endBound;
    } else {
        clampedScrollStart = scrollStart;
    }
    // Translate back to absolute coordinates.
    final float targetScrollX;
    if (isLayoutRtl()) {
        targetScrollX = MAX_SCROLL_X - clampedScrollStart;
    } else {
        targetScrollX = clampedScrollStart;
    }
    // Don't lose the rounded component.
    mLastMotionX += targetScrollX - (int) targetScrollX;
    scrollTo((int) targetScrollX, getScrollY());
    pageScrolled((int) targetScrollX);
    return needsInvalidate;
}
Also used : EdgeEffect(android.widget.EdgeEffect)

Example 7 with EdgeEffect

use of android.widget.EdgeEffect in project android_frameworks_base by DirtyUnicorns.

the class ViewPager method performDrag.

private boolean performDrag(float x) {
    boolean needsInvalidate = false;
    final int width = getPaddedWidth();
    final float deltaX = mLastMotionX - x;
    mLastMotionX = x;
    final EdgeEffect startEdge;
    final EdgeEffect endEdge;
    if (isLayoutRtl()) {
        startEdge = mRightEdge;
        endEdge = mLeftEdge;
    } else {
        startEdge = mLeftEdge;
        endEdge = mRightEdge;
    }
    // Translate scroll to relative coordinates.
    final float nextScrollX = getScrollX() + deltaX;
    final float scrollStart;
    if (isLayoutRtl()) {
        scrollStart = MAX_SCROLL_X - nextScrollX;
    } else {
        scrollStart = nextScrollX;
    }
    final float startBound;
    final ItemInfo startItem = mItems.get(0);
    final boolean startAbsolute = startItem.position == 0;
    if (startAbsolute) {
        startBound = startItem.offset * width;
    } else {
        startBound = width * mFirstOffset;
    }
    final float endBound;
    final ItemInfo endItem = mItems.get(mItems.size() - 1);
    final boolean endAbsolute = endItem.position == mAdapter.getCount() - 1;
    if (endAbsolute) {
        endBound = endItem.offset * width;
    } else {
        endBound = width * mLastOffset;
    }
    final float clampedScrollStart;
    if (scrollStart < startBound) {
        if (startAbsolute) {
            final float over = startBound - scrollStart;
            startEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = startBound;
    } else if (scrollStart > endBound) {
        if (endAbsolute) {
            final float over = scrollStart - endBound;
            endEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = endBound;
    } else {
        clampedScrollStart = scrollStart;
    }
    // Translate back to absolute coordinates.
    final float targetScrollX;
    if (isLayoutRtl()) {
        targetScrollX = MAX_SCROLL_X - clampedScrollStart;
    } else {
        targetScrollX = clampedScrollStart;
    }
    // Don't lose the rounded component.
    mLastMotionX += targetScrollX - (int) targetScrollX;
    scrollTo((int) targetScrollX, getScrollY());
    pageScrolled((int) targetScrollX);
    return needsInvalidate;
}
Also used : EdgeEffect(android.widget.EdgeEffect)

Example 8 with EdgeEffect

use of android.widget.EdgeEffect in project android_frameworks_base by AOSPA.

the class ViewPager method performDrag.

private boolean performDrag(float x) {
    boolean needsInvalidate = false;
    final int width = getPaddedWidth();
    final float deltaX = mLastMotionX - x;
    mLastMotionX = x;
    final EdgeEffect startEdge;
    final EdgeEffect endEdge;
    if (isLayoutRtl()) {
        startEdge = mRightEdge;
        endEdge = mLeftEdge;
    } else {
        startEdge = mLeftEdge;
        endEdge = mRightEdge;
    }
    // Translate scroll to relative coordinates.
    final float nextScrollX = getScrollX() + deltaX;
    final float scrollStart;
    if (isLayoutRtl()) {
        scrollStart = MAX_SCROLL_X - nextScrollX;
    } else {
        scrollStart = nextScrollX;
    }
    final float startBound;
    final ItemInfo startItem = mItems.get(0);
    final boolean startAbsolute = startItem.position == 0;
    if (startAbsolute) {
        startBound = startItem.offset * width;
    } else {
        startBound = width * mFirstOffset;
    }
    final float endBound;
    final ItemInfo endItem = mItems.get(mItems.size() - 1);
    final boolean endAbsolute = endItem.position == mAdapter.getCount() - 1;
    if (endAbsolute) {
        endBound = endItem.offset * width;
    } else {
        endBound = width * mLastOffset;
    }
    final float clampedScrollStart;
    if (scrollStart < startBound) {
        if (startAbsolute) {
            final float over = startBound - scrollStart;
            startEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = startBound;
    } else if (scrollStart > endBound) {
        if (endAbsolute) {
            final float over = scrollStart - endBound;
            endEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = endBound;
    } else {
        clampedScrollStart = scrollStart;
    }
    // Translate back to absolute coordinates.
    final float targetScrollX;
    if (isLayoutRtl()) {
        targetScrollX = MAX_SCROLL_X - clampedScrollStart;
    } else {
        targetScrollX = clampedScrollStart;
    }
    // Don't lose the rounded component.
    mLastMotionX += targetScrollX - (int) targetScrollX;
    scrollTo((int) targetScrollX, getScrollY());
    pageScrolled((int) targetScrollX);
    return needsInvalidate;
}
Also used : EdgeEffect(android.widget.EdgeEffect)

Example 9 with EdgeEffect

use of android.widget.EdgeEffect in project UltimateAndroid by cymcsg.

the class FreeFlowContainer method setEdgeEffectsEnabled.

/**
	 * Controls whether the edge glows are enabled or not
	 */
public void setEdgeEffectsEnabled(boolean val) {
    mEdgeEffectsEnabled = val;
    if (val) {
        Context context = getContext();
        setWillNotDraw(false);
        mLeftEdge = new EdgeEffect(context);
        mRightEdge = new EdgeEffect(context);
        mTopEdge = new EdgeEffect(context);
        mBottomEdge = new EdgeEffect(context);
    } else {
        setWillNotDraw(true);
        mLeftEdge = mRightEdge = mTopEdge = mBottomEdge = null;
    }
}
Also used : Context(android.content.Context) EdgeEffect(android.widget.EdgeEffect)

Example 10 with EdgeEffect

use of android.widget.EdgeEffect in project android_frameworks_base by ResurrectionRemix.

the class ViewPager method performDrag.

private boolean performDrag(float x) {
    boolean needsInvalidate = false;
    final int width = getPaddedWidth();
    final float deltaX = mLastMotionX - x;
    mLastMotionX = x;
    final EdgeEffect startEdge;
    final EdgeEffect endEdge;
    if (isLayoutRtl()) {
        startEdge = mRightEdge;
        endEdge = mLeftEdge;
    } else {
        startEdge = mLeftEdge;
        endEdge = mRightEdge;
    }
    // Translate scroll to relative coordinates.
    final float nextScrollX = getScrollX() + deltaX;
    final float scrollStart;
    if (isLayoutRtl()) {
        scrollStart = MAX_SCROLL_X - nextScrollX;
    } else {
        scrollStart = nextScrollX;
    }
    final float startBound;
    final ItemInfo startItem = mItems.get(0);
    final boolean startAbsolute = startItem.position == 0;
    if (startAbsolute) {
        startBound = startItem.offset * width;
    } else {
        startBound = width * mFirstOffset;
    }
    final float endBound;
    final ItemInfo endItem = mItems.get(mItems.size() - 1);
    final boolean endAbsolute = endItem.position == mAdapter.getCount() - 1;
    if (endAbsolute) {
        endBound = endItem.offset * width;
    } else {
        endBound = width * mLastOffset;
    }
    final float clampedScrollStart;
    if (scrollStart < startBound) {
        if (startAbsolute) {
            final float over = startBound - scrollStart;
            startEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = startBound;
    } else if (scrollStart > endBound) {
        if (endAbsolute) {
            final float over = scrollStart - endBound;
            endEdge.onPull(Math.abs(over) / width);
            needsInvalidate = true;
        }
        clampedScrollStart = endBound;
    } else {
        clampedScrollStart = scrollStart;
    }
    // Translate back to absolute coordinates.
    final float targetScrollX;
    if (isLayoutRtl()) {
        targetScrollX = MAX_SCROLL_X - clampedScrollStart;
    } else {
        targetScrollX = clampedScrollStart;
    }
    // Don't lose the rounded component.
    mLastMotionX += targetScrollX - (int) targetScrollX;
    scrollTo((int) targetScrollX, getScrollY());
    pageScrolled((int) targetScrollX);
    return needsInvalidate;
}
Also used : EdgeEffect(android.widget.EdgeEffect)

Aggregations

EdgeEffect (android.widget.EdgeEffect)11 Context (android.content.Context)2 TargetApi (android.annotation.TargetApi)1 Drawable (android.graphics.drawable.Drawable)1 EdgeEffectCompat (android.support.v4.widget.EdgeEffectCompat)1 ViewConfiguration (android.view.ViewConfiguration)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 Scroller (android.widget.Scroller)1