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.v4.widget; 18 19import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; 20 21import android.support.test.espresso.UiController; 22import android.support.test.espresso.ViewAction; 23import android.view.View; 24 25import org.hamcrest.Matcher; 26 27 28public class SwipeRefreshLayoutActions { 29 public static ViewAction setRefreshing() { 30 return new ViewAction() { 31 @Override 32 public Matcher<View> getConstraints() { 33 return isAssignableFrom(SwipeRefreshLayout.class); 34 } 35 36 @Override 37 public String getDescription() { 38 return "Set SwipeRefreshLayout refreshing state"; 39 } 40 41 @Override 42 public void perform(UiController uiController, View view) { 43 uiController.loopMainThreadUntilIdle(); 44 45 SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) view; 46 swipeRefreshLayout.setRefreshing(true); 47 48 // Intentionally not waiting until idle here because it will not become idle due to 49 // the animation. 50 } 51 }; 52 } 53 54 public static ViewAction setSize(final int size) { 55 return new ViewAction() { 56 @Override 57 public Matcher<View> getConstraints() { 58 return isAssignableFrom(SwipeRefreshLayout.class); 59 } 60 61 @Override 62 public String getDescription() { 63 return "Set SwipeRefreshLayout size"; 64 } 65 66 @Override 67 public void perform(UiController uiController, View view) { 68 uiController.loopMainThreadUntilIdle(); 69 70 SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) view; 71 swipeRefreshLayout.setSize(size); 72 73 uiController.loopMainThreadUntilIdle(); 74 } 75 }; 76 } 77} 78