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;
}
Aggregations