Java源码示例:com.nextgis.maplib.util.LayerUtil

示例1
private void fillFields() {
    mFieldNames = new ArrayList<>();
    mFieldAliases = new ArrayList<>();
    mFieldNames.add(FIELD_ID);
    mFieldAliases.add(FIELD_ID + " - " + LayerUtil.typeToString(getContext(), GeoConstants.FTInteger));

    int fieldsCount = mVectorLayer.getFields().size();
    String labelField = mVectorLayer.getPreferences().getString(SettingsConstantsUI.KEY_PREF_LAYER_LABEL, Constants.FIELD_ID);

    for (int i = 0; i < fieldsCount; i++) {
        Field field = mVectorLayer.getFields().get(i);
        String fieldInfo = field.getAlias() + " - " + LayerUtil.typeToString(getContext(), field.getType());
        if (field.getName().equals(labelField))
            mDefault = i + 1;

        mFieldNames.add(field.getName());
        mFieldAliases.add(fieldInfo);
    }
}
 
示例2
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater inflater = LayoutInflater.from(CreateVectorLayerActivity.this);
        view = inflater.inflate(R.layout.item_field, parent, false);
    }

    final Field field = mFields.get(position);
    TextView fieldName = (TextView) view.findViewById(R.id.tv_field_name);
    TextView fieldType = (TextView) view.findViewById(R.id.tv_field_type);
    fieldName.setText(field.getAlias());
    fieldType.setText(LayerUtil.typeToString(CreateVectorLayerActivity.this, field.getType()));

    view.findViewById(R.id.ib_remove_field).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFields.remove(field);
            notifyDataSetChanged();
        }
    });

    return view;
}
 
示例3
public void createField(Field field)
        throws SQLiteException
{
    if (null == mFields || mFields.isEmpty()) //the db table is not yet created
    {
        return;
    }
    if (mFields.containsKey(field.getName())) {
        return;
    }

    if (!LayerUtil.isFieldNameValid(field.getName())) {
        return;
    } else {
        field.setName(LayerUtil.normalizeFieldName(field.getName()));
    }

    mFields.put(field.getName(), field);

    String fieldCreate = "ALTER TABLE " + mPath.getName() + " ADD COLUMN '" + field.getName() + "'";

    switch (field.getType()) {
        case FTString:
            fieldCreate += " TEXT";
            break;
        case FTInteger:
            fieldCreate += " INTEGER";
            break;
        case FTReal:
            fieldCreate += " REAL";
            break;
        case FTDateTime:
        case FTDate:
        case FTTime:
            fieldCreate += " TIMESTAMP";
            break;
    }

    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(false);
    db.execSQL(fieldCreate);
}