3

After reading posts I figured out how to emulate a touch event :

adb shell input tap 100 100

I've installed MagicMarker in order to see if anything is drawn, nothing appears.

I've also tried with monkeyrunner/androidViewClient Touch functions :

device.touch(100 , 100, 'DOWN_AND_UP');

My whole code for AndroidViewClient :

#! /usr/bin/env python
# -*- coding: utf-8 -*-

import getopt, sys
import os

# Add android to path becayuse it seems to not appear on windows

sys.path.append("D:/Dev/adt-bundle-windows-x86_64-20131030/sdk/tools")
sys.path.append("D:/Dev/adt-bundle-windows-x86_64-20131030/sdk/tools/lib")
sys.path.append("D:/Dev/adt-bundle-windows-x86_64-20131030/sdk/platform-tools")

# PyDev sets PYTHONPATH, use it
try:
    for p in os.environ['PYTHONPATH'].split(':'):
        if not p in sys.path:
            sys.path.append(p)
except:
    pass

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient, ViewNotFoundException
device, serialno = ViewClient.connectToDeviceOrExit()   
vc = ViewClient(device, serialno)
device.touch(100,100,"DOWN_AND_UP")

I successfully used device.press("KEYCODE_MENU", "DOWN_AND_UP") or device.takeSnapshot(), I don't understand at all why touch events are not received by my handset.

By the way, I am using real devices (a GS3 and GS4 both in 4.3)

Do not hesitate to ask further information.

AdrienG
  • 310
  • 4
  • 9
  • 1
    I have not yet succeeds in using the monkeyrunner Drag function but : - MagicMarker is not a good way to test touch events - adb shell input swipe x0 y0 x1 y1 works like a charm I still would like to know why the drag function is not working, will pursue my anlysis :) – AdrienG Mar 13 '14 at 14:28
  • Looking at Monkeyrunner's source code, they do not have a **swipe** event for a device: https://android.googlesource.com/platform/sdk/+/6db5720/monkeyrunner/src/com/android/monkeyrunner/MonkeyDevice.java – IgorGanapolsky Jul 08 '16 at 16:32

1 Answers1

4

I've tested MagicMarker using this simple AndroidViewClient script. Notice that some fixes to adbclient.drag() were introduced in version 5.1.1 so be sure you have the latest version.

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2014  Diego Torres Milano
'''

__requires__ = ["androidviewclient >= 5.1.1"]
import pkg_resources
from com.dtmilano.android.adb.adbclient import AdbClient

AdbClient(serialno='.*').drag((100, 100), (400, 400), 1000)

This produces:

enter image description here

Also notice than in your script device is the AdbClient instance.

If you check how drag() is implemented in AdbClient, you'll see that is using input swipe with parameters according to the corresponding API level:

def drag(self, (x0, y0), (x1, y1), duration, steps=1):
'''
Sends drag event (actually it's using C{input swipe} command.

@param (x0, y0): starting point
@param (x1, y1): ending point
@param duration: duration of the event in ms
@param steps: number of steps (currently ignored by @{input swipe}
'''

version = int(self.getProperty('ro.build.version.sdk'))
if version <= 15:
    raise RuntimeError('drag: API <= 15 not supported (version=%d)' % version)
elif version <= 17:
    self.shell('input swipe %d %d %d %d' % (x0, y0, x1, y1))
else:
    self.shell('input swipe %d %d %d %d %d' % (x0, y0, x1, y1, duration))
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Thanks for your answer. Indeed I had an older version of AVC (4.6.0), I made the update but it is still not working. In fact, it seems whenever a drag function got a duration, it is not working. The only drag motions I could made were : device.shell('input swipe 300 1270 300 10') but it was too slow and inacurate. For now, I'm using the "ugly" method of touchDown<->several touchMoves <-> touchUp, which is working well – AdrienG Mar 14 '14 at 16:05
  • See my edit, it may give you some hints about how drag is translated to swipe – Diego Torres Milano Mar 14 '14 at 16:26
  • @dtmilano Where are all of the new sample scripts for the 5.1.1? Can't seem to find them and the stuff [here](https://github.com/dtmilano/AndroidViewClient/tree/master/AndroidViewClient/examples) all looks a few years old... – Micro May 29 '14 at 20:05
  • These are the latest examples. Perhaps a bit old but they should work with latest versions too. – Diego Torres Milano May 29 '14 at 21:34