Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d38eee35 authored by Roy Chou's avatar Roy Chou
Browse files

fix(brightness): adjust brightness slider bar layout width to fit in the window safe area

In BrightnessDialog it uses the window full width to calculate the
slider bar layout width. However the window full width may contain the
display screen cutout area. Therefore, we change to calculate the window
available width (for safe area) for the following slider bar width
calculation.

Bug: 347826058
Flag: EXEMPT bugfix
Test: manually
Change-Id: I2c6e94116759021356db82064c1a898a144a6d83
parent c92aa737
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;

import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Gravity;
@@ -32,7 +33,9 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowMetrics;
import android.view.accessibility.AccessibilityManager;
import android.widget.FrameLayout;

@@ -152,18 +155,27 @@ public class BrightnessDialog extends Activity {

        Configuration configuration = getResources().getConfiguration();
        int orientation = configuration.orientation;
        int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
        int windowWidth = getWindowAvailableWidth();

        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            boolean shouldBeFullWidth = getIntent()
                    .getBooleanExtra(EXTRA_BRIGHTNESS_DIALOG_IS_FULL_WIDTH, false);
            lp.width = (shouldBeFullWidth ? screenWidth : screenWidth / 2) - horizontalMargin * 2;
            lp.width = (shouldBeFullWidth ? windowWidth : windowWidth / 2) - horizontalMargin * 2;
        } else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            lp.width = screenWidth - horizontalMargin * 2;
            lp.width = windowWidth - horizontalMargin * 2;
        }

        frame.setLayoutParams(lp);
    }

    private int getWindowAvailableWidth() {
        final WindowMetrics metrics = getWindowManager().getCurrentWindowMetrics();
        // Gets all excluding insets
        final WindowInsets windowInsets = metrics.getWindowInsets();
        Insets insets = windowInsets.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars()
                | WindowInsets.Type.displayCutout());
        int insetsWidth = insets.right + insets.left;
        return metrics.getBounds().width() - insetsWidth;
    }

    @Override