diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 8acdc8f2c1934..9462d1ce1a1a5 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -23910,7 +23910,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * Determine if this view is rendered on a round wearable device and is the main view * on the screen. */ - private boolean shouldDrawRoundScrollbar() { + boolean shouldDrawRoundScrollbar() { if (!mResources.getConfiguration().isScreenRound() || mAttachInfo == null) { return false; } @@ -23927,7 +23927,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return false; } - getLocationOnScreen(mAttachInfo.mTmpLocation); + getLocationInWindow(mAttachInfo.mTmpLocation); return mAttachInfo.mTmpLocation[0] == insets.getStableInsetLeft() && mAttachInfo.mTmpLocation[1] == insets.getStableInsetTop(); } diff --git a/core/tests/coretests/src/android/view/ViewAttachTest.java b/core/tests/coretests/src/android/view/ViewAttachTest.java index a73f5a64c2cc9..44fcd13b53132 100644 --- a/core/tests/coretests/src/android/view/ViewAttachTest.java +++ b/core/tests/coretests/src/android/view/ViewAttachTest.java @@ -16,9 +16,17 @@ package android.view; +import android.content.Context; import android.content.pm.ActivityInfo; +import android.graphics.PixelFormat; import android.os.SystemClock; import android.test.ActivityInstrumentationTestCase2; +import android.test.UiThreadTest; +import android.view.View; +import android.view.ViewGroup; +import android.view.WindowManager; + +import com.android.frameworks.coretests.R; public class ViewAttachTest extends ActivityInstrumentationTestCase2 { @@ -51,4 +59,38 @@ public class ViewAttachTest extends SystemClock.sleep(250); } } + + /** + * Make sure that on any attached view, if the view is full-screen and hosted + * on a round device, the round scrollbars will be displayed even if the activity + * window is offset. + * + * @throws Throwable + */ + @UiThreadTest + public void testRoundScrollbars() throws Throwable { + final ViewAttachTestActivity activity = getActivity(); + final View rootView = activity.getWindow().getDecorView(); + final WindowManager.LayoutParams params = + new WindowManager.LayoutParams( + rootView.getWidth(), + rootView.getHeight(), + 50, /* xPosition */ + 0, /* yPosition */ + WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, + WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, + PixelFormat.TRANSLUCENT); + + rootView.setLayoutParams(params); + + View contentView = activity.findViewById(R.id.view_attach_view); + boolean shouldDrawRoundScrollbars = contentView.shouldDrawRoundScrollbar(); + + if (activity.getResources().getConfiguration().isScreenRound()) { + assertTrue(shouldDrawRoundScrollbars); + } else { + // Never draw round scrollbars on non-round devices. + assertFalse(shouldDrawRoundScrollbars); + } + } }