Added card flip animation to feed info fragment

This commit is contained in:
ByteHamster 2019-09-16 00:07:35 +02:00
parent 26e47b9efd
commit f17737e987
8 changed files with 120 additions and 5 deletions

View File

@ -32,6 +32,7 @@ import android.widget.Toast;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import de.danoeh.antennapod.fragment.TransitionEffect;
import de.danoeh.antennapod.preferences.PreferenceUpgrader; import de.danoeh.antennapod.preferences.PreferenceUpgrader;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
@ -368,15 +369,32 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
} }
} }
public void loadChildFragment(Fragment fragment) { public void loadChildFragment(Fragment fragment, TransitionEffect transition) {
Validate.notNull(fragment); Validate.notNull(fragment);
FragmentManager fm = getSupportFragmentManager(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
fm.beginTransaction()
.replace(R.id.main_view, fragment, "main") switch (transition) {
case FADE:
transaction.setCustomAnimations(R.anim.fade_in, R.anim.fade_out);
break;
case FLIP:
transaction.setCustomAnimations(
R.anim.card_flip_right_in,
R.anim.card_flip_right_out,
R.anim.card_flip_left_in,
R.anim.card_flip_left_out);
break;
}
transaction.replace(R.id.main_view, fragment, "main")
.addToBackStack(null) .addToBackStack(null)
.commit(); .commit();
} }
public void loadChildFragment(Fragment fragment) {
loadChildFragment(fragment, TransitionEffect.NONE);
}
public void dismissChildFragment() { public void dismissChildFragment() {
getSupportFragmentManager().popBackStack(); getSupportFragmentManager().popBackStack();
} }

View File

@ -516,7 +516,8 @@ public class FeedItemlistFragment extends ListFragment {
private void showFeedInfo() { private void showFeedInfo() {
if (feed != null) { if (feed != null) {
((MainActivity) getActivity()).loadChildFragment(FeedInfoFragment.newInstance(feed)); FeedInfoFragment fragment = FeedInfoFragment.newInstance(feed);
((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.FLIP);
} }
} }

View File

@ -0,0 +1,5 @@
package de.danoeh.antennapod.fragment;
public enum TransitionEffect {
NONE, FLIP, FADE
}

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<!-- Rotate. -->
<objectAnimator
android:valueFrom="-180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Rotate. -->
<objectAnimator
android:valueFrom="0"
android:valueTo="180"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Before rotating, immediately set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<!-- Rotate. -->
<objectAnimator
android:valueFrom="180"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 1. -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Rotate. -->
<objectAnimator
android:valueFrom="0"
android:valueTo="-180"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="@integer/card_flip_time_full" />
<!-- Half-way through the rotation (see startOffset), set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:startOffset="@integer/card_flip_time_half"
android:duration="1" />
</set>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="card_flip_time_full">400</integer>
<integer name="card_flip_time_half">200</integer>
</resources>