1/* 2 * Copyright (C) 2015 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 */ 16package com.android.tv.testing.uihelper; 17 18import android.content.res.Resources; 19import android.support.test.uiautomator.By; 20import android.support.test.uiautomator.BySelector; 21 22/** 23 * Convenience methods for creating {@link BySelector}s using resource ids. 24 */ 25public final class ByResource { 26 27 /** 28 * Creates a BySelector for the {@code resId} from {@code resources} 29 * 30 * @see By#res(String) 31 */ 32 public static BySelector id(Resources resources, int resId) { 33 String id = resources.getResourceName(resId); 34 return By.res(id); 35 } 36 37 /** 38 * Creates a BySelector for the text of {@code stringRes} from {@code resources}. 39 * 40 * @see By#text(String) 41 */ 42 public static BySelector text(Resources resources, int stringRes) { 43 String text = resources.getString(stringRes); 44 return By.text(text); 45 } 46 47 private ByResource() { 48 } 49} 50