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

Commit cadfa24f authored by narinder Rana's avatar narinder Rana Committed by Romain Hunault
Browse files

find device notch and update clock location

parent 5d6ebe24
Loading
Loading
Loading
Loading
+41 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ public class ClockController implements TunerService.Tunable {

    private static final String TAG = "ClockController";

    private int mCutoutLocation = -1;
    private static final int CLOCK_POSITION_RIGHT = 0;
    private static final int CLOCK_POSITION_CENTER = 1;
    private static final int CLOCK_POSITION_LEFT = 2;
@@ -59,11 +60,50 @@ public class ClockController implements TunerService.Tunable {
                return mCenterClock;
            case CLOCK_POSITION_LEFT:
            default:
                if(mCutoutLocation == 1)
                {
                    return mRightClock;
                }else {
                    return mLeftClock;
                }
        }
    }

    private void updateActiveClock() {

        if(mStatusBar instanceof PhoneStatusBarView)
            mDisplayCutout = ((PhoneStatusBarView)mStatusBar).getRootWindowInsets().getDisplayCutout();
        else {
            mDisplayCutout = ((StatusBarWindowView)mStatusBar).getRootWindowInsets().getDisplayCutout();
        }
        DisplayMetrics metrics = new DisplayMetrics();
        mStatusBar.getDisplay().getMetrics(metrics);
        int middle = metrics.widthPixels/2;
        Pair<Integer, Integer> margins = null;
        if (mDisplayCutout != null) {
            List<Rect> bounding = mDisplayCutout.getBoundingRects();
            for (int i=0; i<bounding.size(); i++) {
                int left = bounding.get(i).left;
                int right = bounding.get(i).right;
                int top = bounding.get(i).top;
                int bottom = bounding.get(i).bottom;
                if(left >0 && right >0){
                    margins = new Pair<Integer, Integer>(left, right);
                    break;
                }
            }
        }
        if(margins == null)
            mCutoutLocation = -1;
        else if(margins.first < middle && margins.second > middle)
            mCutoutLocation = 1;
        else if(margins.first < middle)
            mCutoutLocation = 0;
        else
            mCutoutLocation = 2;



        mActiveClock.setClockVisibleByUser(false);
        mActiveClock = getClock();
        mActiveClock.setClockVisibleByUser(true);