1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view; 18 19 import android.content.Context; 20 import android.content.pm.ActivityInfo; 21 import android.graphics.PixelFormat; 22 import android.os.SystemClock; 23 import android.support.test.filters.LargeTest; 24 import android.test.ActivityInstrumentationTestCase2; 25 import android.test.UiThreadTest; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import android.view.WindowManager; 29 30 import com.android.frameworks.coretests.R; 31 32 @LargeTest 33 public class ViewAttachTest extends 34 ActivityInstrumentationTestCase2<ViewAttachTestActivity> { 35 36 public ViewAttachTest() { 37 super(ViewAttachTestActivity.class); 38 } 39 40 /** 41 * Make sure that onAttachedToWindow and onDetachedToWindow is called in the 42 * correct order. The ViewAttachTestActivity contains a view that will throw 43 * a RuntimeException if onDetachedToWindow and onAttachedToWindow are 44 * called in the wrong order. 45 * 46 * 1. Initiate the activity 2. Perform a series of orientation changes to 47 * the activity (this will force the View hierarchy to be rebuilt, 48 * generating onAttachedToWindow and onDetachedToWindow) 49 * 50 * Expected result: No RuntimeException is thrown from the TestView in 51 * ViewFlipperTestActivity. 52 * 53 * @throws Throwable 54 */ 55 public void testAttached() throws Throwable { 56 final ViewAttachTestActivity activity = getActivity(); 57 for (int i = 0; i < 20; i++) { 58 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 59 SystemClock.sleep(250); 60 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 61 SystemClock.sleep(250); 62 } 63 } 64 65 /** 66 * Make sure that on any attached view, if the view is full-screen and hosted 67 * on a round device, the round scrollbars will be displayed even if the activity 68 * window is offset. 69 * 70 * @throws Throwable 71 */ 72 @UiThreadTest 73 public void testRoundScrollbars() throws Throwable { 74 final ViewAttachTestActivity activity = getActivity(); 75 final View rootView = activity.getWindow().getDecorView(); 76 final WindowManager.LayoutParams params = 77 new WindowManager.LayoutParams( 78 rootView.getWidth(), 79 rootView.getHeight(), 80 50, /* xPosition */ 81 0, /* yPosition */ 82 WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 83 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, 84 PixelFormat.TRANSLUCENT); 85 86 rootView.setLayoutParams(params); 87 88 View contentView = activity.findViewById(R.id.view_attach_view); 89 boolean shouldDrawRoundScrollbars = contentView.shouldDrawRoundScrollbar(); 90 91 if (activity.getResources().getConfiguration().isScreenRound()) { 92 assertTrue(shouldDrawRoundScrollbars); 93 } else { 94 // Never draw round scrollbars on non-round devices. 95 assertFalse(shouldDrawRoundScrollbars); 96 } 97 } 98 } 99