Search in sources :

Example 1 with ValueMap

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

the class RenderList method renderField.

@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
    if (field == null) {
        throw new InvalidParameterException("Error rendering list, field may not be null");
    }
    if (inputDataPersister == null) {
        throw new InvalidParameterException("Error rendering list, inputDataPersister may not be null");
    }
    if (rowView == null) {
        throw new InvalidParameterException("Error rendering list, rowView may not be null");
    }
    this.field = field;
    this.inputDataPersister = inputDataPersister;
    // Create new spinner and fill its values
    Spinner spinner = new Spinner(rowView.getContext());
    // Parse the loaded values to array and set as ArrayAdapter
    values = new ArrayList<>();
    // Fill values
    for (ValueMap valueMap : field.getDisplayHints().getFormElement().getValueMapping()) {
        values.add(getDisplayNameFromDisplayElements(valueMap.getDisplayElements()));
    }
    // Make and set adapter to spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(rowView.getContext(), android.R.layout.simple_spinner_item, values);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);
    // Set the spinner to the stored value in the account
    if (inputDataPersister.getAccountOnFile() != null) {
        for (KeyValuePair attribute : inputDataPersister.getAccountOnFile().getAttributes()) {
            if (attribute.getKey().equals(field.getId())) {
                int spinnerPosition = dataAdapter.getPosition(attribute.getValue());
                spinner.setSelection(spinnerPosition);
                if (!attribute.isEditingAllowed()) {
                    spinner.setEnabled(false);
                }
            }
        }
    }
    // is redrawn (i.e. when the user turns the phone)
    if (inputDataPersister.getValue(field.getId()) != null) {
        int spinnerPosition = dataAdapter.getPosition(inputDataPersister.getValue(field.getId()));
        spinner.setSelection(spinnerPosition);
    }
    // Add this as listener for this inputfield
    spinner.setOnItemSelectedListener(this);
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    rowView.addView(spinner, params);
    return spinner;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) LayoutParams(android.widget.LinearLayout.LayoutParams) KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) Spinner(android.widget.Spinner) ValueMap(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.ValueMap) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with ValueMap

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

the class RenderList method onItemSelected.

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // Update value in inputDataPersister
    String value = (String) parent.getItemAtPosition(position);
    // Get the id from the valuesmap
    for (String listValue : values) {
        if (listValue.equals(value)) {
            for (ValueMap valueMap : field.getDisplayHints().getFormElement().getValueMapping()) {
                if (getDisplayNameFromDisplayElements(valueMap.getDisplayElements()).equals(value)) {
                    inputDataPersister.setValue(field.getId(), valueMap.getValue());
                    inputDataPersister.setFocusFieldId(field.getId());
                }
            }
        }
    }
}
Also used : ValueMap(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.ValueMap)

Aggregations

ValueMap (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.ValueMap)2 ArrayAdapter (android.widget.ArrayAdapter)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 Spinner (android.widget.Spinner)1 KeyValuePair (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair)1 InvalidParameterException (java.security.InvalidParameterException)1