On orientation change, update rounded corners
When rotating landscape/seascape/upsidedown, the 'top' and 'bottom'
corners are in the correct place
Change-Id: I19858ca42939d81911c5f45bd80d163d0c22eee9
Fixes: 79163187
Test: manual, ScreenDecorationsTest
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 139215a0..2746a71 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -22,8 +22,8 @@
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
-import static com.android.systemui.tuner.TunablePadding.FLAG_START;
import static com.android.systemui.tuner.TunablePadding.FLAG_END;
+import static com.android.systemui.tuner.TunablePadding.FLAG_START;
import android.annotation.Dimension;
import android.app.Fragment;
@@ -66,6 +66,7 @@
import com.android.systemui.tuner.TunablePadding;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService.Tunable;
+import com.android.systemui.util.leak.RotationUtils;
/**
* An overlay that draws screen decorations in software (e.g for rounded corners or display cutout)
@@ -77,6 +78,9 @@
private static final boolean DEBUG_SCREENSHOT_ROUNDED_CORNERS =
SystemProperties.getBoolean("debug.screenshot_rounded_corners", false);
+ private DisplayManager mDisplayManager;
+ private DisplayManager.DisplayListener mDisplayListener;
+
private int mRoundedDefault;
private int mRoundedDefaultTop;
private int mRoundedDefaultBottom;
@@ -84,7 +88,7 @@
private View mBottomOverlay;
private float mDensity;
private WindowManager mWindowManager;
- private boolean mLandscape;
+ private int mRotation;
@Override
public void start() {
@@ -104,6 +108,28 @@
if (padding != 0) {
setupPadding(padding);
}
+
+ mDisplayListener = new DisplayManager.DisplayListener() {
+ @Override
+ public void onDisplayAdded(int displayId) {
+ // do nothing
+ }
+
+ @Override
+ public void onDisplayRemoved(int displayId) {
+ // do nothing
+ }
+
+ @Override
+ public void onDisplayChanged(int displayId) {
+ updateOrientation();
+ }
+ };
+
+ mRotation = -1;
+ mDisplayManager = (DisplayManager) mContext.getSystemService(
+ Context.DISPLAY_SERVICE);
+ mDisplayManager.registerDisplayListener(mDisplayListener, null);
}
private void setupDecorations() {
@@ -169,17 +195,22 @@
@Override
protected void onConfigurationChanged(Configuration newConfig) {
- boolean newLanscape = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE;
- if (newLanscape != mLandscape) {
- mLandscape = newLanscape;
+ updateOrientation();
+ }
+
+ protected void updateOrientation() {
+ int newRotation = RotationUtils.getExactRotation(mContext);
+ if (newRotation != mRotation) {
+ mRotation = newRotation;
if (mOverlay != null) {
updateLayoutParams();
updateViews();
}
- }
- if (shouldDrawCutout() && mOverlay == null) {
- setupDecorations();
+
+ if (shouldDrawCutout() && mOverlay == null) {
+ setupDecorations();
+ }
}
}
@@ -188,16 +219,28 @@
View topRight = mOverlay.findViewById(R.id.right);
View bottomLeft = mBottomOverlay.findViewById(R.id.left);
View bottomRight = mBottomOverlay.findViewById(R.id.right);
- if (mLandscape) {
- // Flip corners
- View tmp = topRight;
- topRight = bottomLeft;
- bottomLeft = tmp;
+
+ if (mRotation == RotationUtils.ROTATION_NONE) {
+ updateView(topLeft, Gravity.TOP | Gravity.LEFT, 0);
+ updateView(topRight, Gravity.TOP | Gravity.RIGHT, 90);
+ updateView(bottomLeft, Gravity.BOTTOM | Gravity.LEFT, 270);
+ updateView(bottomRight, Gravity.BOTTOM | Gravity.RIGHT, 180);
+ } else if (mRotation == RotationUtils.ROTATION_LANDSCAPE) {
+ updateView(topLeft, Gravity.TOP | Gravity.LEFT, 0);
+ updateView(topRight, Gravity.BOTTOM | Gravity.LEFT, 270);
+ updateView(bottomLeft, Gravity.TOP | Gravity.RIGHT, 90);;
+ updateView(bottomRight, Gravity.BOTTOM | Gravity.RIGHT, 180);
+ } else if (mRotation == RotationUtils.ROTATION_UPSIDE_DOWN) {
+ updateView(topLeft, Gravity.BOTTOM | Gravity.LEFT, 270);
+ updateView(topRight, Gravity.BOTTOM | Gravity.RIGHT, 180);
+ updateView(bottomLeft, Gravity.TOP | Gravity.LEFT, 0);
+ updateView(bottomRight, Gravity.TOP | Gravity.RIGHT, 90);
+ } else if (mRotation == RotationUtils.ROTATION_SEASCAPE) {
+ updateView(topLeft, Gravity.BOTTOM | Gravity.RIGHT, 180);
+ updateView(topRight, Gravity.TOP | Gravity.RIGHT, 90);
+ updateView(bottomLeft, Gravity.BOTTOM | Gravity.LEFT, 270);
+ updateView(bottomRight, Gravity.TOP | Gravity.LEFT, 0);
}
- updateView(topLeft, Gravity.TOP | Gravity.LEFT, 0);
- updateView(topRight, Gravity.TOP | Gravity.RIGHT, 90);
- updateView(bottomLeft, Gravity.BOTTOM | Gravity.LEFT, 270);
- updateView(bottomRight, Gravity.BOTTOM | Gravity.RIGHT, 180);
updateWindowVisibilities();
}
@@ -269,9 +312,14 @@
}
lp.setTitle("ScreenDecorOverlay");
- lp.gravity = Gravity.TOP | Gravity.LEFT;
+ if (mRotation == RotationUtils.ROTATION_SEASCAPE
+ || mRotation == RotationUtils.ROTATION_UPSIDE_DOWN) {
+ lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
+ } else {
+ lp.gravity = Gravity.TOP | Gravity.LEFT;
+ }
lp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
- if (mLandscape) {
+ if (isLandscape(mRotation)) {
lp.width = WRAP_CONTENT;
lp.height = MATCH_PARENT;
}
@@ -281,7 +329,12 @@
private WindowManager.LayoutParams getBottomLayoutParams() {
WindowManager.LayoutParams lp = getWindowLayoutParams();
lp.setTitle("ScreenDecorOverlayBottom");
- lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
+ if (mRotation == RotationUtils.ROTATION_SEASCAPE
+ || mRotation == RotationUtils.ROTATION_UPSIDE_DOWN) {
+ lp.gravity = Gravity.TOP | Gravity.LEFT;
+ } else {
+ lp.gravity = Gravity.BOTTOM | Gravity.RIGHT;
+ }
return lp;
}
@@ -568,4 +621,9 @@
return cutoutBounds;
}
}
+
+ private boolean isLandscape(int rotation) {
+ return rotation == RotationUtils.ROTATION_LANDSCAPE || rotation ==
+ RotationUtils.ROTATION_SEASCAPE;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java b/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java
index ad20900..11c72c4 100644
--- a/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java
+++ b/packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java
@@ -23,6 +23,7 @@
public static final int ROTATION_NONE = 0;
public static final int ROTATION_LANDSCAPE = 1;
public static final int ROTATION_SEASCAPE = 2;
+ public static final int ROTATION_UPSIDE_DOWN = 3;
public static int getRotation(Context context) {
Configuration config = context.getResources().getConfiguration();
@@ -36,4 +37,19 @@
}
return ROTATION_NONE;
}
+
+ public static int getExactRotation(Context context) {
+ Configuration config = context.getResources().getConfiguration();
+ int rot = context.getDisplay().getRotation();
+ if (config.smallestScreenWidthDp < 600) {
+ if (rot == Surface.ROTATION_90) {
+ return ROTATION_LANDSCAPE;
+ } else if (rot == Surface.ROTATION_270) {
+ return ROTATION_SEASCAPE;
+ } else if (rot == Surface.ROTATION_180) {
+ return ROTATION_UPSIDE_DOWN;
+ }
+ }
+ return ROTATION_NONE;
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
index 2f05b06..f1bf31d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
@@ -36,6 +36,7 @@
import android.content.res.Configuration;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper.RunWithLooper;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
@@ -54,6 +55,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
+@RunWithLooper
@RunWith(AndroidTestingRunner.class)
@SmallTest
public class ScreenDecorationsTest extends SysuiTestCase {
@@ -98,6 +100,8 @@
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius, 0);
+ mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius_top, 0);
+ mContext.getOrCreateTestableResources().addOverride(dimen.rounded_corner_radius_bottom, 0);
mContext.getOrCreateTestableResources()
.addOverride(dimen.rounded_corner_content_padding, 0);