Search in sources :

Example 6 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project open-event-android by fossasia.

the class Views method setEdgeGlowColorScrollView.

/*Check if the version is above Lollipop to change the edge glow color of Nested ScrollView
    according to the session detail activity color*/
public static void setEdgeGlowColorScrollView(int color, NestedScrollView scrollView) {
    try {
        Field edgeGlowTop = NestedScrollView.class.getDeclaredField("mEdgeGlowTop");
        edgeGlowTop.setAccessible(true);
        Field edgeGlowBottom = NestedScrollView.class.getDeclaredField("mEdgeGlowBottom");
        edgeGlowBottom.setAccessible(true);
        EdgeEffectCompat edgeEffect = (EdgeEffectCompat) edgeGlowTop.get(scrollView);
        if (edgeEffect == null) {
            edgeEffect = new EdgeEffectCompat(scrollView.getContext());
            edgeGlowTop.set(scrollView, edgeEffect);
        }
        Views.setEdgeGlowColor(edgeEffect, color);
        edgeEffect = (EdgeEffectCompat) edgeGlowBottom.get(scrollView);
        if (edgeEffect == null) {
            edgeEffect = new EdgeEffectCompat(scrollView.getContext());
            edgeGlowBottom.set(scrollView, edgeEffect);
        }
        Views.setEdgeGlowColor(edgeEffect, color);
    } catch (Exception ex) {
        ex.printStackTrace();
    // Catching the error that can be caused by EdgeEffectCompat
    }
}
Also used : Field(java.lang.reflect.Field) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat)

Example 7 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project BlogSource by TeachCourse.

the class ViewPagerCompat 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();
    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 android.support.v4.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);
        }
    });
}
Also used : Context(android.content.Context) Rect(android.graphics.Rect) View(android.view.View) WindowInsetsCompat(android.support.v4.view.WindowInsetsCompat) ViewConfiguration(android.view.ViewConfiguration) EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) Scroller(android.widget.Scroller)

Example 8 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project CodenameOne by codenameone.

the class ViewPager 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();
    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) Scroller(android.widget.Scroller)

Example 9 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project HL4A by HL4A.

the class 滑动视图 method 变色.

private void 变色(String... $变量) {
    if (设备.取SDK() > 21) {
        int $颜色 = 视图.检查颜色("控件");
        for (String $单个 : $变量) {
            EdgeEffectCompat $兼容 = 反射.取变量(this, $单个);
            EdgeEffect $设置 = 反射.取变量($兼容, "mEdgeEffect");
            $设置.setColor($颜色);
        }
    }
}
Also used : EdgeEffectCompat(android.support.v4.widget.EdgeEffectCompat) EdgeEffect(android.widget.EdgeEffect)

Example 10 with EdgeEffectCompat

use of android.support.v4.widget.EdgeEffectCompat in project CircleBar by songnick.

the class ScaleViewPager 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();
    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) Scroller(android.widget.Scroller)

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