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 package io.appium.droiddriver.scroll;
17 
18 import io.appium.droiddriver.DroidDriver;
19 import io.appium.droiddriver.UiElement;
20 import io.appium.droiddriver.finders.Finder;
21 import io.appium.droiddriver.scroll.Direction.DirectionConverter;
22 import io.appium.droiddriver.scroll.Direction.PhysicalDirection;
23 
24 /**
25  * Interface for determining whether scrolling is possible.
26  */
27 public interface ScrollStepStrategy {
28   /**
29    * Tries to scroll {@code containerFinder} in {@code direction}. Returns whether scrolling is
30    * effective.
31    *
32    * @param driver          a DroidDriver instance
33    * @param containerFinder Finder for the container that can scroll, for instance a ListView
34    * @param direction       specifies where the view port will move instead of the finger
35    * @return whether scrolling is effective
36    */
scroll(DroidDriver driver, Finder containerFinder, PhysicalDirection direction)37   boolean scroll(DroidDriver driver, Finder containerFinder, PhysicalDirection direction);
38 
39   /**
40    * Returns the {@link DirectionConverter}.
41    */
getDirectionConverter()42   DirectionConverter getDirectionConverter();
43 
44   /**
45    * Called only if this step is at the beginning of a series of scroll steps with regard to the
46    * given arguments.
47    *
48    * @param driver          a DroidDriver instance
49    * @param containerFinder Finder for the container that can scroll, for instance a ListView
50    * @param itemFinder      Finder for the desired item; relative to {@code containerFinder}
51    * @param direction       specifies where the view port will move instead of the finger
52    */
beginScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder, PhysicalDirection direction)53   void beginScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder,
54                       PhysicalDirection direction);
55 
56   /**
57    * Called only if this step is at the end of a series of scroll steps with regard to the given
58    * arguments.
59    *
60    * @param driver          a DroidDriver instance
61    * @param containerFinder Finder for the container that can scroll, for instance a ListView
62    * @param itemFinder      Finder for the desired item; relative to {@code containerFinder}
63    * @param direction       specifies where the view port will move instead of the finger
64    */
endScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder, PhysicalDirection direction)65   void endScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder,
66                     PhysicalDirection direction);
67 
68   /**
69    * Performs the scroll action on {@code container}. Subclasses can override this to customize the
70    * scroll action, for example, to adjust the scroll margins.
71    *
72    * @param container the container that can scroll
73    * @param direction specifies where the view port will move instead of the finger
74    */
doScroll(UiElement container, PhysicalDirection direction)75   void doScroll(UiElement container, PhysicalDirection direction);
76 
77   /**
78    * {@inheritDoc} It is recommended that this method return a description to help debugging.
79    */
80   @Override
toString()81   String toString();
82 }
83