diff options
author | Kevin Jin <kjin@google.com> | 2013-11-13 16:00:15 -0800 |
---|---|---|
committer | Kevin Jin <kjin@google.com> | 2013-11-13 16:00:15 -0800 |
commit | 8d19bb634c670a49f7a58636a2a535c86b57d538 (patch) | |
tree | a217342b9c9c3a9a7a1afe66300757f1dbc1dc4a /src | |
parent | 337ca4544bae72b86e92d0cc18fada5dcb685ab4 (diff) | |
download | droiddriver-8d19bb634c670a49f7a58636a2a535c86b57d538.tar.gz |
adjust fling steps for GingerBread
fix NoSuchMethodError for GingerBread
Change-Id: I4883c8b90a5e6aee6a4392e67f038139edb85fe5
Diffstat (limited to 'src')
5 files changed, 36 insertions, 17 deletions
diff --git a/src/com/google/android/droiddriver/actions/SingleKeyAction.java b/src/com/google/android/droiddriver/actions/SingleKeyAction.java index 6f8d292..9faba80 100644 --- a/src/com/google/android/droiddriver/actions/SingleKeyAction.java +++ b/src/com/google/android/droiddriver/actions/SingleKeyAction.java @@ -16,6 +16,7 @@ package com.google.android.droiddriver.actions; +import android.os.Build; import android.os.SystemClock; import android.view.KeyEvent; @@ -66,6 +67,9 @@ public class SingleKeyAction extends KeyAction { @Override public String toString() { - return Objects.toStringHelper(this).addValue(KeyEvent.keyCodeToString(keyCode)).toString(); + String keyCodeString = + Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1 ? String.valueOf(keyCode) + : KeyEvent.keyCodeToString(keyCode); + return Objects.toStringHelper(this).addValue(keyCodeString).toString(); } } diff --git a/src/com/google/android/droiddriver/actions/SwipeAction.java b/src/com/google/android/droiddriver/actions/SwipeAction.java index 27700d6..ca165f1 100644 --- a/src/com/google/android/droiddriver/actions/SwipeAction.java +++ b/src/com/google/android/droiddriver/actions/SwipeAction.java @@ -47,26 +47,29 @@ public class SwipeAction extends ScrollAction { // theory a swipe of 20 steps is a scroll instead of fling on devices that // have 20 * 50 * 5 = 5000 pixels in one direction. Make it 40 for safety. private static final int SCROLL_STEPS = 40; - private static final int FLING_STEPS = 2; + // FLING_STEPS = 2 does not work on GingerBread + private static final int FLING_STEPS = 3; /** * Common instances for convenience. The direction in names reflects the * direction of finger rather than the scroll direction. */ - public static final SwipeAction SWIPE_DOWN = new SwipeAction(UP, SCROLL_STEPS); - public static final SwipeAction SWIPE_UP = new SwipeAction(DOWN, SCROLL_STEPS); - public static final SwipeAction SWIPE_RIGHT = new SwipeAction(LEFT, SCROLL_STEPS); - public static final SwipeAction SWIPE_LEFT = new SwipeAction(RIGHT, SCROLL_STEPS); + private static final SwipeAction SWIPE_DOWN = new SwipeAction(UP, SCROLL_STEPS); + private static final SwipeAction SWIPE_UP = new SwipeAction(DOWN, SCROLL_STEPS); + private static final SwipeAction SWIPE_RIGHT = new SwipeAction(LEFT, SCROLL_STEPS); + private static final SwipeAction SWIPE_LEFT = new SwipeAction(RIGHT, SCROLL_STEPS); - public static final SwipeAction FLING_DOWN = new SwipeAction(UP, FLING_STEPS); - public static final SwipeAction FLING_UP = new SwipeAction(DOWN, FLING_STEPS); - public static final SwipeAction FLING_RIGHT = new SwipeAction(LEFT, FLING_STEPS); - public static final SwipeAction FLING_LEFT = new SwipeAction(RIGHT, FLING_STEPS); + private static final SwipeAction FLING_DOWN = new SwipeAction(UP, FLING_STEPS); + private static final SwipeAction FLING_UP = new SwipeAction(DOWN, FLING_STEPS); + private static final SwipeAction FLING_RIGHT = new SwipeAction(LEFT, FLING_STEPS); + private static final SwipeAction FLING_LEFT = new SwipeAction(RIGHT, FLING_STEPS); /** * Gets canned common instances for scrolling. Note the scroll direction * specifies where the content will move, instead of the finger. */ + // TODO: We may use "smart" steps that depend on the size of the UiElement and + // ViewConfiguration#getScaledMinimumFlingVelocity. public static SwipeAction toScroll(PhysicalDirection direction) { switch (direction) { case UP: @@ -86,6 +89,8 @@ public class SwipeAction extends ScrollAction { * Gets canned common instances for flinging. Note the scroll direction * specifies where the content will move, instead of the finger. */ + // TODO: We may use "smart" steps that depend on the size of the UiElement and + // ViewConfiguration#getScaledMinimumFlingVelocity. public static SwipeAction toFling(PhysicalDirection direction) { switch (direction) { case UP: @@ -179,6 +184,7 @@ public class SwipeAction extends ScrollAction { // First touch starts exactly at the point requested long downTime = Events.touchDown(injector, startX, startY); + SystemClock.sleep(ACTION_MOVE_INTERVAL); if (drag) { SystemClock.sleep((long) (ViewConfiguration.getLongPressTimeout() * 1.5f)); } diff --git a/src/com/google/android/droiddriver/actions/TextAction.java b/src/com/google/android/droiddriver/actions/TextAction.java index 80250f7..35f13bd 100644 --- a/src/com/google/android/droiddriver/actions/TextAction.java +++ b/src/com/google/android/droiddriver/actions/TextAction.java @@ -16,6 +16,7 @@ package com.google.android.droiddriver.actions; +import android.os.Build; import android.os.SystemClock; import android.view.KeyCharacterMap; import android.view.KeyEvent; @@ -30,8 +31,11 @@ import com.google.common.base.Preconditions; */ public class TextAction extends KeyAction { - private static final KeyCharacterMap KEY_CHAR_MAP = KeyCharacterMap - .load(KeyCharacterMap.VIRTUAL_KEYBOARD); + @SuppressWarnings("deprecation") + private static final KeyCharacterMap KEY_CHAR_MAP = + Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? KeyCharacterMap + .load(KeyCharacterMap.BUILT_IN_KEYBOARD) : KeyCharacterMap + .load(KeyCharacterMap.VIRTUAL_KEYBOARD); private final String text; diff --git a/src/com/google/android/droiddriver/base/BaseUiElement.java b/src/com/google/android/droiddriver/base/BaseUiElement.java index c028a8e..c82c2f0 100644 --- a/src/com/google/android/droiddriver/base/BaseUiElement.java +++ b/src/com/google/android/droiddriver/base/BaseUiElement.java @@ -145,10 +145,7 @@ public abstract class BaseUiElement implements UiElement { return action.perform(getInjector(), this); } - protected void doPerformAndWait(FutureTask<Boolean> futureTask, long timeoutMillis) { - // ignores timeoutMillis; subclasses can override this behavior - futureTask.run(); - } + protected abstract void doPerformAndWait(FutureTask<Boolean> futureTask, long timeoutMillis); private boolean performAndWait(final Action action) { // timeoutMillis <= 0 means no need to wait @@ -236,7 +233,7 @@ public abstract class BaseUiElement implements UiElement { } if (!isVisible()) { toStringHelper.addValue(ATTRIB_NOT_VISIBLE); - } else if (!getVisibleBounds().equals(getBounds())){ + } else if (!getVisibleBounds().equals(getBounds())) { toStringHelper.add(ATTRIB_VISIBLE_BOUNDS, getVisibleBounds().toShortString()); } return toStringHelper.toString(); diff --git a/src/com/google/android/droiddriver/instrumentation/ViewElement.java b/src/com/google/android/droiddriver/instrumentation/ViewElement.java index 070d14f..3a16677 100644 --- a/src/com/google/android/droiddriver/instrumentation/ViewElement.java +++ b/src/com/google/android/droiddriver/instrumentation/ViewElement.java @@ -39,6 +39,7 @@ import com.google.common.collect.Maps; import java.util.List; import java.util.Map; +import java.util.concurrent.FutureTask; /** * A UiElement that is backed by a View. @@ -258,4 +259,11 @@ public class ViewElement extends BaseUiElement { public InputInjector getInjector() { return context.getInjector(); } + + @Override + protected void doPerformAndWait(FutureTask<Boolean> futureTask, long timeoutMillis) { + futureTask.run(); + // Instead of specific timeoutMillis, wait for idle + context.getInstrumentation().waitForIdleSync(); + } } |