fix: hdr-auto-brightness patch (#74)

This commit is contained in:
Chris 2022-07-11 18:24:32 +02:00 committed by GitHub
parent 134d7e33bd
commit 7314032a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 16 deletions

View File

@ -1,14 +1,41 @@
package app.revanced.integrations.patches; package app.revanced.integrations.patches;
import android.view.WindowManager;
import app.revanced.integrations.settings.SettingsEnum; 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 { 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) { public static float getHDRBrightness(float original) {
if (!SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getBoolean()) return original; // do nothing if disabled
//return SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getBoolean() ? BrightnessHelper.getBrightness() : -1.0f; if (!SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.getBoolean()) {
return -1; 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;
}
} }

View File

@ -2,8 +2,11 @@ package app.revanced.integrations.patches;
import android.app.Activity; import android.app.Activity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.lang.ref.WeakReference;
import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout; import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;
/** /**
@ -14,6 +17,14 @@ import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class SwipeControlsPatch { 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 * Hook into the main activity lifecycle
* (using onStart here, but really anything up until onResume should be fine) * (using onStart here, but really anything up until onResume should be fine)
@ -24,7 +35,8 @@ public class SwipeControlsPatch {
public static void WatchWhileActivity_onStartHookEX(@Nullable Object thisRef) { public static void WatchWhileActivity_onStartHookEX(@Nullable Object thisRef) {
if (thisRef == null) return; if (thisRef == null) return;
if (thisRef instanceof Activity) { if (thisRef instanceof Activity) {
SwipeControlsHostLayout.attachTo((Activity) thisRef, false); SwipeControlsHostLayout swipeControlsHost = SwipeControlsHostLayout.attachTo((Activity) thisRef, false);
CURRENT_HOST = new WeakReference<>(swipeControlsHost);
} }
} }
} }

View File

@ -60,7 +60,7 @@ public enum SettingsEnum {
//Misc. Settings //Misc. Settings
AUTOREPEAT_BUTTON_SHOWN_BOOLEAN("revanced_pref_auto_repeat_button", false), AUTOREPEAT_BUTTON_SHOWN_BOOLEAN("revanced_pref_auto_repeat_button", false),
PREFERRED_AUTO_REPEAT_BOOLEAN("revanced_pref_auto_repeat", true), 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), TAP_SEEKING_ENABLED_BOOLEAN("revanced_enable_tap_seeking", true),
//Swipe controls //Swipe controls

View File

@ -159,8 +159,8 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
editTextPreference5.setSummary(editTextPreference5.getText()); editTextPreference5.setSummary(editTextPreference5.getText());
SettingsEnum.MAX_PLAYBACK_BUFFER_AFTER_REBUFFER_INTEGER.setValue(Integer.parseInt(editTextPreference5.getText())); SettingsEnum.MAX_PLAYBACK_BUFFER_AFTER_REBUFFER_INTEGER.setValue(Integer.parseInt(editTextPreference5.getText()));
} }
} else if (str.equals(SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.getPath())) { } else if (str.equals(SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.getPath())) {
SettingsEnum.USE_HDR_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) miscsPreferenceScreen.findPreference(str)).isChecked()); SettingsEnum.USE_HDR_AUTO_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) miscsPreferenceScreen.findPreference(str)).isChecked());
} else if (str.equals(SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getPath())) { } else if (str.equals(SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.getPath())) {
SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) xSwipeControlPreferenceScreen.findPreference(str)).isChecked()); SettingsEnum.ENABLE_SWIPE_BRIGHTNESS_BOOLEAN.setValue(((SwitchPreference) xSwipeControlPreferenceScreen.findPreference(str)).isChecked());
} else if (str.equals(SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.getPath())) { } else if (str.equals(SettingsEnum.ENABLE_SWIPE_VOLUME_BOOLEAN.getPath())) {

View File

@ -33,11 +33,17 @@ class ScreenBrightnessController(
rawScreenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE 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] * save the current screen brightness, to be brought back using [restore]
*/ */
fun save() { fun save() {
if(savedScreenBrightness == null) { if (savedScreenBrightness == null) {
savedScreenBrightness = rawScreenBrightness savedScreenBrightness = rawScreenBrightness
} }
} }
@ -55,9 +61,9 @@ class ScreenBrightnessController(
/** /**
* wrapper for the raw screen brightness in [WindowManager.LayoutParams.screenBrightness] * wrapper for the raw screen brightness in [WindowManager.LayoutParams.screenBrightness]
*/ */
private var rawScreenBrightness: Float var rawScreenBrightness: Float
get() = host.window.attributes.screenBrightness get() = host.window.attributes.screenBrightness
set(value) { private set(value) {
val attr = host.window.attributes val attr = host.window.attributes
attr.screenBrightness = value attr.screenBrightness = value
host.window.attributes = attr host.window.attributes = attr

View File

@ -25,9 +25,9 @@
<string name="revanced_default_codec_title">Default codec</string> <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_summary">Tap to join ReVanced on Discord</string>
<string name="revanced_discord_title">Discord server</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 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_summary_off">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_title">Override HDR Video Brightness</string>
<string name="revanced_info_cards_summary_off">Info cards are hidden</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_summary_on">Info cards are shown</string>
<string name="revanced_info_cards_title">Info cards</string> <string name="revanced_info_cards_title">Info cards</string>