https://plus.universal-robots.com/urcap-basics/api-reference-docs/
Quick link to the API guide.
In your Contribution’s constructor, it can be helpful to assign an instance of the UserInteraction interface like so:
userInteraction = apiProvider.getUserInterfaceAPI().getUserInteraction();
Here’s an example of the code used in the Contribution to create an Integer keyboard, complete with a Validator that will restrict user input to be between whatever is passed as the minValue and maxValue.
public KeyboardNumberInput<Integer> getIntegerKeyoard(Integer initialValue, Integer minValue, Integer maxValue) {
KeyboardInputFactory keyboardFactory = userInteraction.getKeyboardInputFactory();
InputValidationFactory validationFactory = userInteraction.getInputValidationFactory();
InputValidator<Integer> validator = validationFactory.createIntegerRangeValidator(minValue, maxValue);
final KeyboardNumberInput<Integer> keyboardInput = keyboardFactory.createIntegerKeypadInput();
keyboardInput.setErrorValidator(validator);
keyboardInput.setInitialValue(initialValue);
return keyboardInput;
}
This example is written to take 3 arguments: a value that will appear by default in the field when clicked (almost always just pulling the .getText() of the object) , a minimum value, and a maximum value.
This is called from the View by putting the following inside whatever onClick listener you’ve chosen:
final KeyboardNumberInput<Integer> keyboardInput = provider.get().getIntegerKeyoard(
Integer.valueOf(myTextField.getText()),
(int)minValue,
(int)maxValue);
keyboardInput.show(myTextField, provider.get().getCallbackForMyTextField());
Then finally you also need to include a Callback method in your contribution that overrides the “on ok” method so you can capture the user pressing the OK button:
@Override
public KeyboardInputCallback<Integer> getCallbackForMyTextField() {
return new KeyboardInputCallback<Integer>() {
@Override
public void onOk(final Integer value) {
onMyTextFieldValueChanged(value);
}
};
}
Then you can do whatever you want to do in the “onMyTextFieldValueChanged()” method. You could also just put it in the onOK method if you wanted, but I like to break things up for clarity. Typically this is where you’d do some model.set() calls to store whatever the user has typed to the model.