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