1/* 2 * Copyright (C) 2015 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 */ 16package android.support.v17.leanback.widget; 17 18import android.test.AndroidTestCase; 19import android.view.View.MeasureSpec; 20import android.view.ViewGroup.LayoutParams; 21import android.widget.FrameLayout; 22import android.widget.TextView; 23 24 25public class ShadowOverlayContainerTest extends AndroidTestCase { 26 27 public void testWrapContent() { 28 FrameLayout frameLayout = new FrameLayout(getContext()); 29 TextView textView = new TextView(getContext()); 30 textView.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 31 LayoutParams.WRAP_CONTENT)); 32 textView.setText("abc"); 33 ShadowOverlayContainer container = new ShadowOverlayContainer(getContext()); 34 container.initialize(true, true, true); 35 container.wrap(textView); 36 frameLayout.addView(container); 37 frameLayout.measure(MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY), 38 MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY)); 39 frameLayout.layout(0, 0, 500, 500); 40 assertTrue(textView.getWidth() > 0); 41 assertTrue(textView.getWidth() < 500); 42 assertTrue(textView.getHeight() > 0); 43 assertTrue(textView.getHeight() < 500); 44 assertEquals(container.getWidth(), textView.getWidth()); 45 assertEquals(container.getHeight(), textView.getHeight()); 46 47 // change layout size of textView after wrap() 48 textView.setLayoutParams(new FrameLayout.LayoutParams(123, 123)); 49 frameLayout.measure(MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY), 50 MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY)); 51 frameLayout.layout(0, 0, 500, 500); 52 assertTrue(textView.getWidth() == 123); 53 assertTrue(textView.getHeight() == 123); 54 assertEquals(container.getWidth(), textView.getWidth()); 55 assertEquals(container.getHeight(), textView.getHeight()); 56 } 57 58 public void testFixedSize() { 59 FrameLayout frameLayout = new FrameLayout(getContext()); 60 TextView textView = new TextView(getContext()); 61 textView.setLayoutParams(new FrameLayout.LayoutParams(200, LayoutParams.WRAP_CONTENT)); 62 textView.setText("abc"); 63 ShadowOverlayContainer container = new ShadowOverlayContainer(getContext()); 64 container.initialize(true, true, true); 65 container.wrap(textView); 66 frameLayout.addView(container); 67 frameLayout.measure(MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY), 68 MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY)); 69 frameLayout.layout(0, 0, 500, 500); 70 assertTrue(textView.getWidth() == 200); 71 assertTrue(textView.getHeight() > 0); 72 assertTrue(textView.getHeight() < 500); 73 assertEquals(container.getWidth(), textView.getWidth()); 74 assertEquals(container.getHeight(), textView.getHeight()); 75 76 // change layout size of textView after wrap() 77 textView.setLayoutParams(new FrameLayout.LayoutParams(123, 123)); 78 frameLayout.measure(MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY), 79 MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY)); 80 frameLayout.layout(0, 0, 500, 500); 81 assertTrue(textView.getWidth() == 123); 82 assertTrue(textView.getHeight() == 123); 83 assertEquals(container.getWidth(), textView.getWidth()); 84 assertEquals(container.getHeight(), textView.getHeight()); 85 } 86 87 public void testMatchParent() { 88 FrameLayout frameLayout = new FrameLayout(getContext()); 89 TextView textView = new TextView(getContext()); 90 textView.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 91 LayoutParams.WRAP_CONTENT)); 92 textView.setText("abc"); 93 ShadowOverlayContainer container = new ShadowOverlayContainer(getContext()); 94 container.initialize(true, true, true); 95 container.wrap(textView); 96 frameLayout.addView(container); 97 frameLayout.measure(MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY), 98 MeasureSpec.makeMeasureSpec(500, MeasureSpec.EXACTLY)); 99 frameLayout.layout(0, 0, 500, 500); 100 assertTrue(textView.getWidth() == 500); 101 assertTrue(textView.getHeight() > 0); 102 assertTrue(textView.getHeight() < 500); 103 assertEquals(container.getWidth(), textView.getWidth()); 104 assertEquals(container.getHeight(), textView.getHeight()); 105 } 106} 107