all: deslopping pt 1

This commit is contained in:
Alexander Capehart
2026-04-12 15:25:10 -06:00
parent 3f2e5bc0b1
commit fae6ff4cdf
7 changed files with 158 additions and 308 deletions
@@ -83,7 +83,7 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
binding.detailNormalToolbar.apply {
setNavigationOnClickListener { findNavController().navigateUp() }
setOnMenuItemClickListener(this@DetailFragment)
overrideOnOverflowMenuClick { onOpenParentMenu() }
setOnOverflowMenuClick { onOpenParentMenu() }
}
binding.detailRecycler.apply {
@@ -123,7 +123,7 @@ abstract class DetailFragment<P : MusicParent, C : Music> :
detailHeader.alpha = 1 - outRatio
val inRatio = max(ratio - 0.5f, 0f) * 2
animateToolbarView(binding.detailNormalToolbar.getTitleContainer(), inRatio)
animateToolbarView(binding.detailNormalToolbar.titleContainer, inRatio)
animateToolbarActionButton(
binding.detailNormalToolbar.getMenuButton(R.id.action_play),
inRatio,
@@ -48,7 +48,7 @@ abstract class SelectionFragment<VB : ViewBinding> :
// Add cancel and menu item listeners to manage what occurs with the selection.
setNavigationOnClickListener { listModel.dropSelection() }
setOnMenuItemClickListener(this@SelectionFragment)
overrideOnOverflowMenuClick {
setOnOverflowMenuClick {
listModel.openMenu(R.menu.selection, listModel.peekSelection())
}
}
@@ -279,15 +279,6 @@ class PlaybackPanelFragment :
playbackModel.song.value?.let { detailModel.showAlbum(it.album) }
}
// PlayerFastSeekOverlay.PerformListener implementation
override fun onDoubleTap() {
// Already handled by onStepForward/onStepBack
}
override fun onDoubleTapEnd() {
// Animation cleanup is handled by the overlay
}
override fun getFastSeekDirection(
portion: DisplayPortion
): PlayerFastSeekOverlay.PerformListener.FastSeekDirection {
@@ -20,7 +20,6 @@ package org.oxycblt.auxio.playback.ui.stepper
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.GestureDetector
import android.view.LayoutInflater
import android.view.MotionEvent
@@ -29,9 +28,9 @@ import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.ShapeAppearanceModel
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.UISettings
import timber.log.Timber as L
enum class DisplayPortion {
LEFT,
@@ -160,7 +159,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
private var rightFadeOutRunnable: Runnable? = null
override fun onDoubleTapStarted(portion: DisplayPortion) {
if (DEBUG) Log.d(TAG, "onDoubleTapStarted called with portion = [$portion]")
L.d("onDoubleTapStarted called with portion = [$portion]")
val shouldForward: Boolean =
performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
@@ -178,8 +177,7 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
val shouldForward: Boolean =
performListener?.getFastSeekDirection(portion)?.directionAsBoolean ?: return
if (DEBUG)
Log.d(TAG, "onDoubleTapProgressDown called with " + "shouldForward = [$shouldForward]")
L.d("onDoubleTapProgressDown called with shouldForward = [$shouldForward]")
if (shouldForward) {
handleRightOverlayTap()
@@ -187,7 +185,6 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
handleLeftOverlayTap()
}
performListener?.onDoubleTap()
performListener?.seek(forward = shouldForward)
}
@@ -270,11 +267,10 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
}
override fun onDoubleTapFinished() {
if (DEBUG) Log.d(TAG, "onDoubleTapFinished called")
L.d("onDoubleTapFinished called")
// Handle left overlay fade out
if (leftInitTap) {
performListener?.onDoubleTapEnd()
leftInitTap = false
leftSecondsView.stopAnimation()
@@ -303,7 +299,6 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
// Handle right overlay fade out
if (rightInitTap) {
performListener?.onDoubleTapEnd()
rightInitTap = false
rightSecondsView.stopAnimation()
@@ -332,9 +327,6 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
}
interface PerformListener {
fun onDoubleTap()
fun onDoubleTapEnd()
/** Determines if the playback should forward/rewind or do nothing. */
fun getFastSeekDirection(portion: DisplayPortion): FastSeekDirection
@@ -348,11 +340,9 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
}
}
override fun onTouchEvent(event: MotionEvent): Boolean {
return gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
}
override fun onTouchEvent(event: MotionEvent): Boolean =
gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
// GestureDetector.OnDoubleTapListener implementation
override fun onSingleTapConfirmed(e: MotionEvent) = false
override fun onDoubleTap(e: MotionEvent): Boolean {
@@ -376,9 +366,4 @@ class PlayerFastSeekOverlay(context: Context, attrs: AttributeSet?) :
}
override fun onDoubleTapEvent(e: MotionEvent) = false
companion object {
private const val TAG = "PlayerFastSeekOverlay"
private val DEBUG = BuildConfig.DEBUG
}
}
@@ -20,8 +20,6 @@ package org.oxycblt.auxio.ui
import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
@@ -30,244 +28,174 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes
import androidx.annotation.MenuRes
import androidx.annotation.StringRes
import androidx.annotation.StyleRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.R as AR
import androidx.appcompat.view.SupportMenuInflater
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.view.menu.MenuItemImpl
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.Toolbar
import androidx.appcompat.widget.TooltipCompat
import androidx.core.view.MenuCompat
import androidx.core.view.children
import androidx.core.view.get
import androidx.core.view.isNotEmpty
import androidx.core.view.isVisible
import androidx.core.widget.TextViewCompat
import androidx.core.view.size
import com.google.android.material.R as MR
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.ViewToolbarBinding
import org.oxycblt.auxio.util.unlikelyToBeNull
/**
* A compound toolbar view that owns its entire layout instead of piggybacking on AppCompat's
* internal Toolbar structure. It preserves the small API surface Auxio actually uses while
* rendering action items as an M3 Expressive
* [com.google.android.material.button.MaterialButtonGroup].
* Minimal MaterialToolbar replacement that implements everything with MaterialButtons compared to
* the main androidx/MDC toolbar which is more or less unusable.
*
* @author Alexander Capehart (OxygenCobalt)
*/
class AuxioToolbar
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
@AttrRes defStyleAttr: Int = androidx.appcompat.R.attr.toolbarStyle,
@AttrRes defStyleAttr: Int = AR.attr.toolbarStyle,
) : FrameLayout(context, attrs, defStyleAttr) {
private var menuItemClickListener: Toolbar.OnMenuItemClickListener? = null
private var navigationClickListener: OnClickListener? = null
private var navigationIconDrawable: Drawable? = null
private var navigationContentDescriptionText: CharSequence? = null
private var titleText: CharSequence? = null
private var subtitleText: CharSequence? = null
private var titleCentered = false
private var subtitleCentered = false
private var overflowClickListener: ((View) -> Unit)? = null
private var isInflatingInternalLayout = true
private var _binding: ViewToolbarBinding? = null
private var inflatingLayout: Boolean
private val binding: ViewToolbarBinding
get() = checkNotNull(_binding) { "Toolbar binding was not initialized" }
private var menuItemClickListener: Toolbar.OnMenuItemClickListener? = null
private var overflowClickListener: OnClickListener? = null
private val actionButtons = mutableMapOf<Int, RippleFixMaterialButton>()
@SuppressLint("RestrictedApi") private var menuBuilder = MenuBuilder(context)
init {
_binding = ViewToolbarBinding.inflate(LayoutInflater.from(context), this, true)
isInflatingInternalLayout = false
inflatingLayout = true
binding = ViewToolbarBinding.inflate(LayoutInflater.from(context), this, true)
inflatingLayout = false
clipChildren = false
clipToPadding = false
binding.toolbarRoot.clipChildren = false
binding.toolbarRoot.clipToPadding = false
binding.toolbarContentFrame.clipChildren = false
binding.toolbarContentFrame.clipToPadding = false
binding.toolbarActionGroup.clipChildren = false
binding.toolbarActionGroup.clipToPadding = false
binding.toolbarActionGroup.spacing = 0
binding.toolbarRoot.apply {
clipChildren = false
clipToPadding = false
}
binding.toolbarContentFrame.apply {
clipChildren = false
clipToPadding = false
}
binding.toolbarActionGroup.apply {
clipChildren = false
clipToPadding = false
spacing = 0
}
configureIconButton(binding.toolbarNavigationButton)
val toolbarAttrs =
context.obtainStyledAttributes(
attrs,
androidx.appcompat.R.styleable.Toolbar,
defStyleAttr,
0,
)
context.obtainStyledAttributes(attrs, AR.styleable.Toolbar, defStyleAttr, 0)
val materialToolbarAttrs =
context.obtainStyledAttributes(attrs, MR.styleable.MaterialToolbar, defStyleAttr, 0)
titleText = toolbarAttrs.getText(androidx.appcompat.R.styleable.Toolbar_title)
subtitleText = toolbarAttrs.getText(androidx.appcompat.R.styleable.Toolbar_subtitle)
binding.toolbarTitle.text = titleText
binding.toolbarSubtitle.text = subtitleText
binding.toolbarSubtitle.isVisible = !subtitleText.isNullOrEmpty()
val titleTextAppearance =
toolbarAttrs.getResourceId(
androidx.appcompat.R.styleable.Toolbar_titleTextAppearance,
0,
)
if (titleTextAppearance != 0) {
setTitleTextAppearance(titleTextAppearance)
}
val subtitleTextAppearance =
toolbarAttrs.getResourceId(
androidx.appcompat.R.styleable.Toolbar_subtitleTextAppearance,
0,
)
if (subtitleTextAppearance != 0) {
setSubtitleTextAppearance(subtitleTextAppearance)
}
val titleTextColor =
toolbarAttrs.getColorStateList(androidx.appcompat.R.styleable.Toolbar_titleTextColor)
if (titleTextColor != null) {
setTitleTextColor(titleTextColor)
}
val subtitleTextColor =
toolbarAttrs.getColorStateList(androidx.appcompat.R.styleable.Toolbar_subtitleTextColor)
if (subtitleTextColor != null) {
setSubtitleTextColor(subtitleTextColor)
}
titleCentered =
val titleCentered =
materialToolbarAttrs.getBoolean(MR.styleable.MaterialToolbar_titleCentered, false)
subtitleCentered =
materialToolbarAttrs.getBoolean(MR.styleable.MaterialToolbar_subtitleCentered, false)
updateTextGravity()
setNavigationIcon(
toolbarAttrs.getDrawable(androidx.appcompat.R.styleable.Toolbar_navigationIcon)
)
setNavigationContentDescription(
toolbarAttrs.getText(
androidx.appcompat.R.styleable.Toolbar_navigationContentDescription
binding.toolbarTitle.apply {
text = toolbarAttrs.getText(AR.styleable.Toolbar_title)
isVisible = !text.isNullOrEmpty()
gravity =
if (titleCentered) android.view.Gravity.CENTER_HORIZONTAL
else android.view.Gravity.START
textAlignment =
if (titleCentered) {
TEXT_ALIGNMENT_CENTER
} else {
TEXT_ALIGNMENT_VIEW_START
}
setTextAppearance(
toolbarAttrs.getResourceId(
AR.styleable.Toolbar_titleTextAppearance,
MR.attr.textAppearanceDisplaySmallEmphasized,
)
)
)
}
val menuResId = toolbarAttrs.getResourceId(androidx.appcompat.R.styleable.Toolbar_menu, 0)
val subtitleCentered =
materialToolbarAttrs.getBoolean(MR.styleable.MaterialToolbar_subtitleCentered, false)
binding.toolbarSubtitle.apply {
text = toolbarAttrs.getText(AR.styleable.Toolbar_subtitle)
isVisible = !text.isNullOrEmpty()
gravity =
if (subtitleCentered) android.view.Gravity.CENTER_HORIZONTAL
else android.view.Gravity.START
textAlignment =
if (subtitleCentered) {
TEXT_ALIGNMENT_CENTER
} else {
TEXT_ALIGNMENT_VIEW_START
}
setTextAppearance(
toolbarAttrs.getResourceId(
AR.styleable.Toolbar_subtitleTextAppearance,
MR.attr.textAppearanceTitleLarge,
)
)
}
binding.toolbarNavigationButton.apply {
icon = toolbarAttrs.getDrawable(AR.styleable.Toolbar_navigationIcon)
contentDescription =
toolbarAttrs.getText(AR.styleable.Toolbar_navigationContentDescription)
isVisible = icon != null
TooltipCompat.setTooltipText(this, contentDescription)
}
val menuResId = toolbarAttrs.getResourceId(AR.styleable.Toolbar_menu, 0)
toolbarAttrs.recycle()
materialToolbarAttrs.recycle()
updateNavigationButton()
updateCenterContentVisibility()
if (menuResId != 0) {
inflateMenu(menuResId)
}
}
override fun addView(child: View, index: Int, params: ViewGroup.LayoutParams?) {
val binding = _binding
if (isInflatingInternalLayout || binding == null || child === binding.root) {
override fun addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) {
if (inflatingLayout) {
super.addView(child, index, params)
return
} else {
// hardcode layoutparams because injectable children logic is insane and never
binding.toolbarTitleContainer.addView(
child,
LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT),
)
}
binding.toolbarContentFrame.addView(child, params)
updateCenterContentVisibility()
}
override fun removeView(view: View) {
val binding = _binding
if (
binding != null &&
view.parent === binding.toolbarContentFrame &&
view !== binding.toolbarTitleContainer
) {
binding.toolbarContentFrame.removeView(view)
updateCenterContentVisibility()
return
}
super.removeView(view)
override fun onFinishInflate() {
super.onFinishInflate()
}
var title: CharSequence?
get() = titleText
get() = binding.toolbarTitle.text
set(value) {
titleText = value
binding.toolbarTitle.text = value
updateCenterContentVisibility()
binding.toolbarTitle.apply {
text = value
isVisible = !text.isNullOrEmpty()
}
}
fun setTitle(@StringRes resId: Int) {
title = if (resId != 0) context.getText(resId) else null
}
var subtitle: CharSequence?
get() = subtitleText
get() = binding.toolbarSubtitle.text
set(value) {
subtitleText = value
binding.toolbarSubtitle.text = value
binding.toolbarSubtitle.isVisible = !value.isNullOrEmpty()
updateCenterContentVisibility()
binding.toolbarSubtitle.apply {
text = value
isVisible = !text.isNullOrEmpty()
}
}
fun setSubtitle(@StringRes resId: Int) {
subtitle = if (resId != 0) context.getText(resId) else null
}
fun setTitleTextAppearance(@StyleRes resId: Int) {
TextViewCompat.setTextAppearance(binding.toolbarTitle, resId)
}
fun setSubtitleTextAppearance(@StyleRes resId: Int) {
TextViewCompat.setTextAppearance(binding.toolbarSubtitle, resId)
}
fun setTitleTextColor(color: ColorStateList) {
binding.toolbarTitle.setTextColor(color)
}
fun setSubtitleTextColor(color: ColorStateList) {
binding.toolbarSubtitle.setTextColor(color)
}
fun setNavigationIcon(@DrawableRes resId: Int) {
setNavigationIcon(if (resId != 0) AppCompatResources.getDrawable(context, resId) else null)
}
fun setNavigationIcon(icon: Drawable?) {
navigationIconDrawable = icon
updateNavigationButton()
}
fun getNavigationIcon(): Drawable? = navigationIconDrawable
fun setNavigationContentDescription(description: CharSequence?) {
navigationContentDescriptionText = description
updateNavigationButton()
}
fun setNavigationContentDescription(@StringRes resId: Int) {
setNavigationContentDescription(if (resId != 0) context.getText(resId) else null)
}
fun getNavigationContentDescription(): CharSequence? = navigationContentDescriptionText
fun setNavigationOnClickListener(listener: OnClickListener?) {
navigationClickListener = listener
updateNavigationButton()
}
val menu: Menu
get() = menuBuilder
@SuppressLint("RestrictedApi")
fun inflateMenu(@MenuRes resId: Int) {
val builder = MenuBuilder(context)
SupportMenuInflater(context).inflate(resId, builder)
@@ -281,18 +209,24 @@ constructor(
fun getMenuButton(itemId: Int): RippleFixMaterialButton? = actionButtons[itemId]
@SuppressLint("RestrictedApi")
fun setMenuItemEnabled(itemId: Int, enabled: Boolean) {
menuBuilder.findItem(itemId)?.isEnabled = enabled
getMenuButton(itemId)?.isEnabled = enabled
}
fun getTitleContainer(): View = binding.toolbarTitleContainer
val titleContainer: View
get() = binding.toolbarTitleContainer
fun setNavigationOnClickListener(listener: OnClickListener) {
binding.toolbarNavigationButton.setOnClickListener(listener)
}
/**
* Override the overflow button's click behavior. When set, the overflow button will call
* [block] instead of showing the default popup menu.
*/
fun overrideOnOverflowMenuClick(block: (View) -> Unit) {
fun setOnOverflowMenuClick(block: OnClickListener) {
overflowClickListener = block
}
@@ -302,49 +236,6 @@ constructor(
button.iconSize = resources.getDimensionPixelSize(R.dimen.size_icon_small)
}
private fun updateNavigationButton() {
binding.toolbarNavigationButton.apply {
icon = navigationIconDrawable
contentDescription = navigationContentDescriptionText
isVisible = navigationIconDrawable != null
setOnClickListener(navigationClickListener)
TooltipCompat.setTooltipText(this, navigationContentDescriptionText)
}
}
private fun updateTextGravity() {
binding.toolbarTitle.apply {
gravity =
if (titleCentered) android.view.Gravity.CENTER_HORIZONTAL
else android.view.Gravity.START
textAlignment =
if (titleCentered) {
View.TEXT_ALIGNMENT_CENTER
} else {
View.TEXT_ALIGNMENT_VIEW_START
}
}
binding.toolbarSubtitle.apply {
gravity =
if (subtitleCentered) android.view.Gravity.CENTER_HORIZONTAL
else android.view.Gravity.START
textAlignment =
if (subtitleCentered) {
View.TEXT_ALIGNMENT_CENTER
} else {
View.TEXT_ALIGNMENT_VIEW_START
}
}
}
private fun updateCenterContentVisibility() {
val hasCustomContent =
binding.toolbarContentFrame.children.any { it !== binding.toolbarTitleContainer }
val showBuiltInTitle =
!hasCustomContent && (!titleText.isNullOrEmpty() || !subtitleText.isNullOrEmpty())
binding.toolbarTitleContainer.isVisible = showBuiltInTitle
}
@SuppressLint("RestrictedApi")
private fun rebuildActionButtons() {
actionButtons.clear()
@@ -363,49 +254,45 @@ constructor(
}
for (item in actionItems) {
createActionButton(item)?.let { button ->
binding.toolbarActionGroup.addView(button)
actionButtons[item.itemId] = button
}
val btn = createActionButton(item)
binding.toolbarActionGroup.addView(btn)
actionButtons[item.itemId] = btn
}
if (overflowItems.isNotEmpty()) {
binding.toolbarActionGroup.addView(createOverflowButton(overflowItems))
}
binding.toolbarActionGroup.isVisible = binding.toolbarActionGroup.childCount > 0
binding.toolbarActionGroup.isVisible = binding.toolbarActionGroup.isNotEmpty()
}
@SuppressLint("RestrictedApi")
private fun createActionButton(item: MenuItemImpl): RippleFixMaterialButton? {
val button =
RippleFixMaterialButton(
createActionButtonContext(item.itemId),
null,
MR.attr.materialIconButtonStyle,
)
.apply {
configureIconButton(this)
id = item.itemId
icon = item.icon
contentDescription = item.title
isEnabled = item.isEnabled
TooltipCompat.setTooltipText(this, item.title)
setOnClickListener { view ->
if (item.hasSubMenu()) {
showPopupMenu(view, item.subMenu)
} else {
menuItemClickListener?.onMenuItemClick(item)
}
private fun createActionButton(item: MenuItemImpl) =
RippleFixMaterialButton(
createActionButtonContext(item.itemId),
null,
MR.attr.materialIconButtonStyle,
)
.apply {
configureIconButton(this)
id = item.itemId
icon = item.icon
contentDescription = item.title
isEnabled = item.isEnabled
TooltipCompat.setTooltipText(this, item.title)
setOnClickListener { view ->
if (item.hasSubMenu()) {
val subMenu = unlikelyToBeNull(item.subMenu)
showPopupMenu(view, subMenu.children.toList())
} else {
menuItemClickListener?.onMenuItemClick(item)
}
}
return button
}
}
@SuppressLint("RestrictedApi")
private fun createOverflowButton(overflowItems: List<MenuItemImpl>): RippleFixMaterialButton {
return RippleFixMaterialButton(context, null, MR.attr.materialIconButtonStyle).apply {
private fun createOverflowButton(overflowItems: List<MenuItemImpl>) =
RippleFixMaterialButton(context, null, MR.attr.materialIconButtonStyle).apply {
configureIconButton(this)
setIconResource(R.drawable.ic_more_vert_24)
contentDescription = context.getString(R.string.lbl_more)
@@ -413,28 +300,16 @@ constructor(
setOnClickListener { view ->
val customListener = overflowClickListener
if (customListener != null) {
customListener(view)
customListener.onClick(view)
} else {
showPopupMenu(view, overflowItems, menuBuilder)
showPopupMenu(view, overflowItems)
}
}
}
}
private fun showPopupMenu(anchor: View, menu: Menu?) {
if (menu == null) {
return
}
showPopupMenu(anchor, List(menu.size()) { menu.getItem(it) }.filter { it.isVisible }, menu)
}
private fun showPopupMenu(anchor: View, items: List<MenuItem>, sourceMenu: Menu) {
@SuppressLint("RestrictedApi")
private fun showPopupMenu(anchor: View, items: List<MenuItem>) {
val popup = PopupMenu(context, anchor)
MenuCompat.setGroupDividerEnabled(
popup.menu,
(sourceMenu as? MenuBuilder)?.isGroupDividerEnabled ?: false,
)
val originalItems = mutableMapOf<Int, MenuItem>()
for (item in items) {
popup.menu.add(item.groupId, item.itemId, item.order, item.title).apply {
@@ -445,16 +320,10 @@ constructor(
}
originalItems[item.itemId] = item
}
popup.setOnMenuItemClickListener { clickedItem ->
val originalItem =
originalItems[clickedItem.itemId] ?: return@setOnMenuItemClickListener false
if (originalItem.hasSubMenu()) {
showPopupMenu(anchor, originalItem.subMenu)
true
} else {
menuItemClickListener?.onMenuItemClick(originalItem) ?: false
}
menuItemClickListener?.onMenuItemClick(originalItem) ?: false
}
popup.show()
}
@@ -25,11 +25,12 @@ import androidx.annotation.DrawableRes
import com.google.android.material.R
/**
* A [RippleFixMaterialButton] that works around a bug where changing the icon while the button's
* ripple/press animation is active causes a width change that "sticks". The workaround defers
* re-applying the icon until the button is no longer pressed.
* [RippleFixMaterialButton] that works around another bug where switching the icon during a press
* breaks width expansion animations.
*
* @author Alexander Capehart (OxygenCobalt)
*
* TODO: Should animate icon transitions to make this look less bad.
*/
class WidthFixMaterialButton
@JvmOverloads
@@ -60,6 +61,7 @@ constructor(
override fun setIconResource(@DrawableRes iconRes: Int) {
super.setIconResource(iconRes)
pendingIconRes = iconRes
postOnAnimation(applyPendingIconRunnable)
removeCallbacks(applyPendingIconRunnable)
postOnAnimation(applyPendingIconRunnable)
}
+4 -1
View File
@@ -44,6 +44,7 @@
android:includeFontPadding="false"
android:maxLines="1"
android:singleLine="true"
android:textAppearance="?attr/textAppearanceDisplaySmallEmphasized"
android:textColor="?attr/colorOnSurface" />
<TextView
@@ -54,8 +55,10 @@
android:includeFontPadding="false"
android:maxLines="1"
android:singleLine="true"
android:textColor="?android:attr/textColorSecondary"
android:textColor="?attr/colorOnSurfaceVariant"
android:visibility="gone" />
</LinearLayout>
</FrameLayout>