Commits

Fred Grott committed 5a8bf36

first commit

Comments (0)

Files changed (12)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="lib" path="/home/fredgrott/opt/android/android-sdk-linux/tools/lib/chimpchat.jar"/>
+	<classpathentry kind="lib" path="/home/fredgrott/opt/android/android-sdk-linux/tools/lib/ddmlib.jar"/>
+	<classpathentry kind="lib" path="/home/fredgrott/opt/android/android-sdk-linux/tools/lib/guavalib.jar"/>
+	<classpathentry kind="lib" path="/home/fredgrott/opt/android/android-sdk-linux/tools/lib/sdklib.jar"/>
+	<classpathentry kind="lib" path="libs/sikuli-script.jar"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>
+bin/*
+local.properties
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>GWSSikuliChimp</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6

libs/sikuli-script.jar

Binary file added.
+GWSSikuliChimp
+---
+
+Forked from SikuliChimp at GoogleCode.

src/org/bitbucket/fredgrott/gwssikulichimp/device/ISikuliChimpDevice.java

+package org.bitbucket.fredgrott.gwssikulichimp.device;
+
+import java.io.IOException;
+
+import com.android.chimpchat.core.IChimpDevice;
+import com.android.chimpchat.core.TouchPressType;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface ISikuliChimpDevice.
+ *
+ * @author rohit
+ */
+public interface ISikuliChimpDevice extends IChimpDevice {
+
+    /**
+     * Touch.
+     *
+     * @param imageName the image name
+     * @param pressType the press type
+     * @throws IOException Signals that an I/O exception has occurred.
+     */
+    public void touch(String imageName,TouchPressType pressType) throws IOException;
+    
+    /**
+     * Drag.
+     *
+     * @param from the from
+     * @param to the to
+     * @param steps the steps
+     * @param distance the distance
+     * @throws IOException Signals that an I/O exception has occurred.
+     */
+    public void drag(String from, String to, int steps, long distance) throws IOException;
+    
+    /**
+     * Wait for.
+     *
+     * @param imageName the image name
+     * @throws IOException Signals that an I/O exception has occurred.
+     */
+    public void waitFor(String imageName) throws IOException;
+    
+    /**
+     * Wait for.
+     *
+     * @param imageName the image name
+     * @param timeout the timeout
+     * @throws IOException Signals that an I/O exception has occurred.
+     */
+    public void waitFor(String imageName, int timeout) throws IOException;
+    
+    /**
+     * Unlock device.
+     */
+    public void unlockDevice();
+    
+    /**
+     * Lock device.
+     */
+    public void lockDevice();
+    
+    /**
+     * Start activity.
+     *
+     * @param component the component
+     */
+    public void startActivity(String component);
+}

src/org/bitbucket/fredgrott/gwssikulichimp/device/SikuliChimpDevice.java

+package org.bitbucket.fredgrott.gwssikulichimp.device;
+
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.sikuli.script.Finder;
+import org.sikuli.script.Match;
+import org.sikuli.script.Region;
+import org.sikuli.script.ScreenImage;
+
+import com.android.chimpchat.ChimpManager;
+import com.android.chimpchat.adb.LinearInterpolator.Point;
+import com.android.chimpchat.core.IChimpDevice;
+import com.android.chimpchat.core.IChimpImage;
+import com.android.chimpchat.core.IChimpView;
+import com.android.chimpchat.core.IMultiSelector;
+import com.android.chimpchat.core.ISelector;
+import com.android.chimpchat.core.PhysicalButton;
+import com.android.chimpchat.core.TouchPressType;
+import com.android.chimpchat.hierarchyviewer.HierarchyViewer;
+import org.bitbucket.fredgrott.gwssikulichimp.resolver.IImageResolver;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class SikuliChimpDevice.
+ *
+ * @author rohit
+ */
+public class SikuliChimpDevice implements ISikuliChimpDevice {
+
+    /** The device. */
+    private IChimpDevice device = null;
+    
+    /** The image resolver. */
+    private IImageResolver imageResolver = null;
+
+    /**
+     * Instantiates a new sikuli chimp device.
+     *
+     * @param device the device
+     * @param imageResolver the image resolver
+     */
+    public SikuliChimpDevice(IChimpDevice device, IImageResolver imageResolver) {
+        this.device = device;
+        this.imageResolver = imageResolver;
+    }
+
+    /**
+     * Broadcast intent.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @param arg2 the arg2
+     * @param arg3 the arg3
+     * @param arg4 the arg4
+     * @param arg5 the arg5
+     * @param arg6 the arg6
+     * @param arg7 the arg7
+     * @see com.android.chimpchat.adb.AdbChimpDevice#broadcastIntent(java.lang.String,
+     * java.lang.String, java.lang.String, java.lang.String,
+     * java.util.Collection, java.util.Map, java.lang.String, int)
+     */
+    public void broadcastIntent(String arg0, String arg1, String arg2,
+            String arg3, Collection<String> arg4, Map<String, Object> arg5,
+            String arg6, int arg7) {
+        device.broadcastIntent(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+    }
+
+    /**
+     * Dispose.
+     *
+     * @see com.android.chimpchat.adb.AdbChimpDevice#dispose()
+     */
+    public void dispose() {
+        device.dispose();
+    }
+
+    /**
+     * Drag.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @param arg2 the arg2
+     * @param arg3 the arg3
+     * @param arg4 the arg4
+     * @param arg5 the arg5
+     * @see com.android.chimpchat.adb.AdbChimpDevice#drag(int, int, int, int,
+     * int, long)
+     */
+    public void drag(int arg0, int arg1, int arg2, int arg3, int arg4, long arg5) {
+        device.drag(arg0, arg1, arg2, arg3, arg4, arg5);
+    }
+
+    /**
+     * Equals.
+     *
+     * @param arg0 the arg0
+     * @return true, if successful
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals(Object arg0) {
+        return device.equals(arg0);
+    }
+
+    /**
+     * Gets the hierarchy viewer.
+     *
+     * @return the hierarchy viewer
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getHierarchyViewer()
+     */
+    public HierarchyViewer getHierarchyViewer() {
+        return device.getHierarchyViewer();
+    }
+
+    /**
+     * Gets the manager.
+     *
+     * @return the manager
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getManager()
+     */
+    public ChimpManager getManager() {
+        return device.getManager();
+    }
+
+    /**
+     * Gets the property.
+     *
+     * @param key the key
+     * @return the property
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getProperty(java.lang.String)
+     */
+    public String getProperty(String key) {
+        return device.getProperty(key);
+    }
+
+    /**
+     * Gets the property list.
+     *
+     * @return the property list
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getPropertyList()
+     */
+    public Collection<String> getPropertyList() {
+        return device.getPropertyList();
+    }
+
+    /**
+     * Gets the root view.
+     *
+     * @return the root view
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getRootView()
+     */
+    public IChimpView getRootView() {
+        return device.getRootView();
+    }
+
+    /**
+     * Gets the system property.
+     *
+     * @param key the key
+     * @return the system property
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getSystemProperty(java.lang.String)
+     */
+    public String getSystemProperty(String key) {
+        return device.getSystemProperty(key);
+    }
+
+    /**
+     * Gets the view.
+     *
+     * @param selector the selector
+     * @return the view
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getView(com.android.chimpchat.core.ISelector)
+     */
+    public IChimpView getView(ISelector selector) {
+        return device.getView(selector);
+    }
+
+    /**
+     * Gets the view id list.
+     *
+     * @return the view id list
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getViewIdList()
+     */
+    public Collection<String> getViewIdList() {
+        return device.getViewIdList();
+    }
+
+    /**
+     * Gets the views.
+     *
+     * @param multiSelector the multi selector
+     * @return the views
+     * @see com.android.chimpchat.adb.AdbChimpDevice#getViews(com.android.chimpchat.core.IMultiSelector)
+     */
+    public Collection<IChimpView> getViews(IMultiSelector multiSelector) {
+        return device.getViews(multiSelector);
+    }
+
+    /**
+     * Hash code.
+     *
+     * @return the int
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        return device.hashCode();
+    }
+
+    /**
+     * Install package.
+     *
+     * @param packageName the package name
+     * @return true, if successful
+     * @see com.android.chimpchat.adb.AdbChimpDevice#installPackage(java.lang.String)
+     */
+    public boolean installPackage(String packageName) {
+        return device.installPackage(packageName);
+    }
+
+    /**
+     * Instrument.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @return the map
+     * @see com.android.chimpchat.adb.AdbChimpDevice#instrument(java.lang.String,
+     * java.util.Map)
+     */
+    public Map<String, Object> instrument(String arg0, Map<String, Object> arg1) {
+        return device.instrument(arg0, arg1);
+    }
+
+    /**
+     * Press.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @see com.android.chimpchat.adb.AdbChimpDevice#press(com.android.chimpchat.core.PhysicalButton,
+     * com.android.chimpchat.core.TouchPressType)
+     */
+    public void press(PhysicalButton arg0, TouchPressType arg1) {
+        device.press(arg0, arg1);
+    }
+
+    /**
+     * Press.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @see com.android.chimpchat.adb.AdbChimpDevice#press(java.lang.String,
+     * com.android.chimpchat.core.TouchPressType)
+     */
+    public void press(String arg0, TouchPressType arg1) {
+        device.press(arg0, arg1);
+    }
+
+    /**
+     * Reboot.
+     *
+     * @param arg0 the arg0
+     * @see com.android.chimpchat.adb.AdbChimpDevice#reboot(java.lang.String)
+     */
+    public void reboot(String arg0) {
+        device.reboot(arg0);
+    }
+
+    /**
+     * Removes the package.
+     *
+     * @param arg0 the arg0
+     * @return true, if successful
+     * @see com.android.chimpchat.adb.AdbChimpDevice#removePackage(java.lang.String)
+     */
+    public boolean removePackage(String arg0) {
+        return device.removePackage(arg0);
+    }
+
+    /**
+     * Shell.
+     *
+     * @param arg0 the arg0
+     * @return the string
+     * @see com.android.chimpchat.adb.AdbChimpDevice#shell(java.lang.String)
+     */
+    public String shell(String arg0) {
+        return device.shell(arg0);
+    }
+
+    /**
+     * Start activity.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @param arg2 the arg2
+     * @param arg3 the arg3
+     * @param arg4 the arg4
+     * @param arg5 the arg5
+     * @param arg6 the arg6
+     * @param arg7 the arg7
+     * @see com.android.chimpchat.adb.AdbChimpDevice#startActivity(java.lang.String,
+     * java.lang.String, java.lang.String, java.lang.String,
+     * java.util.Collection, java.util.Map, java.lang.String, int)
+     */
+    public void startActivity(String arg0, String arg1, String arg2,
+            String arg3, Collection<String> arg4, Map<String, Object> arg5,
+            String arg6, int arg7) {
+        device.startActivity(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+    }
+
+    /**
+     * Take snapshot.
+     *
+     * @return the i chimp image
+     * @see com.android.chimpchat.adb.AdbChimpDevice#takeSnapshot()
+     */
+    public IChimpImage takeSnapshot() {
+        return device.takeSnapshot();
+    }
+
+    /**
+     * To string.
+     *
+     * @return the string
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return device.toString();
+    }
+
+    /**
+     * Touch.
+     *
+     * @param arg0 the arg0
+     * @param arg1 the arg1
+     * @param arg2 the arg2
+     * @see com.android.chimpchat.adb.AdbChimpDevice#touch(int, int,
+     * com.android.chimpchat.core.TouchPressType)
+     */
+    public void touch(int arg0, int arg1, TouchPressType arg2) {
+        device.touch(arg0, arg1, arg2);
+    }
+
+    /**
+     * Type.
+     *
+     * @param arg0 the arg0
+     * @see com.android.chimpchat.adb.AdbChimpDevice#type(java.lang.String)
+     */
+    public void type(String arg0) {
+        device.type(arg0);
+    }
+
+    /**
+     * Wake.
+     *
+     * @see com.android.chimpchat.adb.AdbChimpDevice#wake()
+     */
+    public void wake() {
+        device.wake();
+    }
+
+    /**
+     * Touch.
+     *
+     * @param imageName the image name
+     * @param pressType the press type
+     * @throws IOException Signals that an I/O exception has occurred.
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#touch(java.lang.String, com.android.chimpchat.core.TouchPressType)
+     */
+    @Override
+    public void touch(String imageName, TouchPressType pressType)
+            throws IOException {
+        Point point = findClickPoint(imageName);
+        if (null != point) {
+            device.touch(point.getX(), point.getY(), TouchPressType.DOWN_AND_UP);
+        }
+        else{
+            //FIXME - Log
+        }
+    }
+
+    /**
+     * Drag.
+     *
+     * @param from the from
+     * @param to the to
+     * @param steps the steps
+     * @param distance the distance
+     * @throws IOException Signals that an I/O exception has occurred.
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#drag(java.lang.String, java.lang.String, int, long)
+     */
+    @Override
+    public void drag(String from, String to, int steps, long distance)
+            throws IOException {
+        Point fromPoint = findClickPoint(from);
+        Point toPoint = findClickPoint(to);
+        if(null!=fromPoint && null!=to){
+            device.drag(fromPoint.getX(), fromPoint.getY(), toPoint.getX(), toPoint.getY(), steps, distance);
+        }
+        else{
+            //FIXME - Log
+        }
+
+        
+    }
+
+    /**
+     * Wait for.
+     *
+     * @param imageName the image name
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#waitFor(java.lang.String)
+     */
+    @Override
+    public void waitFor(String imageName) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Wait for.
+     *
+     * @param imageName the image name
+     * @param timeout the timeout
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#waitFor(java.lang.String, int)
+     */
+    @Override
+    public void waitFor(String imageName, int timeout) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Unlock device.
+     *
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#unlockDevice()
+     */
+    @Override
+    public void unlockDevice() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Lock device.
+     *
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#lockDevice()
+     */
+    @Override
+    public void lockDevice() {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Start activity.
+     *
+     * @param component the component
+     * @see org.bitbucket.fredgrott.gwssikulichimp.device.ISikuliChimpDevice#startActivity(java.lang.String)
+     */
+    @Override
+    public void startActivity(String component) {
+        device.startActivity(null, null, null, null, new ArrayList<String>(),
+                new HashMap<String, Object>(), component, 0);
+
+    }
+
+    /**
+     * Gets the current screen finder.
+     *
+     * @param device the device
+     * @return the current screen finder
+     */
+    @SuppressWarnings("deprecation")
+    private Finder getCurrentScreenFinder(IChimpDevice device) {
+        BufferedImage buffImage = device.takeSnapshot().createBufferedImage();
+        Rectangle rect = new Rectangle(0, 0, buffImage.getWidth(),
+                buffImage.getHeight());
+        ScreenImage screenImage = new ScreenImage(rect, buffImage);
+
+        Finder finder = new Finder(screenImage, new Region(0, 0,
+                buffImage.getWidth(), buffImage.getHeight()));
+
+        return finder;
+    }
+
+    /**
+     * Touch.
+     *
+     * @param match the match
+     * @param device the device
+     */
+    @SuppressWarnings("unused")
+    private void touch(Match match, IChimpDevice device) {
+
+    }
+
+    /**
+     * Find the Point for the given Image incurrent screen on Android.
+     *
+     * @param imageName the image name
+     * @return the point
+     * @throws IOException Signals that an I/O exception has occurred.
+     */
+    private Point findClickPoint(String imageName) throws IOException {
+        Point point = null;
+        String actualImageName = imageResolver.getImagePath(imageName);
+        Finder finder = getCurrentScreenFinder(device);
+        finder.find(actualImageName, 0.7);
+        if (finder.hasNext()) {
+            Match match = finder.next();
+            point = new Point(match.x + (match.w / 2), match.y + (match.h / 2));
+        }
+        return point;
+    }
+
+}

src/org/bitbucket/fredgrott/gwssikulichimp/device/package-info.java

+/**
+ * 
+ */
+/**
+ * @author fredgrott
+ *
+ */
+
+package org.bitbucket.fredgrott.gwssikulichimp.device;

src/org/bitbucket/fredgrott/gwssikulichimp/resolver/IImageResolver.java

+package org.bitbucket.fredgrott.gwssikulichimp.resolver;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface IImageResolver.
+ *
+ * @author rohit
+ */
+public interface IImageResolver {
+
+    /**
+     * Gets the image path.
+     *
+     * @param imageName the image name
+     * @return the image path
+     */
+    public String getImagePath(String imageName);
+}

src/org/bitbucket/fredgrott/gwssikulichimp/resolver/PrefixPostFixImageResolver.java

+package org.bitbucket.fredgrott.gwssikulichimp.resolver;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class PrefixPostFixImageResolver.
+ *
+ * @author rohit
+ */
+public class PrefixPostFixImageResolver implements IImageResolver {
+
+    /** The prefix. */
+    private String prefix;
+    
+    /** The post fix. */
+    private String postFix;
+    
+    /**
+     * Instantiates a new prefix post fix image resolver.
+     *
+     * @param prefix the prefix
+     * @param postFix the post fix
+     */
+    public PrefixPostFixImageResolver(String prefix,String postFix){
+        this.prefix=prefix;
+        this.postFix=postFix;
+    }
+    /**
+     * Given that the imageName is "button", this method returns
+     * "screenshots/button.png"
+     * 
+     * @param imageName
+     *            Name of the Image
+     * @return screenhots/<<imageName>>.png
+     */
+    @Override
+    public String getImagePath(String imageName) {
+        return prefix + imageName + postFix;
+    }
+
+}

src/org/bitbucket/fredgrott/gwssikulichimp/resolver/package-info.java

+/**
+ * 
+ */
+/**
+ * @author fredgrott
+ *
+ */
+
+package org.bitbucket.fredgrott.gwssikulichimp.resolver;