android.provider.SyncStateContract#com.nextgis.maplib.datasource.Field源码实例Demo

下面列出了android.provider.SyncStateContract#com.nextgis.maplib.datasource.Field 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_maplibui   文件: Coordinates.java
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException{
    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mHidden = attributes.optBoolean(JSON_HIDDEN_KEY);

    // TODO crs, format
    String value;
    if (ControlHelper.hasKey(savedState, mFieldName))
        value = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else
        value = getFormattedValue();

    setText(value);
    setSingleLine(true);
    setEnabled(false);
}
 
源代码2 项目: android_maplibui   文件: Tabs.java
protected void addToLayout(IFormControl control, JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, LinearLayout layout)
        throws JSONException {
    if (null != control) {
        appendData(mLayer, mPreferences, mTable, mRow, control, element);

        if (control instanceof PhotoGallery) {
            if (savedState != null)
                savedState.putBoolean("<tabs&", true);
        }
        control.init(element, fields, savedState, featureCursor, mSharedPreferences, mTranslations);
        control.addToLayout(layout);
        if (mIsViewOnly)
            control.setEnabled(false);

        String fieldName = control.getFieldName();
        if (null != fieldName)
            mFields.put(fieldName, control);
        if (control instanceof Tabs) {
            Tabs tabs = (Tabs) control;
            mFields.putAll(tabs.getFields());
        }
    }
}
 
源代码3 项目: android_maplibui   文件: Averaging.java
@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState,
                 Cursor featureCursor, SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException {

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mMeasures = attributes.getLong(MEASUREMENT_COUNT);

    if (null != featureCursor) { // feature exists
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            mValue = featureCursor.getDouble(column);
    } else if (ControlHelper.hasKey(savedState, mFieldName)) {
        mValue = savedState.getDouble(ControlHelper.getSavedStateKey(mFieldName));
    } else {    // new feature
        mValue = 0.0;
    }

    setEnabled(false);
    setValue();
    Button average = findViewById(R.id.average);
    average.setOnClickListener(this);
}
 
protected void addToLayout(IFormControl control, JSONObject element, List<Field> fields, Bundle savedState,
                           Cursor featureCursor, LinearLayout layout) throws JSONException {
    if (null != control) {
        appendData(mLayer, mPreferences, mTable, mRow, control, element);

        control.init(element, fields, savedState, featureCursor, mSharedPreferences, mTranslations);
        control.addToLayout(layout);
        if (mIsViewOnly)
            control.setEnabled(false);

        String fieldName = control.getFieldName();
        if (null != fieldName)
            mFields.put(fieldName, control);
        if (control instanceof Tabs) {
            Tabs tabs = (Tabs) control;
            mFields.putAll(tabs.getFields());
        }
    }
}
 
protected Object putFieldValue(ContentValues values, Field field) {
    Object value = super.putFieldValue(values, field);
    IFormControl control = (IFormControl) mFields.get(field.getName());
    if (null == control)
        return null;

    if (null != value) {
        if (value instanceof DoubleComboboxValue) {
            DoubleComboboxValue dcValue = (DoubleComboboxValue) value;
            values.put(dcValue.mFieldName, dcValue.mValue);
            values.put(dcValue.mSubFieldName, dcValue.mSubValue);
        }
    }

    return value;
}
 
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);
    }
}
 
源代码7 项目: android_maplib   文件: NGWUtil.java
public static List<Field> getFieldsFromJson(JSONArray fieldsJSONArray)
        throws JSONException
{
    List<Field> fields = new LinkedList<>();
    for (int i = 0; i < fieldsJSONArray.length(); i++) {
        JSONObject fieldJSONObject = fieldsJSONArray.getJSONObject(i);
        String type = fieldJSONObject.getString("datatype");
        String alias = fieldJSONObject.getString("display_name");
        String name = fieldJSONObject.getString("keyname");

        int nType = LayerUtil.stringToType(type);
        if (Constants.NOT_FOUND != nType) {
            fields.add(new Field(nType, name, alias));
        }
    }
    return fields;
}
 
private boolean createNewLayer() {
    MainApplication app = (MainApplication) getApplication();
    int geomType = getResources().getIntArray(R.array.geom_types)[mSpLayerType.getSelectedItemPosition()];
    List<Field> fields = mFieldAdapter.getFields();
    if (fields.size() == 0)
        fields.add(new Field(GeoConstants.FTString, "description", getString(R.string.default_field_name)));
    else
        for (int i = 0; i < fields.size(); i++)
            fields.get(i).setName("field_" + (i + 1));

    VectorLayer layer = app.createEmptyVectorLayer(mEtLayerName.getText().toString().trim(), null, geomType, fields);

    SimpleFeatureRenderer sfr = (SimpleFeatureRenderer) layer.getRenderer();
    if (null != sfr) {
        Style style = sfr.getStyle();
        if (null != style) {
            Random rnd = new Random(System.currentTimeMillis());
            style.setColor(Color.rgb(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)));
        }
    }

    MapBase map = app.getMap();
    map.addLayer(layer);
    return map.save();
}
 
@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;
}
 
源代码10 项目: android_maplibui   文件: Counter.java
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException{

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = true;

    String value = null;
    if (null != featureCursor) { // feature exists
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            value = featureCursor.getString(column);
    } else if (ControlHelper.hasKey(savedState, mFieldName)) {
        mIncremented = savedState.getLong(ControlHelper.getSavedStateKey(mFieldName));
        value = getNewValue(attributes);
    } else {    // new feature
        String last = preferences.getString(mFieldName, null);
        if (last == null)
            mIncremented = attributes.getInt(JSON_INIT_VALUE_KEY);
        else {
            int inc = attributes.getInt(INCREMENT);
            mIncremented = Long.valueOf(last) + inc;
        }
        value = getNewValue(attributes);
    }

    setEnabled(false);
    setText(value);
    setSingleLine(true);
}
 
源代码11 项目: android_maplibui   文件: Checkbox.java
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException {

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);

    Boolean value = null;
    if (ControlHelper.hasKey(savedState, mFieldName))
        value = savedState.getBoolean(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) {
        int column = featureCursor.getColumnIndex(mFieldName);

        if (column >= 0)
            value = featureCursor.getInt(column) != 0;
    } else {
        value = attributes.getBoolean(JSON_INIT_VALUE_KEY);

        if (mIsShowLast)
            value = preferences.getBoolean(mFieldName, value);
    }

    if (value == null)
        value = false;

    setChecked(value);
    setText(ControlHelper.translate(attributes.getString(JSON_TEXT_KEY), translations));
    setEnabled(ControlHelper.isEnabled(fields, mFieldName));
}
 
源代码12 项目: android_maplibui   文件: Distance.java
@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState,
                 Cursor featureCursor, SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException {
    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mHidden = attributes.optBoolean(JSON_HIDDEN_KEY);

    String value;
    if (null != featureCursor) { // feature exists
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            mValue = featureCursor.getDouble(column);
        value = getFormattedValue();
    } else if (ControlHelper.hasKey(savedState, mFieldName))
        value = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else {
        calculate(false);
        value = getFormattedValue();
    }

    ((AppCompatEditText) findViewById(R.id.distance)).setText(value);
    findViewById(R.id.refresh).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            calculate(true);
            ((AppCompatEditText) findViewById(R.id.distance)).setText(getFormattedValue());
        }
    });
}
 
源代码13 项目: android_maplibui   文件: TextLabel.java
@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState,
                 Cursor featureCursor, SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException {
    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    setText(ControlHelper.translate(attributes.getString(JSON_TEXT_KEY), translations));
}
 
源代码14 项目: android_maplibui   文件: TextEdit.java
@Override
public void init(Field field,
                 Bundle savedState,
                 Cursor featureCursor){
    ControlHelper.setClearAction(this);

    mFieldName = field.getName();
    String text = "";

    if (ControlHelper.hasKey(savedState, mFieldName))
        text = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) {
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            text = featureCursor.getString(column);
    }

    setText(text);

    switch (field.getType()) {

        case GeoConstants.FTString:
            break;

        case GeoConstants.FTInteger:
            setSingleLine(true);
            setInputType(InputType.TYPE_CLASS_NUMBER);
            break;

        case GeoConstants.FTReal:
            setSingleLine(true);
            setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            break;
    }
}
 
源代码15 项目: android_maplibui   文件: LayerFillService.java
@Override
public boolean execute(IProgressor progressor) {
    try {
        VectorLayer vectorLayer = (VectorLayer) mLayer;
        if (null == vectorLayer)
            return false;
        File meta = new File(mPath.getParentFile(), NGFP_META);

        if (meta.exists()) {
            String jsonText = FileUtil.readFromFile(meta);
            JSONObject metaJson = new JSONObject(jsonText);
            //read fields
            List<Field> fields = NGWUtil.getFieldsFromJson(metaJson.getJSONArray(NGWUtil.NGWKEY_FIELDS));
            //read geometry type
            String geomTypeString = metaJson.getString("geometry_type");
            int geomType = GeoGeometryFactory.typeFromString(geomTypeString);
            vectorLayer.create(geomType, fields);

            if (GeoJSONUtil.isGeoJsonHasFeatures(mPath)) {
                //read SRS -- not need as we will be fill layer with 3857
                JSONObject srs = metaJson.getJSONObject(NGWUtil.NGWKEY_SRS);
                int nSRS = srs.getInt(NGWUtil.NGWKEY_ID);
                vectorLayer.fillFromGeoJson(mPath, nSRS, progressor);
            }
        } else
            vectorLayer.createFromGeoJson(mPath, progressor); // should never get there
    } catch (IOException | JSONException | SQLiteException | NGException | ClassCastException e) {
        e.printStackTrace();
        setError(e, progressor);
        notifyError(mProgressMessage);
        return false;
    }

    if (mDeletePath)
        FileUtil.deleteRecursive(mPath);

    return true;
}
 
protected void fillTabControls(
        LinearLayout layout,
        Bundle savedState,
        JSONArray elements)
        throws JSONException {

    Cursor featureCursor = getFeatureCursor();
    List<Field> fields = mLayer.getFields();
    for (int i = 0; i < elements.length(); i++) {
        IFormControl control;
        JSONObject element = elements.getJSONObject(i);
        String type = element.optString(JSON_TYPE_KEY);
        if (type.equals(JSON_COORDINATES_VALUE)) {
            JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
            String fieldY = attributes.optString(JSON_FIELD_NAME_KEY + "_lat");
            attributes.put(JSON_FIELD_NAME_KEY, fieldY);
            element.put(JSON_TYPE_KEY, type + "_lat");
            control = getControl(this, element, mLayer, mFeatureId, mGeometry, mIsViewOnly);
            addToLayout(control, element, fields, savedState, featureCursor, layout);

            attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
            String fieldX = attributes.optString(JSON_FIELD_NAME_KEY + "_long");
            attributes.put(JSON_FIELD_NAME_KEY, fieldX);
            element.put(JSON_TYPE_KEY, type + "_lon");
        }

        control = getControl(this, element, mLayer, mFeatureId, mGeometry, mIsViewOnly);
        if (type.equals(JSON_TABS_KEY))
            ((Tabs) control).init(mLayer, mFeatureId, mGeometry, mTable, mRow, mSharedPreferences,
                                  mPreferences, getSupportFragmentManager(), mIsViewOnly);

        addToLayout(control, element, fields, savedState, featureCursor, layout);
    }

    if (null != featureCursor) {
        featureCursor.close();
    }

    layout.requestLayout();
}
 
@Override
protected boolean saveFeature() {
    boolean success = super.saveFeature();
    if (success)
        for (Field field : mLayer.getFields())
            saveLastValue(field);

    return success;
}
 
protected Object putFieldValue(
        ContentValues values,
        Field field)
{
    String fieldName = field.getName();
    IControl control = mFields.get(fieldName);

    if (null == control) {
        return null;
    }

    Object value = control.getValue();
    fieldName = "'" + fieldName + "'";

    if (null != value) {
        Log.d(TAG, "field: " + field.getName() + " value: " + value.toString());

        if (value instanceof Long) {
            values.put(fieldName, (Long) value);
        } else if (value instanceof Integer) {
            values.put(fieldName, (Integer) value);
        } else if (value instanceof String) {
            values.put(fieldName, (String) value);
        } else if (value instanceof Double) {
            values.put(fieldName, (Double) value);
        } else if (value instanceof Float) {
            values.put(fieldName, (Float) value);
        }
    }

    return value;
}
 
源代码19 项目: android_maplibui   文件: ControlHelper.java
public static boolean isEnabled(
        List<Field> fields,
        String fieldName)
{
    for (Field field : fields) {
        if (field.getName().equals(fieldName)) {
            return true;
        }
    }

    return false;
}
 
源代码20 项目: android_maplib   文件: NGWVectorLayer.java
@Override
public void create(
        int geometryType,
        List<Field> fields)
        throws SQLiteException
{
    if (mNgwVersionMajor < Constants.NGW_v3 && geometryType < 4
            && mNGWLayerType == Connection.NGWResourceTypeVectorLayer) {
        // to multi
        geometryType += 3;
    }

    super.create(geometryType, fields);
    FeatureChanges.initialize(getChangeTableName());
}
 
源代码21 项目: android_maplib   文件: VectorLayer.java
@Override
public JSONObject toJSON()
        throws JSONException
{
    JSONObject rootConfig = super.toJSON();
    rootConfig.put(JSON_GEOMETRY_TYPE_KEY, mGeometryType);
    rootConfig.put(JSON_EDITABLE_KEY, mIsEditable);

    if (null != mFields) {
        JSONArray fields = new JSONArray();
        for (Field field : mFields.values()) {
            JSONObject fieldJsonObject = field.toJSON();
            fields.put(fieldJsonObject);
        }
        rootConfig.put(JSON_FIELDS_KEY, fields);
    }

    if (null != mRenderer && mRenderer instanceof IJSONStore) {
        IJSONStore jsonStore = (IJSONStore) mRenderer;
        rootConfig.put(Constants.JSON_RENDERERPROPS_KEY, jsonStore.toJSON());
    }

    if (mExtents.isInit()) {
        rootConfig.put(Constants.JSON_BBOX_MAXX_KEY, mExtents.getMaxX());
        rootConfig.put(Constants.JSON_BBOX_MINX_KEY, mExtents.getMinX());
        rootConfig.put(Constants.JSON_BBOX_MAXY_KEY, mExtents.getMaxY());
        rootConfig.put(Constants.JSON_BBOX_MINY_KEY, mExtents.getMinY());
    }

    if (!mIsCacheRebuilding) {
        mCache.save(new File(mPath, RTREE));
        if (DEBUG_MODE)
            Log.d(Constants.TAG, "mCache: saving toJSON");
    }

    return rootConfig;
}
 
源代码22 项目: android_maplib   文件: VectorLayer.java
@Override
public void fromJSON(JSONObject jsonObject)
        throws JSONException, SQLiteException
{
    super.fromJSON(jsonObject);
    mGeometryType = jsonObject.getInt(JSON_GEOMETRY_TYPE_KEY);
    mIsEditable = jsonObject.optBoolean(JSON_EDITABLE_KEY, true);

    if (jsonObject.has(JSON_FIELDS_KEY)) {
        mFields = new HashMap<>();
        JSONArray fields = jsonObject.getJSONArray(JSON_FIELDS_KEY);
        for (int i = 0; i < fields.length(); i++) {
            Field field = new Field();
            field.fromJSON(fields.getJSONObject(i));
            mFields.put(field.getName(), field);
        }
    }

    if (jsonObject.has(Constants.JSON_BBOX_MAXX_KEY)) {
        mExtents.setMaxX(jsonObject.getDouble(Constants.JSON_BBOX_MAXX_KEY));
    }
    if (jsonObject.has(Constants.JSON_BBOX_MAXY_KEY)) {
        mExtents.setMaxY(jsonObject.getDouble(Constants.JSON_BBOX_MAXY_KEY));
    }
    if (jsonObject.has(Constants.JSON_BBOX_MINX_KEY)) {
        mExtents.setMinX(jsonObject.getDouble(Constants.JSON_BBOX_MINX_KEY));
    }
    if (jsonObject.has(Constants.JSON_BBOX_MINY_KEY)) {
        mExtents.setMinY(jsonObject.getDouble(Constants.JSON_BBOX_MINY_KEY));
    }

    reloadCache();

    if (jsonObject.has(Constants.JSON_RENDERERPROPS_KEY)) {
        setRenderer(jsonObject.getJSONObject(Constants.JSON_RENDERERPROPS_KEY));
    } else {
        setDefaultRenderer();
    }
}
 
源代码23 项目: android_maplib   文件: VectorLayer.java
public List<Field> getFields()
{
    if (null == mFields) {
        return new ArrayList<>();
    }
    return new LinkedList<>(mFields.values());
}
 
源代码24 项目: android_maplib   文件: NGWUtil.java
public static Feature readNGWFeature(
        JsonReader reader,
        List<Field> fields,
        int nSRS)
        throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError
{
    final Feature feature = new Feature(Constants.NOT_FOUND, fields);

    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(NGWUtil.NGWKEY_ID)) {
            feature.setId(reader.nextLong());
        } else if (name.equals(NGWUtil.NGWKEY_GEOM)) {
            String wkt = reader.nextString();
            GeoGeometry geom = GeoGeometryFactory.fromWKT(wkt, nSRS);
            geom.setCRS(nSRS);
            if (nSRS != GeoConstants.CRS_WEB_MERCATOR) {
                geom.project(GeoConstants.CRS_WEB_MERCATOR);
            }
            feature.setGeometry(geom);
        } else if (name.equals(NGWUtil.NGWKEY_FIELDS)) {
            readNGWFeatureFields(feature, reader, fields);
        } else if (name.equals(NGWUtil.NGWKEY_EXTENSIONS)) {
            if (reader.peek() != JsonToken.NULL) {
                readNGWFeatureAttachments(feature, reader);
            }
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return feature;
}
 
源代码25 项目: android_gisapp   文件: MainApplication.java
public VectorLayer createEmptyVectorLayer(
        String layerName,
        String layerPath,
        int layerType,
        List<Field> fields)
{
    VectorLayerUI vectorLayer = new VectorLayerUI(this, mMap.createLayerStorage(layerPath));
    vectorLayer.setName(layerName);
    vectorLayer.setVisible(true);
    vectorLayer.setMinZoom(GeoConstants.DEFAULT_MIN_ZOOM);
    vectorLayer.setMaxZoom(GeoConstants.DEFAULT_MAX_ZOOM);

    vectorLayer.create(layerType, fields);
    return vectorLayer;
}
 
源代码26 项目: android_gisapp   文件: CreateVectorLayerActivity.java
@Override
public void OnFieldChosen(String alias, int type) {
    if (TextUtils.isEmpty(alias))
        Toast.makeText(this, R.string.empty_name, Toast.LENGTH_SHORT).show();
    else if (mFieldAdapter.containsField(alias))
        Toast.makeText(this, R.string.same_field_name, Toast.LENGTH_LONG).show();
    else
        mFieldAdapter.addField(new Field(type, null, alias));
}
 
源代码27 项目: android_gisapp   文件: CreateVectorLayerActivity.java
public boolean containsField(String fieldName) {
    for (Field field : mFields)
        if (field.getAlias().equalsIgnoreCase(fieldName))
            return true;

    return false;
}
 
源代码28 项目: android_maplibui   文件: Combobox.java
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException{

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);
    setEnabled(ControlHelper.isEnabled(fields, mFieldName));

    String lastValue = null;
    if (ControlHelper.hasKey(savedState, mFieldName))
        lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) {
            int column = featureCursor.getColumnIndex(mFieldName);
            if (column >= 0)
                lastValue = featureCursor.getString(column);
    } else if (mIsShowLast)
        lastValue = preferences.getString(mFieldName, null);

    int defaultPosition = 0;
    int lastValuePosition = -1;
    mAliasValueMap = new HashMap<>();

    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.formtemplate_spinner);
    setAdapter(spinnerArrayAdapter);

    if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) {
        MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
        if (null == map)
            throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited");

        String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME);
        long id = attributes.optLong(JSON_NGW_ID_KEY, -1);
        for (int i = 0; i < map.getLayerCount(); i++) {
            if (map.getLayer(i) instanceof NGWLookupTable) {
                NGWLookupTable table = (NGWLookupTable) map.getLayer(i);
                if (table.getRemoteId() != id || !table.getAccountName().equals(account))
                    continue;

                int j = 0;
                for (Map.Entry<String, String> entry : table.getData().entrySet()) {
                    mAliasValueMap.put(entry.getValue(), entry.getKey());

                    if (null != lastValue && lastValue.equals(entry.getKey()))
                        lastValuePosition = j;

                    spinnerArrayAdapter.add(entry.getValue());
                    j++;
                }

                break;
            }
        }
    } else {
        JSONArray values = attributes.optJSONArray(JSON_VALUES_KEY);
        if (values != null) {
            for (int j = 0; j < values.length(); j++) {
                JSONObject keyValue = values.getJSONObject(j);
                String value = keyValue.getString(JSON_VALUE_NAME_KEY);
                String value_alias = keyValue.getString(JSON_VALUE_ALIAS_KEY);

                if (keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY))
                    defaultPosition = j;

                if (null != lastValue && lastValue.equals(value))
                    lastValuePosition = j;

                mAliasValueMap.put(value_alias, value);
                spinnerArrayAdapter.add(value_alias);
            }
        }
    }

    setSelection(lastValuePosition >= 0 ? lastValuePosition : defaultPosition);

    // The drop down view
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    float minHeight = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics());
    setPadding(0, (int) minHeight, 0, (int) minHeight);
}
 
源代码29 项目: android_maplibui   文件: RadioGroup.java
@Override
public void init(JSONObject element,
                 List<Field> fields,
                 Bundle savedState,
                 Cursor featureCursor,
                 SharedPreferences preferences,
                 Map<String, Map<String, String>> translations) throws JSONException{

    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_NAME_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);
    boolean isEnabled = ControlHelper.isEnabled(fields, mFieldName);
    setEnabled(isEnabled);

    String lastValue = null;
    if (ControlHelper.hasKey(savedState, mFieldName))
        lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
    else if (null != featureCursor) { // feature exists
        int column = featureCursor.getColumnIndex(mFieldName);
        if (column >= 0)
            lastValue = featureCursor.getString(column);
    } else if (mIsShowLast)
        lastValue = preferences.getString(mFieldName, null);

    JSONArray values = attributes.getJSONArray(JSON_VALUES_KEY);
    int position = Constants.NOT_FOUND;
    mAliasValueMap = new HashMap<>();

    for (int j = 0; j < values.length(); j++) {
        JSONObject keyValue = values.getJSONObject(j);
        String value = keyValue.getString(JSON_VALUE_NAME_KEY);
        String value_alias = keyValue.getString(JSON_VALUE_ALIAS_KEY);

        if (lastValue == null && keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY)) {
            position = j;
        }

        if (lastValue != null && lastValue.equals(value)) { // if modify data
            position = j;
        }

        mAliasValueMap.put(value_alias, value);
        AppCompatRadioButton radioButton = new AppCompatRadioButton(getContext());
        radioButton.setText(value_alias);
        radioButton.setEnabled(isEnabled);
        addView(radioButton);
    }

    if (getChildAt(position) != null)
        check(getChildAt(position).getId());
    setOrientation(RadioGroup.VERTICAL);
}
 
源代码30 项目: android_maplibui   文件: Sign.java
@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState,
                 Cursor featureCursor, SharedPreferences lastValue,
                 Map<String, Map<String, String>> translations) {
    init();
}