Skip to content

Commit

Permalink
Fix some bug & clean code.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeBoisney committed Apr 21, 2019
1 parent f836f70 commit 72ee08e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/io/philippeboisney/material/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<View, String>): ActivityOptionsCompat {
val updatedPairs = pairs.toMutableList()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val navBar = activity.findViewById<View>(android.R.id.navigationBarBackground)
if (navBar != null) {
updatedPairs.add(Pair(navBar, Window.NAVIGATION_BAR_BACKGROUND_TRANSITION_NAME))
}
}
return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, *updatedPairs.toTypedArray())
}
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

Expand Down
9 changes: 0 additions & 9 deletions app/src/main/res/transition-v21/activity_detail_return.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,4 @@
</targets>
</fade>

<!-- Start fading those views to avoid them to blink during transition -->
<transitionSet>
<targets>
<target android:targetId="@android:id/navigationBarBackground" />
<target android:targetId="@android:id/statusBarBackground" />
</targets>
<fade />
</transitionSet>

</transitionSet>
9 changes: 0 additions & 9 deletions app/src/main/res/transition-v21/activity_main_exit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,4 @@
app:endAlpha="0.3"/>
</transitionSet>

<!-- Start fading those views to avoid them to blink during transition -->
<transitionSet>
<targets>
<target android:targetId="@android:id/navigationBarBackground" />
<target android:targetId="@android:id/statusBarBackground" />
</targets>
<fade/>
</transitionSet>

</transitionSet>

0 comments on commit 72ee08e

Please sign in to comment.