2017-01-22 17:13:07 -05:00
|
|
|
package eu.kanade.tachiyomi.widget
|
|
|
|
|
|
|
|
import android.animation.ObjectAnimator
|
|
|
|
import android.animation.StateListAnimator
|
|
|
|
import android.content.Context
|
2020-01-28 22:47:57 -05:00
|
|
|
import android.util.AttributeSet
|
2020-01-05 11:29:27 -05:00
|
|
|
import com.google.android.material.R
|
|
|
|
import com.google.android.material.appbar.AppBarLayout
|
2017-01-22 17:13:07 -05:00
|
|
|
|
|
|
|
class ElevationAppBarLayout @JvmOverloads constructor(
|
2020-02-26 18:03:34 -05:00
|
|
|
context: Context,
|
|
|
|
attrs: AttributeSet? = null
|
2017-01-22 17:13:07 -05:00
|
|
|
) : AppBarLayout(context, attrs) {
|
|
|
|
|
|
|
|
private var origStateAnimator: StateListAnimator? = null
|
|
|
|
|
|
|
|
init {
|
2020-01-07 18:46:31 -05:00
|
|
|
origStateAnimator = stateListAnimator
|
2017-01-22 17:13:07 -05:00
|
|
|
}
|
|
|
|
|
2020-08-10 12:04:51 -04:00
|
|
|
fun enableElevation(liftOnScroll: Boolean) {
|
2021-04-19 15:29:00 -04:00
|
|
|
setElevation(liftOnScroll)
|
2021-01-18 17:24:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun setElevation(liftOnScroll: Boolean) {
|
2020-01-07 18:46:31 -05:00
|
|
|
stateListAnimator = origStateAnimator
|
2020-08-10 12:04:51 -04:00
|
|
|
isLiftOnScroll = liftOnScroll
|
2017-01-22 17:13:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fun disableElevation() {
|
2020-01-07 18:46:31 -05:00
|
|
|
stateListAnimator = StateListAnimator().apply {
|
|
|
|
val objAnimator = ObjectAnimator.ofFloat(this, "elevation", 0f)
|
2017-01-22 17:13:07 -05:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Enabled and collapsible, but not collapsed means not elevated
|
2020-04-25 14:24:45 -04:00
|
|
|
addState(
|
|
|
|
intArrayOf(android.R.attr.enabled, R.attr.state_collapsible, -R.attr.state_collapsed),
|
|
|
|
objAnimator
|
|
|
|
)
|
2017-01-22 17:13:07 -05:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Default enabled state
|
|
|
|
addState(intArrayOf(android.R.attr.enabled), objAnimator)
|
2017-01-22 17:13:07 -05:00
|
|
|
|
2020-01-07 18:46:31 -05:00
|
|
|
// Disabled state
|
|
|
|
addState(IntArray(0), objAnimator)
|
2017-01-22 17:13:07 -05:00
|
|
|
}
|
|
|
|
}
|
2020-01-05 11:29:27 -05:00
|
|
|
}
|