Search in sources :

Example 1 with AssetManager

use of com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager in project connect-sdk-client-android by Ingenico-ePayments.

the class PaymentProductSelectionActivity method updateLogos.

private void updateLogos(Region region, EnvironmentType environment, List<BasicPaymentItem> basicPaymentItems) {
    // if you want to specify the size of the logos you update, set resizedLogo to a size (width, height)
    Size resizedLogo = new Size(100, 100);
    // if you just want to get the default images, set
    // resizedLogo = null;
    AssetManager manager = AssetManager.getInstance(getApplicationContext());
    manager.updateLogos(region, environment, basicPaymentItems, resizedLogo);
}
Also used : AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) Size(com.globalcollect.gateway.sdk.client.android.sdk.model.Size)

Example 2 with AssetManager

use of com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager in project connect-sdk-client-android by Ingenico-ePayments.

the class DetailInputViewCreditCardImpl method renderCoBrandNotification.

@Override
public void renderCoBrandNotification(List<BasicPaymentItem> paymentProductsAllowedInContext, View.OnClickListener listener) {
    // Show the user he can choose another cobrand if there are indeed more cobrands available
    if (paymentProductsAllowedInContext.size() > 1) {
        // Retrieve the logo from the top most PaymentProduct
        AssetManager logoManager = AssetManager.getInstance(rootView.getContext().getApplicationContext());
        coBrandRenderer.renderIinCoBrandNotification(rootView.getContext(), paymentProductsAllowedInContext, renderInputFieldsLayout, CREDIT_CARD_NUMBER_FIELD_ID, logoManager, listener);
    }
}
Also used : AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)

Example 3 with AssetManager

use of com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager 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)

Example 4 with AssetManager

use of com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager in project connect-sdk-client-android by Ingenico-ePayments.

the class DetailInputViewCreditCardImpl method renderPaymentProductLogoInCreditCardField.

@Override
public void renderPaymentProductLogoInCreditCardField(String productId) {
    // Retrieve the logo from the top most PaymentProduct
    AssetManager logoManager = AssetManager.getInstance(rootView.getContext().getApplicationContext());
    // Get the logo from backgroundimage
    BitmapDrawable drawable = (BitmapDrawable) logoManager.getLogo(productId);
    if (drawable != null) {
        int scaledHeight = (int) creditCardField.getTextSize();
        int scaledWidth = (int) (drawable.getIntrinsicWidth() * ((double) scaledHeight / (double) drawable.getIntrinsicHeight()));
        Bitmap resizedBitmap = Bitmap.createScaledBitmap(drawable.getBitmap(), scaledWidth, scaledHeight, true);
        Drawable resizedDrawable = new BitmapDrawable(rootView.getContext().getResources(), resizedBitmap);
        // Set compoundDrawables allow you to place a image at a certain position
        creditCardField.setCompoundDrawablesWithIntrinsicBounds(null, null, resizedDrawable, null);
    }
}
Also used : Bitmap(android.graphics.Bitmap) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 5 with AssetManager

use of com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager in project connect-sdk-client-android by Ingenico-ePayments.

the class C2sCommunicator method getBasicPaymentProducts.

/**
 * Retrieves a list of basicpaymentproducts from the GC gateway without any fields
 *
 * @param context, used for reading device metadata which is send to the GC gateway
 * @param paymentContext, payment information that is used to retrieve the correct payment products
 *
 * @return list of BasicPaymentProducts, or null when an error has occured
 */
public BasicPaymentProducts getBasicPaymentProducts(PaymentContext paymentContext, Context context) {
    if (paymentContext == null) {
        throw new InvalidParameterException("Error getting BasicPaymentProducts, request may not be null");
    }
    HttpURLConnection connection = null;
    try {
        // Build the complete url which is called
        String baseUrl = configuration.getBaseUrl();
        String paymentProductPath = Constants.GC_GATEWAY_RETRIEVE_PAYMENTPRODUCTS_PATH.replace("[cid]", configuration.getCustomerId());
        String completePath = baseUrl + paymentProductPath;
        // Add query parameters
        StringBuilder queryString = new StringBuilder();
        queryString.append("?countryCode=").append(paymentContext.getCountryCode());
        queryString.append("&amount=").append(paymentContext.getAmountOfMoney().getAmount());
        queryString.append("&isRecurring=").append(paymentContext.isRecurring());
        queryString.append("&currencyCode=").append(paymentContext.getAmountOfMoney().getCurrencyCode());
        queryString.append("&hide=fields");
        queryString.append("&").append(createCacheBusterParameter());
        // Add query string to complete path
        completePath += queryString.toString();
        // Do the call and deserialise the result to BasicPaymentProducts
        connection = doHTTPGetRequest(completePath, configuration.getClientSessionId(), configuration.getMetadata(context));
        String responseBody = new Scanner(connection.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        // Log the response
        if (Constants.ENABLE_REQUEST_LOGGING) {
            logResponse(connection, responseBody);
        }
        BasicPaymentProducts basicPaymentProducts = gson.fromJson(responseBody, BasicPaymentProducts.class);
        // Set the logos for all paymentproducts
        for (BasicPaymentProduct paymentProduct : basicPaymentProducts.getBasicPaymentProducts()) {
            AssetManager manager = AssetManager.getInstance(context);
            Drawable logo = manager.getLogo(paymentProduct.getId());
            paymentProduct.getDisplayHints().setLogo(logo);
        }
        return basicPaymentProducts;
    } catch (CommunicationException e) {
        Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
        return null;
    } catch (Exception e) {
        Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
        return null;
    } finally {
        try {
            if (connection != null) {
                connection.getInputStream().close();
                connection.disconnect();
            }
        } catch (IOException e) {
            Log.i(TAG, "Error while getting paymentproducts:" + e.getMessage());
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Scanner(java.util.Scanner) HttpURLConnection(java.net.HttpURLConnection) AssetManager(com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) Drawable(android.graphics.drawable.Drawable) BasicPaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct) IOException(java.io.IOException) CommunicationException(com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException) InvalidParameterException(java.security.InvalidParameterException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BasicPaymentProducts(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProducts)

Aggregations

AssetManager (com.globalcollect.gateway.sdk.client.android.sdk.manager.AssetManager)6 Drawable (android.graphics.drawable.Drawable)4 InvalidParameterException (java.security.InvalidParameterException)3 CommunicationException (com.globalcollect.gateway.sdk.client.android.sdk.exception.CommunicationException)2 IOException (java.io.IOException)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 Scanner (java.util.Scanner)2 Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)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 Size (com.globalcollect.gateway.sdk.client.android.sdk.model.Size)1 AccountOnFileDisplay (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFileDisplay)1 BasicPaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProduct)1 BasicPaymentProductGroup (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroup)1 BasicPaymentProductGroups (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.BasicPaymentProductGroups)1