separate enforceContainerWithinScreen logic to a private method

Change-Id: Ifcf8c6a79286269646a845b5be6cfa92b64fcbcc
This commit is contained in:
Hyunyoung Song
2017-07-20 13:57:23 -07:00
parent 435a35dec3
commit 27790352a3

View File

@@ -402,9 +402,14 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
enforceContainedWithinScreen(l, r);
}
private void enforceContainedWithinScreen(int left, int right) {
DragLayer dragLayer = mLauncher.getDragLayer();
if (getTranslationX() + l < 0 ||
getTranslationX() + l + getMeasuredWidth() > dragLayer.getWidth()) {
if (getTranslationX() + left < 0 ||
getTranslationX() + right > dragLayer.getWidth()) {
// If we are still off screen, center horizontally too.
mGravity |= Gravity.CENTER_HORIZONTAL;
}