mihon/app/src/main/java/eu/kanade/tachiyomi/widget/ElevationAppBarLayout.kt

43 lines
1.2 KiB
Kotlin
Raw Normal View History

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
import com.google.android.material.R
import com.google.android.material.appbar.AppBarLayout
class ElevationAppBarLayout @JvmOverloads constructor(
2020-02-26 18:03:34 -05:00
context: Context,
attrs: AttributeSet? = null
) : AppBarLayout(context, attrs) {
private var origStateAnimator: StateListAnimator? = null
init {
origStateAnimator = stateListAnimator
}
fun enableElevation() {
stateListAnimator = origStateAnimator
}
fun disableElevation() {
stateListAnimator = StateListAnimator().apply {
val objAnimator = ObjectAnimator.ofFloat(this, "elevation", 0f)
// 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
)
// Default enabled state
addState(intArrayOf(android.R.attr.enabled), objAnimator)
// Disabled state
addState(IntArray(0), objAnimator)
}
}
}