18ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov/* 28ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Copyright (C) 2016 The Android Open Source Project 38ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * 48ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Licensed under the Apache License, Version 2.0 (the "License"); 58ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * you may not use this file except in compliance with the License. 68ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * You may obtain a copy of the License at 78ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * 88ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * http://www.apache.org/licenses/LICENSE-2.0 98ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * 108ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Unless required by applicable law or agreed to in writing, software 118ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * distributed under the License is distributed on an "AS IS" BASIS, 128ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * See the License for the specific language governing permissions and 148ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * limitations under the License. 158ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov */ 168ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 178ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovpackage android.support.design.testutils; 188ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 198ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.content.res.ColorStateList; 208ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.graphics.drawable.Drawable; 218ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.support.annotation.DrawableRes; 22a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikovimport android.support.annotation.IdRes; 23a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikovimport android.support.annotation.LayoutRes; 24a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikovimport android.support.annotation.NonNull; 258ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.support.annotation.Nullable; 268ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.support.annotation.StyleRes; 278ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.support.design.widget.NavigationView; 288ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.support.test.espresso.UiController; 298ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.support.test.espresso.ViewAction; 30a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikovimport android.view.LayoutInflater; 318ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport android.view.View; 328ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport org.hamcrest.Matcher; 338ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 348ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovimport static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 358ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 368ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikovpublic class NavigationViewActions { 378ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov /** 388ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Sets item text appearance on the content of the navigation view. 398ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov */ 408ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public static ViewAction setItemTextAppearance(final @StyleRes int resId) { 418ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return new ViewAction() { 428ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 438ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public Matcher<View> getConstraints() { 448ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return isDisplayed(); 458ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 468ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 478ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 488ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public String getDescription() { 498ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return "Set item text appearance"; 508ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 518ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 528ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 538ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public void perform(UiController uiController, View view) { 548ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 558ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 568ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov NavigationView navigationView = (NavigationView) view; 578ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov navigationView.setItemTextAppearance(resId); 588ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 598ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 608ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 618ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov }; 628ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 638ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 648ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov /** 658ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Sets item text color on the content of the navigation view. 668ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov */ 678ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public static ViewAction setItemTextColor(final ColorStateList textColor) { 688ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return new ViewAction() { 698ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 708ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public Matcher<View> getConstraints() { 718ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return isDisplayed(); 728ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 738ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 748ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 758ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public String getDescription() { 768ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return "Set item text color"; 778ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 788ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 798ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 808ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public void perform(UiController uiController, View view) { 818ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 828ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 838ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov NavigationView navigationView = (NavigationView) view; 848ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov navigationView.setItemTextColor(textColor); 858ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 868ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 878ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 888ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov }; 898ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 908ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 918ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov /** 928ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Sets item background on the content of the navigation view. 938ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov */ 94a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public static ViewAction setItemBackground(final @Nullable Drawable itemBackground) { 958ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return new ViewAction() { 968ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 978ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public Matcher<View> getConstraints() { 988ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return isDisplayed(); 998ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1008ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1018ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1028ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public String getDescription() { 1038ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return "Set item background"; 1048ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1058ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1068ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1078ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public void perform(UiController uiController, View view) { 1088ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 1098ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1108ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov NavigationView navigationView = (NavigationView) view; 1118ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov navigationView.setItemBackground(itemBackground); 1128ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1138ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 1148ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1158ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov }; 1168ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1178ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1188ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov /** 1198ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Sets item background on the content of the navigation view. 1208ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov */ 1218ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public static ViewAction setItemBackgroundResource(final @DrawableRes int resId) { 1228ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return new ViewAction() { 1238ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1248ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public Matcher<View> getConstraints() { 1258ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return isDisplayed(); 1268ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1278ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1288ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1298ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public String getDescription() { 1308ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return "Set item background"; 1318ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1328ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1338ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1348ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public void perform(UiController uiController, View view) { 1358ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 1368ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1378ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov NavigationView navigationView = (NavigationView) view; 1388ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov navigationView.setItemBackgroundResource(resId); 1398ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1408ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 1418ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1428ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov }; 1438ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1448ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1458ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov /** 1468ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov * Sets item icon tint list on the content of the navigation view. 1478ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov */ 1488ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public static ViewAction setItemIconTintList(final @Nullable ColorStateList tint) { 1498ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return new ViewAction() { 1508ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1518ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public Matcher<View> getConstraints() { 1528ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return isDisplayed(); 1538ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1548ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1558ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1568ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public String getDescription() { 1578ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov return "Set item icon tint list"; 1588ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1598ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1608ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov @Override 1618ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov public void perform(UiController uiController, View view) { 1628ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 1638ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1648ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov NavigationView navigationView = (NavigationView) view; 1658ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov navigationView.setItemIconTintList(tint); 1668ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov 1678ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 1688ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 1698ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov }; 1708ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov } 171a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 172a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov /** 173a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov * Add the specified view as a header to the navigation view. 174a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov */ 175a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public static ViewAction addHeaderView(final @NonNull LayoutInflater inflater, 176a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov final @LayoutRes int res) { 177a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return new ViewAction() { 178a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 179a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public Matcher<View> getConstraints() { 180a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return isDisplayed(); 181a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 182a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 183a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 184a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public String getDescription() { 185a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return "Add header view"; 186a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 187a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 188a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 189a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public void perform(UiController uiController, View view) { 190a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 191a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 192a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov NavigationView navigationView = (NavigationView) view; 193a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov navigationView.addHeaderView(inflater.inflate(res, null, false)); 194a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 195a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 196a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 197a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov }; 198a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 199a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 200a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov /** 201a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov * Inflates a view from the specified layout ID and adds it as a header to the navigation view. 202a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov */ 203a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public static ViewAction inflateHeaderView(final @LayoutRes int res) { 204a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return new ViewAction() { 205a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 206a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public Matcher<View> getConstraints() { 207a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return isDisplayed(); 208a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 209a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 210a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 211a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public String getDescription() { 212a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return "Inflate and add header view"; 213a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 214a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 215a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 216a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public void perform(UiController uiController, View view) { 217a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 218a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 219a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov NavigationView navigationView = (NavigationView) view; 220a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov navigationView.inflateHeaderView(res); 221a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 222a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 223a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 224a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov }; 225a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 226a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 227a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov /** 228a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov * Removes a previously added header view from the navigation view. 229a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov */ 230a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public static ViewAction removeHeaderView(final @Nullable View headerView) { 231a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return new ViewAction() { 232a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 233a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public Matcher<View> getConstraints() { 234a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return isDisplayed(); 235a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 236a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 237a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 238a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public String getDescription() { 239a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return "Remove header view"; 240a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 241a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 242a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 243a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public void perform(UiController uiController, View view) { 244a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 245a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 246a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov NavigationView navigationView = (NavigationView) view; 247a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov navigationView.removeHeaderView(headerView); 248a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 249a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 250a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 251a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov }; 252a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 253a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 254a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov /** 255a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov * Sets checked item on the navigation view. 256a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov */ 257a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public static ViewAction setCheckedItem(final @IdRes int id) { 258a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return new ViewAction() { 259a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 260a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public Matcher<View> getConstraints() { 261a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return isDisplayed(); 262a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 263a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 264a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 265a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public String getDescription() { 266a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov return "Set checked item"; 267a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 268a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 269a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov @Override 270a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov public void perform(UiController uiController, View view) { 271a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 272a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 273a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov NavigationView navigationView = (NavigationView) view; 274a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov navigationView.setCheckedItem(id); 275a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov 276a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov uiController.loopMainThreadUntilIdle(); 277a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 278a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov }; 279a3c0da0361aa877077aeb21df876226def2f98caKirill Grouchnikov } 28088f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov 28188f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov /** 28288f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov * Sets icon for the menu item of the navigation view. 28388f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov */ 28488f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov public static ViewAction setIconForMenuItem(final @IdRes int menuItemId, 28588f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov final Drawable iconDrawable) { 28688f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov return new ViewAction() { 28788f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov @Override 28888f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov public Matcher<View> getConstraints() { 28988f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov return isDisplayed(); 29088f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov } 29188f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov 29288f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov @Override 29388f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov public String getDescription() { 29488f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov return "Set menu item icon"; 29588f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov } 29688f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov 29788f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov @Override 29888f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov public void perform(UiController uiController, View view) { 29988f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 30088f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov 30188f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov NavigationView navigationView = (NavigationView) view; 30288f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov navigationView.getMenu().findItem(menuItemId).setIcon(iconDrawable); 30388f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov 30488f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov uiController.loopMainThreadUntilIdle(); 30588f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov } 30688f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov }; 30788f685bc75d52b18f45f22c99ef8d4910708a3e3Kirill Grouchnikov } 3088ea47e618ba5dad21c7b023aa998979eebcf2103Kirill Grouchnikov} 309