1/*
2 * Copyright (C) 2015 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 io.appium.droiddriver.actions.view;
18
19import android.view.View;
20
21import io.appium.droiddriver.UiElement;
22import io.appium.droiddriver.actions.BaseAction;
23import io.appium.droiddriver.instrumentation.ViewElement;
24
25/**
26 * Implements {@link io.appium.droiddriver.actions.Action} using the associated {@link View}. This
27 * can only be used with {@link ViewElement}.
28 */
29public abstract class ViewAction extends BaseAction {
30  protected ViewAction(long timeoutMillis) {
31    super(timeoutMillis);
32  }
33
34  @Override
35  public final boolean perform(UiElement element) {
36    return perform(((ViewElement) element).getRawElement(), element);
37  }
38
39  /**
40   * Performs the action on the associated {@link View}.
41   *
42   * @param view    the View associated with the UiElement
43   * @param element the UiElement to perform the action on
44   * @return Whether the action is successful. Some actions throw exceptions in case of failure,
45   * when that behavior is more appropriate.
46   */
47  protected abstract boolean perform(View view, UiElement element);
48}
49