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 17package com.google.android.droiddriver.actions.accessibility; 18 19import android.view.accessibility.AccessibilityNodeInfo; 20 21import com.google.android.droiddriver.UiElement; 22import com.google.android.droiddriver.actions.Action; 23import com.google.android.droiddriver.actions.BaseAction; 24import com.google.android.droiddriver.uiautomation.UiAutomationElement; 25 26/** 27 * Implements {@link Action} via the Accessibility API. 28 */ 29public abstract class AccessibilityAction extends BaseAction { 30 protected AccessibilityAction(long timeoutMillis) { 31 super(timeoutMillis); 32 } 33 34 @Override 35 public boolean perform(UiElement element) { 36 return perform(((UiAutomationElement) element).getRawElement(), element); 37 } 38 39 /** 40 * Performs the action via the Accessibility API. 41 * 42 * @param node the AccessibilityNodeInfo used to create the UiElement 43 * @param element the UiElement to perform the action on 44 * @return Whether the action is successful. Some actions throw exceptions in 45 * case of failure, when that behavior is more appropriate. 46 */ 47 protected abstract boolean perform(AccessibilityNodeInfo node, UiElement element); 48} 49