use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderCurrency method renderField.
@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
if (field == null) {
throw new InvalidParameterException("Error rendering currency, field may not be null");
}
if (inputDataPersister == null) {
throw new InvalidParameterException("Error rendering currency, inputDataPersister may not be null");
}
if (rowView == null) {
throw new InvalidParameterException("Error rendering currency, rowView may not be null");
}
if (paymentContext == null) {
throw new InvalidParameterException("Error rendering currency, paymentContext may not be null");
}
PaymentItem paymentItem = inputDataPersister.getPaymentItem();
// Create new EditText and set its style, restrictions, mask and keyboardtype
EditText integerPart = new EditText(rowView.getContext());
// maxlength is 9 - 2 so no integer overflow
integerPart.setFilters(new InputFilter[] { new InputFilter.LengthFilter(7) });
Translator translator = Translator.getInstance(rowView.getContext());
String label = translator.getPaymentProductFieldLabel(paymentItem.getId(), field.getId());
integerPart.setHint(label);
// Set correct inputType type
switch(field.getDisplayHints().getPreferredInputType()) {
case INTEGER_KEYBOARD:
integerPart.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
break;
case STRING_KEYBOARD:
integerPart.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
break;
case PHONE_NUMBER_KEYBOARD:
integerPart.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
break;
case EMAIL_ADDRESS_KEYBOARD:
integerPart.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
break;
default:
integerPart.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
break;
}
// Check if this edittext should be obfuscated
if (field.getDisplayHints().isObfuscate()) {
integerPart.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
// Set values from account on file
if (inputDataPersister.getAccountOnFile() != null) {
for (KeyValuePair attribute : inputDataPersister.getAccountOnFile().getAttributes()) {
if (attribute.getKey().equals(field.getId())) {
StringFormatter stringFormatter = new StringFormatter();
String maskedValue = stringFormatter.applyMask(field.getDisplayHints().getMask().replace("9", "*"), attribute.getValue());
integerPart.setText(maskedValue);
if (!attribute.isEditingAllowed()) {
integerPart.setEnabled(false);
}
}
}
}
LinearLayout linearLayout = new LinearLayout(rowView.getContext());
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TextView currencySymbol = new TextView(rowView.getContext());
currencySymbol.setText(paymentContext.getAmountOfMoney().getCurrencyCode().toString());
TextView separator = new TextView(rowView.getContext());
String separatorLabel = translator.getPaymentProductFieldLabel(paymentItem.getId(), "separator");
separator.setText(separatorLabel);
EditText decimalPart = new EditText(rowView.getContext());
decimalPart.setHint("00");
decimalPart.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
decimalPart.setFilters(new InputFilter[] { new InputFilter.LengthFilter(2) });
integerPart.addTextChangedListener(new FieldInputTextWatcherCurrency(inputDataPersister, field.getId(), decimalPart, true));
decimalPart.addTextChangedListener(new FieldInputTextWatcherCurrency(inputDataPersister, field.getId(), integerPart, false));
// Restore data that has previously been entered in this field
if (inputDataPersister.getValue(field.getId()) != null) {
String value = inputDataPersister.getValue(field.getId());
if (value.length() > 2) {
integerPart.setText(value.substring(0, value.length() - 2));
}
if (!value.endsWith("00")) {
decimalPart.setText(value.substring(value.length() - 2));
}
}
LinearLayout.LayoutParams params0 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
linearLayout.addView(currencySymbol, params0);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f);
linearLayout.addView(integerPart, params1);
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
linearLayout.addView(separator, params2);
LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
linearLayout.addView(decimalPart, params3);
// Add it to parentView
rowView.addView(linearLayout);
return linearLayout;
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderInputFieldHelper method renderField.
/**
* Renders a given field with the given renderer
* @param renderer, the RenderInputFieldInterface which determines how the PaymentProductField is rendered
* @param field, the PaymentProductField which is rendered
*/
public void renderField(RenderInputFieldInterface renderer, PaymentProductField field, InputDataPersister inputDataPersister, PaymentContext paymentContext) {
PaymentItem paymentItem = inputDataPersister.getPaymentItem();
if (renderer != null) {
// Create new row
LinearLayout rowView = new LinearLayout(parentView.getContext());
rowView.setOrientation(LinearLayout.VERTICAL);
rowView.setPadding(0, 20, 0, 0);
// Create new row entry
LinearLayout rowContentView = new LinearLayout(parentView.getContext());
rowContentView.setOrientation(LinearLayout.HORIZONTAL);
// be in the row content view
if (renderer instanceof RenderBoolean) {
labelRenderer.renderLabel(field, paymentItem, rowContentView);
} else {
labelRenderer.renderLabel(field, paymentItem, rowView);
}
// Render field in row and set a tag so we can look it up later
View view = renderer.renderField(field, inputDataPersister, rowContentView, paymentContext);
view.setTag(field.getId());
// Set focus on the first field
if (!isFocusSet) {
view.requestFocus();
isFocusSet = true;
}
// Render tooltip in row
if (view.isEnabled()) {
tooltipRenderer.renderTooltip(field.getId(), paymentItem, rowContentView);
}
rowView.addView(rowContentView);
// Add row to parentView
LayoutParams rowParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
parentView.addView(rowView, rowParams);
}
}
use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentItem in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderTextField method renderField.
@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
if (field == null) {
throw new InvalidParameterException("Error rendering textfield, field may not be null");
}
if (rowView == null) {
throw new InvalidParameterException("Error rendering textfield, rowView may not be null");
}
if (inputDataPersister == null) {
throw new InvalidParameterException("Error rendering textfield, inputDataPersister may not be null");
}
PaymentItem paymentItem = inputDataPersister.getPaymentItem();
AccountOnFile accountOnFile = inputDataPersister.getAccountOnFile();
// Create new EditText and set its style, restrictions, mask and keyboardtype
EditText editText = new EditText(rowView.getContext());
editText.setTextAppearance(rowView.getContext(), R.style.TextField);
if (field.getDataRestrictions().getValidator().getLength() != null) {
// Set maxLength for field
Integer maxLength = field.getDataRestrictions().getValidator().getLength().getMaxLength();
if (maxLength > 0) {
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });
editText.setEms(maxLength);
}
}
Translator translator = Translator.getInstance(rowView.getContext());
String label = translator.getPaymentProductFieldPlaceholderText(paymentItem.getId(), field.getId());
editText.setHint(label);
// Set correct inputType type
switch(field.getDisplayHints().getPreferredInputType()) {
case INTEGER_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_CLASS_NUMBER);
break;
case STRING_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
break;
case PHONE_NUMBER_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
break;
case EMAIL_ADDRESS_KEYBOARD:
editText.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
break;
case DATE_PICKER:
editText.setInputType(InputType.TYPE_DATETIME_VARIATION_DATE);
default:
editText.setInputType(android.text.InputType.TYPE_CLASS_TEXT);
break;
}
// Check if this edittext should be obfuscated
if (field.getDisplayHints().isObfuscate()) {
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
// Add mask functionality when a mask is set
Boolean addMasking = field.getDisplayHints().getMask() != null;
Integer maskLength = 0;
if (field.getDisplayHints().getMask() != null) {
maskLength = field.getDisplayHints().getMask().replace("{", "").replace("}", "").length();
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maskLength) });
} else if (field.getDataRestrictions().getValidator().getLength() != null) {
maskLength = field.getDataRestrictions().getValidator().getLength().getMaxLength();
}
// Set values from account on file
if (accountOnFile != null) {
for (KeyValuePair attribute : accountOnFile.getAttributes()) {
if (attribute.getKey().equals(field.getId())) {
if (field.getDisplayHints().getMask() != null) {
StringFormatter stringFormatter = new StringFormatter();
String maskedValue = stringFormatter.applyMask(field.getDisplayHints().getMask().replace("9", "*"), attribute.getValue());
editText.setText(maskedValue);
} else {
editText.setText(attribute.getValue());
}
if (!attribute.isEditingAllowed()) {
editText.setEnabled(false);
}
}
}
}
// Add OnTextChanged watcher for this inputfield
editText.addTextChangedListener(new FieldInputTextWatcher(inputDataPersister, field.getId(), editText, addMasking));
// get input information from inputDataPersister
String paymentProductValue = inputDataPersister.getValue(field.getId());
if (paymentProductValue != null && accountOnFile == null) {
editText.setText(paymentProductValue);
}
// Add it to parentView
rowView.addView(editText);
return editText;
}
Aggregations