Search in sources :

Example 1 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project actor-platform by actorapp.

the class VerticalViewPager method initViewPager.

void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new Scroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = new EdgeEffectCompat(context);
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}
Also used : Context(android.content.Context) ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Scroller(android.widget.Scroller)

Example 2 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project AndroidDevelop by 7449.

the class TabView method init.

private void init() {
    // 把一个值从dip转换成px
    mIndicatorHeight = dip2px(mIndicatorHeight);
    mDividerPadding = dip2px(mDividerPadding);
    mTabPadding = dip2px(mTabPadding);
    mDividerWidth = dip2px(mDividerWidth);
    mTabTextSize = dip2px(mTabTextSize);
    // 创建一个scroller
    mScroller = ScrollerCompat.create(getContext());
    // 获取一个系统关于View的常量配置类
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    // 获取滑动的最小距离
    mTouchSlop = configuration.getScaledTouchSlop();
    // 获取fling的最小速度
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    // 获取fling的最大速度
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(getContext());
    mRightEdge = new EdgeEffectCompat(getContext());
}
Also used : ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat)

Example 3 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project JamsMusicPlayer by psaravan.

the class VelocityViewPager method initViewPager.

void initViewPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new VelocityScroller(context, sInterpolator);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
    ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());
    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
}
Also used : Context(android.content.Context) ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat)

Example 4 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project android_packages_apps_OmniClock by omnirom.

the class StaggeredGridView method trackMotionScroll.

/**
 * @param deltaY Pixels that content should move by
 * @return true if the movement completed, false if it was stopped prematurely.
 */
private boolean trackMotionScroll(int deltaY, boolean allowOverScroll) {
    final boolean contentFits = contentFits();
    final int allowOverhang = Math.abs(deltaY);
    final int overScrolledBy;
    final int movedBy;
    if (!contentFits) {
        int overhang;
        final boolean up;
        mPopulating = true;
        if (deltaY > 0) {
            overhang = fillUp(mFirstPosition - 1, allowOverhang);
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang);
            if (overhang < 0) {
                // Overhang when filling down indicates how many pixels past the bottom of the
                // screen has been filled in.  If this value is negative, it should be set to
                // 0 so that we don't allow over scrolling.
                overhang = 0;
            }
            up = false;
        }
        movedBy = Math.min(overhang, allowOverhang);
        offsetChildren(up ? movedBy : -movedBy);
        recycleOffscreenViews();
        mPopulating = false;
        overScrolledBy = allowOverhang - overhang;
    } else {
        overScrolledBy = allowOverhang;
        movedBy = 0;
    }
    if (allowOverScroll) {
        final int overScrollMode = ViewCompat.getOverScrollMode(this);
        if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS || (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && !contentFits)) {
            if (overScrolledBy > 0) {
                final EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge;
                edge.onPull((float) Math.abs(deltaY) / getHeight());
                ViewCompat.postInvalidateOnAnimation(this);
            }
        }
    }
    awakenScrollBars(0, /* show immediately */
    true);
    return deltaY == 0 || movedBy != 0;
}
Also used : EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 5 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project android_packages_apps_OmniClock by omnirom.

the class StaggeredGridView method computeScroll.

@Override
public void computeScroll() {
    if (mTouchMode == TOUCH_MODE_OVERFLING) {
        handleOverfling();
    } else if (mScroller.computeScrollOffset()) {
        final int overScrollMode = ViewCompat.getOverScrollMode(this);
        final boolean supportsOverscroll = overScrollMode != ViewCompat.OVER_SCROLL_NEVER;
        final int y = mScroller.getCurrY();
        final int dy = (int) (y - mLastTouchY);
        // TODO: Figure out why mLastTouchY is being updated here. Consider using a new class
        // variable since this value does not represent the last place on the screen where a
        // touch occurred.
        mLastTouchY = y;
        // Check if the top of the motion view is where it is
        // supposed to be
        final View motionView = supportsOverscroll && getChildCount() > 0 ? getChildAt(0) : null;
        final int motionViewPrevTop = motionView != null ? motionView.getTop() : 0;
        final boolean stopped = !trackMotionScroll(dy, false);
        if (!stopped && !mScroller.isFinished()) {
            mTouchMode = TOUCH_MODE_IDLE;
            ViewCompat.postInvalidateOnAnimation(this);
        } else if (stopped && dy != 0 && supportsOverscroll) {
            // Check to see if we have bumped into the scroll limit
            if (motionView != null) {
                final int motionViewRealTop = motionView.getTop();
                // Apply overscroll
                final int overscroll = -dy - (motionViewRealTop - motionViewPrevTop);
                overScrollBy(0, overscroll, 0, getScrollY(), 0, 0, 0, mOverscrollDistance, true);
            }
            final EdgeEffectCompat edge;
            if (dy > 0) {
                edge = mTopEdge;
                mBottomEdge.finish();
            } else {
                edge = mBottomEdge;
                mTopEdge.finish();
            }
            edge.onAbsorb(Math.abs((int) mScroller.getCurrVelocity()));
            if (mScroller.computeScrollOffset()) {
                mScroller.notifyVerticalEdgeReached(getScrollY(), 0, mOverscrollDistance);
            }
            mTouchMode = TOUCH_MODE_OVERFLING;
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            mTouchMode = TOUCH_MODE_IDLE;
        }
    }
}
Also used : EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Aggregations

EdgeEffectCompat (android.support.v4.widget.EdgeEffectCompat)33 Context (android.content.Context)18 ViewConfiguration (android.view.ViewConfiguration)18 Scroller (android.widget.Scroller)17 View (android.view.View)5 Rect (android.graphics.Rect)4 WindowInsetsCompat (android.support.v4.view.WindowInsetsCompat)3 SuppressLint (android.annotation.SuppressLint)2 Point (android.graphics.Point)2 EdgeEffect (android.widget.EdgeEffect)2 TargetApi (android.annotation.TargetApi)1 Resources (android.content.res.Resources)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 ScrollView (android.widget.ScrollView)1 Field (java.lang.reflect.Field)1