mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Add slide animation definition
Add animation helper
This commit is contained in:
parent
703c9cec9c
commit
a38b7cacba
6 changed files with 90 additions and 0 deletions
|
@ -0,0 +1,62 @@
|
|||
package net.foucry.pilldroid;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnimationUtils;
|
||||
|
||||
public class SlideAnimationUtil {
|
||||
|
||||
/**
|
||||
* Animates a view so that it slides in from the left of it's container.
|
||||
*
|
||||
* @param context Context
|
||||
* @param view View
|
||||
*/
|
||||
public static void slideInFromLeft(Context context, View view) {
|
||||
runSimpleAnimation(context, view, R.anim.slide_from_left);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates a view so that it slides from its current position, out of view to the left.
|
||||
*
|
||||
* @param context Context
|
||||
* @param view View
|
||||
*/
|
||||
public static void slideOutToLeft(Context context, View view) {
|
||||
runSimpleAnimation(context, view, R.anim.slide_to_left);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates a view so that it slides in the from the right of it's container.
|
||||
*
|
||||
* @param context Context
|
||||
* @param view View
|
||||
*/
|
||||
public static void slideInFromRight(Context context, View view) {
|
||||
runSimpleAnimation(context, view, R.anim.slide_from_right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Animates a view so that it slides from its current position, out of view to the right.
|
||||
*
|
||||
* @param context Context
|
||||
* @param view View
|
||||
*/
|
||||
public static void slideOutToRight(Context context, View view) {
|
||||
runSimpleAnimation(context, view, R.anim.slide_to_right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a simple animation on a View with no extra parameters.
|
||||
*
|
||||
* @param context Context
|
||||
* @param view View
|
||||
* @param animationId int
|
||||
*/
|
||||
private static void runSimpleAnimation(Context context, View view, int animationId) {
|
||||
view.startAnimation(AnimationUtils.loadAnimation(
|
||||
context, animationId
|
||||
));
|
||||
}
|
||||
|
||||
}
|
6
app/src/main/res/anim/slide_from_left.xml
Normal file
6
app/src/main/res/anim/slide_from_left.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="-100%p" android:toXDelta="0"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="@integer/slide_animation_duration"/>
|
||||
</set>
|
6
app/src/main/res/anim/slide_from_right.xml
Normal file
6
app/src/main/res/anim/slide_from_right.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="100%p" android:toXDelta="0"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="@integer/slide_animation_duration"/>
|
||||
</set>
|
6
app/src/main/res/anim/slide_to_left.xml
Normal file
6
app/src/main/res/anim/slide_to_left.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="0" android:toXDelta="-100%p"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="@integer/slide_animation_duration"/>
|
||||
</set>
|
6
app/src/main/res/anim/slide_to_right.xml
Normal file
6
app/src/main/res/anim/slide_to_right.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<translate android:fromXDelta="0" android:toXDelta="100%p"
|
||||
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
|
||||
android:duration="@integer/slide_animation_duration"/>
|
||||
</set>
|
4
app/src/main/res/values/slide_animations_duration.xml
Normal file
4
app/src/main/res/values/slide_animations_duration.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="slide_animation_duration">300</integer>
|
||||
</resources>
|
Loading…
Reference in a new issue