Skip to content

feat(YouTube - Swipe controls): Add separate color settings for the brightness and volume bars #5043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ public class Settings extends BaseSettings {
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final IntegerSetting SWIPE_OVERLAY_OPACITY = new IntegerSetting("revanced_swipe_overlay_background_opacity", 60, true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final StringSetting SWIPE_OVERLAY_PROGRESS_COLOR = new StringSetting("revanced_swipe_overlay_progress_color", "#FFFFFF", true,
public static final StringSetting SWIPE_OVERLAY_BRIGHTNESS_COLOR = new StringSetting("revanced_swipe_overlay_progress_brightness_color", "#FFFFFF", true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final StringSetting SWIPE_OVERLAY_VOLUME_COLOR = new StringSetting("revanced_swipe_overlay_progress_volume_color", "#FFFFFF", true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
public static final LongSetting SWIPE_OVERLAY_TIMEOUT = new LongSetting("revanced_swipe_overlay_timeout", 500L, true,
parentsAny(SWIPE_BRIGHTNESS, SWIPE_VOLUME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,38 @@ class SwipeControlsConfigurationProvider {
}

/**
* The color of the progress bar in the overlay.
* The color of the progress bar in the overlay for brightness.
* Resets to default and shows a toast if the color string is invalid or empty.
*/
val overlayProgressColor: Int
val overlayBrightnessProgressColor: Int
get() {
try {
@SuppressLint("UseKtx")
val color = Color.parseColor(Settings.SWIPE_OVERLAY_PROGRESS_COLOR.get())
val color = Color.parseColor(Settings.SWIPE_OVERLAY_BRIGHTNESS_COLOR.get())
return (0xBF000000.toInt() or (color and 0xFFFFFF))
} catch (ex: IllegalArgumentException) {
Logger.printDebug({ "Could not parse color" }, ex)
Logger.printDebug({ "Could not parse brightness color" }, ex)
Utils.showToastLong(str("revanced_swipe_overlay_progress_color_invalid_toast"))
Settings.SWIPE_OVERLAY_PROGRESS_COLOR.resetToDefault()
return overlayProgressColor // Recursively return.
Settings.SWIPE_OVERLAY_BRIGHTNESS_COLOR.resetToDefault()
return overlayBrightnessProgressColor // Recursively return.
}
}

/**
* The color of the progress bar in the overlay for volume.
* Resets to default and shows a toast if the color string is invalid or empty.
*/
val overlayVolumeProgressColor: Int
get() {
try {
@SuppressLint("UseKtx")
val color = Color.parseColor(Settings.SWIPE_OVERLAY_VOLUME_COLOR.get())
return (0xBF000000.toInt() or (color and 0xFFFFFF))
} catch (ex: IllegalArgumentException) {
Logger.printDebug({ "Could not parse volume color" }, ex)
Utils.showToastLong(str("revanced_swipe_overlay_progress_color_invalid_toast"))
Settings.SWIPE_OVERLAY_VOLUME_COLOR.resetToDefault()
return overlayVolumeProgressColor // Recursively return.
}
}

Expand Down Expand Up @@ -199,7 +217,7 @@ class SwipeControlsConfigurationProvider {
/**
* A minimal vertical progress bar.
*/
VERTICAL_MINIMAL(isMinimal = true, isVertical = true)
VERTICAL_MINIMAL(isMinimal = true, isVertical = true)
}

/**
Expand Down Expand Up @@ -229,4 +247,4 @@ class SwipeControlsConfigurationProvider {
get() = Settings.SWIPE_BRIGHTNESS_VALUE.get()
set(value) = Settings.SWIPE_BRIGHTNESS_VALUE.save(value)
//endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SwipeControlsOverlayLayout(

constructor(context: Context) : this(context, SwipeControlsConfigurationProvider())

// Drawable icons for brightness and volume
// Drawable icons for brightness and volume.
private val autoBrightnessIcon: Drawable = getDrawable("revanced_ic_sc_brightness_auto")
private val lowBrightnessIcon: Drawable = getDrawable("revanced_ic_sc_brightness_low")
private val mediumBrightnessIcon: Drawable = getDrawable("revanced_ic_sc_brightness_medium")
Expand All @@ -50,7 +50,7 @@ class SwipeControlsOverlayLayout(
private val normalVolumeIcon: Drawable = getDrawable("revanced_ic_sc_volume_normal")
private val fullVolumeIcon: Drawable = getDrawable("revanced_ic_sc_volume_high")

// Function to retrieve drawable resources by name
// Function to retrieve drawable resources by name.
private fun getDrawable(name: String): Drawable {
val drawable = resources.getDrawable(
Utils.getResourceIdentifier(context, name, "drawable"),
Expand All @@ -60,38 +60,38 @@ class SwipeControlsOverlayLayout(
return drawable
}

// Initialize progress bars
// Initialize progress bars.
private val circularProgressView: CircularProgressView
private val horizontalProgressView: HorizontalProgressView
private val verticalBrightnessProgressView: VerticalProgressView
private val verticalVolumeProgressView: VerticalProgressView

init {
// Initialize circular progress bar
// Initialize circular progress bar.
circularProgressView = CircularProgressView(
context,
config.overlayBackgroundOpacity,
config.overlayStyle.isMinimal,
config.overlayProgressColor,
config.overlayBrightnessProgressColor, // Placeholder, updated in showFeedbackView.
config.overlayFillBackgroundPaint,
config.overlayTextColor,
config.overlayTextSize
).apply {
layoutParams = LayoutParams(100f.toDisplayPixels().toInt(), 100f.toDisplayPixels().toInt()).apply {
addRule(CENTER_IN_PARENT, TRUE)
}
visibility = GONE // Initially hidden
visibility = GONE // Initially hidden.
}
addView(circularProgressView)

// Initialize horizontal progress bar
// Initialize horizontal progress bar.
val screenWidth = resources.displayMetrics.widthPixels
val layoutWidth = (screenWidth * 4 / 5).toInt() // Cap at ~360dp
val layoutWidth = (screenWidth * 4 / 5).toInt() // Cap at ~360dp.
horizontalProgressView = HorizontalProgressView(
context,
config.overlayBackgroundOpacity,
config.overlayStyle.isMinimal,
config.overlayProgressColor,
config.overlayBrightnessProgressColor, // Placeholder, updated in showFeedbackView.
config.overlayFillBackgroundPaint,
config.overlayTextColor,
config.overlayTextSize
Expand All @@ -104,16 +104,16 @@ class SwipeControlsOverlayLayout(
topMargin = 20f.toDisplayPixels().toInt()
}
}
visibility = GONE // Initially hidden
visibility = GONE // Initially hidden.
}
addView(horizontalProgressView)

// Initialize vertical progress bar for brightness (right side)
// Initialize vertical progress bar for brightness (right side).
verticalBrightnessProgressView = VerticalProgressView(
context,
config.overlayBackgroundOpacity,
config.overlayStyle.isMinimal,
config.overlayProgressColor,
config.overlayBrightnessProgressColor,
config.overlayFillBackgroundPaint,
config.overlayTextColor,
config.overlayTextSize
Expand All @@ -123,16 +123,16 @@ class SwipeControlsOverlayLayout(
rightMargin = 40f.toDisplayPixels().toInt()
addRule(CENTER_VERTICAL)
}
visibility = GONE // Initially hidden
visibility = GONE // Initially hidden.
}
addView(verticalBrightnessProgressView)

// Initialize vertical progress bar for volume (left side)
// Initialize vertical progress bar for volume (left side).
verticalVolumeProgressView = VerticalProgressView(
context,
config.overlayBackgroundOpacity,
config.overlayStyle.isMinimal,
config.overlayProgressColor,
config.overlayVolumeProgressColor,
config.overlayFillBackgroundPaint,
config.overlayTextColor,
config.overlayTextSize
Expand All @@ -142,12 +142,12 @@ class SwipeControlsOverlayLayout(
leftMargin = 40f.toDisplayPixels().toInt()
addRule(CENTER_VERTICAL)
}
visibility = GONE // Initially hidden
visibility = GONE // Initially hidden.
}
addView(verticalVolumeProgressView)
}

// Handler and callback for hiding progress bars
// Handler and callback for hiding progress bars.
private val feedbackHideHandler = Handler(Looper.getMainLooper())
private val feedbackHideCallback = Runnable {
circularProgressView.visibility = GONE
Expand All @@ -165,29 +165,42 @@ class SwipeControlsOverlayLayout(

val viewToShow = when {
config.overlayStyle.isCircular -> circularProgressView
config.overlayStyle.isVertical -> if (isBrightness) verticalBrightnessProgressView else verticalVolumeProgressView
config.overlayStyle.isVertical ->
if (isBrightness)
verticalBrightnessProgressView
else
verticalVolumeProgressView
else -> horizontalProgressView
}
viewToShow.apply {
// Set the appropriate progress color.
if (this is CircularProgressView || this is HorizontalProgressView) {
setProgressColor(
if (isBrightness)
config.overlayBrightnessProgressColor
else
config.overlayVolumeProgressColor
)
}
setProgress(progress, max, value, isBrightness)
this.icon = icon
visibility = VISIBLE
}
}

// Handle volume change
// Handle volume change.
override fun onVolumeChanged(newVolume: Int, maximumVolume: Int) {
val volumePercentage = (newVolume.toFloat() / maximumVolume) * 100
val icon = when {
newVolume == 0 -> mutedVolumeIcon
volumePercentage < 33 -> lowVolumeIcon
volumePercentage < 66 -> normalVolumeIcon
volumePercentage < 25 -> lowVolumeIcon
volumePercentage < 50 -> normalVolumeIcon
else -> fullVolumeIcon
}
showFeedbackView("$newVolume", newVolume, maximumVolume, icon, isBrightness = false)
}

// Handle brightness change
// Handle brightness change.
override fun onBrightnessChanged(brightness: Double) {
if (config.shouldLowestValueEnableAutoBrightness && brightness <= 0) {
val displayText = if (config.overlayStyle.isVertical) "А"
Expand All @@ -206,7 +219,7 @@ class SwipeControlsOverlayLayout(
}
}

// Begin swipe session
// Begin swipe session.
override fun onEnterSwipeSession() {
if (config.shouldEnableHapticFeedback) {
@Suppress("DEPRECATION")
Expand All @@ -233,25 +246,41 @@ abstract class AbstractProgressView(
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

// Combined paint creation function for both fill and stroke styles
private fun createPaint(color: Int, style: Paint.Style = Paint.Style.FILL, strokeCap: Paint.Cap = Paint.Cap.BUTT, strokeWidth: Float = 0f) = Paint(Paint.ANTI_ALIAS_FLAG).apply {
// Combined paint creation function for both fill and stroke styles.
private fun createPaint(
color: Int,
style: Paint.Style = Paint.Style.FILL,
strokeCap: Paint.Cap = Paint.Cap.BUTT,
strokeWidth: Float = 0f
) = Paint(Paint.ANTI_ALIAS_FLAG).apply {
this.style = style
this.color = color
this.strokeCap = strokeCap
this.strokeWidth = strokeWidth
}

// Initialize paints
val backgroundPaint = createPaint(overlayBackgroundOpacity, style = Paint.Style.FILL)
val progressPaint = createPaint(overlayProgressColor, style = Paint.Style.STROKE, strokeCap = Paint.Cap.ROUND, strokeWidth = 6f.toDisplayPixels())
val fillBackgroundPaint = createPaint(overlayFillBackgroundPaint, style = Paint.Style.FILL)
val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = overlayTextColor
// Initialize paints.
val backgroundPaint = createPaint(
overlayBackgroundOpacity,
style = Paint.Style.FILL
)
val progressPaint = createPaint(
overlayProgressColor,
style = Paint.Style.STROKE,
strokeCap = Paint.Cap.ROUND,
strokeWidth = 6f.toDisplayPixels()
)
val fillBackgroundPaint = createPaint(
overlayFillBackgroundPaint,
style = Paint.Style.FILL
)
val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = overlayTextColor
textAlign = Paint.Align.CENTER
textSize = overlayTextSize.toFloat().toDisplayPixels()
textSize = overlayTextSize.toFloat().toDisplayPixels()
}

// Rect for text measurement
// Rect for text measurement.
protected val textBounds = Rect()

protected var progress = 0
Expand All @@ -268,13 +297,18 @@ abstract class AbstractProgressView(
invalidate()
}

fun setProgressColor(color: Int) {
progressPaint.color = color
invalidate()
}

protected fun measureTextWidth(text: String, paint: Paint): Int {
paint.getTextBounds(text, 0, text.length, textBounds)
return textBounds.width()
}

override fun onDraw(canvas: Canvas) {
// Base class implementation can be empty
// Base class implementation can be empty.
}
}

Expand Down Expand Up @@ -393,8 +427,8 @@ class HorizontalProgressView(
}

/**
* Calculate required width based on content
* @return Required width to display all elements
* Calculate required width based on content.
* @return Required width to display all elements.
*/
private fun calculateRequiredWidth(): Float {
textWidth = measureTextWidth(displayText, textPaint).toFloat()
Expand Down Expand Up @@ -537,8 +571,8 @@ class VerticalProgressView(
}

/**
* Calculate required height based on content
* @return Required height to display all elements
* Calculate required height based on content.
* @return Required height to display all elements.
*/
private fun calculateRequiredHeight(): Float {
return if (!isMinimalStyle) {
Expand Down Expand Up @@ -633,4 +667,4 @@ class VerticalProgressView(
super.setProgress(value, max, text, isBrightnessMode)
requestLayout()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ private val swipeControlsResourcePatch = resourcePatch {
summaryKey = null,
),
TextPreference("revanced_swipe_overlay_background_opacity", inputType = InputType.NUMBER),
TextPreference("revanced_swipe_overlay_progress_color",
TextPreference("revanced_swipe_overlay_progress_brightness_color",
tag = "app.revanced.extension.shared.settings.preference.ColorPickerPreference",
inputType = InputType.TEXT_CAP_CHARACTERS),
TextPreference("revanced_swipe_overlay_progress_volume_color",
tag = "app.revanced.extension.shared.settings.preference.ColorPickerPreference",
inputType = InputType.TEXT_CAP_CHARACTERS),
TextPreference("revanced_swipe_text_overlay_size", inputType = InputType.NUMBER),
Expand Down
6 changes: 4 additions & 2 deletions patches/src/main/resources/addresources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,10 @@ Adjust volume by swiping vertically on the right side of the screen"</string>
<string name="revanced_swipe_overlay_background_opacity_title">Swipe overlay background opacity</string>
<string name="revanced_swipe_overlay_background_opacity_summary">Opacity value between 0-100</string>
<string name="revanced_swipe_overlay_background_opacity_invalid_toast">Swipe opacity must be between 0-100</string>
<string name="revanced_swipe_overlay_progress_color_title">Swipe overlay progress bar color</string>
<string name="revanced_swipe_overlay_progress_color_summary">The color of the progress bar for volume and brightness controls</string>
<string name="revanced_swipe_overlay_progress_brightness_color_title">Swipe overlay brightness color</string>
<string name="revanced_swipe_overlay_progress_brightness_color_summary">The color of the progress bar for brightness controls</string>
<string name="revanced_swipe_overlay_progress_volume_color_title">Swipe overlay volume color</string>
<string name="revanced_swipe_overlay_progress_volume_color_summary">The color of the progress bar for volume controls</string>
<string name="revanced_swipe_overlay_progress_color_invalid_toast">Invalid progress bar color</string>
<string name="revanced_swipe_text_overlay_size_title">Swipe overlay text size</string>
<string name="revanced_swipe_text_overlay_size_summary">The text size for swipe overlay between 1-30</string>
Expand Down