Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 7314032

Browse files
authored
fix: hdr-auto-brightness patch (#74)
1 parent 134d7e3 commit 7314032

6 files changed

Lines changed: 61 additions & 16 deletions

File tree

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
package app.revanced.integrations.patches;
22

3+
import android.view.WindowManager;
4+
35
import app.revanced.integrations.settings.SettingsEnum;
6+
import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;
47

8+
/**
9+
* Patch class for 'hdr-max-brightness' patch
10+
*
11+
* @usedBy app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch
12+
* @smali app/revanced/integrations/patches/HDRMaxBrightnessPatch
13+
*/
514
public class HDRMaxBrightnessPatch {
6-
7-
//Used by app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch
15+
/**
16+
* get brightness override for HDR brightness
17+
*
18+
* @param original brightness youtube would normally set
19+
* @return brightness to set on HRD video
20+
* @smali getHDRBrightness(F)F
21+
*/
822
public static float getHDRBrightness(float original) {
9-
if (!SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getBoolean()) return original;
10-
//return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getBoolean() ? BrightnessHelper.getBrightness() : -1.0f;
11-
return -1;
12-
}
23+
// do nothing if disabled
24+
if (!SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.getBoolean()) {
25+
return original;
26+
}
1327

28+
// override with brightness set by swipe-controls
29+
// only when swipe-controls is active and has overridden the brightness
30+
final SwipeControlsHostLayout swipeControlsHost = SwipeControlsPatch.CURRENT_HOST.get();
31+
if (swipeControlsHost != null
32+
&& swipeControlsHost.getScreen() != null
33+
&& swipeControlsHost.getConfig().getEnableBrightnessControl()
34+
&& !swipeControlsHost.getScreen().isDefaultBrightness()) {
35+
return swipeControlsHost.getScreen().getRawScreenBrightness();
36+
}
37+
38+
// otherwise, set the brightness to auto
39+
return WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
40+
}
1441
}

app/src/main/java/app/revanced/integrations/patches/SwipeControlsPatch.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import android.app.Activity;
44

5+
import androidx.annotation.NonNull;
56
import androidx.annotation.Nullable;
67

8+
import java.lang.ref.WeakReference;
9+
710
import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;
811

912
/**
@@ -14,6 +17,14 @@
1417
*/
1518
@SuppressWarnings("unused")
1619
public class SwipeControlsPatch {
20+
21+
/**
22+
* the currently active swipe controls host.
23+
* the reference may be null!
24+
*/
25+
@NonNull
26+
public static WeakReference<SwipeControlsHostLayout> CURRENT_HOST = new WeakReference<>(null);
27+
1728
/**
1829
* Hook into the main activity lifecycle
1930
* (using onStart here, but really anything up until onResume should be fine)
@@ -24,7 +35,8 @@ public class SwipeControlsPatch {
2435
public static void WatchWhileActivity_onStartHookEX(@Nullable Object thisRef) {
2536
if (thisRef == null) return;
2637
if (thisRef instanceof Activity) {
27-
SwipeControlsHostLayout.attachTo((Activity) thisRef, false);
38+
SwipeControlsHostLayout swipeControlsHost = SwipeControlsHostLayout.attachTo((Activity) thisRef, false);
39+
CURRENT_HOST = new WeakReference<>(swipeControlsHost);
2840
}
2941
}
3042
}

app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public enum SettingsEnum {
6060
//Misc. Settings
6161
AUTOREPEAT_BUTTON_SHOWN_BOOLEAN("revanced_pref_auto_repeat_button", false),
6262
PREFERRED_AUTO_REPEAT_BOOLEAN("revanced_pref_auto_repeat", true),
63-
USE_HDR_BRIGHTNESS_BOOLEAN("revanced_pref_hdr_autobrightness", true),
63+
USE_HDR_AUTO_BRIGHTNESS_BOOLEAN("revanced_pref_hdr_autobrightness", true),
6464
TAP_SEEKING_ENABLED_BOOLEAN("revanced_enable_tap_seeking", true),
6565

6666
//Swipe controls

app/src/main/java/app/revanced/integrations/settingsmenu/ReVancedSettingsFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
159159
editTextPreference5.setSummary(editTextPreference5.getText());
160160
SettingsEnum.MAX_PLAYBACK_BUFFER_AFTER_REBUFFER_INTEGER.setValue(Integer.parseInt(editTextPreference5.getText()));
161161
}
162-
} else if (str.equals(SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getPath())) {
163-
SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) miscsPreferenceScreen.findPreference(str)).isChecked());
162+
} else if (str.equals(SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.getPath())) {
163+
SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) miscsPreferenceScreen.findPreference(str)).isChecked());
164164
} else if (str.equals(SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getPath())) {
165165
SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) xSwipeControlPreferenceScreen.findPreference(str)).isChecked());
166166
} else if (str.equals(SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.getPath())) {

app/src/main/java/app/revanced/integrations/swipecontrols/controller/ScreenBrightnessController.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ class ScreenBrightnessController(
3333
rawScreenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
3434
}
3535

36+
/**
37+
* is the screen brightness set to device- default?
38+
*/
39+
val isDefaultBrightness
40+
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
41+
3642
/**
3743
* save the current screen brightness, to be brought back using [restore]
3844
*/
3945
fun save() {
40-
if(savedScreenBrightness == null) {
46+
if (savedScreenBrightness == null) {
4147
savedScreenBrightness = rawScreenBrightness
4248
}
4349
}
@@ -55,9 +61,9 @@ class ScreenBrightnessController(
5561
/**
5662
* wrapper for the raw screen brightness in [WindowManager.LayoutParams.screenBrightness]
5763
*/
58-
private var rawScreenBrightness: Float
64+
var rawScreenBrightness: Float
5965
get() = host.window.attributes.screenBrightness
60-
set(value) {
66+
private set(value) {
6167
val attr = host.window.attributes
6268
attr.screenBrightness = value
6369
host.window.attributes = attr

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
<string name="revanced_default_codec_title">Default codec</string>
2626
<string name="revanced_discord_summary">Tap to join ReVanced on Discord</string>
2727
<string name="revanced_discord_title">Discord server</string>
28-
<string name="revanced_hdr_full_brightness_summary_off">Video brightness will follow your device\'s brightness on HDR landscape videos</string>
29-
<string name="revanced_hdr_full_brightness_summary_on">Video brightness is set to max on HDR landscape videos</string>
30-
<string name="revanced_hdr_full_brightness_title">HDR max brightness</string>
28+
<string name="revanced_hdr_full_brightness_summary_on">Video brightness will follow your device\'s brightness on HDR landscape videos</string>
29+
<string name="revanced_hdr_full_brightness_summary_off">Video brightness is set to max on HDR landscape videos</string>
30+
<string name="revanced_hdr_full_brightness_title">Override HDR Video Brightness</string>
3131
<string name="revanced_info_cards_summary_off">Info cards are hidden</string>
3232
<string name="revanced_info_cards_summary_on">Info cards are shown</string>
3333
<string name="revanced_info_cards_title">Info cards</string>

0 commit comments

Comments
 (0)