Skip to content

Commit

Permalink
Normalise Android value and retrieve it from window when set
Browse files Browse the repository at this point in the history
  • Loading branch information
nll authored and Nuno Luis committed Mar 31, 2023
1 parent ff6d106 commit 20b7b26
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Plugin.Maui.ScreenBrightness/ScreenBrightness.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ public float Brightness
{
get
{
if (Platform.CurrentActivity is null)
{
var activity = Platform.CurrentActivity;
if (activity is null) {
return 0;
}

return Settings.System.GetInt(Platform.CurrentActivity.ContentResolver,
Settings.System.ScreenBrightness);
var window = activity.Window;
if (window is null) {
return 0;
}

var windowBrightness = window.Attributes?.ScreenBrightness ?? 0;
if (windowBrightness < 0) {
return Settings.System.GetInt(activity.ContentResolver, Settings.System.ScreenBrightness) / 255f;
}

return windowBrightness;
}

set
Expand Down

0 comments on commit 20b7b26

Please sign in to comment.