1 /* 2 * Copyright (C) 2013 DroidDriver committers 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 17 package io.appium.droiddriver.validators; 18 19 import android.text.TextUtils; 20 import android.util.Log; 21 22 import io.appium.droiddriver.UiElement; 23 import io.appium.droiddriver.actions.Action; 24 import io.appium.droiddriver.util.Logs; 25 26 /** 27 * Always validates the classes that TalkBack always has speech. 28 */ 29 public class ExemptedClassesValidator implements Validator { 30 private static final Class<?>[] EXEMPTED_CLASSES = {android.widget.Spinner.class, 31 android.widget.EditText.class, android.widget.SeekBar.class, 32 android.widget.AbsListView.class, android.widget.TabWidget.class}; 33 34 @Override isApplicable(UiElement element, Action action)35 public boolean isApplicable(UiElement element, Action action) { 36 String className = element.getClassName(); 37 if (TextUtils.isEmpty(className)) { 38 return false; 39 } 40 41 Class<?> elementClass = null; 42 try { 43 elementClass = Class.forName(className); 44 } catch (ClassNotFoundException e) { 45 Logs.log(Log.WARN, e); 46 return false; 47 } 48 49 for (Class<?> clazz : EXEMPTED_CLASSES) { 50 if (clazz.isAssignableFrom(elementClass)) { 51 return true; 52 } 53 } 54 return false; 55 } 56 57 @Override validate(UiElement element, Action action)58 public String validate(UiElement element, Action action) { 59 return null; 60 } 61 } 62