use of com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator 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.exampleapp.translation.Translator in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderLabel method renderLabel.
@Override
public TextView renderLabel(PaymentProductField field, BasicPaymentItem selectedPaymentProduct, ViewGroup rowView) {
TextView label = new TextView(rowView.getContext());
// Get the labeltext
Translator translator = Translator.getInstance(rowView.getContext());
String labelText = translator.getPaymentProductFieldLabel(selectedPaymentProduct.getId(), field.getId());
if (labelText.contains(Constants.LINK_PLACEHOLDER)) {
String linkLabel = translator.getPaymentProductFieldLabel(selectedPaymentProduct.getId(), field.getId() + ".link");
String link = "<a href=\"" + field.getDisplayHints().getLink() + "\">" + linkLabel + "</a>";
labelText = labelText.replace(Constants.LINK_PLACEHOLDER, link);
label.setMovementMethod(LinkMovementMethod.getInstance());
}
// Create new label
label.setTextAppearance(rowView.getContext(), R.style.ListViewTextView);
label.setText(Html.fromHtml(labelText));
rowView.addView(label);
return label;
}
use of com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderIinCoBranding method addCoBrandToolTip.
private void addCoBrandToolTip(List<BasicPaymentItem> paymentProductsAllowedInContext, ViewGroup rowView, String fieldId, AssetManager logoManager, View.OnClickListener listener, Context context) {
// Create a new LinearLayout and add it under the rowView.
LinearLayout coBrandTooltipLayout = new LinearLayout(rowView.getContext());
coBrandTooltipLayout.setOrientation(LinearLayout.VERTICAL);
coBrandTooltipLayout.setBackgroundResource(R.drawable.special_section_background);
coBrandTooltipLayout.setTag(COBRAND_TOOLTIP_TAG_PREFIX + fieldId);
LinearLayout.LayoutParams coBrandTooltipLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
coBrandTooltipLayoutParams.setMargins(TOOLTIP_TEXT_MARGIN, TOOLTIP_TEXT_MARGIN, TOOLTIP_TEXT_MARGIN, TOOLTIP_TEXT_MARGIN);
// Create a new TextView and add it to the coBrandToolTipLayout
TextView tooltipTextView = new TextView(rowView.getContext());
tooltipTextView.setText(translate(INTRO_TEXT, context));
coBrandTooltipLayout.addView(tooltipTextView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
// Render the paymentproducts the user can choose from in the tooltip box
for (BasicPaymentItem basicPaymentItem : paymentProductsAllowedInContext) {
// Inflate the activity_select_payment_product_render layout
LayoutInflater inflater = (LayoutInflater) coBrandTooltipLayout.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View paymentProductLayout = inflater.inflate(R.layout.activity_render_cobrand_payment_product, coBrandTooltipLayout, false);
// Set a tag, so we can find it back after it has been clicked
paymentProductLayout.setTag(basicPaymentItem);
// Get the TextView and ImageView which will be filled
TextView paymentProductNameTextView = (TextView) paymentProductLayout.findViewById(R.id.coBrandPaymentProductName);
ImageView paymentProductNameLogoImageView = (ImageView) paymentProductLayout.findViewById(R.id.coBrandPaymentProductLogo);
// Set the translated value
Translator translator = Translator.getInstance(coBrandTooltipLayout.getContext());
paymentProductNameTextView.setText(translator.getPaymentProductName(basicPaymentItem.getId()));
// Get the logo for the product and set it as the background
BitmapDrawable drawable = (BitmapDrawable) logoManager.getLogo(basicPaymentItem.getId());
if (Build.VERSION.SDK_INT < 16) {
paymentProductNameLogoImageView.setBackgroundDrawable(drawable);
} else {
paymentProductNameLogoImageView.setBackground(drawable);
}
paymentProductLayout.setOnClickListener(listener);
coBrandTooltipLayout.addView(paymentProductLayout);
}
// Add the tooltip view to the ViewGroup
ViewGroup parentViewGroup = (ViewGroup) rowView.getParent();
parentViewGroup.addView(coBrandTooltipLayout, parentViewGroup.indexOfChild(rowView) + 1, coBrandTooltipLayoutParams);
}
use of com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator in project connect-sdk-client-android by Ingenico-ePayments.
the class RenderTooltip method renderTooltip.
@Override
public void renderTooltip(final String fieldId, BasicPaymentItem selectedPaymentProduct, final ViewGroup rowView) {
// Check if the translated tooltip text is in the translationsfile.
// If not, don't show the tooltip
Translator translator = Translator.getInstance(rowView.getContext());
final String tooltipText = translator.getPaymentProductFieldTooltipText(selectedPaymentProduct.getId(), fieldId);
final Integer drawableId = translator.getPaymentProductFieldTooltipImage(selectedPaymentProduct.getId(), fieldId);
renderTooltip(fieldId, tooltipText, drawableId, rowView);
}
use of com.globalcollect.gateway.sdk.client.android.exampleapp.translation.Translator 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