color mode setting for wide gamut

This commit is contained in:
Thibault Deckers 2025-03-02 17:47:39 +01:00
parent f850178afd
commit 1f95506abe
7 changed files with 29 additions and 16 deletions

View file

@ -85,15 +85,22 @@ class ActivityWindowHandler(private val activity: Activity) : WindowHandler(acti
result.success(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.resources.configuration.isScreenHdr) result.success(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.resources.configuration.isScreenHdr)
} }
override fun setHdrColorMode(call: MethodCall, result: MethodChannel.Result) { override fun setColorMode(call: MethodCall, result: MethodChannel.Result) {
val on = call.argument<Boolean>("on") val wideColorGamut = call.argument<Boolean>("wideColorGamut")
if (on == null) { val hdr = call.argument<Boolean>("hdr")
result.error("setHdrColorMode-args", "missing arguments", null) if (wideColorGamut == null || hdr == null) {
result.error("setColorMode-args", "missing arguments", null)
return return
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
activity.window.colorMode = if (on) ActivityInfo.COLOR_MODE_HDR else ActivityInfo.COLOR_MODE_DEFAULT activity.window.colorMode = if (hdr) {
ActivityInfo.COLOR_MODE_HDR
} else if (wideColorGamut) {
ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT
} else {
ActivityInfo.COLOR_MODE_DEFAULT
}
} }
result.success(null) result.success(null)
} }

View file

@ -37,7 +37,7 @@ class ServiceWindowHandler(service: Service) : WindowHandler(service) {
result.success(false) result.success(false)
} }
override fun setHdrColorMode(call: MethodCall, result: MethodChannel.Result) { override fun setColorMode(call: MethodCall, result: MethodChannel.Result) {
result.success(null) result.success(null)
} }
} }

View file

@ -20,7 +20,7 @@ abstract class WindowHandler(private val contextWrapper: ContextWrapper) : Metho
"getCutoutInsets" -> Coresult.safe(call, result, ::getCutoutInsets) "getCutoutInsets" -> Coresult.safe(call, result, ::getCutoutInsets)
"supportsWideGamut" -> Coresult.safe(call, result, ::supportsWideGamut) "supportsWideGamut" -> Coresult.safe(call, result, ::supportsWideGamut)
"supportsHdr" -> Coresult.safe(call, result, ::supportsHdr) "supportsHdr" -> Coresult.safe(call, result, ::supportsHdr)
"setHdrColorMode" -> Coresult.safe(call, result, ::setHdrColorMode) "setColorMode" -> Coresult.safe(call, result, ::setColorMode)
else -> result.notImplemented() else -> result.notImplemented()
} }
} }
@ -51,7 +51,7 @@ abstract class WindowHandler(private val contextWrapper: ContextWrapper) : Metho
abstract fun supportsHdr(call: MethodCall, result: MethodChannel.Result) abstract fun supportsHdr(call: MethodCall, result: MethodChannel.Result)
abstract fun setHdrColorMode(call: MethodCall, result: MethodChannel.Result) abstract fun setColorMode(call: MethodCall, result: MethodChannel.Result)
companion object { companion object {
private val LOG_TAG = LogUtils.createTag<WindowHandler>() private val LOG_TAG = LogUtils.createTag<WindowHandler>()

View file

@ -22,7 +22,7 @@ abstract class WindowService {
Future<bool> supportsHdr(); Future<bool> supportsHdr();
Future<void> setHdrColorMode(bool on); Future<void> setColorMode({required bool wideColorGamut, required bool hdr});
} }
class PlatformWindowService implements WindowService { class PlatformWindowService implements WindowService {
@ -153,11 +153,12 @@ class PlatformWindowService implements WindowService {
} }
@override @override
Future<void> setHdrColorMode(bool on) async { Future<void> setColorMode({required bool wideColorGamut, required bool hdr}) async {
// TODO TLAD [hdr] enable when ready // TODO TLAD [hdr] enable when ready
// try { // try {
// await _platform.invokeMethod('setHdrColorMode', <String, dynamic>{ // await _platform.invokeMethod('setColorMode', <String, dynamic>{
// 'on': on, // 'wideColorGamut': wideColorGamut,
// 'hdr': hdr,
// }); // });
// } on PlatformException catch (e, stack) { // } on PlatformException catch (e, stack) {
// await reportService.recordError(e, stack); // await reportService.recordError(e, stack);

View file

@ -626,6 +626,9 @@ class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerPr
void _onQueryFocusRequest() => _queryBarFocusNode.requestFocus(); void _onQueryFocusRequest() => _queryBarFocusNode.requestFocus();
void _updateStatusBarHeight() { void _updateStatusBarHeight() {
if (!context.mounted) {
return;
}
_statusBarHeight = MediaQuery.paddingOf(context).top; _statusBarHeight = MediaQuery.paddingOf(context).top;
_updateAppBarHeight(); _updateAppBarHeight();
} }

View file

@ -70,7 +70,7 @@ class ViewerController with CastMixin {
LeakTracking.dispatchObjectDisposed(object: this); LeakTracking.dispatchObjectDisposed(object: this);
} }
entryNotifier.removeListener(_onEntryChanged); entryNotifier.removeListener(_onEntryChanged);
windowService.setHdrColorMode(false); windowService.setColorMode(wideColorGamut: false, hdr: false);
_autopilotNotifier.dispose(); _autopilotNotifier.dispose();
_clearAutopilotAnimations(); _clearAutopilotAnimations();
_stopPlayTimer(); _stopPlayTimer();
@ -79,8 +79,10 @@ class ViewerController with CastMixin {
Future<void> _onEntryChanged() async { Future<void> _onEntryChanged() async {
if (await windowService.supportsHdr()) { if (await windowService.supportsHdr()) {
final enabled = entryNotifier.value?.isHdr ?? false; await windowService.setColorMode(
await windowService.setHdrColorMode(enabled); wideColorGamut: false,
hdr: entryNotifier.value?.isHdr ?? false,
);
} }
} }

View file

@ -26,5 +26,5 @@ class FakeWindowService extends Fake implements WindowService {
Future<bool> supportsHdr() => SynchronousFuture(false); Future<bool> supportsHdr() => SynchronousFuture(false);
@override @override
Future<void> setHdrColorMode(bool on) => SynchronousFuture(null); Future<void> setColorMode({required bool wideColorGamut, required bool hdr}) => SynchronousFuture(null);
} }