Search in sources :

Example 31 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project ZXVerticalViewPager by zhaoxin1943.

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 32 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project StaggeredGridView by bulletnoid.

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;
    int movedBy;
    if (!contentFits) {
        final int overhang;
        final boolean up;
        mPopulating = true;
        if (deltaY > 0) {
            overhang = fillUp(mFirstPosition - 1, allowOverhang) + mItemMargin;
            up = true;
        } else {
            overhang = fillDown(mFirstPosition + getChildCount(), allowOverhang) + mItemMargin;
            up = false;
        }
        movedBy = Math.min(overhang, allowOverhang);
        if (movedBy < 0) {
            movedBy = 0;
        }
        if (movedBy == 0) {
            if (up) {
                mGetToTop = true;
                lazyload = false;
            } else {
                mGetToTop = false;
                lazyload = true;
                if (!loadlock) {
                    mLoadListener.onLoadmore();
                    loadlock = true;
                }
            }
        } else {
            mGetToTop = false;
            lazyload = true;
        }
        offsetChildren(up ? movedBy : -movedBy);
        if (getChildCount() > MAX_CHILD_COUNT) {
            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) {
                EdgeEffectCompat edge = deltaY > 0 ? mTopEdge : mBottomEdge;
                edge.onPull((float) Math.abs(deltaY) / getHeight());
                invalidate();
            }
        }
    }
    if (mSelectorPosition != INVALID_POSITION) {
        final int childIndex = mSelectorPosition - mFirstPosition;
        if (childIndex >= 0 && childIndex < getChildCount()) {
            positionSelector(INVALID_POSITION, getChildAt(childIndex));
        }
    } else {
        mSelectorRect.setEmpty();
    }
    return deltaY == 0 || movedBy != 0;
}
Also used : EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat)

Example 33 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project Shuttle by timusus.

the class EdgeGlowUtil method setEffectColor.

// Utilities
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void setEffectColor(Object edgeEffect, @ColorInt int color) {
    invalidateEdgeEffectFields();
    if (edgeEffect instanceof EdgeEffectCompat) {
        // EdgeEffectCompat
        try {
            EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.setAccessible(true);
            edgeEffect = EDGE_EFFECT_COMPAT_FIELD_EDGE_EFFECT.get(edgeEffect);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return;
        }
    }
    if (edgeEffect == null) {
        return;
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // EdgeGlow
        try {
            EDGE_GLOW_FIELD_EDGE.setAccessible(true);
            final Drawable mEdge = (Drawable) EDGE_GLOW_FIELD_EDGE.get(edgeEffect);
            EDGE_GLOW_FIELD_GLOW.setAccessible(true);
            final Drawable mGlow = (Drawable) EDGE_GLOW_FIELD_GLOW.get(edgeEffect);
            mEdge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            mGlow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
            // free up any references
            mEdge.setCallback(null);
            // free up any references
            mGlow.setCallback(null);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        // EdgeEffect
        ((EdgeEffect) edgeEffect).setColor(color);
    }
}
Also used : EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Drawable(android.graphics.drawable.Drawable) EdgeEffect(android.widget.EdgeEffect) TargetApi(android.annotation.TargetApi)

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