11711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes/* 21711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * Copyright (C) 2016 The Android Open Source Project 31711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * 41711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * Licensed under the Apache License, Version 2.0 (the "License"); 51711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * you may not use this file except in compliance with the License. 61711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * You may obtain a copy of the License at 71711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * 81711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * http://www.apache.org/licenses/LICENSE-2.0 91711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * 101711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * Unless required by applicable law or agreed to in writing, software 111711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * distributed under the License is distributed on an "AS IS" BASIS, 121711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * See the License for the specific language governing permissions and 141711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes * limitations under the License. 151711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes */ 161711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 171711e8729c1b901b73f530e87b7c9cc9370f33beChris Banespackage android.support.design.testutils; 181711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 191711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom; 201711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 211711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.content.res.ColorStateList; 221711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.support.annotation.ColorInt; 231711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.support.annotation.DrawableRes; 241711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.support.design.widget.FloatingActionButton; 251711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.support.test.espresso.UiController; 261711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.support.test.espresso.ViewAction; 271711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport android.view.View; 281711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 291711e8729c1b901b73f530e87b7c9cc9370f33beChris Banesimport org.hamcrest.Matcher; 301711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 311711e8729c1b901b73f530e87b7c9cc9370f33beChris Banespublic class FloatingActionButtonActions { 321711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 331711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public static ViewAction setBackgroundTintColor(@ColorInt final int color) { 341711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes return new ViewAction() { 351711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes @Override 361711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public Matcher<View> getConstraints() { 371711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes return isAssignableFrom(FloatingActionButton.class); 381711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 391711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 401711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes @Override 411711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public String getDescription() { 421711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes return "Sets FloatingActionButton background tint"; 431711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 441711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 451711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes @Override 461711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public void perform(UiController uiController, View view) { 471711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes uiController.loopMainThreadUntilIdle(); 481711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 491711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes final FloatingActionButton fab = (FloatingActionButton) view; 501711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes fab.setBackgroundTintList(ColorStateList.valueOf(color)); 511711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 521711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes uiController.loopMainThreadUntilIdle(); 531711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 541711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes }; 551711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 561711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 571711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public static ViewAction setImageResource(@DrawableRes final int resId) { 581711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes return new ViewAction() { 591711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes @Override 601711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public Matcher<View> getConstraints() { 611711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes return isAssignableFrom(FloatingActionButton.class); 621711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 631711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 641711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes @Override 651711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public String getDescription() { 661711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes return "Sets FloatingActionButton image resource"; 671711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 681711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 691711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes @Override 701711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes public void perform(UiController uiController, View view) { 711711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes uiController.loopMainThreadUntilIdle(); 721711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 731711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes final FloatingActionButton fab = (FloatingActionButton) view; 741711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes fab.setImageResource(resId); 751711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 761711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes uiController.loopMainThreadUntilIdle(); 771711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 781711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes }; 791711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes } 801711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes 81a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes public static ViewAction setSize(@FloatingActionButton.Size final int size) { 82a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes return new ViewAction() { 83a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes @Override 84a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes public Matcher<View> getConstraints() { 85a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes return isAssignableFrom(FloatingActionButton.class); 86a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes } 87a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes 88a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes @Override 89a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes public String getDescription() { 90a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes return "Sets FloatingActionButton size"; 91a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes } 92a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes 93a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes @Override 94a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes public void perform(UiController uiController, View view) { 95a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes uiController.loopMainThreadUntilIdle(); 96a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes 97a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes final FloatingActionButton fab = (FloatingActionButton) view; 98a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes fab.setSize(size); 99a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes 100a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes uiController.loopMainThreadUntilIdle(); 101a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes } 102a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes }; 103a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes } 104a1de3eef9bb5ef90d00a23c65f13e1fc83254455Chris Banes 1051711e8729c1b901b73f530e87b7c9cc9370f33beChris Banes} 106