mirror of
https://github.com/appium/appium.git
synced 2026-01-26 12:18:51 -06:00
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:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user