Search in sources :

Example 1 with AccountOnFileDisplay

use of com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFileDisplay in project connect-sdk-client-android by Ingenico-ePayments.

the class RenderAccountOnFile method renderAccountOnFile.

@SuppressWarnings("deprecation")
@Override
public void renderAccountOnFile(AccountOnFile accountOnFile, String productId, ViewGroup parent) {
    if (accountOnFile == null) {
        throw new InvalidParameterException("Error renderingAccountOnFile, accountOnFile may not be null");
    }
    if (productId == null) {
        throw new InvalidParameterException("Error renderingAccountOnFile, productId may not be null");
    }
    if (parent == null) {
        throw new InvalidParameterException("Error renderingAccountOnFile, parent may not be null");
    }
    // Inflate the activity_select_payment_product_render layout
    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View paymentProductLayout = inflater.inflate(R.layout.activity_render_payment_product, parent, false);
    // Set the belonging accountOnFile on the tag of the row so we can retrieve it when clicked
    paymentProductLayout.findViewById(R.id.paymentProductRow).setTag(accountOnFile);
    // Get the TextView and ImageView which will be filled
    TextView accountOnFileTextView = (TextView) paymentProductLayout.findViewById(R.id.paymentProductName);
    ImageView accountOnFileLogoImageView = (ImageView) paymentProductLayout.findViewById(R.id.paymentProductLogo);
    // Set the correct value
    String formattedValue = null;
    for (KeyValuePair attribute : accountOnFile.getAttributes()) {
        for (AccountOnFileDisplay displayEntry : accountOnFile.getDisplayHints().getLabelTemplate()) {
            if (attribute.getKey().equals(displayEntry.getKey())) {
                // Format the value if there is a mask in the accountonfile text
                if (displayEntry.getMask() != null) {
                    StringFormatter stringFormatter = new StringFormatter();
                    String maskedValue = stringFormatter.applyMask(displayEntry.getMask().replace("9", "*"), attribute.getValue());
                    formattedValue = maskedValue;
                } else {
                    formattedValue = attribute.getValue();
                }
            }
        }
    }
    accountOnFileTextView.setText(formattedValue);
    // Set the logo via the AssetManager
    AssetManager logoManager = AssetManager.getInstance(parent.getContext());
    Drawable logo = logoManager.getLogo(productId);
    if (Build.VERSION.SDK_INT < 16) {
        accountOnFileLogoImageView.setBackgroundDrawable(logo);
    } else {
        accountOnFileLogoImageView.setBackground(logo);
    }
    parent.addView(paymentProductLayout);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) LayoutInflater(android.view.LayoutInflater) AccountOnFileDisplay(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFileDisplay) Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) StringFormatter(com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter)

Aggregations

Drawable (android.graphics.drawable.Drawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 StringFormatter (com.globalcollect.gateway.sdk.client.android.sdk.formatter.StringFormatter)1 AssetManager (com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)1 AccountOnFileDisplay (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFileDisplay)1 KeyValuePair (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair)1 InvalidParameterException (java.security.InvalidParameterException)1