com.nextgis.maplib.util.Constants Java Examples

The following examples show how to use com.nextgis.maplib.util.Constants. 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: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Uri insertTempAttach(
        long featureId,
        AttachItem attachItem)
{
    Uri uri = Uri.parse("content://" + mAuthority + "/" + mPath.getName() +
            "/" + featureId + "/" + Constants.URI_ATTACH);

    uri = uri.buildUpon()
            .appendQueryParameter(URI_PARAMETER_TEMP, Boolean.TRUE.toString())
            .build();

    Uri result = insert(uri, attachItem.getContentValues(false));

    if (result == null) {
        Log.d(TAG, "insert attach failed");
        return null;
    }

    return result;
}
 
Example #2
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Delete feature and add information to changes table for sync purposes
 *
 * @param id
 *         Feature identificator to delete
 *
 * @return Count of deleted features
 */
public int deleteAddChanges(long id)
{
    int result;
    if (id == Constants.NOT_FOUND) {
        result = delete(id, null, null);
    } else {
        result = delete(id, FIELD_ID + " = " + id, null);
    }

    if (result > 0) {
        addChange(id, CHANGE_OPERATION_DELETE);
    }

    return result;
}
 
Example #3
Source File: TileDownloadService.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void addTask(
        String layerPathName,
        GeoEnvelope env,
        List<Integer> zoomList)
{
    DownloadTask task = new DownloadTask(layerPathName, env, zoomList);
    mQueue.add(task);

    if (mDownloadThread == null) {
        if (Constants.DEBUG_MODE) {
            Log.d(
                    Constants.TAG,
                    "TileDownloadService.addTask(), create and run download thread");
        }
        mDownloadThread = createDownloadThread();
        mDownloadThread.start();
    }
}
 
Example #4
Source File: MapView.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void zoomStop()
{
    if (mDrawingState == DRAW_STATE_zooming && mMap != null) {

        float zoom = MapUtil.getZoomForScaleFactor(mScaleFactor, mMap.getZoomLevel());

        GeoEnvelope env = mMap.getFullScreenBounds();
        GeoPoint focusPt = new GeoPoint(-mCurrentFocusLocation.x, -mCurrentFocusLocation.y);

        double invertScale = 1 / mScaleFactor;

        double offX = (1 - invertScale) * focusPt.getX();
        double offY = (1 - invertScale) * focusPt.getY();
        env.scale(invertScale);
        env.offset(offX, offY);

        GeoPoint newCenterPt = env.getCenter();
        GeoPoint newCenterPtMap = mMap.screenToMap(newCenterPt);

        if(Constants.DEBUG_MODE) {
            Log.d(TAG, "zoomStop: setZoomAndCenter");
        }

        setZoomAndCenter(zoom, newCenterPtMap);
    }
}
 
Example #5
Source File: GeoLinearRing.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public GeoGeometry simplify(double tolerance){
    double sqTolerance = tolerance * tolerance;

    GeoEnvelope env = getEnvelope();
    double area = env.getArea() * Constants.SIMPLIFY_TOENV_AREA_MULTIPLY;
    if(sqTolerance > area * Constants.SIMPLIFY_SKIP_AREA_MULTIPLY) { //don't show this geometry on this zoom
        return null;
    }
    else if(sqTolerance > area){
        GeoLinearRing result = new GeoLinearRing();
        result.setCRS(getCRS());
        result.add(new GeoPoint(env.getMinX(), env.getMinY()));
        result.add(new GeoPoint(env.getMinX(), env.getMaxY()));
        result.add(new GeoPoint(env.getMaxX(), env.getMaxY()));
        result.add(new GeoPoint(env.getMaxX(), env.getMinY()));
        result.add(new GeoPoint(env.getMinX(), env.getMinY()));
        return result;
    }

    return simplifyRadialDistance(sqTolerance);
}
 
Example #6
Source File: GeoLineString.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public GeoGeometry simplify(double tolerance){
    double sqTolerance = tolerance * tolerance;

    GeoEnvelope env = getEnvelope();
    double area = env.getArea() * Constants.SIMPLIFY_TOENV_AREA_MULTIPLY;
    if(sqTolerance > area * Constants.SIMPLIFY_SKIP_AREA_MULTIPLY) { //don't show this geometry on this zoom
        return null;
    }
    else if(sqTolerance > area){
        GeoLineString result = new GeoLineString();
        result.setCRS(getCRS());
        result.add(new GeoPoint(env.getMinX(), env.getMinY()));
        result.add(new GeoPoint(env.getMaxX(), env.getMaxY()));
        return result;
    }

    return simplifyRadialDistance(sqTolerance);
}
 
Example #7
Source File: NGWLookupTable.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public JSONObject toJSON()
        throws JSONException
{
    JSONObject rootConfig = super.toJSON();
    rootConfig.put(JSON_ACCOUNT_KEY, mAccountName);
    rootConfig.put(Constants.JSON_ID_KEY, mRemoteId);
    rootConfig.put(JSON_SYNC_TYPE_KEY, mSyncType);

    JSONObject dataArray = new JSONObject();

    for (Map.Entry<String, String> entry : mData.entrySet()) {
        dataArray.put(entry.getKey(), entry.getValue());
    }

    rootConfig.put(JSON_LT_DATA_KEY, dataArray);

    return rootConfig;
}
 
Example #8
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected boolean proceedAttach(JSONObject result, SyncResult syncResult) throws JSONException {
    // get attach info
    if (!result.has("upload_meta")) {
        if (Constants.DEBUG_MODE) {
            Log.d(Constants.TAG, "Problem sendAttachOnServer(), result has not upload_meta, result: " + result.toString());
        }
        syncResult.stats.numParseExceptions++;
        return false;
    }

    JSONArray uploadMetaArray = result.getJSONArray("upload_meta");
    if (uploadMetaArray.length() == 0) {
        if (Constants.DEBUG_MODE) {
            Log.d(Constants.TAG, "Problem sendAttachOnServer(), result upload_meta length() == 0");
        }
        syncResult.stats.numParseExceptions++;
        return false;
    }

    return true;
}
 
Example #9
Source File: AttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.NOTIFY_DELETE);
    intentFilter.addAction(Constants.NOTIFY_DELETE_ALL);
    registerReceiver(mReceiver, intentFilter);

    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();

    if (null != map) {
        ILayer layer = map.getLayerById(mLayerId);
        if (null != layer && layer instanceof VectorLayer) {
            mLayer = (VectorLayer) layer;
            mTable.setAdapter(getAdapter());
            Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
            toolbar.setSubtitle(mLayer.getName());
        } else
            Toast.makeText(this, R.string.error_layer_not_inited, Toast.LENGTH_SHORT).show();
    }
}
 
Example #10
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected HttpResponse sendFeatureAttachOnServer(JSONObject result, long featureId, AttachItem attach) throws JSONException, IOException {
    // add attachment to row
    JSONObject postJsonData = new JSONObject();
    JSONArray uploadMetaArray = result.getJSONArray("upload_meta");
    postJsonData.put("file_upload", uploadMetaArray.get(0));
    postJsonData.put("description", attach.getDescription());
    String postload = postJsonData.toString();
    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "postload: " + postload);
    }

    // get account data
    AccountUtil.AccountData accountData = AccountUtil.getAccountData(mContext, mAccountName);

    // upload file
    String url = NGWUtil.getFeatureAttachmentUrl(accountData.url, mRemoteId, featureId);

    // update record in NGW
    return NetworkUtil.post(url, postload, accountData.login, accountData.password, false);
}
 
Example #11
Source File: Layer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void fromJSON(JSONObject jsonObject)
        throws JSONException
{
    super.fromJSON(jsonObject);
    if (jsonObject.has(JSON_MAXLEVEL_KEY)) {
        mMaxZoom = (float) jsonObject.getDouble(JSON_MAXLEVEL_KEY);
    } else {
        mMaxZoom = GeoConstants.DEFAULT_MAX_ZOOM;
    }
    if (jsonObject.has(JSON_MINLEVEL_KEY)) {
        mMinZoom = (float) jsonObject.getDouble(JSON_MINLEVEL_KEY);
    } else {
        mMinZoom = GeoConstants.DEFAULT_MIN_ZOOM;
    }

    mIsVisible = jsonObject.getBoolean(JSON_VISIBILITY_KEY);

    if(Constants.DEBUG_MODE){
        Log.d(Constants.TAG, "Layer " + getName() + " is visible " + mIsVisible);
        Log.d(Constants.TAG, "Layer " + getName() + " zoom limits from " + mMinZoom + " to " + mMaxZoom);
    }
}
 
Example #12
Source File: TMSLayerSettingsActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (mLayer == null)
        return;

    if (mLayer.getType() == Constants.LAYERTYPE_REMOTE_TMS ||
            mLayer.getType() == Constants.LAYERTYPE_LOCAL_TMS ||
            mLayer.getType() == Constants.LAYERTYPE_NGW_RASTER ||
            mLayer.getType() == Constants.LAYERTYPE_NGW_WEBMAP) {
        mRasterLayer = (TMSLayer) mLayer;
        mLayerMinZoom = mRasterLayer.getMinZoom();
        mLayerMaxZoom = mRasterLayer.getMaxZoom();
    }

    mClearCache = false;
}
 
Example #13
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 #14
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void proceedAddedFeatures(List<Feature> added, String authority, String changeTableName) {
    if (added != null) {
        for (Feature remoteFeature : added) {
            Cursor cursor = query(null, Constants.FIELD_ID + " = " + remoteFeature.getId(), null, null, null);
            boolean hasFeature = false;
            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    compareFeature(cursor, authority, remoteFeature, changeTableName);
                    hasFeature = true;
                }
                cursor.close();
            }

            if (!hasFeature)
                createNewFeature(remoteFeature, authority);
        }
    }
}
 
Example #15
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void toNGW(Long id, String account, int syncType, Pair<Integer, Integer> ver) {
    if (id != null && id != NOT_FOUND) {
        mLayerType = Constants.LAYERTYPE_NGW_VECTOR;
        try {
            JSONObject rootConfig = toJSON();
            if (ver != null) {
                rootConfig.put(NGWVectorLayer.JSON_NGW_VERSION_MAJOR_KEY, ver.first);
                rootConfig.put(NGWVectorLayer.JSON_NGW_VERSION_MINOR_KEY, ver.second);
            }

            rootConfig.put(NGWVectorLayer.JSON_ACCOUNT_KEY, account);
            rootConfig.put(Constants.JSON_ID_KEY, id);
            rootConfig.put(NGWVectorLayer.JSON_SYNC_TYPE_KEY, syncType);
            rootConfig.put(NGWVectorLayer.JSON_NGWLAYER_TYPE_KEY, Connection.NGWResourceTypeVectorLayer);
            FileUtil.writeToFile(getFileName(), rootConfig.toString());
            MapBase map = MapDrawable.getInstance();
            map.load();
            new Sync().execute();
        } catch (IOException | JSONException ignored) { }
    }
}
 
Example #16
Source File: VectorLayerSettingsActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example #17
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 #18
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
void testDelete()
{
    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();
    NGWVectorLayer ngwVectorLayer = null;
    for (int i = 0; i < map.getLayerCount(); i++) {
        ILayer layer = map.getLayer(i);
        if (layer instanceof NGWVectorLayer) {
            ngwVectorLayer = (NGWVectorLayer) layer;
        }
    }
    if (null != ngwVectorLayer) {
        Uri uri = Uri.parse(
                "content://" + AppSettingsConstants.AUTHORITY + "/" +
                ngwVectorLayer.getPath().getName());
        Uri deleteUri = ContentUris.withAppendedId(uri, 27);
        int result = getContentResolver().delete(deleteUri, null, null);
        if(Constants.DEBUG_MODE){
            if (result == 0) {
                Log.d(TAG, "delete failed");
            } else {
                Log.d(TAG, "" + result);
            }
        }
    }
}
 
Example #19
Source File: VectorLayerSettingsActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (mLayer == null)
        return;

    if (mLayer.getType() == Constants.LAYERTYPE_LOCAL_VECTOR
            || mLayer.getType() == Constants.LAYERTYPE_NGW_VECTOR
            || mLayer.getType() == Constants.LAYERTYPE_NGW_WEBMAP) {
        mVectorLayer = (VectorLayer) mLayer;
        mLayerMinZoom = mVectorLayer.getMinZoom();
        mLayerMaxZoom = mVectorLayer.getMaxZoom();
        mRenderer = mVectorLayer.getRenderer();
        mToolbar = findViewById(R.id.main_toolbar);
        setSubtitle();
    }
}
 
Example #20
Source File: AccurateLocationTaker.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void stopTaking()
{
    mIsStopped = true;

    mHandler.removeCallbacks(mStopTakingRunner);
    mHandler.removeCallbacks(mProgressUpdateRunner);

    if (null != mGpsTakings && !isCancelled() && null != mOnGetAccurateLocationListener) {
        Log.d(Constants.TAG, "Get the GPS accurate location");
        mOnGetAccurateLocationListener.onGetAccurateLocation(
                getAccurateLocation(mCircularError), (long) mGpsTakings.size(),
                mTakeTimeMillis);
    }

    if (!PermissionUtil.hasLocationPermissions(mContext))
        return;

    if (null != mLocationManager) {
        mLocationManager.removeUpdates(this);
    }
}
 
Example #21
Source File: LocalTMSLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void fromJSON(JSONObject jsonObject)
        throws JSONException
{
    super.fromJSON(jsonObject);
    mLimits = new HashMap<>();

    if(jsonObject.has(JSON_LEVELS_KEY)) {
        final JSONArray jsonArray = jsonObject.getJSONArray(JSON_LEVELS_KEY);
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonLevel = jsonArray.getJSONObject(i);
            int nLevel = jsonLevel.getInt(JSON_LEVEL_KEY);
            int nMaxX = jsonLevel.getInt(JSON_BBOX_MAXX_KEY);
            int nMaxY = jsonLevel.getInt(JSON_BBOX_MAXY_KEY);
            int nMinX = jsonLevel.getInt(JSON_BBOX_MINX_KEY);
            int nMinY = jsonLevel.getInt(JSON_BBOX_MINY_KEY);

            mLimits.put(nLevel, new TileCacheLevelDescItem(nMaxX, nMinX, nMaxY, nMinY));

            if(Constants.DEBUG_MODE) {
                Log.d(Constants.TAG, "Raster layer " + getName() + " limits: zoom " + nLevel + " X[" + nMinX + "," + nMaxX + "] Y[" + nMinY + "," + nMaxY + "]");
            }
        }
    }
}
 
Example #22
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoGeometry getGeometryForId(
        long rowId,
        SQLiteDatabase db)
{
    String[] columns = new String[] {Constants.FIELD_GEOM};
    String selection = Constants.FIELD_ID + " = " + rowId;
    return getGeometryFromQuery(columns, selection, db);
}
 
Example #23
Source File: NGWWebMapLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void fromJSON(JSONObject jsonObject) throws JSONException {
    super.fromJSON(jsonObject);

    JSONArray children = jsonObject.getJSONArray(Constants.JSON_LAYERS_KEY);
    for (int i = 0; i < children.length(); i++) {
        JSONObject child = children.getJSONObject(i);
        long id = child.getLong(Constants.JSON_ID_KEY);
        String name = child.getString(Constants.JSON_NAME_KEY);
        boolean visible = child.getBoolean(Constants.JSON_VISIBILITY_KEY);
        mChildren.add(new WebMapChild(id, name, visible));
    }
}
 
Example #24
Source File: NGWWebMapLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public JSONObject toJSON() throws JSONException {
    JSONObject root = super.toJSON();
    JSONArray children = new JSONArray();
    for (WebMapChild layer : mChildren) {
        JSONObject object = new JSONObject();
        object.put(Constants.JSON_ID_KEY, layer.getId());
        object.put(Constants.JSON_NAME_KEY, layer.getName());
        object.put(Constants.JSON_VISIBILITY_KEY, layer.isVisible());
        children.put(object);
    }

    root.put(Constants.JSON_LAYERS_KEY, children);
    return root;
}
 
Example #25
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void deleteAllTempFeatures()
{
    String layerPathName = mPath.getName();

    while (true) {
        Cursor cursor = queryFirstTempFeatureFlags();
        Long featureId;

        if (null != cursor) {
            int featureIdColumn = cursor.getColumnIndex(Constants.FIELD_FEATURE_ID);
            featureId = cursor.getLong(featureIdColumn);
            cursor.close();
        } else {
            break;
        }

        // delete all feature's attaches
        Uri uri = Uri.parse(
                "content://" + mAuthority + "/" + layerPathName + "/" + featureId + "/"
                        + URI_ATTACH);
        uri = uri.buildUpon()
                .appendQueryParameter(URI_PARAMETER_TEMP, Boolean.FALSE.toString())
                .build();
        delete(uri, null, null);

        // delete feature
        uri = Uri.parse("content://" + mAuthority + "/" + layerPathName + "/" + featureId);
        uri = uri.buildUpon()
                .appendQueryParameter(URI_PARAMETER_TEMP, Boolean.FALSE.toString())
                .build();
        delete(uri, null, null);
    }
}
 
Example #26
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 #27
Source File: ResourceGroup.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addResource(JSONObject data) {
    int type = getType(data);
    Resource resource = null;
    switch (type) {
        case Connection.NGWResourceTypeResourceGroup:
            resource = new ResourceGroup(data, mConnection);
            break;
        case Connection.NGWResourceTypePostgisLayer:
            if (mConnection.getNgwVersionMajor() < Constants.NGW_v3)
                break;
        case Connection.NGWResourceTypeVectorLayer:
        case Connection.NGWResourceTypeRasterLayer:
            LayerWithStyles layer = new LayerWithStyles(data, mConnection);
            layer.fillExtent();
            layer.fillStyles();
            resource = layer;
            break;
        case Connection.NGWResourceTypeWMSClient:
            resource = new LayerWithStyles(data, mConnection);
            break;
        case Connection.NGWResourceTypeLookupTable:
            resource = new ResourceWithoutChildren(data, mConnection);
            break;
        case Connection.NGWResourceTypeWebMap:
            resource = new WebMap(data, mConnection);
            break;
    }

    if (null != resource) {
        resource.setParent(this);
        resource.fillPermissions();
        mChildren.add(resource);
    }
}
 
Example #28
Source File: TMSLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setCacheSizeMultiply(int cacheSizeMult)
{
    mCacheSizeMult = cacheSizeMult;
    if (mCacheSizeMult == 0) {
        synchronized (lock) {
            mBitmapCache = null;
        }
        return;
    }

    // calc new hash size
    int nTileCount = (int) (mViewWidth * Constants.OFFSCREEN_EXTRASIZE_RATIO /
                            Constants.DEFAULT_TILE_SIZE) *
                     (int) (mViewHeight * Constants.OFFSCREEN_EXTRASIZE_RATIO /
                            Constants.DEFAULT_TILE_SIZE) * mCacheSizeMult;

    if (null != mBitmapCache && mCacheSize >= nTileCount) {
        return;
    }
    if (nTileCount < 30) {
        nTileCount = 30;
    }

    synchronized (lock) {
        mBitmapCache = lruCache(nTileCount);
    }

    mCacheSize = nTileCount;
}
 
Example #29
Source File: TMSLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void fillFromZipInt(Uri uri, IProgressor progressor) throws IOException, NGException, RuntimeException {
    InputStream inputStream;
    String url = uri.toString();
    if (NetworkUtil.isValidUri(url))
        inputStream = new URL(url).openStream();
    else
        inputStream = mContext.getContentResolver().openInputStream(uri);

    if (inputStream == null)
        throw new NGException(mContext.getString(R.string.error_download_data));

    int streamSize = inputStream.available();
    if (null != progressor)
        progressor.setMax(streamSize);

    int increment = 0;
    byte[] buffer = new byte[Constants.IO_BUFFER_SIZE];

    ZipInputStream zis = new ZipInputStream(inputStream);
    ZipEntry ze;
    while ((ze = zis.getNextEntry()) != null) {
        FileUtil.unzipEntry(zis, ze, buffer, mPath);
        increment += ze.getCompressedSize();
        zis.closeEntry();
        if (null != progressor) {
            if(progressor.isCanceled())
                return;
            progressor.setValue(increment);
            progressor.setMessage(getContext().getString(R.string.processed) + " " + increment + " " + getContext().getString(R.string.of) + " " + streamSize);
        }
    }
}
 
Example #30
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected synchronized void applySync(int syncType)
{
    if (syncType == Constants.SYNC_NONE) {
        FeatureChanges.removeAllChanges(getChangeTableName());
    } else {
        if (mTracked)
            return;

        for (Long featureId : query(null)) {
            addChange(featureId, Constants.CHANGE_OPERATION_NEW);
            //add attach
            File attacheFolder = new File(mPath, "" + featureId);
            if (attacheFolder.isDirectory()) {
                for (File attach : attacheFolder.listFiles()) {
                    String attachId = attach.getName();
                    if (attachId.equals(META)) {
                        continue;
                    }
                    Long attachIdL = Long.parseLong(attachId);
                    if (attachIdL >= Constants.MIN_LOCAL_FEATURE_ID) {
                        addChange(featureId, attachIdL, Constants.CHANGE_OPERATION_NEW);
                    }
                }
            }
        }
    }
}