Add slide animation definition

Add animation helper
This commit is contained in:
jacques 2020-10-01 13:36:53 +02:00
parent 703c9cec9c
commit a38b7cacba
6 changed files with 90 additions and 0 deletions

View file

@ -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
));
}
}

View 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>

View 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>

View 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>

View 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>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="slide_animation_duration">300</integer>
</resources>