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);
}
}
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;
}
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);
}
}
Aggregations