Merge "KeyguardClockPositionAlgorithm Test updates" into sc-dev

This commit is contained in:
Matt Pietal
2021-06-12 14:54:15 +00:00
committed by Android (Google) Code Review
6 changed files with 47 additions and 146 deletions

View File

@@ -287,20 +287,6 @@ public class KeyguardClockSwitch extends RelativeLayout {
return mClockView.getTextSize();
}
/**
* Returns the preferred Y position of the clock.
*
* @param totalHeight Height of the parent container.
* @return preferred Y position.
*/
int getPreferredY(int totalHeight) {
if (mClockPlugin != null) {
return mClockPlugin.getPreferredY(totalHeight);
} else {
return totalHeight / 2;
}
}
/**
* Refresh the time of the clock, due to either time tick broadcast or doze time tick alarm.
*/

View File

@@ -256,16 +256,6 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
return mView.getTextSize();
}
/**
* Returns the preferred Y position of the clock.
*
* @param totalHeight The height available to position the clock.
* @return Y position of clock.
*/
public int getClockPreferredY(int totalHeight) {
return mView.getPreferredY(totalHeight);
}
/**
* Refresh clock. Called in response to TIME_TICK broadcasts.
*/

View File

@@ -186,16 +186,6 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
return mKeyguardClockSwitchController.getClockTextSize();
}
/**
* Returns the preferred Y position of the clock.
*
* @param totalHeight The height available to position the clock.
* @return Y position of clock.
*/
public int getClockPreferredY(int totalHeight) {
return mKeyguardClockSwitchController.getClockPreferredY(totalHeight);
}
/**
* Get the height of the keyguard status view.
*/

View File

@@ -62,11 +62,6 @@ public class KeyguardClockPositionAlgorithm {
*/
private int mUserSwitchHeight;
/**
* Preferred Y position of clock.
*/
private int mClockPreferredY;
/**
* Preferred Y position of user avatar used by the multi-user switcher.
*/
@@ -176,8 +171,8 @@ public class KeyguardClockPositionAlgorithm {
*/
public void setup(int keyguardStatusBarHeaderHeight, int maxShadeBottom,
int notificationStackHeight, float panelExpansion, int parentHeight,
int keyguardStatusHeight, int userSwitchHeight, int clockPreferredY,
int userSwitchPreferredY, boolean hasCustomClock, boolean hasVisibleNotifs, float dark,
int keyguardStatusHeight, int userSwitchHeight, int userSwitchPreferredY,
boolean hasCustomClock, boolean hasVisibleNotifs, float dark,
float overStrechAmount, boolean bypassEnabled, int unlockedStackScrollerPadding,
float qsExpansion, int cutoutTopInset, boolean isSplitShade) {
mMinTopMargin = keyguardStatusBarHeaderHeight + Math.max(mContainerTopPadding,
@@ -188,7 +183,6 @@ public class KeyguardClockPositionAlgorithm {
mHeight = parentHeight;
mKeyguardStatusHeight = keyguardStatusHeight;
mUserSwitchHeight = userSwitchHeight;
mClockPreferredY = clockPreferredY;
mUserSwitchPreferredY = userSwitchPreferredY;
mHasCustomClock = hasCustomClock;
mHasVisibleNotifs = hasVisibleNotifs;

View File

@@ -1228,7 +1228,6 @@ public class NotificationPanelViewController extends PanelViewController {
private void updateClockAppearance() {
int totalHeight = mView.getHeight();
int bottomPadding = Math.max(mIndicationBottomPadding, mAmbientIndicationBottomPadding);
int clockPreferredY = mKeyguardStatusViewController.getClockPreferredY(totalHeight);
int userSwitcherPreferredY = mStatusBarHeaderHeightKeyguard;
boolean bypassEnabled = mKeyguardBypassController.getBypassEnabled();
final boolean hasVisibleNotifications = mNotificationStackScrollLayoutController
@@ -1249,7 +1248,7 @@ public class NotificationPanelViewController extends PanelViewController {
totalHeight,
mKeyguardStatusViewController.getHeight(),
userIconHeight,
clockPreferredY, userSwitcherPreferredY, hasCustomClock(),
userSwitcherPreferredY, hasCustomClock(),
hasVisibleNotifications, darkamount, mOverStretchAmount,
bypassEnabled, getUnlockedStackScrollerPadding(),
computeQsExpansionFraction(),

View File

@@ -33,7 +33,6 @@ import org.junit.runner.RunWith;
public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
private static final int SCREEN_HEIGHT = 2000;
private static final int PREFERRED_CLOCK_Y = SCREEN_HEIGHT / 2;
private static final int EMPTY_MARGIN = 0;
private static final int EMPTY_HEIGHT = 0;
private static final float ZERO_DRAG = 0.f;
@@ -48,7 +47,6 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
private float mPanelExpansion;
private int mKeyguardStatusHeight;
private float mDark;
private int mPreferredClockY;
private boolean mHasCustomClock;
private boolean mHasVisibleNotifs;
private float mQsExpansion;
@@ -60,21 +58,36 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mClockPositionAlgorithm = new KeyguardClockPositionAlgorithm();
mClockPosition = new KeyguardClockPositionAlgorithm.Result();
mPreferredClockY = PREFERRED_CLOCK_Y;
mHasCustomClock = HAS_CUSTOM_CLOCK;
mHasVisibleNotifs = HAS_VISIBLE_NOTIFS;
}
@Test
public void clockPositionMiddleOfScreenOnAOD() {
public void clockPositionTopOfScreenOnAOD() {
// GIVEN on AOD and both stack scroll and clock have 0 height
givenAOD();
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is the middle of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.clockY).isEqualTo(1000);
// THEN the clock Y position is the top of the screen
assertThat(mClockPosition.clockY).isEqualTo(0);
// AND the clock is opaque and positioned on the left.
assertThat(mClockPosition.clockX).isEqualTo(0);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
}
@Test
public void clockPositionBelowCutout() {
// GIVEN on AOD and both stack scroll and clock have 0 height
givenAOD();
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
mCutoutTopInset = 300;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is below the cutout
assertThat(mClockPosition.clockY).isEqualTo(300);
// AND the clock is opaque and positioned on the left.
assertThat(mClockPosition.clockX).isEqualTo(0);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
@@ -88,8 +101,8 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = 100;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position adjusts for the clock height (SCREEN_HEIGHT / 2 - 100).
assertThat(mClockPosition.clockY).isEqualTo(900);
// THEN the clock Y position is at the top
assertThat(mClockPosition.clockY).isEqualTo(0);
// AND the clock is opaque and positioned on the left.
assertThat(mClockPosition.clockX).isEqualTo(0);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
@@ -111,18 +124,17 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
}
@Test
public void clockPositionMiddleOfScreenOnLockScreen() {
public void clockPositionTopOfScreenOnLockScreen() {
// GIVEN on lock screen with stack scroll and clock of 0 height
givenLockScreen();
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is the middle of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.clockY).isEqualTo(1000);
// AND the clock is opaque and positioned on the left.
// THEN the clock Y position is the top of the screen
assertThat(mClockPosition.clockY).isEqualTo(0);
// AND the clock is positioned on the left.
assertThat(mClockPosition.clockX).isEqualTo(0);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
}
@Test
@@ -133,11 +145,10 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position adjusts for stack scroll height ( (SCREEN_HEIGHT - 500 ) / 2).
assertThat(mClockPosition.clockY).isEqualTo(750);
// AND the clock is opaque and positioned on the left.
// THEN the clock Y position stays to the top
assertThat(mClockPosition.clockY).isEqualTo(0);
// AND the clock is positioned on the left.
assertThat(mClockPosition.clockX).isEqualTo(0);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
}
@Test
@@ -182,15 +193,15 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
}
@Test
public void notifPositionMiddleOfScreenOnAOD() {
public void notifPositionTopOfScreenOnAOD() {
// GIVEN on AOD and both stack scroll and clock have 0 height
givenAOD();
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
// THEN the notif padding is 0 (top of screen)
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
}
@Test
@@ -201,8 +212,8 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = 100;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
// THEN the notif padding adjusts for keyguard status height
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(100);
}
@Test
@@ -225,8 +236,8 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
// THEN the notif are placed to the top of the screen
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
}
@Test
@@ -237,8 +248,8 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding adjusts for the expanded notif stack.
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(750);
// THEN the notif padding adjusts for keyguard status height
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
}
@Test
@@ -250,7 +261,7 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding adjusts for both clock and notif stack.
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(200);
}
@Test
@@ -261,8 +272,8 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = 200;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding adjusts for both clock and notif stack.
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(810);
// THEN the notifs are placed below the statusview
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(200);
}
@Test
@@ -270,12 +281,11 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
// GIVEN on lock screen and split shade mode
givenLockScreen();
mIsSplitShade = true;
mPreferredClockY = 100;
mHasCustomClock = true;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding DOESN'T adjust for keyguard status height.
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(mPreferredClockY);
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
}
@Test
@@ -286,8 +296,8 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
mKeyguardStatusHeight = SCREEN_HEIGHT;
// WHEN the position algorithm is run
positionClock();
// THEN the notif padding is half of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(1000);
// THEN the notif padding is below keyguard status area
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(SCREEN_HEIGHT);
}
@Test
@@ -316,58 +326,6 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
assertThat(mClockPosition.stackScrollerPadding).isEqualTo(0);
}
@Test
public void preferredCustomClockPositionNoNotifications() {
// GIVEN on the lock screen with a custom clock and no visible notifications
givenLockScreen();
mPreferredClockY = 100;
mHasCustomClock = true;
mHasVisibleNotifs = false;
// AND given empty height for clock and stack scroller
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is the preferred Y position.
assertThat(mClockPosition.clockY).isEqualTo(100);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
}
@Test
public void preferredDefaultClockPositionNoNotifications() {
// GIVEN on the lock screen with a custom clock and no visible notifications
givenLockScreen();
mPreferredClockY = 100;
mHasCustomClock = false;
mHasVisibleNotifs = false;
// AND given empty height for clock and stack scroller
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is the middle of the screen (SCREEN_HEIGHT / 2) and not
// preferred.
assertThat(mClockPosition.clockY).isEqualTo(1000);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
}
@Test
public void preferredCustomClockPositionWithVisibleNotifications() {
// GIVEN on the lock screen with a custom clock and visible notifications
givenLockScreen();
mPreferredClockY = 100;
mHasCustomClock = true;
mHasVisibleNotifs = true;
// AND given empty height for clock and stack scroller
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is the middle of the screen (SCREEN_HEIGHT / 2).
assertThat(mClockPosition.clockY).isEqualTo(1000);
assertThat(mClockPosition.clockAlpha).isEqualTo(OPAQUE);
}
@Test
public void clockHiddenWhenQsIsExpanded() {
// GIVEN on the lock screen with a custom clock and visible notifications
@@ -379,22 +337,6 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
assertThat(mClockPosition.clockAlpha).isEqualTo(TRANSPARENT);
}
@Test
public void preferredCustomClockPositionWithVisibleNotificationsOnAod() {
// GIVEN on the lock screen with a custom clock and visible notifications
givenAOD();
mPreferredClockY = 100;
mHasCustomClock = true;
mHasVisibleNotifs = true;
// AND given empty height for clock and stack scroller
mNotificationStackHeight = EMPTY_HEIGHT;
mKeyguardStatusHeight = EMPTY_HEIGHT;
// WHEN the clock position algorithm is run
positionClock();
// THEN the clock Y position is the preferred Y position.
assertThat(mClockPosition.clockY).isEqualTo(100);
}
private void givenAOD() {
mPanelExpansion = 1.f;
mDark = 1.f;
@@ -408,7 +350,7 @@ public class KeyguardClockPositionAlgorithmTest extends SysuiTestCase {
private void positionClock() {
mClockPositionAlgorithm.setup(EMPTY_MARGIN, SCREEN_HEIGHT, mNotificationStackHeight,
mPanelExpansion, SCREEN_HEIGHT, mKeyguardStatusHeight,
0 /* userSwitchHeight */, mPreferredClockY, 0 /* userSwitchPreferredY */,
0 /* userSwitchHeight */, 0 /* userSwitchPreferredY */,
mHasCustomClock, mHasVisibleNotifs, mDark, ZERO_DRAG, false /* bypassEnabled */,
0 /* unlockedStackScrollerPadding */, mQsExpansion,
mCutoutTopInset, mIsSplitShade);