/**
   * Helper method to create a spinner for a field and insert it into the View container. This uses,
   * the String[] to create the list, and selects the value that is passed in from the list (the
   * features value). Can be used for domains as well as types.
   */
  Spinner createSpinnerViewFromArray(View container, Field field, Object value, String[] values) {

    TextView fieldAlias = (TextView) container.findViewById(R.id.field_alias_txt);
    Spinner spinner = (Spinner) container.findViewById(R.id.field_value_spinner);
    fieldAlias.setText(field.getAlias());
    spinner.setPrompt(field.getAlias());

    ArrayAdapter<String> spinnerAdapter =
        new ArrayAdapter<String>(this.context, android.R.layout.simple_spinner_item, values);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerAdapter);
    // set current selection based on the value passed in
    spinner.setSelection(spinnerAdapter.getPosition(value.toString()));

    return spinner;
  }
  /**
   * @author lilin
   * @date 2012-9-19 下午2:26:54
   * @annotation 属性是否可编辑
   */
  public static boolean isFieldValidForEditing(Field field) {

    int fieldType = field.getFieldType();

    if (field.isEditable()
        && fieldType != Field.esriFieldTypeOID
        && fieldType != Field.esriFieldTypeGeometry
        && fieldType != Field.esriFieldTypeBlob
        && fieldType != Field.esriFieldTypeRaster
        && fieldType != Field.esriFieldTypeGUID
        && fieldType != Field.esriFieldTypeXML) {

      return true;
    }

    return false;
  }
  /**
   * Helper method to add the field alias and the fields value into columns of a view using standard
   * id names. If the field has a length set, then this is used to constrain the EditText's
   * allowable characters. No validation is applied here, it is assumed that the container has this
   * set already (in XML).
   */
  View createAttributeRow(View container, Field field, Object value) {

    TextView fieldAlias = (TextView) container.findViewById(R.id.field_alias_txt);
    EditText fieldValue = (EditText) container.findViewById(R.id.field_value_txt);
    fieldAlias.setText(field.getAlias());

    // set the length of the text field and its value
    if (field.getLength() > 0) {
      InputFilter.LengthFilter filter = new InputFilter.LengthFilter(field.getLength());
      fieldValue.setFilters(new InputFilter[] {filter});
    }

    Log.d(AttributeEditorActivity.TAG, "value is null? =" + (value == null));
    Log.d(AttributeEditorActivity.TAG, "value=" + value);

    if (value != null) {
      fieldValue.setText(value.toString(), BufferType.EDITABLE);
    } else {
      fieldValue.setText("", BufferType.EDITABLE);
    }

    return fieldValue;
  }
  /**
   * Helper method to create a date button, with appropriate onClick and onDateSet listeners to
   * handle dates as a long (milliseconds since 1970), it uses the locale and presents a button with
   * the date and time in short format.
   */
  Button createDateButtonFromLongValue(View container, Field field, long date) {

    TextView fieldAlias = (TextView) container.findViewById(R.id.field_alias_txt);
    Button dateButton = (Button) container.findViewById(R.id.field_date_btn);
    fieldAlias.setText(field.getAlias());

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);
    dateButton.setText(formatter.format(c.getTime()));

    addListenersToDatebutton(dateButton);

    return dateButton;
  }
    public static FieldType determineFieldType(Field field) {

      if (field.getFieldType() == Field.esriFieldTypeString) {
        return FieldType.STRING;
      } else if (field.getFieldType() == Field.esriFieldTypeSmallInteger
          || field.getFieldType() == Field.esriFieldTypeInteger) {
        return FieldType.NUMBER;
      } else if (field.getFieldType() == Field.esriFieldTypeSingle
          || field.getFieldType() == Field.esriFieldTypeDouble) {
        return FieldType.DECIMAL;
      } else if (field.getFieldType() == Field.esriFieldTypeDate) {
        return FieldType.DATE;
      }
      return null;
    }
  /**
   * Helper method to set attributes on a graphic. Only sets the attributes on the newGraphic
   * variable if the value has changed. Returns true if the value has changed and has been set on
   * the graphic.
   *
   * @return boolean hasValueChanged
   */
  public static boolean setAttribute(
      Map<String, Object> attrs,
      Graphic oldGraphic,
      Field field,
      String value,
      DateFormat formatter) {

    boolean hasValueChanged = false;

    // if its a string, and it has changed from the oldGraphic value
    if (FieldType.determineFieldType(field) == FieldType.STRING) {

      if (!value.equals(oldGraphic.getAttributeValue(field.getName()))) {

        // set the value as it is
        attrs.put(field.getName(), value);
        hasValueChanged = true;
      }
    } else if (FieldType.determineFieldType(field) == FieldType.NUMBER) {

      // if its an empty string, its a 0 number value (nulls not
      // supported), check this is a
      // change before making it a 0
      if (value.equals("") && oldGraphic.getAttributeValue(field.getName()) != Integer.valueOf(0)) {

        // set a null value on the new graphic
        attrs.put(field.getName(), new Integer(0));
        hasValueChanged = true;

      } else {

        // parse as an int and check this is a change
        int intValue = Integer.parseInt(value);
        if (intValue
            != Integer.parseInt(oldGraphic.getAttributeValue(field.getName()).toString())) {

          attrs.put(field.getName(), Integer.valueOf(intValue));
          hasValueChanged = true;
        }
      }
    } else if (FieldType.determineFieldType(field) == FieldType.DECIMAL) {

      // if its an empty string, its a 0 double value (nulls not
      // supported), check this is a
      // change before making it a 0
      if ((value.equals("")
          && oldGraphic.getAttributeValue(field.getName()) != Double.valueOf(0))) {

        // set a null value on the new graphic
        attrs.put(field.getName(), new Double(0));
        hasValueChanged = true;

      } else {

        // parse as an double and check this is a change
        double dValue = Double.parseDouble(value);
        if (dValue
            != Double.parseDouble(oldGraphic.getAttributeValue(field.getName()).toString())) {

          attrs.put(field.getName(), Double.valueOf(dValue));
          hasValueChanged = true;
        }
      }
    } else if (FieldType.determineFieldType(field) == FieldType.DATE) {

      // if its a date, get the milliseconds value
      Calendar c = Calendar.getInstance();
      long dateInMillis = 0;

      try {

        // parse to a double and check this is a change
        c.setTime(formatter.parse(value));
        dateInMillis = c.getTimeInMillis();

        if (dateInMillis
            != Long.parseLong(oldGraphic.getAttributeValue(field.getName()).toString())) {

          attrs.put(field.getName(), Long.valueOf(dateInMillis));
          hasValueChanged = true;
        }
      } catch (ParseException e) {
        // do nothing
      }
    }
    // }

    return hasValueChanged;
  }