Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit 0be7f5f

Browse files
authored
Merge pull request #8 from material-components/reply/motion_interp
Add motion theming
2 parents 233dfa9 + f83e8b4 commit 0be7f5f

File tree

12 files changed

+48
-65
lines changed

12 files changed

+48
-65
lines changed

Reply/app/src/main/java/com/materialstudies/reply/ui/compose/ComposeFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import com.materialstudies.reply.data.Email
3333
import com.materialstudies.reply.data.EmailStore
3434
import com.materialstudies.reply.databinding.ComposeRecipientChipBinding
3535
import com.materialstudies.reply.databinding.FragmentComposeBinding
36-
import com.materialstudies.reply.util.FastOutUltraSlowIn
36+
import com.materialstudies.reply.util.themeInterpolator
3737
import com.materialstudies.reply.util.transition.MaterialContainerTransition
3838
import kotlin.LazyThreadSafetyMode.NONE
3939

@@ -118,12 +118,12 @@ class ComposeFragment : Fragment() {
118118
requireActivity().findViewById(R.id.fab),
119119
binding.emailCardView
120120
)
121-
duration = resources.getInteger(R.integer.reply_motion_default_duration).toLong()
122-
interpolator = FastOutUltraSlowIn()
121+
duration = resources.getInteger(R.integer.reply_motion_default_large).toLong()
122+
interpolator = requireContext().themeInterpolator(R.attr.motionInterpolatorPersistent)
123123
}
124124
returnTransition = Slide().apply {
125-
duration = resources.getInteger(R.integer.reply_motion_micro_duration).toLong()
126-
interpolator = AccelerateInterpolator()
125+
duration = resources.getInteger(R.integer.reply_motion_duration_medium).toLong()
126+
interpolator = requireContext().themeInterpolator(R.attr.motionInterpolatorOutgoing)
127127
}
128128
startPostponedEnterTransition()
129129
}

Reply/app/src/main/java/com/materialstudies/reply/ui/email/EmailFragment.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import androidx.recyclerview.widget.GridLayoutManager
2727
import com.materialstudies.reply.R
2828
import com.materialstudies.reply.data.EmailStore
2929
import com.materialstudies.reply.databinding.FragmentEmailBinding
30-
import com.materialstudies.reply.util.FastOutUltraSlowIn
30+
import com.materialstudies.reply.util.themeInterpolator
3131
import com.materialstudies.reply.util.transition.MaterialContainerTransition
3232
import kotlin.LazyThreadSafetyMode.NONE
3333

@@ -95,15 +95,15 @@ class EmailFragment : Fragment() {
9595
R.id.nested_scroll_view,
9696
correctForZOrdering = true
9797
).apply {
98-
duration = resources.getInteger(R.integer.reply_motion_default_duration).toLong()
99-
interpolator = FastOutUltraSlowIn()
98+
duration = resources.getInteger(R.integer.reply_motion_default_large).toLong()
99+
interpolator = requireContext().themeInterpolator(R.attr.motionInterpolatorPersistent)
100100
}
101101
sharedElementReturnTransition = MaterialContainerTransition(
102102
R.id.recycler_view,
103103
correctForZOrdering = true
104104
).apply {
105-
duration = resources.getInteger(R.integer.reply_motion_default_duration).toLong()
106-
interpolator = FastOutUltraSlowIn()
105+
duration = resources.getInteger(R.integer.reply_motion_default_large).toLong()
106+
interpolator = requireContext().themeInterpolator(R.attr.motionInterpolatorPersistent)
107107
}
108108
}
109109

Reply/app/src/main/java/com/materialstudies/reply/ui/home/EmailSwipeActionDrawable.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import android.graphics.RectF
2727
import android.graphics.drawable.Drawable
2828
import androidx.annotation.ColorInt
2929
import androidx.appcompat.content.res.AppCompatResources
30-
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
3130
import com.materialstudies.reply.R
3231
import com.materialstudies.reply.util.lerp
3332
import com.materialstudies.reply.util.lerpArgb
3433
import com.materialstudies.reply.util.themeColor
34+
import com.materialstudies.reply.util.themeInterpolator
3535
import kotlin.math.abs
3636
import kotlin.math.hypot
3737
import kotlin.math.sin
@@ -78,8 +78,8 @@ class EmailSwipeActionDrawable(context: Context) : Drawable() {
7878
}
7979
}
8080
private var progressAnim: ValueAnimator? = null
81-
private val dur = context.resources.getInteger(R.integer.reply_motion_short_duration)
82-
private val interp = FastOutSlowInInterpolator()
81+
private val dur = context.resources.getInteger(R.integer.reply_motion_duration_medium)
82+
private val interp = context.themeInterpolator(R.attr.motionInterpolatorPersistent)
8383

8484
override fun onBoundsChange(bounds: Rect?) {
8585
if (bounds == null) return

Reply/app/src/main/java/com/materialstudies/reply/ui/nav/BottomNavDrawerFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import com.materialstudies.reply.R
3737
import com.materialstudies.reply.data.Account
3838
import com.materialstudies.reply.data.AccountStore
3939
import com.materialstudies.reply.databinding.FragmentBottomNavDrawerBinding
40-
import com.materialstudies.reply.util.FastOutUltraSlowIn
4140
import com.materialstudies.reply.util.lerp
4241
import com.materialstudies.reply.util.themeColor
42+
import com.materialstudies.reply.util.themeInterpolator
4343
import kotlin.LazyThreadSafetyMode.NONE
4444
import kotlin.math.abs
4545

@@ -128,7 +128,9 @@ class BottomNavDrawerFragment :
128128

129129
private var sandwichState: SandwichState = SandwichState.CLOSED
130130
private var sandwichAnim: ValueAnimator? = null
131-
private val sandwichInterp = FastOutUltraSlowIn()
131+
private val sandwichInterp by lazy(NONE) {
132+
requireContext().themeInterpolator(R.attr.motionInterpolatorPersistent)
133+
}
132134
// Progress value which drives the animation of the sandwiching account picker. Responsible
133135
// for both calling progress updates and state updates.
134136
private var sandwichProgress: Float = 0F
@@ -304,7 +306,7 @@ class BottomNavDrawerFragment :
304306
addUpdateListener { sandwichProgress = animatedValue as Float }
305307
interpolator = sandwichInterp
306308
duration = (abs(newProgress - initialProgress) *
307-
resources.getInteger(R.integer.reply_motion_short_duration)).toLong()
309+
resources.getInteger(R.integer.reply_motion_duration_medium)).toLong()
308310
}
309311
sandwichAnim?.start()
310312
}

Reply/app/src/main/java/com/materialstudies/reply/util/ContextExtensions.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import android.content.Context
2121
import android.graphics.Color
2222
import android.graphics.drawable.Drawable
2323
import android.util.TypedValue
24+
import android.view.animation.AnimationUtils
25+
import android.view.animation.Interpolator
2426
import androidx.annotation.AttrRes
2527
import androidx.annotation.ColorInt
2628
import androidx.annotation.DrawableRes
@@ -47,12 +49,22 @@ fun Context.themeColor(
4749
* Retrieve a style from the current [android.content.res.Resources.Theme].
4850
*/
4951
@StyleRes
50-
fun Context.themeStyle(attr: Int): Int {
52+
fun Context.themeStyle(@AttrRes attr: Int): Int {
5153
val tv = TypedValue()
5254
theme.resolveAttribute(attr, tv, true)
5355
return tv.data
5456
}
5557

58+
@SuppressLint("Recycle")
59+
fun Context.themeInterpolator(@AttrRes attr: Int): Interpolator {
60+
return AnimationUtils.loadInterpolator(
61+
this,
62+
obtainStyledAttributes(intArrayOf(attr)).use {
63+
it.getResourceId(0, android.R.interpolator.fast_out_slow_in)
64+
}
65+
)
66+
}
67+
5668
fun Context.getDrawableOrNull(@DrawableRes id: Int?): Drawable? {
5769
return if (id == null || id == 0) null else AppCompatResources.getDrawable(this, id)
5870
}

Reply/app/src/main/java/com/materialstudies/reply/util/FastOutUltraSlowIn.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.

Reply/app/src/main/java/com/materialstudies/reply/util/transition/MaterialContainerTransition.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ private class MaterialContainerTransitionDrawable(
341341
// Fade out the startView while pinning it to the top of currentBounds and scaling it to
342342
// fit the width of currentBounds.
343343
val startAlpha = lerp(1F, 0F, alphaOutStartPoint, alphaOutEndPoint, progress)
344-
println("startAlpha: progress: $progress, $startAlpha")
345344
// Translate to pin to top
346345
if (startAlpha > 0F) {
347346
canvas.withTranslation(currentBounds.left, currentBounds.top) {

Reply/app/src/main/res/animator/fab_hide.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
android:propertyName="scale"
1818
android:valueFrom="1"
1919
android:valueTo="0"
20-
android:duration="@integer/reply_motion_micro_duration"
20+
android:duration="@integer/reply_motion_duration_small"
2121
android:repeatMode="restart"
2222
android:interpolator="@android:interpolator/fast_out_slow_in"/>
2323
<objectAnimator
2424
android:propertyName="iconScale"
2525
android:valueFrom="1"
2626
android:valueTo="0"
27-
android:duration="@integer/reply_motion_micro_duration"
27+
android:duration="@integer/reply_motion_duration_small"
2828
android:repeatMode="restart"
2929
android:interpolator="@android:interpolator/fast_out_slow_in"/>
3030
<objectAnimator
3131
android:propertyName="opacity"
3232
android:valueFrom="1"
3333
android:valueTo="0"
34-
android:duration="@integer/reply_motion_micro_duration"
34+
android:duration="@integer/reply_motion_duration_small"
3535
android:repeatMode="restart"
3636
android:interpolator="@android:interpolator/fast_out_slow_in"/>
3737
</set>

Reply/app/src/main/res/animator/fab_show.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
android:propertyName="scale"
1919
android:valueFrom="0"
2020
android:valueTo="1"
21-
android:duration="@integer/reply_motion_micro_duration"
21+
android:duration="@integer/reply_motion_duration_small"
2222
android:repeatMode="restart"
2323
android:interpolator="@android:interpolator/fast_out_slow_in"/>
2424
<objectAnimator
2525
android:propertyName="iconScale"
2626
android:valueFrom="0"
2727
android:valueTo="1"
28-
android:duration="@integer/reply_motion_micro_duration"
28+
android:duration="@integer/reply_motion_duration_small"
2929
android:repeatMode="restart"
3030
android:interpolator="@android:interpolator/fast_out_slow_in"/>
3131
<objectAnimator
3232
android:propertyName="opacity"
3333
android:valueFrom="0"
3434
android:valueTo="1"
35-
android:duration="@integer/reply_motion_micro_duration"
35+
android:duration="@integer/reply_motion_duration_small"
3636
android:repeatMode="restart"
3737
android:interpolator="@android:interpolator/fast_out_slow_in"/>
3838
</set>

Reply/app/src/main/res/values/attrs.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
<attr name="emphasisMediumAlpha" format="float"/>
2525
<attr name="emphasisDisabledAlpha" format="float"/>
2626

27+
<attr name="motionInterpolatorPersistent" format="reference"/>
28+
<attr name="motionInterpolatorIncoming" format="reference"/>
29+
<attr name="motionInterpolatorOutgoing" format="reference"/>
30+
2731
<!--Custom view themes/styles-->
2832
<attr name="bottomNavigationDrawerStyle" format="reference" />
2933
<attr name="bottomNavigationDrawerNavigationViewTheme" format="reference" />

0 commit comments

Comments
 (0)