1/* 2 * Copyright 2018 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 17package androidx.gridlayout.widget; 18 19import static org.hamcrest.CoreMatchers.equalTo; 20import static org.junit.Assert.assertThat; 21 22import android.content.Context; 23import android.util.AttributeSet; 24import android.widget.FrameLayout; 25 26import androidx.annotation.NonNull; 27import androidx.annotation.Nullable; 28 29import java.util.concurrent.CountDownLatch; 30import java.util.concurrent.TimeUnit; 31 32public class TestContentView extends FrameLayout { 33 34 private CountDownLatch mLayoutCountDownLatch; 35 36 public TestContentView(@NonNull Context context) { 37 super(context); 38 } 39 40 public TestContentView(@NonNull Context context, 41 @Nullable AttributeSet attrs) { 42 super(context, attrs); 43 } 44 45 public TestContentView(@NonNull Context context, @Nullable AttributeSet attrs, 46 int defStyleAttr) { 47 super(context, attrs, defStyleAttr); 48 } 49 50 @SuppressWarnings("unused") 51 public TestContentView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, 52 int defStyleRes) { 53 super(context, attrs, defStyleAttr, defStyleRes); 54 } 55 56 public void expectLayouts(int count) { 57 mLayoutCountDownLatch = new CountDownLatch(count); 58 } 59 60 @SuppressWarnings("SameParameterValue") 61 public void awaitLayouts(int seconds) throws InterruptedException { 62 assertThat(mLayoutCountDownLatch.await(seconds, TimeUnit.SECONDS), equalTo(true)); 63 } 64 65 @Override 66 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 67 super.onLayout(changed, left, top, right, bottom); 68 if (mLayoutCountDownLatch != null) { 69 mLayoutCountDownLatch.countDown(); 70 } 71 } 72} 73