all: reformat

This commit is contained in:
Alexander Capehart
2026-02-16 12:01:58 -07:00
parent d8811c9322
commit 94673123e5
4 changed files with 63 additions and 65 deletions
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.google.android.material.progressindicator
import android.animation.Animator
@@ -46,9 +46,9 @@ import kotlin.math.roundToInt
/**
* Custom playback progress renderer with deterministic wave behavior.
*
* The base line/segment geometry is a direct port of MDC's linear determinate draw delegate,
* while wave amplitude/phase control remains local so playback can toggle waves without touching
* MDC internals.
* The base line/segment geometry is a direct port of MDC's linear determinate draw delegate, while
* wave amplitude/phase control remains local so playback can toggle waves without touching MDC
* internals.
*/
class PatchedLinearProgressIndicator
@JvmOverloads
@@ -57,14 +57,8 @@ constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = MR.attr.linearProgressIndicatorStyle,
) : View(context, attrs, defStyleAttr) {
private val trackPaint =
Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
}
private val activePaint =
Paint(Paint.ANTI_ALIAS_FLAG).apply {
style = Paint.Style.FILL
}
private val trackPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
private val activePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.FILL }
private val cachedWavePath = Path()
private val displayedWavePath = Path()
@@ -172,12 +166,7 @@ constructor(
)
val fallbackWavelength =
abs(
styledAttrs.getDimensionPixelSize(
MR.styleable.BaseProgressIndicator_wavelength,
0,
)
)
abs(styledAttrs.getDimensionPixelSize(MR.styleable.BaseProgressIndicator_wavelength, 0))
configuredWavelengthPx =
abs(
styledAttrs.getDimensionPixelSize(
@@ -345,9 +334,7 @@ constructor(
val preferredHeight = getPreferredHeight()
val centerX = contentLeft + availableWidth / 2f
val centerY =
contentTop +
availableHeight / 2f +
max(0f, (availableHeight - preferredHeight) / 2f)
contentTop + availableHeight / 2f + max(0f, (availableHeight - preferredHeight) / 2f)
canvas.save()
canvas.translate(centerX, centerY)
@@ -376,7 +363,8 @@ constructor(
if (progressFraction > 0f) {
val activeLength = progressFraction * trackLength
val shouldDrawWave =
canDrawWave(trackLength, activeLength) && (waveEnabled || waveTransitionAnimator != null)
canDrawWave(trackLength, activeLength) &&
(waveEnabled || waveTransitionAnimator != null)
val ramp =
applyRampEasing(
calculateStartRampFraction(
@@ -454,16 +442,11 @@ constructor(
clampedEnd = lerp(1f - totalTrackLengthFraction, 1f, clampedEnd)
val adjustedStartGapSize =
(startGapSize * clamp(clampedStart, 0f, GAP_TRANSITION_FRACTION) / GAP_TRANSITION_FRACTION)
(startGapSize * clamp(clampedStart, 0f, GAP_TRANSITION_FRACTION) /
GAP_TRANSITION_FRACTION)
.roundToInt()
val adjustedEndGapSize =
(endGapSize *
(1f -
clamp(
clampedEnd,
1f - GAP_TRANSITION_FRACTION,
1f,
)) /
(endGapSize * (1f - clamp(clampedEnd, 1f - GAP_TRANSITION_FRACTION, 1f)) /
GAP_TRANSITION_FRACTION)
.roundToInt()
@@ -473,8 +456,12 @@ constructor(
var startCornerRadius = displayedCornerRadius
var endCornerRadius = displayedCornerRadius
if (abs(displayedCornerRadius - displayedInnerCornerRadius) > EPSILON && trackLength > EPSILON) {
val maxCornerScale = max(displayedCornerRadius, displayedInnerCornerRadius) / trackLength
if (
abs(displayedCornerRadius - displayedInnerCornerRadius) > EPSILON &&
trackLength > EPSILON
) {
val maxCornerScale =
max(displayedCornerRadius, displayedInnerCornerRadius) / trackLength
if (maxCornerScale > EPSILON) {
startCornerRadius =
lerp(
@@ -742,15 +729,18 @@ constructor(
if (fullFraction - thresholdFraction <= EPSILON) {
1f
} else {
((progressFraction - thresholdFraction) / (fullFraction - thresholdFraction))
((progressFraction - thresholdFraction) /
(fullFraction - thresholdFraction))
.coerceIn(0f, 1f)
}
}
}
val lengthRamp =
((activeLength - calculateWaveStartLengthPx()) / calculateWaveRampLengthPx())
.coerceIn(0f, 1f)
((activeLength - calculateWaveStartLengthPx()) / calculateWaveRampLengthPx()).coerceIn(
0f,
1f,
)
return min(progressRamp, min(edgeRamp, lengthRamp))
}
@@ -777,7 +767,8 @@ constructor(
private fun calculateWaveRampLengthPx(): Float {
val wavelengthRamp = configuredWavelengthPx * WAVELENGTH_RAMP_MULTIPLIER
return max(displayedCornerRadius * 2f + indicatorTrackGapPx, wavelengthRamp).coerceAtLeast(1f)
return max(displayedCornerRadius * 2f + indicatorTrackGapPx, wavelengthRamp)
.coerceAtLeast(1f)
}
private fun useStrokeCap(): Boolean {
@@ -979,8 +970,7 @@ constructor(
val phaseScale = MIN_PHASE_SPEED_SCALE + (1f - MIN_PHASE_SPEED_SCALE) * rampScale
val amplitudeScale =
MIN_PHASE_AMPLITUDE_SCALE +
(1f - MIN_PHASE_AMPLITUDE_SCALE) * currentAmplitudeFraction
MIN_PHASE_AMPLITUDE_SCALE + (1f - MIN_PHASE_AMPLITUDE_SCALE) * currentAmplitudeFraction
val effectiveSpeed = configuredSpeedPx.toFloat() * phaseScale * amplitudeScale
if (effectiveSpeed == 0f) {
return
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.google.android.material.slider
import android.animation.Animator
@@ -33,8 +33,8 @@ import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
import androidx.annotation.Px
import com.google.android.material.progressindicator.PatchedLinearProgressIndicator
import com.google.android.material.R as MR
import com.google.android.material.progressindicator.PatchedLinearProgressIndicator
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.max
@@ -214,8 +214,8 @@ constructor(
}
/**
* Mirrors [PatchedLinearProgressIndicator.setWaveEnabled]:
* keeps geometry stable and animates internal amplitude fraction.
* Mirrors [PatchedLinearProgressIndicator.setWaveEnabled]: keeps geometry stable and animates
* internal amplitude fraction.
*/
fun setWaveEnabled(
enabled: Boolean,
@@ -616,10 +616,14 @@ constructor(
if (clipCenter != null) {
localClipHeight = min(localClipHeight, displayedTrackThickness)
localClipCornerSize =
min(localClipWidth / 2f, localClipCornerSize * localClipHeight / displayedTrackThickness)
min(
localClipWidth / 2f,
localClipCornerSize * localClipHeight / displayedTrackThickness,
)
if (clipRight) {
val leftEdgeDiff =
(clipCenter.posVec[0] - localClipCornerSize) - (drawCenter.posVec[0] - drawCornerSize)
(clipCenter.posVec[0] - localClipCornerSize) -
(drawCenter.posVec[0] - drawCornerSize)
if (leftEdgeDiff > 0f) {
clipCenter.translate(-leftEdgeDiff / 2f, 0f)
localClipWidth += leftEdgeDiff
@@ -627,7 +631,8 @@ constructor(
patchRect.set(0f, -localDrawHeight / 2f, drawWidth / 2f, localDrawHeight / 2f)
} else {
val rightEdgeDiff =
(clipCenter.posVec[0] + localClipCornerSize) - (drawCenter.posVec[0] + drawCornerSize)
(clipCenter.posVec[0] + localClipCornerSize) -
(drawCenter.posVec[0] + drawCornerSize)
if (rightEdgeDiff < 0f) {
clipCenter.translate(-rightEdgeDiff / 2f, 0f)
localClipWidth -= rightEdgeDiff
@@ -644,7 +649,12 @@ constructor(
canvas.translate(clipCenter.posVec[0], clipCenter.posVec[1])
canvas.rotate(vectorToCanvasRotation(clipCenter.tanVec))
roundedRectPath.reset()
roundedRectPath.addRoundRect(clipRect, localClipCornerSize, localClipCornerSize, Path.Direction.CCW)
roundedRectPath.addRoundRect(
clipRect,
localClipCornerSize,
localClipCornerSize,
Path.Direction.CCW,
)
canvas.clipPath(roundedRectPath)
canvas.rotate(-vectorToCanvasRotation(clipCenter.tanVec))
@@ -715,8 +725,10 @@ constructor(
return progressRamp
}
val edgeRamp =
((progressFraction - thresholdFraction) / (fullFraction - thresholdFraction))
.coerceIn(0f, 1f)
((progressFraction - thresholdFraction) / (fullFraction - thresholdFraction)).coerceIn(
0f,
1f,
)
return min(edgeRamp, progressRamp)
}
@@ -757,7 +769,9 @@ constructor(
val animator =
ValueAnimator.ofFloat(currentAmplitudeFraction, clampedTarget).apply {
duration = if (clampedTarget > currentAmplitudeFraction) WAVE_ON_DURATION_MS else WAVE_OFF_DURATION_MS
duration =
if (clampedTarget > currentAmplitudeFraction) WAVE_ON_DURATION_MS
else WAVE_OFF_DURATION_MS
addUpdateListener { animation ->
currentAmplitudeFraction = animation.animatedValue as Float
ensurePhaseTickerState()
@@ -826,7 +840,8 @@ constructor(
return
}
val progressFraction = ((value - valueFrom) / range).coerceIn(0f, 1f)
val phaseSpeedScale = applyRampEasing(calculateStartRampFraction(progressFraction, trackLength))
val phaseSpeedScale =
applyRampEasing(calculateStartRampFraction(progressFraction, trackLength))
val effectiveSpeed = speed.toFloat() * phaseSpeedScale
if (effectiveSpeed == 0f) {
return
@@ -21,7 +21,6 @@ package org.oxycblt.auxio.playback
import android.os.Bundle
import android.view.LayoutInflater
import androidx.fragment.app.activityViewModels
import com.google.android.material.R as MR
import dagger.hilt.android.AndroidEntryPoint
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentPlaybackBarBinding
@@ -31,8 +30,6 @@ import org.oxycblt.auxio.music.resolveNames
import org.oxycblt.auxio.playback.state.RepeatMode
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collectImmediately
import org.oxycblt.auxio.util.getAttrColorCompat
import org.oxycblt.auxio.util.getColorCompat
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.musikr.Song
import timber.log.Timber as L
@@ -45,8 +45,6 @@ import org.oxycblt.auxio.playback.ui.stepper.DisplayPortion
import org.oxycblt.auxio.playback.ui.stepper.PlayerFastSeekOverlay
import org.oxycblt.auxio.ui.ViewBindingFragment
import org.oxycblt.auxio.util.collectImmediately
import org.oxycblt.auxio.util.getDimen
import org.oxycblt.auxio.util.getDimenPixels
import org.oxycblt.auxio.util.showToast
import org.oxycblt.auxio.util.systemBarInsetsCompat
import org.oxycblt.musikr.MusicParent
@@ -127,22 +125,20 @@ class PlaybackPanelFragment :
// Set up actions
// TODO: Add better playback button accessibility
binding.playbackRepeat.setOnClickListener {
playbackModel.toggleRepeatMode()
}
binding.playbackRepeat.setOnClickListener { playbackModel.toggleRepeatMode() }
binding.playbackSkipPrev.setOnClickListener { playbackModel.prev() }
binding.playbackPlayPause.apply {
@SuppressLint("RestrictedApi")
setCornerSpringForce(SpringForce().apply {
stiffness = 700f
dampingRatio = 0.9f
})
setCornerSpringForce(
SpringForce().apply {
stiffness = 700f
dampingRatio = 0.9f
}
)
setOnClickListener { playbackModel.togglePlaying() }
}
binding.playbackSkipNext.setOnClickListener { playbackModel.next() }
binding.playbackShuffle.setOnClickListener {
playbackModel.toggleShuffled()
}
binding.playbackShuffle.setOnClickListener { playbackModel.toggleShuffled() }
binding.playbackMore?.setOnClickListener {
playbackModel.song.value?.let {
listModel.openMenu(R.menu.playback_song, it, PlaySong.ByItself)