Search in sources :

Example 1 with OnDateChangedListener

use of android.widget.DatePicker.OnDateChangedListener in project connect-sdk-client-android by Ingenico-ePayments.

the class RenderDate method renderField.

@Override
public View renderField(PaymentProductField field, InputDataPersister inputDataPersister, ViewGroup rowView, PaymentContext paymentContext) {
    if (field == null) {
        throw new InvalidParameterException("Error rendering datefield, field may not be null");
    }
    if (rowView == null) {
        throw new InvalidParameterException("Error rendering datefield, rowView may not be null");
    }
    if (inputDataPersister == null) {
        throw new InvalidParameterException("Error rendering datefield, inputDataPersister may not be null");
    }
    AccountOnFile accountOnFile = inputDataPersister.getAccountOnFile();
    DatePicker datePicker = new DatePicker(rowView.getContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        datePicker.setCalendarViewShown(false);
        datePicker.setSpinnersShown(true);
    }
    // Create a listener here, which we can use to provide to all init calls
    OnDateChangedListener listener = createOnDateChangedListener(inputDataPersister, field.getId());
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    datePicker.init(year, month, day, listener);
    // Set values from account on file
    if (accountOnFile != null) {
        for (KeyValuePair attribute : accountOnFile.getAttributes()) {
            if (attribute.getKey().equals(field.getId())) {
                String date = attribute.getValue();
                setDateFromString(datePicker, date, listener);
            }
            if (!attribute.isEditingAllowed()) {
                datePicker.setEnabled(false);
            }
        }
    }
    // get input information from inputDataPersister
    String setDate = inputDataPersister.getValue(field.getId());
    if (setDate != null && accountOnFile == null) {
        setDateFromString(datePicker, setDate, listener);
    }
    rowView.addView(datePicker);
    return datePicker;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) AccountOnFile(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile) KeyValuePair(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair) OnDateChangedListener(android.widget.DatePicker.OnDateChangedListener) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker)

Aggregations

DatePicker (android.widget.DatePicker)1 OnDateChangedListener (android.widget.DatePicker.OnDateChangedListener)1 AccountOnFile (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.AccountOnFile)1 KeyValuePair (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.KeyValuePair)1 InvalidParameterException (java.security.InvalidParameterException)1 Calendar (java.util.Calendar)1