public class ViewPositionAnimator
extends java.lang.Object
Animation can be performed from any view (e.g. ImageView) to any gestures controlled
view implementing GestureView (e.g. GestureImageView).
Note, that initial and final views should have same aspect ratio for correct animation.
In case of ImageView initial and final images should have same aspect, but actual views
can have different aspects (e.g. animating from square thumb view with scale type
ImageView.ScaleType.CENTER_CROP to rectangular full image view).
To use this class first create an instance and then call enter(View, boolean).
Alternatively you can manually pass initial view position using
enter(ViewPosition, boolean) method.
To exit back to initial view call exit(boolean) method.
You can listen for position changes using
addPositionUpdateListener(PositionUpdateListener).
If initial view was changed you should call update(View) method to update to new view.
You can also manually update initial view position using update(ViewPosition) method.
| Modifier and Type | Class and Description |
|---|---|
static interface |
ViewPositionAnimator.PositionUpdateListener |
| Constructor and Description |
|---|
ViewPositionAnimator(GestureView to) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPositionUpdateListener(ViewPositionAnimator.PositionUpdateListener listener)
Adds position state changes listener that will be notified during animations.
|
void |
enter(boolean withAnimation)
Starts 'enter' animation from no specific position (position will be calculated based on
gravity set in
Settings). |
void |
enter(android.view.View from,
boolean withAnimation)
Starts 'enter' animation from
from view to to. |
void |
enter(ViewPosition fromPos,
boolean withAnimation)
Starts 'enter' animation from
from position to to view. |
void |
exit(boolean withAnimation)
Starts 'exit' animation from
to view back to from. |
float |
getPosition() |
float |
getToPosition() |
boolean |
isAnimating() |
boolean |
isLeaving() |
void |
removePositionUpdateListener(ViewPositionAnimator.PositionUpdateListener listener)
Removes position state changes listener as added by
addPositionUpdateListener(PositionUpdateListener). |
void |
setState(float pos,
boolean leaving,
boolean animate)
Stops current animation and sets position state to particular values.
|
void |
setToState(State state,
float position)
Specifies target ('to') state and it's position which will be used to interpolate
current state for intermediate positions (i.e.
|
void |
stopAnimation()
Stops current animation, if any.
|
void |
update(android.view.View from)
Updates initial view in case it was changed.
|
void |
update(ViewPosition from)
Updates position of initial view in case it was changed.
|
void |
updateToNone()
Updates position of initial view to no specific position, in case 'to' view is not available
anymore.
|
public ViewPositionAnimator(@NonNull
GestureView to)
public void enter(boolean withAnimation)
Settings).
Note, that in most cases you should use enter(View, boolean) or
enter(ViewPosition, boolean) methods instead.
withAnimation - Whether to animate entering or immediately jump to entered statepublic void enter(@NonNull
android.view.View from,
boolean withAnimation)
from view to to.
Note, if from view was changed (i.e. during list adapter refresh) you should
update to new view using update(View) method.
from - 'From' viewwithAnimation - Whether to animate entering or immediately jump to entered statepublic void enter(@NonNull
ViewPosition fromPos,
boolean withAnimation)
from position to to view.
Note, if from view position was changed (i.e. during list adapter refresh) you
should update to new view using update(ViewPosition) method.
fromPos - 'From' view positionwithAnimation - Whether to animate entering or immediately jump to entered statepublic void update(@NonNull
android.view.View from)
from - New 'from' viewpublic void update(@NonNull
ViewPosition from)
from - New 'from' view positionpublic void updateToNone()
public void exit(boolean withAnimation)
to view back to from.withAnimation - Whether to animate exiting or immediately jump to initial statepublic void addPositionUpdateListener(@NonNull
ViewPositionAnimator.PositionUpdateListener listener)
listener - Position listenerpublic void removePositionUpdateListener(@NonNull
ViewPositionAnimator.PositionUpdateListener listener)
addPositionUpdateListener(PositionUpdateListener).
Note, this method may be called inside listener's callback without throwing
IndexOutOfBoundsException.
listener - Position listener to be removedpublic float getToPosition()
setToState(State, float).
Maybe useful to determine real animation position during exit gesture.
I.e. getPosition() / getToPosition() (changes from 0 to ∞)
represents interpolated position used to calculate intermediate state and bounds.
public float getPosition()
[0, 1], where 0 is for
initial (from) position and 1 is for final (to) position.
Note, that final position can be changed by setToState(State, float), so if you
need to have real value of final position (instead of 1) then you need to use
getToPosition() method.
public boolean isLeaving()
public void setToState(@NonNull
State state,
@FloatRange(from=0.0,to=1.0)
float position)
getPosition()).
Only use this method if you understand what you do.
state - Target ('to') stateposition - Target ('to') positiongetToPosition()public void setState(@FloatRange(from=0.0,to=1.0)
float pos,
boolean leaving,
boolean animate)
Note, that once animator reaches state = 0f and isLeaving = true
it will cleanup all internal stuff. So you will need to call enter(View, boolean)
or enter(ViewPosition, boolean) again in order to continue using animator.
pos - Current positionleaving - Whether we we are in exiting direction (true) or in entering
(false)animate - Whether we should start animating from given position and in given directionpublic boolean isAnimating()
public void stopAnimation()