android.widget.EdgeEffect Java Examples

The following examples show how to use android.widget.EdgeEffect. 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: PhotoViewPager.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
public PhotoViewPager(Context context, Adapter adapter) {
	super(context);
	setWillNotDraw(false);
	float density = ResourceUtils.obtainDensity(context);
	flingDistance = (int) (24 * density);
	ViewConfiguration configuration = ViewConfiguration.get(context);
	minimumVelocity = (int) (MIN_FLING_VELOCITY * density);
	maximumVelocity = configuration.getScaledMaximumFlingVelocity();
	touchSlop = configuration.getScaledTouchSlop();
	scroller = new OverScroller(context);
	edgeEffect = new EdgeEffect(context);
	this.adapter = adapter;
	for (int i = 0; i < 3; i++) {
		View view = adapter.onCreateView(this);
		super.addView(view, -1, generateDefaultLayoutParams());
		photoViews.add(adapter.getPhotoView(view));
	}
}
 
Example #2
Source File: ViewCompat.java    From support with Apache License 2.0 6 votes vote down vote up
public static void setEdgeEffectColor(final EdgeEffect edgeEffect, @ColorRes final int color) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            edgeEffect.setColor(color);
            return;
        }
        final Field edgeField = EdgeEffect.class.getDeclaredField("mEdge");
        final Field glowField = EdgeEffect.class.getDeclaredField("mGlow");
        edgeField.setAccessible(true);
        glowField.setAccessible(true);
        final Drawable edge = (Drawable) edgeField.get(edgeEffect);
        final Drawable glow = (Drawable) glowField.get(edgeEffect);
        edge.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        glow.setColorFilter(color, PorterDuff.Mode.SRC_IN);
        edge.setCallback(null); // free up any references
        glow.setCallback(null); // free up any references
    } catch (final Exception ignored) {
        ignored.printStackTrace();
    }
}
 
Example #3
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static void setViewPagerEdgeEffectColor(ViewPager viewPager, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = ViewPager.class.getDeclaredField("mLeftEdge");
            field.setAccessible(true);
            EdgeEffect mLeftEdge = (EdgeEffect) field.get(viewPager);
            if (mLeftEdge != null) {
                mLeftEdge.setColor(color);
            }

            field = ViewPager.class.getDeclaredField("mRightEdge");
            field.setAccessible(true);
            EdgeEffect mRightEdge = (EdgeEffect) field.get(viewPager);
            if (mRightEdge != null) {
                mRightEdge.setColor(color);
            }
        } catch (Exception ignore) {

        }
    }
}
 
Example #4
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static void setScrollViewEdgeEffectColor(HorizontalScrollView scrollView, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = HorizontalScrollView.class.getDeclaredField("mEdgeGlowLeft");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowTop != null) {
                mEdgeGlowTop.setColor(color);
            }

            field = HorizontalScrollView.class.getDeclaredField("mEdgeGlowRight");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowBottom != null) {
                mEdgeGlowBottom.setColor(color);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example #5
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void setScrollViewEdgeEffectColor(ScrollView scrollView, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = ScrollView.class.getDeclaredField("mEdgeGlowTop");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowTop != null) {
                mEdgeGlowTop.setColor(color);
            }

            field = ScrollView.class.getDeclaredField("mEdgeGlowBottom");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowBottom != null) {
                mEdgeGlowBottom.setColor(color);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example #6
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void setScrollViewEdgeEffectColor(HorizontalScrollView scrollView, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = HorizontalScrollView.class.getDeclaredField("mEdgeGlowLeft");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowTop != null) {
                mEdgeGlowTop.setColor(color);
            }

            field = HorizontalScrollView.class.getDeclaredField("mEdgeGlowRight");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowBottom != null) {
                mEdgeGlowBottom.setColor(color);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example #7
Source File: AndroidUtilities.java    From KrGallery with GNU General Public License v2.0 6 votes vote down vote up
public static void setListViewEdgeEffectColor(AbsListView listView, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = AbsListView.class.getDeclaredField("mEdgeGlowTop");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(listView);
            if (mEdgeGlowTop != null) {
                mEdgeGlowTop.setColor(color);
            }

            field = AbsListView.class.getDeclaredField("mEdgeGlowBottom");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(listView);
            if (mEdgeGlowBottom != null) {
                mEdgeGlowBottom.setColor(color);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #8
Source File: TwoDScrollView.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
private void prepare(AttributeSet attrs)
{
    setFocusable(true);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setWillNotDraw(false);
    mScroller = new Scroller(getContext());
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), mScaleListener);
    mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener);
    if (attrs != null)
    {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomViewExtension, 0, 0);
        autoScrollMargins = a.getDimensionPixelSize(R.styleable.CustomViewExtension_autoScrollMargins, 0);
        a.recycle();
    }
    mEdgeGlowLeft = new EdgeEffect(getContext());
    mEdgeGlowTop = new EdgeEffect(getContext());
    mEdgeGlowRight = new EdgeEffect(getContext());
    mEdgeGlowBottom = new EdgeEffect(getContext());
    setWillNotDraw(false);
}
 
Example #9
Source File: Easel.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
/**
 * Tint the edge effect when you reach the end of a scroll view. API 21+ only
 *
 * @param scrollableView the scrollable view, such as a {@link android.widget.ScrollView}
 * @param color          the color
 * @return true if it worked, false if it did not
 */
@TargetApi(21)
public static boolean tintEdgeEffect(@NonNull View scrollableView, @ColorInt int color) {
    //http://stackoverflow.com/questions/27104521/android-lollipop-scrollview-edge-effect-color
    boolean outcome = false;
    final String[] edgeGlows = {"mEdgeGlowTop", "mEdgeGlowBottom", "mEdgeGlowLeft", "mEdgeGlowRight"};
    for (String edgeGlow : edgeGlows) {
        Class<?> clazz = scrollableView.getClass();
        while (clazz != null) {
            try {
                final Field edgeGlowField = clazz.getDeclaredField(edgeGlow);
                edgeGlowField.setAccessible(true);
                final EdgeEffect edgeEffect = (EdgeEffect) edgeGlowField.get(scrollableView);
                edgeEffect.setColor(color);
                outcome = true;
                break;
            } catch (Exception e) {
                clazz = clazz.getSuperclass();
            }
        }
    }
    return outcome;
}
 
Example #10
Source File: AndroidUtilities.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public static void setScrollViewEdgeEffectColor(ScrollView scrollView, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = ScrollView.class.getDeclaredField("mEdgeGlowTop");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowTop != null) {
                mEdgeGlowTop.setColor(color);
            }

            field = ScrollView.class.getDeclaredField("mEdgeGlowBottom");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowBottom != null) {
                mEdgeGlowBottom.setColor(color);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
 
Example #11
Source File: AndroidUtilities.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public static void setViewPagerEdgeEffectColor(ViewPager viewPager, int color) {
    if (Build.VERSION.SDK_INT >= 21) {
        try {
            Field field = ViewPager.class.getDeclaredField("mLeftEdge");
            field.setAccessible(true);
            EdgeEffect mLeftEdge = (EdgeEffect) field.get(viewPager);
            if (mLeftEdge != null) {
                mLeftEdge.setColor(color);
            }

            field = ViewPager.class.getDeclaredField("mRightEdge");
            field.setAccessible(true);
            EdgeEffect mRightEdge = (EdgeEffect) field.get(viewPager);
            if (mRightEdge != null) {
                mRightEdge.setColor(color);
            }
        } catch (Exception ignore) {

        }
    }
}
 
Example #12
Source File: OverScrollGlow.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public OverScrollGlow(View host) {
    mHostView = host;
    Context context = host.getContext();
    mEdgeGlowTop = new EdgeEffect(context);
    mEdgeGlowBottom = new EdgeEffect(context);
    mEdgeGlowLeft = new EdgeEffect(context);
    mEdgeGlowRight = new EdgeEffect(context);
}
 
Example #13
Source File: FreeFlowContainer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Controls whether the edge glows are enabled or not
 */
public void setEdgeEffectsEnabled(boolean val) {
	mEdgeEffectsEnabled = val;
	if (val) {
		Context context = getContext();
		setWillNotDraw(false);
		mLeftEdge = new EdgeEffect(context);
		mRightEdge = new EdgeEffect(context);
		mTopEdge = new EdgeEffect(context);
		mBottomEdge = new EdgeEffect(context);
	} else {
		setWillNotDraw(true);
		mLeftEdge = mRightEdge = mTopEdge = mBottomEdge = null;
	}
}
 
Example #14
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 #15
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void setScrollViewEdgeEffectColor(ScrollView scrollView, int color)
{
    if (Build.VERSION.SDK_INT >= 21)
    {
        try
        {
            Field field = ScrollView.class.getDeclaredField("mEdgeGlowTop");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowTop != null)
            {
                mEdgeGlowTop.setColor(color);
            }

            field = ScrollView.class.getDeclaredField("mEdgeGlowBottom");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowBottom != null)
            {
                mEdgeGlowBottom.setColor(color);
            }
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    }
}
 
Example #16
Source File: FlipViewPager.java    From Travel-Mate with MIT License 5 votes vote down vote up
private void init() {
    ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mScroller = new Scroller(getContext(), new LinearInterpolator());
    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdgeEffect = new EdgeEffect(getContext());
    mRightEdgeEffect = new EdgeEffect(getContext());
    mShadePaint.setColor(Color.BLACK);
    mShinePaint.setColor(Color.WHITE);
}
 
Example #17
Source File: SdkCenteredViewPager.java    From Android-SDK-Demo with MIT License 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 = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = (int) ( MIN_FLING_VELOCITY * density );
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffect( context );
    mRightEdge = new EdgeEffect( context );

    mFlingDistance = (int) ( MIN_DISTANCE_FOR_FLING * density );
    mCloseEnough = (int) ( CLOSE_ENOUGH * density );
    mDefaultGutterSize = (int) ( DEFAULT_GUTTER_SIZE * density );

    setAccessibilityDelegate( new MyAccessibilityDelegate() );

    if ( this.getImportantForAccessibility()
            == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO )
    {
        setImportantForAccessibility( View.IMPORTANT_FOR_ACCESSIBILITY_YES );
    }
}
 
Example #18
Source File: OverScrollGlow.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public OverScrollGlow(View host) {
    mHostView = host;
    Context context = host.getContext();
    mEdgeGlowTop = new EdgeEffect(context);
    mEdgeGlowBottom = new EdgeEffect(context);
    mEdgeGlowLeft = new EdgeEffect(context);
    mEdgeGlowRight = new EdgeEffect(context);
}
 
Example #19
Source File: SdkCenteredViewPager.java    From Android-SDK-Demo with MIT License 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 = configuration.getScaledPagingTouchSlop();
    mMinimumVelocity = (int) ( MIN_FLING_VELOCITY * density );
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffect( context );
    mRightEdge = new EdgeEffect( context );

    mFlingDistance = (int) ( MIN_DISTANCE_FOR_FLING * density );
    mCloseEnough = (int) ( CLOSE_ENOUGH * density );
    mDefaultGutterSize = (int) ( DEFAULT_GUTTER_SIZE * density );

    setAccessibilityDelegate( new MyAccessibilityDelegate() );

    if ( this.getImportantForAccessibility()
            == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO )
    {
        setImportantForAccessibility( View.IMPORTANT_FOR_ACCESSIBILITY_YES );
    }
}
 
Example #20
Source File: PanView.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
public PanView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Sets up interactions
    mGestureDetector = new GestureDetector(context, new ScrollFlingGestureListener());
    mScroller = new OverScroller(context);
    mEdgeEffectLeft = new EdgeEffect(context);
    mEdgeEffectTop = new EdgeEffect(context);
    mEdgeEffectRight = new EdgeEffect(context);
    mEdgeEffectBottom = new EdgeEffect(context);

    mDrawBlurredPaint = new Paint();
    mDrawBlurredPaint.setDither(true);
}
 
Example #21
Source File: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void setScrollViewEdgeEffectColor(ScrollView scrollView, int color)
{
    if (Build.VERSION.SDK_INT >= 21)
    {
        try
        {
            Field field = ScrollView.class.getDeclaredField("mEdgeGlowTop");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowTop = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowTop != null)
            {
                mEdgeGlowTop.setColor(color);
            }

            field = ScrollView.class.getDeclaredField("mEdgeGlowBottom");
            field.setAccessible(true);
            EdgeEffect mEdgeGlowBottom = (EdgeEffect) field.get(scrollView);
            if (mEdgeGlowBottom != null)
            {
                mEdgeGlowBottom.setColor(color);
            }
        }
        catch (Exception e)
        {
            FileLog.e(e);
        }
    }
}
 
Example #22
Source File: FreeFlowContainer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * Controls whether the edge glows are enabled or not
 */
public void setEdgeEffectsEnabled(boolean val) {
	mEdgeEffectsEnabled = val;
	if (val) {
		Context context = getContext();
		setWillNotDraw(false);
		mLeftEdge = new EdgeEffect(context);
		mRightEdge = new EdgeEffect(context);
		mTopEdge = new EdgeEffect(context);
		mBottomEdge = new EdgeEffect(context);
	} else {
		setWillNotDraw(true);
		mLeftEdge = mRightEdge = mTopEdge = mBottomEdge = null;
	}
}
 
Example #23
Source File: FreeFlowContainer.java    From FreeFlow with Apache License 2.0 5 votes vote down vote up
/**
 * Controls whether the edge glows are enabled or not
 */
public void setEdgeEffectsEnabled(boolean val) {
	mEdgeEffectsEnabled = val;
	if (val) {
		Context context = getContext();
		setWillNotDraw(false);
		mLeftEdge = new EdgeEffect(context);
		mRightEdge = new EdgeEffect(context);
		mTopEdge = new EdgeEffect(context);
		mBottomEdge = new EdgeEffect(context);
	} else {
		setWillNotDraw(true);
		mLeftEdge = mRightEdge = mTopEdge = mBottomEdge = null;
	}
}
 
Example #24
Source File: EdgeEffectCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static void setSize(Object edgeEffect, int width, int height) {
    ((EdgeEffect) edgeEffect).setSize(width, height);
}
 
Example #25
Source File: EdgeEffectCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static boolean onPull(Object edgeEffect, float deltaDistance) {
    ((EdgeEffect) edgeEffect).onPull(deltaDistance);
    return true;
}
 
Example #26
Source File: EdgeEffectCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static void finish(Object edgeEffect) {
    ((EdgeEffect) edgeEffect).finish();
}
 
Example #27
Source File: EdgeEffectCompatIcs.java    From guideshow with MIT License 4 votes vote down vote up
public static boolean draw(Object edgeEffect, Canvas canvas) {
    return ((EdgeEffect) edgeEffect).draw(canvas);
}
 
Example #28
Source File: EdgeEffectCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static Object newEdgeEffect(Context context) {
    return new EdgeEffect(context);
}
 
Example #29
Source File: EdgeEffectCompatIcs.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static boolean isFinished(Object edgeEffect) {
    return ((EdgeEffect) edgeEffect).isFinished();
}
 
Example #30
Source File: EdgeEffectCompatIcs.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static boolean isFinished(Object edgeEffect) {
    return ((EdgeEffect) edgeEffect).isFinished();
}