From 4f50ac9a677225f71350dd83fae1a77f125a6512 Mon Sep 17 00:00:00 2001 From: Ali Lotfi Date: Thu, 24 Aug 2017 18:50:35 +0430 Subject: [PATCH 1/3] Add dynamic hover duration support --- .../materialripple/MaterialRippleLayout.java | 17 +++++++++++++++-- library/src/main/res/values/attributes.xml | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java b/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java index 5cb818a..856a849 100644 --- a/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java +++ b/library/src/main/java/com/balysv/materialripple/MaterialRippleLayout.java @@ -60,6 +60,7 @@ public class MaterialRippleLayout extends FrameLayout { private static final int DEFAULT_COLOR = Color.BLACK; private static final int DEFAULT_BACKGROUND = Color.TRANSPARENT; private static final boolean DEFAULT_HOVER = true; + private static final int DEFAULT_HOVER_DURATION = 2500; private static final boolean DEFAULT_DELAY_CLICK = true; private static final boolean DEFAULT_PERSISTENT = false; private static final boolean DEFAULT_SEARCH_ADAPTER = false; @@ -67,7 +68,6 @@ public class MaterialRippleLayout extends FrameLayout { private static final int DEFAULT_ROUNDED_CORNERS = 0; private static final int FADE_EXTRA_DELAY = 50; - private static final long HOVER_DURATION = 2500; private final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); private final Rect bounds = new Rect(); @@ -75,6 +75,7 @@ public class MaterialRippleLayout extends FrameLayout { private int rippleColor; private boolean rippleOverlay; private boolean rippleHover; + private int rippleHoverDuration; private int rippleDiameter; private int rippleDuration; private int rippleAlpha; @@ -132,6 +133,7 @@ public MaterialRippleLayout(Context context, AttributeSet attrs, int defStyle) { ); rippleOverlay = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleOverlay, DEFAULT_RIPPLE_OVERLAY); rippleHover = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleHover, DEFAULT_HOVER); + rippleHoverDuration = a.getInt(R.styleable.MaterialRippleLayout_mrl_rippleHoverDuration, DEFAULT_HOVER_DURATION); rippleDuration = a.getInt(R.styleable.MaterialRippleLayout_mrl_rippleDuration, DEFAULT_DURATION); rippleAlpha = (int) (255 * a.getFloat(R.styleable.MaterialRippleLayout_mrl_rippleAlpha, DEFAULT_ALPHA)); rippleDelayClick = a.getBoolean(R.styleable.MaterialRippleLayout_mrl_rippleDelayClick, DEFAULT_DELAY_CLICK); @@ -313,7 +315,7 @@ private void startHover() { } final float radius = (float) (Math.sqrt(Math.pow(getWidth(), 2) + Math.pow(getHeight(), 2)) * 1.2f); hoverAnimator = ObjectAnimator.ofFloat(this, radiusProperty, rippleDiameter, radius) - .setDuration(HOVER_DURATION); + .setDuration(rippleHoverDuration); hoverAnimator.setInterpolator(new LinearInterpolator()); hoverAnimator.start(); } @@ -575,6 +577,10 @@ public void setRippleHover(boolean rippleHover) { this.rippleHover = rippleHover; } + public void setRippleHoverDuration(int rippleHoverDuration) { + this.rippleHoverDuration = rippleHoverDuration; + } + public void setRippleDelayClick(boolean rippleDelayClick) { this.rippleDelayClick = rippleDelayClick; } @@ -699,6 +705,7 @@ public static class RippleBuilder { private int rippleColor = DEFAULT_COLOR; private boolean rippleOverlay = DEFAULT_RIPPLE_OVERLAY; private boolean rippleHover = DEFAULT_HOVER; + private int rippleHoverDuration = DEFAULT_HOVER_DURATION; private float rippleDiameter = DEFAULT_DIAMETER_DP; private int rippleDuration = DEFAULT_DURATION; private float rippleAlpha = DEFAULT_ALPHA; @@ -729,6 +736,11 @@ public RippleBuilder rippleHover(boolean hover) { return this; } + public RippleBuilder rippleHoverDuration(int hoverDuration) { + this.rippleHoverDuration = hoverDuration; + return this; + } + public RippleBuilder rippleDiameterDp(int diameterDp) { this.rippleDiameter = diameterDp; return this; @@ -783,6 +795,7 @@ public MaterialRippleLayout create() { layout.setRippleDuration(rippleDuration); layout.setRippleFadeDuration(rippleFadeDuration); layout.setRippleHover(rippleHover); + layout.setRippleHoverDuration(rippleHoverDuration); layout.setRipplePersistent(ripplePersistent); layout.setRippleOverlay(rippleOverlay); layout.setRippleBackground(rippleBackground); diff --git a/library/src/main/res/values/attributes.xml b/library/src/main/res/values/attributes.xml index 9d1b7b7..acf03d9 100644 --- a/library/src/main/res/values/attributes.xml +++ b/library/src/main/res/values/attributes.xml @@ -8,6 +8,7 @@ + From e574c7d83c61ca8653d7260f38f4c44824021268 Mon Sep 17 00:00:00 2001 From: Ali Lotfi Date: Thu, 24 Aug 2017 18:58:23 +0430 Subject: [PATCH 2/3] Modify readme to cover hover duration attribute --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e949d82..53a43a3 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ app:mrl_rippleColor="#ff0000" // color of ripple app:mrl_rippleAlpha="0.1" // alpha of ripple app:mrl_rippleDimension="10dp" // radius of hover and starting ripple app:mrl_rippleHover="true" // if true, a hover effect is drawn when view is touched +app:mrl_rippleHoverDuration="2500" // duration of hover effect app:mrl_rippleRoundedCorners="10dp" // radius of corners of ripples. Note: it uses software rendering pipeline for API 17 and below app:mrl_rippleInAdapter="true" // if true, MaterialRippleLayout will optimize for use in AdapterViews app:mrl_rippleDuration="350" // duration of ripple animation From d4136b8079dbaea89a12690caac92b7ff6cf1943 Mon Sep 17 00:00:00 2001 From: Ali Lotfi Date: Mon, 5 Sep 2022 12:59:58 +0430 Subject: [PATCH 3/3] Update README.md --- README.md | 113 +----------------------------------------------------- 1 file changed, 2 insertions(+), 111 deletions(-) diff --git a/README.md b/README.md index 53a43a3..865dc63 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,3 @@ -Material Ripple Layout -=============== +# Material Ripple Layout (with dynamic hover duration) -Ripple effect wrapper for Android Views - -![Demo Image][1] - -Including in your project -------------------------- - -```groovy -compile 'com.balysv:material-ripple:1.0.2' -``` - -Check for latest version number on the widget below or visit [Releases](https://github.com/balysv/material-ripple/releases) - -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.balysv/material-ripple/badge.svg?style=flat)](http://mvnrepository.com/artifact/com.balysv/material-ripple) - -Usage ------ - -Use static initializer on your `View` (see `xml` attributes below for customization) - -```java -MaterialRippleLayout.on(view) - .rippleColor(Color.BLACK) - .create(); -``` - -Or wrap your `View` with `MaterialRippleLayout` in your layout file: - -```xml - - -