mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-08-30 02:56:21 +02:00
fix: hdr-auto-brightness
patch (#74)
This commit is contained in:
parent
134d7e33bd
commit
7314032a38
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,11 @@ package app.revanced.integrations.patches;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;
|
||||
|
||||
/**
|
||||
@ -14,6 +17,14 @@ import app.revanced.integrations.swipecontrols.views.SwipeControlsHostLayout;
|
||||
*/
|
||||
@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)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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())) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user