304 @Override
305 public boolean onDown(MotionEvent e) {
308 mTouchScrolling = false;
309 mSeenFirstScrollEvent = false;
316 if (sendMotionEventAsGesture(GESTURE_TAP_DOWN, e, null)) {
318 }
319 // Return true to indicate that we want to handle touch
320 return true;
321 }
323 @Override
324 public boolean onScroll(MotionEvent e1, MotionEvent e2,
325 float distanceX, float distanceY) {
327 if (!mSeenFirstScrollEvent) {
328 // Remove the touch slop region from the first scroll event to avoid a
329 // jump.
330 mSeenFirstScrollEvent = true;
331 double distance = Math.sqrt(
332 distanceX * distanceX + distanceY * distanceY);
333 double epsilon = 1e-3;
334 if (distance > epsilon) {
335 double ratio = Math.max(0, distance - scaledTouchSlop) / distance ;
336 distanceX *= ratio;
337 distanceY *= ratio;
338 }
339 }
359 // distanceX and distanceY is the scrolling offset since last onScroll.
360 // Because we are passing integers to webkit, this could introduce
361 // rounding errors. The rounding errors will accumulate overtime.
362 // To solve this, we should be adding back the rounding errors each time
363 // when we calculate the new offset.
364 int x = (int) e2.getX();
365 int y = (int) e2.getY();
366 int dx = (int) (distanceX + mAccumulatedScrollErrorX);
367 int dy = (int) (distanceY + mAccumulatedScrollErrorY);
368 mAccumulatedScrollErrorX = distanceX + mAccumulatedScrollErrorX - dx;
369 mAccumulatedScrollErrorY = distanceY + mAccumulatedScrollErrorY - dy;
370
371 mExtraParamBundleScroll.putInt(DISTANCE_X, dx);
372 mExtraParamBundleScroll.putInt(DISTANCE_Y, dy);
373 assert mExtraParamBundleScroll.size() == 2;
374
375 if ((dx | dy) != 0) {
376 sendGesture(GESTURE_SCROLL_BY,
377 e2.getEventTime(), x, y, mExtraParamBundleScroll);
378 }
# -*- coding:utf-8 -*-
# 決まり文句
import time
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
d = MonkeyRunner.waitForConnection(deviceId="EP7331C9G7")
# screen on
d.wake()
time.sleep(1)
# swipe up for unlock
x=int(d.getProperty("display.width"),10)/2
y1=int(d.getProperty("display.height"),10)/4
y0=y1*3
d.drag((x,y0),(x,y1),0.2,10)
time.sleep(1)
# launch google chrome
d.press("KEYCODE_HOME",MonkeyDevice.DOWN_AND_UP)
time.sleep(1)
d.shell("am start -n com.android.chrome/com.google.android.apps.chrome.Main")
time.sleep(1)
# browse yahoo.com
d.press("KEYCODE_SEARCH",MonkeyDevice.DOWN_AND_UP)
time.sleep(1)
for i in xrange(200):
d.press("KEYCODE_DEL",MonkeyDevice.DOWN_AND_UP)
d.type("http://www.yahoo.com/")
time.sleep(1)
d.press("KEYCODE_ENTER",MonkeyDevice.DOWN_AND_UP)
time.sleep(0.2)
d.press("KEYCODE_ENTER",MonkeyDevice.DOWN_AND_UP)
time.sleep(5)
# swipe up 3 times
y0=y1*2
for i in xrange(3):
d.drag((x,y0),(x,y1),0.2,10)
time.sleep(0.5)
time.sleep(3)
# swipe up 3 times
y0=y1*2
for i in xrange(3):
d.drag((x,y1),(x,y0),0.2,10)
time.sleep(0.5)
time.sleep(3)
# return to HOME
d.press("KEYCODE_HOME",MonkeyDevice.DOWN_AND_UP)
time.sleep(2)
d.press("KEYCODE_POWER",MonkeyDevice.DOWN_AND_UP)
time.sleep(1)
import os,sys
if sys.argv==1:
for i in xrange(1000):
os.system("monkeyrunner %s %d"%(sys.argv[0],d))
else:
i=int(sys.argv[1],10)
print i,"回目のテスト"
doTest()
92 /**
93 * Defines the duration in milliseconds between the first tap's up event and
94 * the second tap's down event for an interaction to be considered a
95 * double-tap.
96 */ 97 privatestaticfinalintDOUBLE_TAP_TIMEOUT = 300;