-
Notifications
You must be signed in to change notification settings - Fork 228
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
14 changed files
with
600 additions
and
47 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
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
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
32 changes: 32 additions & 0 deletions
32
library/src/main/java/ru/noties/scrollable/CloseUpAlgorithm.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,32 @@ | ||
package ru.noties.scrollable; | ||
|
||
/** | ||
* Use this interface to handle specific *close-up* logic for {@link ScrollableLayout}, | ||
* use with {@link ScrollableLayout#setCloseUpAlgorithm(CloseUpAlgorithm)} | ||
* @see DefaultCloseUpAlgorithm | ||
* Created by Dimitry Ivanov on 22.05.2015. | ||
*/ | ||
public interface CloseUpAlgorithm { | ||
|
||
/** | ||
* This method computes end scroll y after fling event was detected | ||
* @param layout {@link ScrollableLayout} | ||
* @param isScrollingBottom whether {@link ScrollableLayout} would scroll to top or bottom | ||
* @param nowY current scroll y of the *layout* | ||
* @param suggestedY scroll y that is suggested | ||
* @param maxY current max scroll y of the *layout* | ||
* @return end scroll y value for the *layout* to animate to | ||
*/ | ||
int getFlingFinalY(ScrollableLayout layout, boolean isScrollingBottom, int nowY, int suggestedY, int maxY); | ||
|
||
/** | ||
* This method will be fired after scroll state of a {@link ScrollableLayout} would be considered idle | ||
* @param layout {@link ScrollableLayout} | ||
* @param nowY current scroll y of the *layout* | ||
* @param maxY current max scroll y of the *layout* | ||
* @see ScrollableLayout#getConsiderIdleMillis() | ||
* @see ScrollableLayout#setConsiderIdleMillis(long) | ||
* @return end scroll y value for the *layout* to animate to | ||
*/ | ||
int getIdleFinalY(ScrollableLayout layout, int nowY, int maxY); | ||
} |
18 changes: 18 additions & 0 deletions
18
library/src/main/java/ru/noties/scrollable/CloseUpAnimatorConfigurator.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,18 @@ | ||
package ru.noties.scrollable; | ||
|
||
import android.animation.ObjectAnimator; | ||
|
||
/** | ||
* This interface might be used to customize {@link android.animation.ObjectAnimator} behavior during close-up animation | ||
* @see android.animation.ObjectAnimator | ||
* @see InterpolatorCloseUpAnimatorConfigurator | ||
* Created by Dimitry Ivanov on 22.05.2015. | ||
*/ | ||
public interface CloseUpAnimatorConfigurator { | ||
|
||
/** | ||
* Note that {@link android.animation.ObjectAnimator#setDuration(long)} would erase current value set by {@link CloseUpIdleAnimationTime} if any present | ||
* @param animator current {@link android.animation.ObjectAnimator} object to animate close-up animation of a {@link ScrollableLayout} | ||
*/ | ||
void configure(ObjectAnimator animator); | ||
} |
19 changes: 19 additions & 0 deletions
19
library/src/main/java/ru/noties/scrollable/CloseUpIdleAnimationTime.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,19 @@ | ||
package ru.noties.scrollable; | ||
|
||
/** | ||
* This interface might be used to dynamically compute close-up animation time of a {@link ScrollableLayout} | ||
* @see ScrollableLayout#setCloseUpIdleAnimationTime(CloseUpIdleAnimationTime) | ||
* @see SimpleCloseUpIdleAnimationTime | ||
* Created by Dimitry Ivanov on 22.05.2015. | ||
*/ | ||
public interface CloseUpIdleAnimationTime { | ||
|
||
/** | ||
* @param layout {@link ScrollableLayout} | ||
* @param nowY current scroll y of the *layout* | ||
* @param endY scroll y value to which *layout* would scroll to | ||
* @param maxY current max scroll y value of the *layout* | ||
* @return animation duration for a close-up animation | ||
*/ | ||
long compute(ScrollableLayout layout, int nowY, int endY, int maxY); | ||
} |
27 changes: 27 additions & 0 deletions
27
library/src/main/java/ru/noties/scrollable/DefaultCloseUpAlgorithm.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,27 @@ | ||
package ru.noties.scrollable; | ||
|
||
/** | ||
* Default implementation of the {@link CloseUpAlgorithm} | ||
* With this implementation {@link ScrollableLayout} would have only two states - collapsed & expanded | ||
* @see ScrollableLayout#setCloseUpAlgorithm(CloseUpAlgorithm) | ||
* Created by Dimitry Ivanov on 23.05.2015. | ||
*/ | ||
public class DefaultCloseUpAlgorithm implements CloseUpAlgorithm { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public int getFlingFinalY(ScrollableLayout layout, boolean isScrollingBottom, int nowY, int suggestedY, int maxY) { | ||
return isScrollingBottom ? 0 : maxY; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public int getIdleFinalY(ScrollableLayout layout, int nowY, int maxY) { | ||
final boolean shouldScrollToTop = nowY < (maxY / 2); | ||
return shouldScrollToTop ? 0 : maxY; | ||
} | ||
} |
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,18 @@ | ||
package ru.noties.scrollable; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
|
||
/** | ||
* Created by Dimitry Ivanov on 23.05.2015. | ||
*/ | ||
class DipUtils { | ||
|
||
private DipUtils() {} | ||
|
||
static int dipToPx(Context context, int dip) { | ||
final Resources r = context.getResources(); | ||
final float scale = r.getDisplayMetrics().density; | ||
return (int) (dip * scale + .5F); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
library/src/main/java/ru/noties/scrollable/InterpolatorCloseUpAnimatorConfigurator.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,24 @@ | ||
package ru.noties.scrollable; | ||
|
||
import android.animation.ObjectAnimator; | ||
import android.view.animation.Interpolator; | ||
|
||
/** | ||
* Created by Dimitry Ivanov on 23.05.2015. | ||
*/ | ||
public class InterpolatorCloseUpAnimatorConfigurator implements CloseUpAnimatorConfigurator { | ||
|
||
private final Interpolator mInterpolator; | ||
|
||
public InterpolatorCloseUpAnimatorConfigurator(Interpolator interpolator) { | ||
this.mInterpolator = interpolator; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void configure(ObjectAnimator animator) { | ||
animator.setInterpolator(mInterpolator); | ||
} | ||
} |
Oops, something went wrong.