AppCompatTintableViewActions.java revision ee9519c17254b5e992164ff278173c4b2c7c5fce
1/* 2 * Copyright (C) 2016 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 android.support.v7.testutils; 18 19import android.content.res.ColorStateList; 20import android.support.test.espresso.UiController; 21import android.support.test.espresso.ViewAction; 22import android.support.v4.view.TintableBackgroundView; 23import android.support.v7.widget.AppCompatTextView; 24import android.view.View; 25import org.hamcrest.Matcher; 26 27import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; 28import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast; 29import static org.hamcrest.core.AllOf.allOf; 30 31public class AppCompatTintableViewActions { 32 /** 33 * Sets enabled state on a <code>View</code> that implements the 34 * <code>TintableBackgroundView</code> interface. 35 */ 36 public static ViewAction setEnabled(final boolean enabled) { 37 return new ViewAction() { 38 @Override 39 public Matcher<View> getConstraints() { 40 return allOf(isDisplayingAtLeast(90), TestUtilsMatchers.isTintableBackgroundView()); 41 } 42 43 @Override 44 public String getDescription() { 45 return "set enabled"; 46 } 47 48 @Override 49 public void perform(UiController uiController, View view) { 50 uiController.loopMainThreadUntilIdle(); 51 52 view.setEnabled(enabled); 53 54 uiController.loopMainThreadUntilIdle(); 55 } 56 }; 57 } 58 59 /** 60 * Sets the passed color state list as the background layer on a <code>View</code> that 61 * implements the <code>TintableBackgroundView</code> interface. 62 */ 63 public static ViewAction setBackgroundTintList(final ColorStateList colorStateList) { 64 return new ViewAction() { 65 @Override 66 public Matcher<View> getConstraints() { 67 return allOf(isDisplayingAtLeast(90), TestUtilsMatchers.isTintableBackgroundView()); 68 } 69 70 @Override 71 public String getDescription() { 72 return "set background tint list"; 73 } 74 75 @Override 76 public void perform(UiController uiController, View view) { 77 uiController.loopMainThreadUntilIdle(); 78 79 TintableBackgroundView tintableBackgroundView = (TintableBackgroundView) view; 80 tintableBackgroundView.setSupportBackgroundTintList(colorStateList); 81 82 uiController.loopMainThreadUntilIdle(); 83 } 84 }; 85 } 86} 87