Merge pull request #1155 from mutualmobile/master

Android support for meta state on key codes (i.e. long press the back ke...
This commit is contained in:
bootstraponline
2013-09-12 12:05:24 -07:00
3 changed files with 23 additions and 9 deletions

View File

@@ -1,16 +1,23 @@
package io.appium.android.bootstrap.handler;
import com.android.uiautomator.core.UiDevice;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Hashtable;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to PressKeyCode.
*
*/
public class PressKeyCode extends CommandHandler {
public Integer keyCode;
public Integer metaState;
/*
* @param command The {@link AndroidCommand} used for this handler.
@@ -23,13 +30,20 @@ public class PressKeyCode extends CommandHandler {
* bootstrap.AndroidCommand)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command) {
public AndroidCommandResult execute(final AndroidCommand command) throws JSONException {
try {
UiDevice.getInstance().pressKeyCode(
(Integer) command.params().get("keycode"));
final Hashtable<String, Object> params = command.params();
keyCode = (Integer) command.params().get("keycode");
if (params.get("metastate") != JSONObject.NULL) {
metaState = (Integer) command.params().get("metastate");
}
UiDevice.getInstance().pressKeyCode(keyCode, metaState);
return getSuccessResult(true);
} catch (final Exception e) {
return getErrorResult(e.getMessage());
}
}
}
}

View File

@@ -74,8 +74,8 @@ Android.prototype.fastReset = function(cb) {
], cb);
};
Android.prototype.keyevent = function(keycode, cb) {
this.proxy(["pressKeyCode", keycode], cb);
Android.prototype.keyevent = function(keycode, metastate, cb) {
this.proxy(["pressKeyCode", {keycode: keycode, metastate: metastate}], cb);
};
Android.prototype.start = function(cb, onDie) {

View File

@@ -1130,7 +1130,7 @@ IOS.prototype.submit = function(elementId, cb) {
}
};
IOS.prototype.keyevent = function(keycode, cb) {
IOS.prototype.keyevent = function(keycode, metastate, cb) {
cb(new NotImplementedError(), null);
};