From 004e24b91e46900280c5e422588e3368504a0a73 Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Thu, 18 Mar 2021 18:43:37 +0530 Subject: [PATCH 1/3] find device notch and update clock location --- .../statusbar/phone/ClockController.java | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java index 563fad840cd9..e0be78dffd7f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java @@ -25,10 +25,19 @@ import com.android.systemui.statusbar.phone.StatusBarIconController; import com.android.systemui.statusbar.policy.Clock; import com.android.systemui.tuner.TunerService; +import android.util.DisplayMetrics; +import android.util.Pair; +import android.view.View; +import android.view.WindowInsets; +import android.view.DisplayCutout; +import android.graphics.Rect; +import java.util.List; +import com.android.systemui.util.leak.RotationUtils; + 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; @@ -38,8 +47,10 @@ public class ClockController implements TunerService.Tunable { private Clock mActiveClock, mCenterClock, mLeftClock, mRightClock; private View mCenterClockLayout, mRightClockLayout; - private int mClockPosition = CLOCK_POSITION_LEFT; + private int mClockPosition = CLOCK_POSITION_CENTER; private boolean mBlackListed = false; + private DisplayCutout mDisplayCutout; + private View mStatusBar; public ClockController(View statusBar) { mCenterClock = statusBar.findViewById(R.id.clock_center); @@ -50,7 +61,12 @@ public class ClockController implements TunerService.Tunable { mRightClockLayout = statusBar.findViewById(R.id.right_clock_layout); mActiveClock = mLeftClock; - + statusBar.setOnApplyWindowInsetsListener(new android.view.View.OnApplyWindowInsetsListener(){ + public WindowInsets onApplyWindowInsets (View v, WindowInsets insets){ + updateActiveClock(); + return insets; + } + }); Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST, CLOCK_POSITION); } @@ -59,15 +75,48 @@ public class ClockController implements TunerService.Tunable { switch (mClockPosition) { case CLOCK_POSITION_RIGHT: return mRightClock; - case CLOCK_POSITION_CENTER: - return mCenterClock; case CLOCK_POSITION_LEFT: + return CLOCK_POSITION_LEFT; + case CLOCK_POSITION_CENTER: default: - return mLeftClock; + if(mCutoutLocation == 1) + return mRightClock; + return mCenterClock; } } 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 margins = null; + if (mDisplayCutout != null) { + List bounding = mDisplayCutout.getBoundingRects(); + for (int i=0; i0 && right >0){ + margins = new Pair(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); -- GitLab From b1891b33326354da10f4c92508d73e9f6fedbacc Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Thu, 18 Mar 2021 19:00:51 +0530 Subject: [PATCH 2/3] find device notch and update clock location : fix bug --- .../com/android/systemui/statusbar/phone/ClockController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java index e0be78dffd7f..3bfe5f91d2fc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java @@ -76,7 +76,7 @@ public class ClockController implements TunerService.Tunable { case CLOCK_POSITION_RIGHT: return mRightClock; case CLOCK_POSITION_LEFT: - return CLOCK_POSITION_LEFT; + return mLeftClock; case CLOCK_POSITION_CENTER: default: if(mCutoutLocation == 1) -- GitLab From ba1f85f09611a26c733d9333289655de7aa329ca Mon Sep 17 00:00:00 2001 From: Narinder Rana Date: Fri, 19 Mar 2021 07:34:35 +0530 Subject: [PATCH 3/3] find device notch and update clock location : fix bug --- .../com/android/systemui/statusbar/phone/ClockController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java index 3bfe5f91d2fc..e1839a522843 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ClockController.java @@ -60,7 +60,9 @@ public class ClockController implements TunerService.Tunable { mCenterClockLayout = statusBar.findViewById(R.id.center_clock_layout); mRightClockLayout = statusBar.findViewById(R.id.right_clock_layout); + mStatusBar = statusBar; mActiveClock = mLeftClock; + statusBar.setOnApplyWindowInsetsListener(new android.view.View.OnApplyWindowInsetsListener(){ public WindowInsets onApplyWindowInsets (View v, WindowInsets insets){ updateActiveClock(); -- GitLab