-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
450 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/skl/permissiontool/springyanimator/SpringAnimationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.skl.permissiontool.springyanimator; | ||
|
||
/** | ||
* Created by salman on 21/11/16. | ||
*/ | ||
|
||
public enum SpringAnimationType { | ||
TRANSLATEX, | ||
TRANSLATEY, | ||
ROTATEX, | ||
ROTATEY, | ||
SCALEXY, | ||
SCALEX, | ||
SCALEY, | ||
ALPHA, | ||
ROTATION | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/skl/permissiontool/springyanimator/SpringyAdapterAnimationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.skl.permissiontool.springyanimator; | ||
|
||
/** | ||
* Created by Zach on 7/1/2017. | ||
*/ | ||
|
||
public enum SpringyAdapterAnimationType { | ||
SLIDE_FROM_BOTTOM, | ||
SLIDE_FROM_RIGHT, | ||
SLIDE_FROM_LEFT, | ||
SCALE | ||
} |
183 changes: 183 additions & 0 deletions
183
app/src/main/java/com/skl/permissiontool/springyanimator/SpringyAdapterAnimator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
package com.skl.permissiontool.springyanimator; | ||
|
||
|
||
import android.view.View; | ||
|
||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.facebook.rebound.SimpleSpringListener; | ||
import com.facebook.rebound.Spring; | ||
import com.facebook.rebound.SpringConfig; | ||
import com.facebook.rebound.SpringSystem; | ||
import com.facebook.rebound.SpringUtil; | ||
|
||
|
||
/** | ||
* Created by Zach on 6/30/2017. | ||
*/ | ||
|
||
public class SpringyAdapterAnimator { | ||
|
||
private static final int INIT_DELAY = 100; | ||
|
||
private static final int INIT_TENSION = 200; | ||
private static final int INIT_FRICTION = 20; | ||
|
||
private int tension; | ||
private int fraction ; | ||
|
||
|
||
private static final int PER_ITEM_GAPE = 100; | ||
|
||
private int parentHeight; | ||
private int parentWidth; | ||
private RecyclerView parent; | ||
private SpringSystem mSpringSystem; | ||
private SpringyAdapterAnimationType animationType; | ||
private boolean mFirstViewInit = true; | ||
private int mLastPosition = -1; | ||
private int mStartDelay; | ||
|
||
public SpringyAdapterAnimator(RecyclerView recyclerView) { | ||
parent = recyclerView; | ||
mSpringSystem = SpringSystem.create(); | ||
animationType = SpringyAdapterAnimationType.SLIDE_FROM_BOTTOM; | ||
parentHeight = parent.getResources().getDisplayMetrics().heightPixels; | ||
parentWidth = parent.getResources().getDisplayMetrics().widthPixels; | ||
mStartDelay = INIT_DELAY; | ||
tension = INIT_TENSION; | ||
fraction= INIT_FRICTION; | ||
} | ||
/* | ||
* setInitDelay @param initDelay for set delay at screen creation | ||
* */ | ||
public void setInitDelay(int initDelay){ | ||
mStartDelay = initDelay; | ||
} | ||
|
||
public void setSpringAnimationType(SpringyAdapterAnimationType type){ | ||
animationType = type; | ||
} | ||
|
||
|
||
public void addConfig(int tension,int fraction){ | ||
this.tension = tension; | ||
this.fraction = fraction; | ||
} | ||
|
||
/** | ||
* onSpringyItemCreate call in Adapter's Constructor method | ||
* @param item itemView instance from RecyclerView's OnCreateView method | ||
* **/ | ||
public void onSpringItemCreate(View item) { | ||
|
||
if (mFirstViewInit) { | ||
setAnimation(item, mStartDelay, tension, fraction); | ||
mStartDelay += PER_ITEM_GAPE; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* * onSpringyItemBind call in RecyclerView's onBind for scroll effects | ||
* @param item itemView instance from RecyclerView's onBind method | ||
* @param position from RecyclerView's onBind method | ||
* **/ | ||
public void onSpringItemBind(View item, int position) { | ||
|
||
if (!mFirstViewInit && position > mLastPosition) { | ||
setAnimation(item, 0, tension - tension/4, fraction); | ||
mLastPosition = position; | ||
} | ||
} | ||
|
||
|
||
private void setAnimation(final View item, final int delay, | ||
final int tension, final int friction) { | ||
setInitValue(item); | ||
Runnable startAnimation = new Runnable() { | ||
@Override | ||
public void run() { | ||
SpringConfig config = new SpringConfig(tension, friction); | ||
Spring spring = mSpringSystem.createSpring(); | ||
spring.setSpringConfig(config); | ||
spring.addListener(new SimpleSpringListener() { | ||
@Override | ||
public void onSpringUpdate(Spring spring) { | ||
switch (animationType) { | ||
case SLIDE_FROM_BOTTOM: | ||
item.setTranslationY(getMappedValue(spring)); | ||
break; | ||
case SLIDE_FROM_LEFT: | ||
item.setTranslationX(getMappedValue(spring)); | ||
break; | ||
case SLIDE_FROM_RIGHT: | ||
item.setTranslationX(getMappedValue(spring)); | ||
break; | ||
case SCALE: | ||
item.setScaleX(getMappedValue(spring)); | ||
item.setScaleY(getMappedValue(spring)); | ||
break; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void onSpringEndStateChange(Spring spring) { | ||
mFirstViewInit = false; | ||
} | ||
}); | ||
spring.setEndValue(1); | ||
|
||
} | ||
}; | ||
|
||
parent.postDelayed(startAnimation, delay); | ||
} | ||
|
||
private void setInitValue(View item) { | ||
|
||
switch (animationType) { | ||
case SLIDE_FROM_BOTTOM: | ||
item.setTranslationY(parentHeight); | ||
break; | ||
case SLIDE_FROM_LEFT: | ||
item.setTranslationX(-parentWidth); | ||
break; | ||
case SLIDE_FROM_RIGHT: | ||
item.setTranslationX(parentWidth); | ||
break; | ||
case SCALE: | ||
item.setScaleX(0); | ||
item.setScaleY(0); | ||
break; | ||
default: | ||
item.setTranslationY(parentHeight); | ||
break; | ||
} | ||
} | ||
|
||
private float getMappedValue(Spring spring) { | ||
|
||
float value; | ||
switch (animationType) { | ||
case SLIDE_FROM_BOTTOM: | ||
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, parentHeight, 0); | ||
break; | ||
case SLIDE_FROM_LEFT: | ||
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, -parentWidth, 0); | ||
break; | ||
case SLIDE_FROM_RIGHT: | ||
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, parentWidth, 0); | ||
break; | ||
case SCALE: | ||
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 0, 1); | ||
break; | ||
default: | ||
value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, parentHeight, 0); | ||
break; | ||
} | ||
return value; | ||
} | ||
|
||
} |
Oops, something went wrong.