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.design.widget; 18 19import org.hamcrest.Matcher; 20 21import android.support.test.espresso.UiController; 22import android.support.test.espresso.ViewAction; 23import android.support.test.espresso.matcher.ViewMatchers; 24import android.view.View; 25 26public final class DesignViewActions { 27 28 private DesignViewActions() { 29 } 30 31 /** 32 * Overwrites the constraints of the specified {@link ViewAction}. 33 */ 34 public static ViewAction withCustomConstraints(final ViewAction action, 35 final Matcher<View> constraints) { 36 return new ViewAction() { 37 @Override 38 public Matcher<View> getConstraints() { 39 return constraints; 40 } 41 42 @Override 43 public String getDescription() { 44 return action.getDescription(); 45 } 46 47 @Override 48 public void perform(UiController uiController, View view) { 49 action.perform(uiController, view); 50 } 51 }; 52 } 53 54 public static ViewAction setVisibility(final int visibility) { 55 return new ViewAction() { 56 @Override 57 public Matcher<View> getConstraints() { 58 return ViewMatchers.isEnabled(); 59 } 60 61 @Override 62 public String getDescription() { 63 return "Set view visibility"; 64 } 65 66 @Override 67 public void perform(UiController uiController, View view) { 68 uiController.loopMainThreadUntilIdle(); 69 view.setVisibility(visibility); 70 uiController.loopMainThreadUntilIdle(); 71 } 72 }; 73 } 74 75} 76