diff options
| author | 2018-05-23 14:35:29 +0000 | |
|---|---|---|
| committer | 2018-05-23 14:35:29 +0000 | |
| commit | 4524e93577895e74c27d36a7f94b05618348cb8c (patch) | |
| tree | 931f6edc82f747cdecdb050eb579a6691ccec688 | |
| parent | 1f8f21af607b6a8449a509d8482f92a194fc1c99 (diff) | |
| parent | e91f0d05dae79cc8effc5fb2328677c16a46f34e (diff) | |
Merge "On orientation change, update rounded corners" into pi-dev
3 files changed, 98 insertions, 20 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index 139215a02995..2746a71e3316 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.MATCH_PARENT; 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.statusbar.phone.StatusBar; 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 @@ public class ScreenDecorations extends SystemUI implements Tunable { 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 @@ public class ScreenDecorations extends SystemUI implements Tunable { private View mBottomOverlay; private float mDensity; private WindowManager mWindowManager; - private boolean mLandscape; + private int mRotation; @Override public void start() { @@ -104,6 +108,28 @@ public class ScreenDecorations extends SystemUI implements Tunable { 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 @@ public class ScreenDecorations extends SystemUI implements Tunable { @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 @@ public class ScreenDecorations extends SystemUI implements Tunable { 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 @@ public class ScreenDecorations extends SystemUI implements Tunable { } 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 @@ public class ScreenDecorations extends SystemUI implements Tunable { 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 @@ public class ScreenDecorations extends SystemUI implements Tunable { 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 ad2090009714..11c72c4c0cb9 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 class RotationUtils { 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 @@ public class RotationUtils { } 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 2f05b06ae0b0..f1bf31d7a58a 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.app.Fragment; 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.Before; import org.junit.Test; import org.junit.runner.RunWith; +@RunWithLooper @RunWith(AndroidTestingRunner.class) @SmallTest public class ScreenDecorationsTest extends SysuiTestCase { @@ -98,6 +100,8 @@ public class ScreenDecorationsTest extends SysuiTestCase { 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); |