Java Code Examples for com.nextgis.maplib.util.Constants#NOT_FOUND

The following examples show how to use com.nextgis.maplib.util.Constants#NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawItem.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void deleteSelectedPoint(VectorLayer layer) {
    float[] points = getSelectedRing();
    if (null == points || mSelectedPoint < 0)
        return;

    if (points.length <= getMinPointCount(layer.getGeometryType()) * 2) {
        mDrawItemsVertex.remove(mSelectedRing);
        mSelectedRing = mDrawItemsVertex.size() > 0 ? 0 : Constants.NOT_FOUND;
        mSelectedPoint = Constants.NOT_FOUND;
        return;
    }

    float[] newPoints = new float[points.length - 2];
    int counter = 0;
    for (int i = 0; i < points.length; i++) {
        if (i == mSelectedPoint || i == mSelectedPoint + 1)
            continue;

        newPoints[counter++] = points[i];
    }

    if (mSelectedPoint >= newPoints.length)
        mSelectedPoint = 0;

    setRing(mSelectedRing, newPoints);
}
 
Example 2
Source File: LayerGroup.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public int getVisibleTopLayerId()
{
   for (int i = mLayers.size() - 1; i >= 0; i--) {
        ILayer layer = mLayers.get(i);
        if (layer instanceof LayerGroup) {
            LayerGroup layerGroup = (LayerGroup) layer;
            int visibleTopLayerId = layerGroup.getVisibleTopLayerId();
            if (Constants.NOT_FOUND != visibleTopLayerId) {
                return visibleTopLayerId;
            }

        } else {
            if (layer.isValid() && layer instanceof ILayerView) {
                ILayerView layerView = (ILayerView) layer;
                if (layerView.isVisible()) {
                    return layer.getId();
                }
            }
        }
    }

    return Constants.NOT_FOUND;
}
 
Example 3
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public long getUniqId()
{
    if (Constants.NOT_FOUND == mUniqId) {
        String columns[] = {FIELD_ID};
        String sortOrder = FIELD_ID + " DESC";
        Cursor cursor = query(columns, null, null, sortOrder, "1");
        if (null != cursor) {
            try {
                if (cursor.moveToFirst()) {
                    mUniqId = cursor.getLong(0) + 1;
                }
            } catch (Exception e) {
                //Log.d(TAG, e.getLocalizedMessage());
            } finally {
                cursor.close();
            }
        }
    }

    return mUniqId;
}
 
Example 4
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void notifyUpdate(
        long rowId,
        long oldRowId,
        boolean attributesOnly)
{
    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "notifyUpdate id: " + rowId + ", old_id: " + oldRowId);
    }

    boolean needSave = false;
    if (oldRowId != Constants.NOT_FOUND) {
        mCache.changeId(oldRowId, rowId);
        if (DEBUG_MODE)
            Log.d(Constants.TAG, "mCache: changing id from " + oldRowId + " to " + rowId);
        needSave = true;
    }

    GeoGeometry geom = getGeometryForId(rowId);
    if (null != geom && !attributesOnly) {
        mCache.removeItem(rowId);
        cacheGeometryEnvelope(rowId, geom);
        if (DEBUG_MODE)
            Log.d(Constants.TAG, "mCache: removing item " + oldRowId + " and caching env");
        needSave = true;
    }

    if (needSave) {
        save();
    }

    notifyLayerChanged();
}
 
Example 5
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public long createFeature(Feature feature)
        throws SQLiteException
{
    if (null == feature.getGeometry() || !checkGeometryType(feature)) {
        return NOT_FOUND;
    }

    if (!mCacheLoaded) {
        reloadCache();
    }

    // check if such id already used
    // maybe was added previous session
    if (mCache.getItem(feature.getId()) != null) {
        return NOT_FOUND;
    }

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

    final ContentValues values = getFeatureContentValues(feature);

    if (Constants.DEBUG_MODE) {
        Log.d(TAG, "Inserting " + values);
    }
    long rowId = db.insert(mPath.getName(), "", values);
    if (rowId != Constants.NOT_FOUND) {
        //update bbox
        cacheGeometryEnvelope(rowId, feature.getGeometry());
        save();
    }

    return rowId;
}
 
Example 6
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addChange(
        long featureId,
        int operation)
{
    if (0 == (mSyncType & Constants.SYNC_DATA)) {
        return;
    }

    String changeTableName = getChangeTableName();
    boolean canAddChanges = true;

    // for delete operation
    if (operation == Constants.CHANGE_OPERATION_DELETE) {

        // if featureId == NOT_FOUND remove all changes for all features
        if (featureId == Constants.NOT_FOUND) {
            FeatureChanges.removeAllChanges(changeTableName);

            // if feature has changes then remove them for the feature
        } else if (FeatureChanges.isChanges(changeTableName, featureId)) {
            // if feature was new then just remove its changes
            canAddChanges = !FeatureChanges.isChanges(changeTableName, featureId,
                    Constants.CHANGE_OPERATION_NEW);
            FeatureChanges.removeChanges(changeTableName, featureId);
        }
    }

    // we are trying to re-create feature - warning
    if (operation == Constants.CHANGE_OPERATION_NEW && FeatureChanges.isChanges(
            changeTableName, featureId)) {
        Log.w(Constants.TAG, "Something wrong. Should nether get here");
        canAddChanges = false;
    }

    // if can then add change
    if (canAddChanges) {
        FeatureChanges.add(changeTableName, featureId, operation);
    }
}
 
Example 7
Source File: GeoMultiPolygon.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setCoordinatesFromWKT(String wkt, int crs)
{
    setCRS(crs);
    if (wkt.contains("EMPTY")) {
        return;
    }

    if (wkt.startsWith("(")) {
        wkt = wkt.substring(1, wkt.length() - 1);
    }

    int pos = wkt.indexOf("((");
    while (pos != Constants.NOT_FOUND) {
        wkt = wkt.substring(pos + 1, wkt.length());
        pos = wkt.indexOf("))") - 1;
        if (pos < 1) {
            return;
        }

        GeoPolygon polygon = new GeoPolygon();
        polygon.setCoordinatesFromWKT(wkt.substring(0, pos).trim(), crs);
        add(polygon);

        pos = wkt.indexOf("((");
    }
}
 
Example 8
Source File: GeoMultiLineString.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setCoordinatesFromWKT(String wkt, int crs)
{
    setCRS(crs);
    if (wkt.contains("EMPTY")) {
        return;
    }

    if (wkt.startsWith("(")) {
        wkt = wkt.substring(1, wkt.length() - 1);
    }

    int pos = wkt.indexOf("(");
    while (pos != Constants.NOT_FOUND) {
        wkt = wkt.substring(pos + 1, wkt.length());
        pos = wkt.indexOf(")") - 1;
        if (pos < 1) {
            return;
        }

        GeoLineString lineString = new GeoLineString();
        lineString.setCoordinatesFromWKT(wkt.substring(0, pos).trim(), crs);
        add(lineString);

        pos = wkt.indexOf("(");
    }
}
 
Example 9
Source File: Feature.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
private long dateObjectToLong(Object value)
{
    if (value instanceof Long) {
        return (Long) value;
    } else if (value instanceof Date) {
        Date date = (Date) value;
        return date.getTime();
    } else if (value instanceof Calendar) {
        Calendar cal = (Calendar) value;
        return cal.getTimeInMillis();
    }

    return Constants.NOT_FOUND;
}
 
Example 10
Source File: Feature.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Feature()
{
    mId = Constants.NOT_FOUND;
    mFields = new ArrayList<>();
    mFieldValues = new ArrayList<>();
    mAttachments = new HashMap<>();
}
 
Example 11
Source File: GeoPolygon.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setCoordinatesFromWKT(String wkt, int crs)
{
    setCRS(crs);
    if (wkt.contains("EMPTY")) {
        return;
    }

    if (wkt.startsWith("(")) {
        wkt = wkt.substring(1, wkt.length() - 1);
    }
    //get outer ring
    int pos = wkt.indexOf(")");
    if (pos == Constants.NOT_FOUND) // no inner rings
    {
        mOuterRing.setCoordinatesFromWKT(wkt, crs);
    } else {
        mOuterRing.setCoordinatesFromWKT(wkt.substring(0, pos), crs);
    }
    pos = wkt.indexOf("(");
    while (pos != Constants.NOT_FOUND) {
        wkt = wkt.substring(pos + 1, wkt.length());
        pos = wkt.indexOf(")") - 1;
        if (pos < 1) {
            return;
        }

        GeoLinearRing innerRing = new GeoLinearRing();
        innerRing.setCoordinatesFromWKT(wkt.substring(0, pos), crs);
        mInnerRings.add(innerRing);

        pos = wkt.indexOf("(");
    }
}
 
Example 12
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Feature cursorToFeature(Cursor cursor)
{
    Feature out = new Feature((long) Constants.NOT_FOUND, getFields());
    out.fromCursor(cursor);
    //add extensions to feature
    out.addAttachments(getAttachMap("" + out.getId()));
    return out;
}
 
Example 13
Source File: RebuildCacheService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setValue(int value) {
    if (mLastUpdate + ConstantsUI.NOTIFICATION_DELAY < System.currentTimeMillis()) {
        mLastUpdate = System.currentTimeMillis();
        mBuilder.setProgress(mProgressMax, value, false);
        mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());
    }

    int id = mLayer != null ? mLayer.getId() : Constants.NOT_FOUND;
    mProgressIntent.putExtra(KEY_PROGRESS, value)
            .putExtra(KEY_MAX, mProgressMax)
            .putExtra(ConstantsUI.KEY_LAYER_ID, id);
    sendBroadcast(mProgressIntent);
}
 
Example 14
Source File: WalkEditService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mSharedPreferencesTemp = getSharedPreferences(TEMP_PREFERENCES, MODE_MULTI_PROCESS);

    mTicker = getString(R.string.walkedit_title);
    mSmallIcon = R.drawable.ic_action_maps_directions_walk;

    mLayerId = Constants.NOT_FOUND;
}
 
Example 15
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setSelectedFeature(long featureId) {
    clearDrawItems();

    if (mLayer != null && featureId > Constants.NOT_FOUND) {
        mFeature = new Feature(featureId, mLayer.getFields());
        mFeature.setGeometry(mLayer.getGeometryForId(featureId));
    } else
        mFeature = null;

    updateMap();
}
 
Example 16
Source File: Feature.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ContentValues getContentValues(boolean withId)
{
    ContentValues values = new ContentValues();
    if (withId) {
        if (mId != Constants.NOT_FOUND) {
            values.put(Constants.FIELD_ID, mId);
        } else {
            values.putNull(Constants.FIELD_ID);
        }
    }

    try {
        if (null != mGeometry) {
            values.put(FIELD_GEOM, mGeometry.toBlob());
        }
    } catch (IOException e) { //if exception - not create geom
        e.printStackTrace();
    }
    if (!values.containsKey(FIELD_GEOM)) {
        values.putNull(FIELD_GEOM);
    }

    for (int i = 0; i < mFields.size(); i++) {
        Field field = mFields.get(i);

        if (!isValuePresent(i)) {
            values.putNull(field.getName());
            continue;
        }

        switch (field.getType()) {
            case FTString:
                values.put(field.getName(), getFieldValueAsString(i));
                break;

            case FTInteger:
                Object intVal = getFieldValue(i);
                if (intVal instanceof Integer) {
                    values.put(field.getName(), (int) intVal);
                } else if (intVal instanceof Long) {
                    values.put(field.getName(), (long) intVal);
                } else {
                    Log.d(TAG, "skip value: " + intVal.toString());
                }
                break;

            case FTReal:
                Object realVal = getFieldValue(i);
                if (realVal instanceof Double) {
                    values.put(field.getName(), (double) realVal);
                } else if (realVal instanceof Float) {
                    values.put(field.getName(), (float) realVal);
                } else {
                    Log.d(TAG, "skip value: " + realVal.toString());
                }
                break;

            case FTDate:
            case FTTime:
            case FTDateTime:
                Object dateVal = getFieldValue(i);
                if (dateVal instanceof Date) {
                    Date date = (Date) dateVal;
                    values.put(field.getName(), date.getTime());
                } else if (dateVal instanceof Long) {
                    values.put(field.getName(), (long) dateVal);
                } else if (dateVal instanceof Calendar) {
                    Calendar cal = (Calendar) dateVal;
                    values.put(field.getName(), cal.getTimeInMillis());
                } else {
                    Log.d(TAG, "skip value: " + dateVal.toString());
                }
                break;
        }
    }

    return values;
}
 
Example 17
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void fillDrawItems(GeoGeometry geom) {
    int lastItemsCount = mDrawItems.size();
    int lastSelectedItemPosition = mDrawItems.indexOf(mSelectedItem);
    DrawItem lastSelectedItem = mSelectedItem;
    mDrawItems.clear();

    if (null == geom) {
        Log.w(Constants.TAG, "the geometry is null in fillDrawItems method");
        return;
    }

    GeoPoint[] geoPoints = new GeoPoint[1];
    Location last = mGpsEventSource.getLastKnownLocation();
    switch (geom.getType()) {
        case GeoConstants.GTPoint:
            geoPoints[0] = (GeoPoint) geom;
            mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
            mDrawItems.add(mSelectedItem);
            break;
        case GeoConstants.GTMultiPoint:
            GeoMultiPoint geoMultiPoint = (GeoMultiPoint) geom;
            for (int i = 0; i < geoMultiPoint.size(); i++) {
                geoPoints[0] = geoMultiPoint.get(i);
                mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
                mDrawItems.add(mSelectedItem);
            }
            break;
        case GeoConstants.GTLineString:
            fillDrawLine((GeoLineString) geom);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geom;
            for (int i = 0; i < multiLineString.size(); i++)
                fillDrawLine(multiLineString.get(i));
            break;
        case GeoConstants.GTPolygon:
            fillDrawPolygon((GeoPolygon) geom);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geom;
            for (int i = 0; i < multiPolygon.size(); i++)
                fillDrawPolygon(multiPolygon.get(i));
            break;
        case GeoConstants.GTGeometryCollection:
            GeoGeometryCollection collection = (GeoGeometryCollection) geom;
            for (int i = 0; i < collection.size(); i++) {
                GeoGeometry geoGeometry = collection.get(i);
                fillDrawItems(geoGeometry);
            }
            break;
        default:
            break;
    }

    if (mDrawItems.size() == lastItemsCount && lastSelectedItem != null &&
            lastSelectedItemPosition != Constants.NOT_FOUND) {
        mSelectedItem = mDrawItems.get(lastSelectedItemPosition);
        mSelectedItem.setSelectedRing(lastSelectedItem.getSelectedRingId());
        mSelectedItem.setSelectedPoint(lastSelectedItem.getSelectedPointId());
    } else {
        mSelectedItem = mDrawItems.get(0);
    }

    switch (geom.getType()) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTMultiPoint:
            updateDistance(last, null);
            break;
    }
}
 
Example 18
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void addChange(
        long featureId,
        long attachId,
        int attachOperation)
{
    if (0 == (mSyncType & Constants.SYNC_ATTACH)) {
        return;
    }

    String changeTableName = getChangeTableName();
    boolean canAddChanges = true;

    // for delete operation
    if (attachOperation == Constants.CHANGE_OPERATION_DELETE) {

        // if attachId == NOT_FOUND remove all attach changes for the feature
        if (attachId == Constants.NOT_FOUND) {
            FeatureChanges.removeAllAttachChanges(changeTableName, featureId);

            // if attachment has changes then remove them for the attachment
        } else if (FeatureChanges.isAttachChanges(changeTableName, featureId, attachId)) {
            // if attachment was new then just remove its changes
            canAddChanges =
                    !FeatureChanges.isAttachChanges(changeTableName, featureId, attachId,
                            Constants.CHANGE_OPERATION_NEW);
            FeatureChanges.removeAttachChanges(changeTableName, featureId, attachId);
        }
    }

    // we are trying to re-create the attach - warning
    // TODO: replace to attachOperation == CHANGE_OPERATION_NEW ???
    if (0 != (attachOperation & Constants.CHANGE_OPERATION_NEW)
            && FeatureChanges.isAttachChanges(changeTableName, featureId, attachId)) {
        Log.w(Constants.TAG, "Something wrong. Should nether get here");
        canAddChanges = false;
    }

    if (canAddChanges) {
        FeatureChanges.add(changeTableName, featureId, attachId, attachOperation);
    }
}
 
Example 19
Source File: DrawItem.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void deleteSelectedRing() {
    mDrawItemsVertex.remove(mSelectedRing);
    mSelectedRing = mSelectedPoint = mDrawItemsVertex.size() > 0 ? 0 : Constants.NOT_FOUND;
}
 
Example 20
Source File: RadioGroup.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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);
}