Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Reduce alpha of AOD Widget on low display brightness #3158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading