/**
   * Collect user input to fill value of parameter.
   *
   * @return true if all data are will entered
   */
  @SuppressWarnings("unchecked")
  private boolean collectInputs() {
    LinearLayout root = (LinearLayout) findViewById(R.id.root);
    int indexView = 1;

    for (Parameter param : parameters) {

      switch (param.getType()) {
        case DATE_PICKER:
          Spinner dp = (Spinner) root.getChildAt(indexView);
          param.setValue(dp.getSelectedItem());
          break;
        case FIELD_SEPARATOR:
          Spinner spf = (Spinner) root.getChildAt(indexView);
          param.setValue(spf.getSelectedItem());
          break;
        case DECIMAL_SEPARATOR:
          Spinner sp = (Spinner) root.getChildAt(indexView);
          param.setValue(sp.getSelectedItem());
          break;
        case BOOLEAN:
          CheckBox chk = (CheckBox) root.getChildAt(indexView);
          param.setValue(chk.isChecked());
          break;
        case DATE_FORMAT:
          Spinner spd = (Spinner) root.getChildAt(indexView);
          param.setValue(spd.getSelectedItem());
          break;
        case FILE_URI:
          Button bt = (Button) root.getChildAt(indexView);
          boolean ok = false;
          try {
            URI uri = new URI("" + bt.getText());
            if (new File(uri).exists()) {
              param.setValue(uri);
              ok = true;
            }
          } catch (Throwable e) {
          }
          if (!ok) {
            Toast.makeText(
                    this,
                    getResources()
                        .getString(
                            R.string.mandatory_field,
                            ((TextView) root.getChildAt(indexView - 1)).getText()),
                    Toast.LENGTH_LONG)
                .show();

            return false;
          }
          break;
      }
      indexView += 3;
    }
    return true;
  }
  /**
   * Build the HMI elements.
   *
   * @param driver
   */
  @SuppressWarnings("unchecked")
  private void buildHMI(FileDriver driver) {
    LinearLayout root = (LinearLayout) findViewById(R.id.root);
    parameters = driver.getParameters(account);
    for (Parameter param : parameters) {
      TextView tv = new TextView(this);
      LayoutParams lp =
          new LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

      tv.setLayoutParams(lp);
      tv.setText(
          getResources().getIdentifier(param.getName(), "string", ApplicationConstants.PACKAGE));
      tv.setBackgroundColor(getResources().getColor(R.color.darkGrey));
      root.addView(tv);
      View editView = null;
      switch (param.getType()) {
        case DATE_PICKER:
          editView = new DatePickerSpinner(this);
          DateAdapter dateAdapter = new DateAdapter(this);
          ((Spinner) editView).setAdapter(dateAdapter);
          if (param.getValue() != null) {
            Date date = (Date) param.getValue();
            dateAdapter.add(date);
          } else {
            dateAdapter.add(new Date());
          }
          break;

        case FIELD_SEPARATOR:
          editView = new Spinner(this);
          ((Spinner) editView).setAdapter(new FieldSeparatorAdapter(this));
          int indexf = FieldSeparatorAdapter.getIndexInList("" + param.getValue());
          if (indexf != -1) {
            ((Spinner) editView).setSelection(indexf);
          }
          break;
        case DECIMAL_SEPARATOR:
          editView = new Spinner(this);
          ((Spinner) editView).setAdapter(new DecimalSepatorAdapter(this));
          break;
        case BOOLEAN:
          editView = new CheckBox(this);
          break;
        case DATE_FORMAT:
          editView = new Spinner(this);
          ((Spinner) editView).setAdapter(new DateFormatAdapter(this));
          int index = DateFormatAdapter.getIndexInList("" + param.getValue());
          if (index != -1) {
            ((Spinner) editView).setSelection(index);
          }
          break;
        case FILE_URI:
          fileUril = new Button(this);
          editView = fileUril;
          editView.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                  intent.addCategory(Intent.CATEGORY_OPENABLE);
                  File file =
                      new File(
                          Environment.getExternalStorageDirectory()
                              + "/"
                              + ApplicationConstants.NAME
                              + "/"
                              + ApplicationConstants.IMPORT_DRIRECTORY);
                  if (DefineImportParameter.this.driver.getSubDirectory() != null) {
                    file = new File(file, DefineImportParameter.this.driver.getSubDirectory());
                  }
                  intent.setDataAndType(Uri.parse(file.toString()), "text/*");

                  try {
                    startActivityForResult(
                        intent, ApplicationConstants.ACTIVITY_RETURN_CHOOSE_FILE);
                  } catch (ActivityNotFoundException e) {
                    // No activity to handle this mime type.
                    // Download for exemple ES File Manager
                    askToDownloadFileManager();
                  }
                }
              });
          break;
      }
      lp =
          new LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
      editView.setLayoutParams(lp);
      root.addView(editView);

      tv = new TextView(this);
      tv.setTextSize(5);
      lp =
          new LayoutParams(
              android.view.ViewGroup.LayoutParams.FILL_PARENT,
              android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
      root.addView(tv);
    }
  }