Loading packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +78 −20 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) Loading @@ -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; Loading @@ -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() { Loading @@ -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() { Loading Loading @@ -169,35 +195,52 @@ 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(); } } } private void updateViews() { View topLeft = mOverlay.findViewById(R.id.left); 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); } updateWindowVisibilities(); } Loading Loading @@ -269,9 +312,14 @@ public class ScreenDecorations extends SystemUI implements Tunable { } lp.setTitle("ScreenDecorOverlay"); 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; } Loading @@ -281,7 +329,12 @@ public class ScreenDecorations extends SystemUI implements Tunable { private WindowManager.LayoutParams getBottomLayoutParams() { WindowManager.LayoutParams lp = getWindowLayoutParams(); lp.setTitle("ScreenDecorOverlayBottom"); 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; } Loading Loading @@ -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; } } packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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; } } packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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); Loading Loading
packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +78 −20 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) Loading @@ -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; Loading @@ -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() { Loading @@ -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() { Loading Loading @@ -169,35 +195,52 @@ 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(); } } } private void updateViews() { View topLeft = mOverlay.findViewById(R.id.left); 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); } updateWindowVisibilities(); } Loading Loading @@ -269,9 +312,14 @@ public class ScreenDecorations extends SystemUI implements Tunable { } lp.setTitle("ScreenDecorOverlay"); 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; } Loading @@ -281,7 +329,12 @@ public class ScreenDecorations extends SystemUI implements Tunable { private WindowManager.LayoutParams getBottomLayoutParams() { WindowManager.LayoutParams lp = getWindowLayoutParams(); lp.setTitle("ScreenDecorOverlayBottom"); 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; } Loading Loading @@ -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; } }
packages/SystemUI/src/com/android/systemui/util/leak/RotationUtils.java +16 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -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; } }
packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { Loading Loading @@ -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); Loading