19c92f46280cf3943701e75349833c68b584992e2Kevin Jin/*
29c92f46280cf3943701e75349833c68b584992e2Kevin Jin * Copyright (C) 2013 DroidDriver committers
39c92f46280cf3943701e75349833c68b584992e2Kevin Jin *
49c92f46280cf3943701e75349833c68b584992e2Kevin Jin * Licensed under the Apache License, Version 2.0 (the "License");
59c92f46280cf3943701e75349833c68b584992e2Kevin Jin * you may not use this file except in compliance with the License.
69c92f46280cf3943701e75349833c68b584992e2Kevin Jin * You may obtain a copy of the License at
79c92f46280cf3943701e75349833c68b584992e2Kevin Jin *
89c92f46280cf3943701e75349833c68b584992e2Kevin Jin *      http://www.apache.org/licenses/LICENSE-2.0
99c92f46280cf3943701e75349833c68b584992e2Kevin Jin *
109c92f46280cf3943701e75349833c68b584992e2Kevin Jin * Unless required by applicable law or agreed to in writing, software
119c92f46280cf3943701e75349833c68b584992e2Kevin Jin * distributed under the License is distributed on an "AS IS" BASIS,
129c92f46280cf3943701e75349833c68b584992e2Kevin Jin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139c92f46280cf3943701e75349833c68b584992e2Kevin Jin * See the License for the specific language governing permissions and
149c92f46280cf3943701e75349833c68b584992e2Kevin Jin * limitations under the License.
159c92f46280cf3943701e75349833c68b584992e2Kevin Jin */
169c92f46280cf3943701e75349833c68b584992e2Kevin Jinpackage com.google.android.droiddriver.scroll;
179c92f46280cf3943701e75349833c68b584992e2Kevin Jin
189c92f46280cf3943701e75349833c68b584992e2Kevin Jinimport com.google.android.droiddriver.DroidDriver;
199031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jinimport com.google.android.droiddriver.UiElement;
209c92f46280cf3943701e75349833c68b584992e2Kevin Jinimport com.google.android.droiddriver.finders.Finder;
219c92f46280cf3943701e75349833c68b584992e2Kevin Jinimport com.google.android.droiddriver.scroll.Direction.DirectionConverter;
229c92f46280cf3943701e75349833c68b584992e2Kevin Jinimport com.google.android.droiddriver.scroll.Direction.PhysicalDirection;
239c92f46280cf3943701e75349833c68b584992e2Kevin Jin
249c92f46280cf3943701e75349833c68b584992e2Kevin Jin/**
259c92f46280cf3943701e75349833c68b584992e2Kevin Jin * Interface for determining whether scrolling is possible.
269c92f46280cf3943701e75349833c68b584992e2Kevin Jin */
279c92f46280cf3943701e75349833c68b584992e2Kevin Jinpublic interface ScrollStepStrategy {
289c92f46280cf3943701e75349833c68b584992e2Kevin Jin  /**
299c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * Tries to scroll {@code containerFinder} in {@code direction}. Returns
309c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * whether scrolling is effective.
319c92f46280cf3943701e75349833c68b584992e2Kevin Jin   *
329c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * @param driver
339c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * @param containerFinder Finder for the container that can scroll, for
349c92f46280cf3943701e75349833c68b584992e2Kevin Jin   *        instance a ListView
359c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * @param direction
369c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * @return whether scrolling is effective
379c92f46280cf3943701e75349833c68b584992e2Kevin Jin   */
389c92f46280cf3943701e75349833c68b584992e2Kevin Jin  boolean scroll(DroidDriver driver, Finder containerFinder, PhysicalDirection direction);
399c92f46280cf3943701e75349833c68b584992e2Kevin Jin
409c92f46280cf3943701e75349833c68b584992e2Kevin Jin  /**
419c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * Returns the {@link DirectionConverter}.
429c92f46280cf3943701e75349833c68b584992e2Kevin Jin   */
439c92f46280cf3943701e75349833c68b584992e2Kevin Jin  DirectionConverter getDirectionConverter();
449c92f46280cf3943701e75349833c68b584992e2Kevin Jin
459c92f46280cf3943701e75349833c68b584992e2Kevin Jin  /**
46026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * Called only if this step is at the beginning of a series of scroll steps
47026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * with regard to the given arguments.
48026e2d0318ee13637adbc71365592705c149c157Kevin Jin   *
495cf5f03c64b65b1f1ecd2140b8d6605ac05b6199Kevin Jin   * @param driver
50026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * @param containerFinder Finder for the container that can scroll, for
51026e2d0318ee13637adbc71365592705c149c157Kevin Jin   *        instance a ListView
52026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * @param itemFinder Finder for the desired item; relative to
53026e2d0318ee13637adbc71365592705c149c157Kevin Jin   *        {@code containerFinder}
54026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * @param direction
55026e2d0318ee13637adbc71365592705c149c157Kevin Jin   */
565cf5f03c64b65b1f1ecd2140b8d6605ac05b6199Kevin Jin  void beginScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder,
575cf5f03c64b65b1f1ecd2140b8d6605ac05b6199Kevin Jin      PhysicalDirection direction);
58026e2d0318ee13637adbc71365592705c149c157Kevin Jin
59026e2d0318ee13637adbc71365592705c149c157Kevin Jin  /**
60026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * Called only if this step is at the end of a series of scroll steps with
61026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * regard to the given arguments.
62026e2d0318ee13637adbc71365592705c149c157Kevin Jin   *
635cf5f03c64b65b1f1ecd2140b8d6605ac05b6199Kevin Jin   * @param driver
64026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * @param containerFinder Finder for the container that can scroll, for
65026e2d0318ee13637adbc71365592705c149c157Kevin Jin   *        instance a ListView
66026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * @param itemFinder Finder for the desired item; relative to
67026e2d0318ee13637adbc71365592705c149c157Kevin Jin   *        {@code containerFinder}
68026e2d0318ee13637adbc71365592705c149c157Kevin Jin   * @param direction
69026e2d0318ee13637adbc71365592705c149c157Kevin Jin   */
705cf5f03c64b65b1f1ecd2140b8d6605ac05b6199Kevin Jin  void endScrolling(DroidDriver driver, Finder containerFinder, Finder itemFinder,
715cf5f03c64b65b1f1ecd2140b8d6605ac05b6199Kevin Jin      PhysicalDirection direction);
72026e2d0318ee13637adbc71365592705c149c157Kevin Jin
73026e2d0318ee13637adbc71365592705c149c157Kevin Jin  /**
749031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   * Performs the scroll action on {@code container}. Subclasses can override
759031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   * this to customize the scroll action, for example, to adjust the scroll
769031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   * margins.
779031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   *
789031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   * @param container the container that can scroll
799031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   * @param direction
809031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin   */
819031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin  void doScroll(UiElement container, PhysicalDirection direction);
829031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin
839031ed9b636ccd3b942eefb85dbfae2aed9e4f11Kevin Jin  /**
849c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * {@inheritDoc}
859c92f46280cf3943701e75349833c68b584992e2Kevin Jin   *
869c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * <p>
879c92f46280cf3943701e75349833c68b584992e2Kevin Jin   * It is recommended that this method return a description to help debugging.
889c92f46280cf3943701e75349833c68b584992e2Kevin Jin   */
899c92f46280cf3943701e75349833c68b584992e2Kevin Jin  @Override
909c92f46280cf3943701e75349833c68b584992e2Kevin Jin  String toString();
919c92f46280cf3943701e75349833c68b584992e2Kevin Jin}
92