Shared element transition of cover

This commit is contained in:
ByteHamster 2017-10-21 20:52:29 +02:00
parent 93c59875b2
commit 30c7ca5437
6 changed files with 40 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Menu;
@ -368,7 +369,16 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
View cover = findViewById(R.id.imgvCover);
if (cover != null && Build.VERSION.SDK_INT >= 16) {
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(MediaplayerActivity.this,
cover, "coverTransition");
startActivity(intent, options.toBundle());
} else {
startActivity(intent);
}
return true;
} else {
if (media != null) {

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.Snackbar;
@ -112,6 +113,12 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
EventBus.getDefault().unregister(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportPostponeEnterTransition();
}
@Override
protected void onStop() {
super.onStop();
@ -277,6 +284,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
pageIndicator.setViewPager(pager);
loadLastFragment();
pager.onSaveInstanceState();
navList.post(this::supportStartPostponedEnterTransition);
}
@Override

View File

@ -1,6 +1,9 @@
package de.danoeh.antennapod.fragment;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
@ -56,8 +59,15 @@ public class ExternalPlayerFragment extends Fragment {
Log.d(TAG, "layoutInfo was clicked");
if (controller != null && controller.getMedia() != null) {
startActivity(PlaybackService.getPlayerActivityIntent(
getActivity(), controller.getMedia()));
Intent intent = PlaybackService.getPlayerActivityIntent(getActivity(), controller.getMedia());
if (Build.VERSION.SDK_INT >= 16) {
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(getActivity(), imgvCover, "coverTransition");
startActivity(intent, options.toBundle());
} else {
startActivity(intent);
}
}
});
return root;

View File

@ -16,6 +16,7 @@
android:scaleType="fitCenter"
app:layout_aspectRatio="100%"
app:layout_widthPercent="82%"
android:transitionName="coverTransition"
tools:src="@android:drawable/sym_def_app_icon" />
<LinearLayout

View File

@ -22,6 +22,7 @@
android:scaleType="centerCrop"
tools:src="@drawable/ic_drag_vertical_white_48dp"
tools:background="@android:color/holo_green_dark"
android:transitionName="coverTransition"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>

View File

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AntennaPod.Light" parent="Theme.Base.AntennaPod.Light">
<item name="android:windowContentTransitions">true</item>
</style>
<style name="Theme.AntennaPod.Dark" parent="Theme.Base.AntennaPod.Dark">
<item name="android:windowContentTransitions">true</item>
</style>
<style name="Widget.AntennaPod.Button" parent="Widget.AppCompat.Button">
<item name="textAllCaps">true</item>