Skip to content

Commit

Permalink
Reduce alpha of AOD Widget on low display brightness
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Der-Schubi committed Dec 11, 2023
1 parent 718d854 commit 628a157
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 628a157

Please sign in to comment.