From 628a1573f22976ebca1389c3a03a1a08559f41cb Mon Sep 17 00:00:00 2001 From: Der-Schubi Date: Fri, 27 Oct 2023 13:06:18 +0200 Subject: [PATCH] Reduce alpha of AOD Widget on low display brightness This tones down the alpha of the Always On Display Widget on low display brightness. Below a display brightness of 60 the alpha is gradually reduced from 1.0 down to 0.4 for brightness 0. --- .../services/AlwaysOnDisplayService.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java b/app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java index a33b707b05..7386a6d8e0 100644 --- a/app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java +++ b/app/src/main/java/com/eveningoutpost/dexdrip/services/AlwaysOnDisplayService.java @@ -9,6 +9,7 @@ import android.graphics.Rect; import android.hardware.display.DisplayManager; import android.os.Build; +import android.provider.Settings; import android.util.DisplayMetrics; import android.view.Display; import android.view.Gravity; @@ -185,6 +186,19 @@ private boolean isScreenOn() { return false; } + private float determineAlpha() { + float alpha = 1.0f; + float brightness = 0.0f; + try { + brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); + if (brightness <= 60) { + alpha = 0.4f + (brightness / 100.0f); + } + } catch (Exception exc) { + alpha = 1.0f; + } + return alpha; + } @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private synchronized void refreshView() { @@ -198,7 +212,7 @@ private synchronized void refreshView() { frameLayout = new FrameLayout(this); } aodView = views.apply(this, frameLayout); - aodView.setAlpha(0.8f); + aodView.setAlpha(determineAlpha()); aodView.setBackgroundColor(Color.TRANSPARENT); if (D) aodView.setBackgroundColor(Color.RED); @@ -267,6 +281,7 @@ void rejigLayout() { UserError.Log.d(TAG, "Couldn't determine max Y so using screen max of: " + screenMaxY); } + aodView.setAlpha(determineAlpha()); layoutParams.y = bf.findRandomAvailablePositionWithFailSafe(layoutParams.height, screenMaxY); windowManager.updateViewLayout(aodView, layoutParams); } catch (Exception e) {