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
|
|
|
|
import android.os.Build
|
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
|
|
|
import android.util.AttributeSet
|
|
|
|
|
|
|
|
class ElevationAppBarLayout @JvmOverloads constructor(
|
|
|
|
context: Context,
|
|
|
|
attrs: AttributeSet? = null
|
|
|
|
) : AppBarLayout(context, attrs) {
|
|
|
|
|
|
|
|
private var origStateAnimator: StateListAnimator? = null
|
|
|
|
|
|
|
|
init {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
origStateAnimator = stateListAnimator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun enableElevation() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
stateListAnimator = origStateAnimator
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun disableElevation() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
stateListAnimator = StateListAnimator().apply {
|
|
|
|
val objAnimator = ObjectAnimator.ofFloat(this, "elevation", 0f)
|
|
|
|
|
|
|
|
// Enabled and collapsible, but not collapsed means not elevated
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-05 11:29:27 -05:00
|
|
|
}
|