aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMingyu Wu <mwu@google.com>2014-02-03 12:26:25 -0800
committerMingyu Wu <mwu@google.com>2014-02-03 17:14:34 -0800
commit5d6ce8025e73d9f7f1631bfe05cff32b055d1939 (patch)
tree1645a407021e5c63a51cdfeabc4bcb814f9db634 /src
parent7655a5e140a667493d177b3e19d3ee415e97d43b (diff)
downloaddroiddriver-5d6ce8025e73d9f7f1631bfe05cff32b055d1939.tar.gz
Add more method for the class and also open up the event variable to be
able to access from inheritted class. Change-Id: If247d6a8d411ffebdee246e0cd0932c693055b7a
Diffstat (limited to 'src')
-rw-r--r--src/com/google/android/droiddriver/helpers/ScrollerHelper.java30
-rw-r--r--src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java12
2 files changed, 40 insertions, 2 deletions
diff --git a/src/com/google/android/droiddriver/helpers/ScrollerHelper.java b/src/com/google/android/droiddriver/helpers/ScrollerHelper.java
index dc946e7..74059ad 100644
--- a/src/com/google/android/droiddriver/helpers/ScrollerHelper.java
+++ b/src/com/google/android/droiddriver/helpers/ScrollerHelper.java
@@ -20,6 +20,7 @@ import com.google.android.droiddriver.DroidDriver;
import com.google.android.droiddriver.UiElement;
import com.google.android.droiddriver.exceptions.ElementNotFoundException;
import com.google.android.droiddriver.finders.Finder;
+import com.google.android.droiddriver.scroll.Direction.PhysicalDirection;
import com.google.android.droiddriver.scroll.Scroller;
/**
@@ -36,10 +37,39 @@ public class ScrollerHelper {
this.containerFinder = containerFinder;
}
+ /**
+ * Scrolls {@code containerFinder} in both directions if necessary to find
+ * {@code itemFinder}, which is a descendant of {@code containerFinder}.
+ *
+ * @param itemFinder Finder for the desired item; relative to
+ * {@code containerFinder}
+ * @return the UiElement matching {@code itemFinder}
+ * @throws ElementNotFoundException If no match is found
+ */
public UiElement scrollTo(Finder itemFinder) {
return scroller.scrollTo(driver, containerFinder, itemFinder);
}
+ /**
+ * Scrolls {@code containerFinder} in {@code direction} if necessary to find
+ * {@code itemFinder}, which is a descendant of {@code containerFinder}.
+ *
+ * @param itemFinder Finder for the desired item; relative to
+ * {@code containerFinder}
+ * @param direction
+ * @return the UiElement matching {@code itemFinder}
+ * @throws ElementNotFoundException If no match is found
+ */
+ public UiElement scrollTo(Finder itemFinder, PhysicalDirection direction) {
+ return scroller.scrollTo(driver, containerFinder, itemFinder, direction);
+ }
+
+ /**
+ * Scrolls to {@code itemFinder} and returns true, otherwise returns false.
+ *
+ * @param itemFinder Finder for the desired item
+ * @return true if successful, otherwise false
+ */
public boolean canScrollTo(Finder itemFinder) {
try {
scrollTo(itemFinder);
diff --git a/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java b/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java
index 4ff3486..447ee08 100644
--- a/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java
+++ b/src/com/google/android/droiddriver/scroll/AccessibilityEventScrollStepStrategy.java
@@ -81,6 +81,9 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy
private final EndData endData = new EndData();
private AccessibilityEvent event;
+ protected AccessibilityEvent getLastEvent() {
+ return event;
+ }
public AccessibilityEventScrollStepStrategy(UiAutomation uiAutomation,
long scrollEventTimeoutMillis, DirectionConverter converter) {
this.uiAutomation = uiAutomation;
@@ -101,6 +104,13 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy
endData.set(containerFinder, direction);
Logs.log(Log.DEBUG, "reached scroll end");
}
+
+ // Clean up the event after use.
+ if (event != null) {
+ event.recycle();
+ event = null;
+ }
+
return true;
}
@@ -120,8 +130,6 @@ public class AccessibilityEventScrollStepStrategy implements ScrollStepStrategy
foundEnd = event.getScrollX() == 0 || event.getScrollX() == event.getMaxScrollX();
}
}
- event.recycle();
- event = null;
return foundEnd;
}