Home | History | Annotate | Download | only in scroll
      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 com.google.android.droiddriver.scroll;
     17 
     18 import com.google.android.droiddriver.DroidDriver;
     19 import com.google.android.droiddriver.UiElement;
     20 import com.google.android.droiddriver.finders.Finder;
     21 import com.google.android.droiddriver.scroll.Direction.DirectionConverter;
     22 import com.google.android.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
     30    * whether scrolling is effective.
     31    *
     32    * @param driver
     33    * @param containerFinder Finder for the container that can scroll, for
     34    *        instance a ListView
     35    * @param direction
     36    * @return whether scrolling is effective
     37    */
     38   boolean scroll(DroidDriver driver, Finder containerFinder, PhysicalDirection direction);
     39 
     40   /**
     41    * Returns the {@link DirectionConverter}.
     42    */
     43   DirectionConverter getDirectionConverter();
     44 
     45   /**
     46    * Called only if this step is at the beginning of a series of scroll steps
     47    * with regard to the given arguments.
     48    *
     49    * @param driver
     50    * @param containerFinder Finder for the container that can scroll, for
     51    *        instance a ListView
     52    * @param itemFinder Finder for the desired item; relative to
     53    *        {@code containerFinder}
     54    * @param direction
     55    */
     56   void beginScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder,
     57       PhysicalDirection direction);
     58 
     59   /**
     60    * Called only if this step is at the end of a series of scroll steps with
     61    * regard to the given arguments.
     62    *
     63    * @param driver
     64    * @param containerFinder Finder for the container that can scroll, for
     65    *        instance a ListView
     66    * @param itemFinder Finder for the desired item; relative to
     67    *        {@code containerFinder}
     68    * @param direction
     69    */
     70   void endScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder,
     71       PhysicalDirection direction);
     72 
     73   /**
     74    * Performs the scroll action on {@code container}. Subclasses can override
     75    * this to customize the scroll action, for example, to adjust the scroll
     76    * margins.
     77    *
     78    * @param container the container that can scroll
     79    * @param direction
     80    */
     81   void doScroll(UiElement container, PhysicalDirection direction);
     82 
     83   /**
     84    * {@inheritDoc}
     85    *
     86    * <p>
     87    * It is recommended that this method return a description to help debugging.
     88    */
     89   @Override
     90   String toString();
     91 }
     92