Skip to content

Commit

Permalink
fix: hdr-auto-brightness patch (ReVanced#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow578 committed Jul 11, 2022
1 parent 134d7e3 commit 7314032
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
package app.revanced.integrations.patches;

import android.view.WindowManager;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;

/**
* Patch class for 'hdr-max-brightness' patch
*
* @usedBy app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch
* @smali app/revanced/integrations/patches/HDRMaxBrightnessPatch
*/
public class HDRMaxBrightnessPatch {

//Used by app/revanced/patches/youtube/misc/hdrbrightness/patch/HDRBrightnessPatch
/**
* get brightness override for HDR brightness
*
* @param original brightness youtube would normally set
* @return brightness to set on HRD video
* @smali getHDRBrightness(F)F
*/
public static float getHDRBrightness(float original) {
if (!SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getBoolean()) return original;
//return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getBoolean() ? BrightnessHelper.getBrightness() : -1.0f;
return -1;
}
// do nothing if disabled
if (!SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.getBoolean()) {
return original;
}

// override with brightness set by swipe-controls
// only when swipe-controls is active and has overridden the brightness
final SwipeControlsHostLayout swipeControlsHost = SwipeControlsPatch.CURRENT_HOST.get();
if (swipeControlsHost != null
&& swipeControlsHost.getScreen() != null
&& swipeControlsHost.getConfig().getEnableBrightnessControl()
&& !swipeControlsHost.getScreen().isDefaultBrightness()) {
return swipeControlsHost.getScreen().getRawScreenBrightness();
}

// otherwise, set the brightness to auto
return WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import android.app.Activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.lang.ref.WeakReference;

import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;

/**
Expand All @@ -14,6 +17,14 @@
*/
@SuppressWarnings("unused")
public class SwipeControlsPatch {

/**
* the currently active swipe controls host.
* the reference may be null!
*/
@NonNull
public static WeakReference<SwipeControlsHostLayout> CURRENT_HOST = new WeakReference<>(null);

/**
* Hook into the main activity lifecycle
* (using onStart here, but really anything up until onResume should be fine)
Expand All @@ -24,7 +35,8 @@ public class SwipeControlsPatch {
public static void WatchWhileActivity_onStartHookEX(@Nullable Object thisRef) {
if (thisRef == null) return;
if (thisRef instanceof Activity) {
SwipeControlsHostLayout.attachTo((Activity) thisRef, false);
SwipeControlsHostLayout swipeControlsHost = SwipeControlsHostLayout.attachTo((Activity) thisRef, false);
CURRENT_HOST = new WeakReference<>(swipeControlsHost);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public enum SettingsEnum {
//Misc. Settings
AUTOREPEAT_BUTTON_SHOWN_BOOLEAN("revanced_pref_auto_repeat_button", false),
PREFERRED_AUTO_REPEAT_BOOLEAN("revanced_pref_auto_repeat", true),
USE_HDR_BRIGHTNESS_BOOLEAN("revanced_pref_hdr_autobrightness", true),
USE_HDR_AUTO_BRIGHTNESS_BOOLEAN("revanced_pref_hdr_autobrightness", true),
TAP_SEEKING_ENABLED_BOOLEAN("revanced_enable_tap_seeking", true),

//Swipe controls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
editTextPreference5.setSummary(editTextPreference5.getText());
SettingsEnum.MAX_PLAYBACK_BUFFER_AFTER_REBUFFER_INTEGER.setValue(Integer.parseInt(editTextPreference5.getText()));
}
} else if (str.equals(SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getPath())) {
SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) miscsPreferenceScreen.findPreference(str)).isChecked());
} else if (str.equals(SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.getPath())) {
SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) miscsPreferenceScreen.findPreference(str)).isChecked());
} else if (str.equals(SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getPath())) {
SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) xSwipeControlPreferenceScreen.findPreference(str)).isChecked());
} else if (str.equals(SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.getPath())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ class ScreenBrightnessController(
rawScreenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
}

/**
* is the screen brightness set to device- default?
*/
val isDefaultBrightness
get() = (rawScreenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)

/**
* save the current screen brightness, to be brought back using [restore]
*/
fun save() {
if(savedScreenBrightness == null) {
if (savedScreenBrightness == null) {
savedScreenBrightness = rawScreenBrightness
}
}
Expand All @@ -55,9 +61,9 @@ class ScreenBrightnessController(
/**
* wrapper for the raw screen brightness in [WindowManager.LayoutParams.screenBrightness]
*/
private var rawScreenBrightness: Float
var rawScreenBrightness: Float
get() = host.window.attributes.screenBrightness
set(value) {
private set(value) {
val attr = host.window.attributes
attr.screenBrightness = value
host.window.attributes = attr
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<string name="revanced_default_codec_title">Default codec</string>
<string name="revanced_discord_summary">Tap to join ReVanced on Discord</string>
<string name="revanced_discord_title">Discord server</string>
<string name="revanced_hdr_full_brightness_summary_off">Video brightness will follow your device\'s brightness on HDR landscape videos</string>
<string name="revanced_hdr_full_brightness_summary_on">Video brightness is set to max on HDR landscape videos</string>
<string name="revanced_hdr_full_brightness_title">HDR max brightness</string>
<string name="revanced_hdr_full_brightness_summary_on">Video brightness will follow your device\'s brightness on HDR landscape videos</string>
<string name="revanced_hdr_full_brightness_summary_off">Video brightness is set to max on HDR landscape videos</string>
<string name="revanced_hdr_full_brightness_title">Override HDR Video Brightness</string>
<string name="revanced_info_cards_summary_off">Info cards are hidden</string>
<string name="revanced_info_cards_summary_on">Info cards are shown</string>
<string name="revanced_info_cards_title">Info cards</string>
Expand Down

0 comments on commit 7314032

Please sign in to comment.