androidx.core.widget.EdgeEffectCompat Java Examples

The following examples show how to use androidx.core.widget.EdgeEffectCompat. 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: DynamicScrollUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Set color of the supplied edge effect object.
 *
 * @param edgeEffect The edge effect object to set the color.
 * @param color The edge effect color to be set.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setEdgeEffectColor(@Nullable Object edgeEffect, @ColorInt int color) {
    initializeEdgeEffectFields();

    if (edgeEffect instanceof EdgeEffectCompat) {
        try {
            F_EDGE_EFFECT_COMPAT_EDGE_EFFECT.setAccessible(true);
            edgeEffect = F_EDGE_EFFECT_COMPAT_EDGE_EFFECT.get(edgeEffect);
        } catch (IllegalAccessException illegalAccessException) {
            return;
        }
    }

    if (edgeEffect == null) {
        return;
    }

    if (DynamicSdkUtils.is21()) {
        ((EdgeEffect) edgeEffect).setColor(color);
    } else {
        try {
            F_EDGE_EFFECT_EDGE.setAccessible(true);
            final Drawable mEdge = (Drawable) F_EDGE_EFFECT_EDGE.get(edgeEffect);
            F_EDGE_EFFECT_GLOW.setAccessible(true);
            final Drawable mGlow = (Drawable) F_EDGE_EFFECT_GLOW.get(edgeEffect);
            if (mGlow != null) {
                mGlow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                mGlow.setCallback(null);
            }

            if (mEdge != null) {
                mEdge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
                mEdge.setCallback(null);
            }
        } catch (Exception ignored) {
        }
    }
}
 
Example #2
Source File: VerticalViewPager.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #3
Source File: DynamicScrollUtils.java    From dynamic-support with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize edge effect or glow fields so that we can access them via reflection.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static void initializeEdgeEffectFields() {
    if (F_EDGE_EFFECT_EDGE != null
            && F_EDGE_EFFECT_GLOW != null
            && F_EDGE_EFFECT_COMPAT_EDGE_EFFECT != null) {
        F_EDGE_EFFECT_EDGE.setAccessible(true);
        F_EDGE_EFFECT_GLOW.setAccessible(true);
        F_EDGE_EFFECT_COMPAT_EDGE_EFFECT.setAccessible(true);

        return;
    }

    if (DynamicSdkUtils.is21()) {
        F_EDGE_EFFECT_EDGE = null;
        F_EDGE_EFFECT_GLOW = null;
    } else if (DynamicSdkUtils.is14()) {
        Field edge = null;
        Field glow = null;
        for (Field field : EdgeEffect.class.getDeclaredFields()) {
            switch (field.getName()) {
                case "mEdge":
                    field.setAccessible(true);
                    edge = field;
                    break;
                case "mGlow":
                    field.setAccessible(true);
                    glow = field;
                    break;
            }
        }

        F_EDGE_EFFECT_EDGE = edge;
        F_EDGE_EFFECT_GLOW = glow;
    }

    Field edgeEffectCompat = null;
    try {
        edgeEffectCompat = EdgeEffectCompat.class.getDeclaredField("mEdgeEffect");
    } catch (NoSuchFieldException ignored) {
    }
    F_EDGE_EFFECT_COMPAT_EDGE_EFFECT = edgeEffectCompat;
}
 
Example #4
Source File: CustomViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
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 = configuration.getScaledPagingTouchSlop();
    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);
    }

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new androidx.core.view.OnApplyWindowInsetsListener() {
                private final Rect mTempRect = new Rect();

                @Override
                public WindowInsetsCompat onApplyWindowInsets(final View v,
                                                              final WindowInsetsCompat originalInsets) {
                    // First let the ViewPager itself try and consume them...
                    final WindowInsetsCompat applied =
                            ViewCompat.onApplyWindowInsets(v, originalInsets);
                    if (applied.isConsumed()) {
                        // If the ViewPager consumed all insets, return now
                        return applied;
                    }

                    // Now we'll manually dispatch the insets to our children. Since ViewPager
                    // children are always full-height, we do not want to use the standard
                    // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
                    // the rest of the children will not receive any insets. To workaround this
                    // we manually dispatch the applied insets, not allowing children to
                    // consume them from each other. We do however keep track of any insets
                    // which are consumed, returning the union of our children's consumption
                    final Rect res = mTempRect;
                    res.left = applied.getSystemWindowInsetLeft();
                    res.top = applied.getSystemWindowInsetTop();
                    res.right = applied.getSystemWindowInsetRight();
                    res.bottom = applied.getSystemWindowInsetBottom();

                    for (int i = 0, count = getChildCount(); i < count; i++) {
                        final WindowInsetsCompat childInsets = ViewCompat
                                .dispatchApplyWindowInsets(getChildAt(i), applied);
                        // Now keep track of any consumed by tracking each dimension's min
                        // value
                        res.left = Math.min(childInsets.getSystemWindowInsetLeft(),
                                res.left);
                        res.top = Math.min(childInsets.getSystemWindowInsetTop(),
                                res.top);
                        res.right = Math.min(childInsets.getSystemWindowInsetRight(),
                                res.right);
                        res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(),
                                res.bottom);
                    }

                    // Now return a new WindowInsets, using the consumed window insets
                    return applied.replaceSystemWindowInsets(
                            res.left, res.top, res.right, res.bottom);
                }
            });
}
 
Example #5
Source File: GlowOverFlipper.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
public GlowOverFlipper(FlipView v) {
	mFlipView = v;
	mTopEdgeEffect = new EdgeEffectCompat(v.getContext());
	mBottomEdgeEffect = new EdgeEffectCompat(v.getContext());
}