diff --git a/app/build.gradle b/app/build.gradle index 0ee2662..583b9b4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,6 +21,11 @@ android { shrinkResources true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + minifyEnabled true + shrinkResources true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } } dataBinding { enabled true diff --git a/app/src/main/java/io/philippeboisney/material/MainFragment.kt b/app/src/main/java/io/philippeboisney/material/MainFragment.kt index 92a54c3..60745a6 100644 --- a/app/src/main/java/io/philippeboisney/material/MainFragment.kt +++ b/app/src/main/java/io/philippeboisney/material/MainFragment.kt @@ -4,12 +4,11 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.view.Window -import androidx.core.app.ActivityOptionsCompat import androidx.core.util.Pair import androidx.fragment.app.Fragment import androidx.navigation.ActivityNavigatorExtras import androidx.navigation.fragment.findNavController +import io.philippeboisney.material.animation.makeSceneTransitionAnimation import io.philippeboisney.material.databinding.FragmentMainBinding import io.philippeboisney.material.model.Mail import io.philippeboisney.material.views.MailAdapter @@ -29,7 +28,7 @@ class MainFragment : Fragment(), MailAdapter.Listener { // --- override fun onClick(mail: Mail, rootView: View, imageView: View) { - val options = ActivityOptionsCompat.makeSceneTransitionAnimation( + val options = makeSceneTransitionAnimation( requireActivity(), Pair(rootView, getString(R.string.transition_root)), Pair(imageView, getString(R.string.transition_image)), diff --git a/app/src/main/java/io/philippeboisney/material/animation/AnimationUtils.kt b/app/src/main/java/io/philippeboisney/material/animation/AnimationUtils.kt new file mode 100644 index 0000000..686bbda --- /dev/null +++ b/app/src/main/java/io/philippeboisney/material/animation/AnimationUtils.kt @@ -0,0 +1,24 @@ +package io.philippeboisney.material.animation + +import android.app.Activity +import android.os.Build +import android.util.Log +import android.view.View +import android.view.Window +import androidx.core.app.ActivityOptionsCompat +import androidx.core.util.Pair + +/** + * Convenient method to avoid the Navigation Bar to blink during transitions on some devices + * @see https://stackoverflow.com/questions/26600263/how-do-i-prevent-the-status-bar-and-navigation-bar-from-animating-during-an-acti + */ +fun makeSceneTransitionAnimation(activity: Activity, vararg pairs: Pair): ActivityOptionsCompat { + val updatedPairs = pairs.toMutableList() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + val navBar = activity.findViewById(android.R.id.navigationBarBackground) + if (navBar != null) { + updatedPairs.add(Pair(navBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME)) + } + } + return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, *updatedPairs.toTypedArray()) +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 7299c50..e0d9e4f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -10,7 +10,6 @@ android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" - android:fragmentExitTransition="@transition/activity_main_exit" app:defaultNavHost="true" app:navGraph="@navigation/nav_graph_home"/> diff --git a/app/src/main/res/transition-v21/activity_detail_return.xml b/app/src/main/res/transition-v21/activity_detail_return.xml index 488b8d0..a6921eb 100644 --- a/app/src/main/res/transition-v21/activity_detail_return.xml +++ b/app/src/main/res/transition-v21/activity_detail_return.xml @@ -28,13 +28,4 @@ - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/transition-v21/activity_main_exit.xml b/app/src/main/res/transition-v21/activity_main_exit.xml index c5e9a14..4f356f4 100644 --- a/app/src/main/res/transition-v21/activity_main_exit.xml +++ b/app/src/main/res/transition-v21/activity_main_exit.xml @@ -19,13 +19,4 @@ app:endAlpha="0.3"/> - - - - - - - - - \ No newline at end of file