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

The following examples show how to use com.nextgis.maplib.util.Constants. These examples are extracted from open source projects. 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 Project: android_maplib   Author: nextgis   File: NGWVectorLayer.java    License: 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 #2
Source Project: android_maplibui   Author: nextgis   File: DrawItem.java    License: 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 #3
Source Project: android_gisapp   Author: nextgis   File: MainActivity.java    License: 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 #4
Source Project: android_maplibui   Author: nextgis   File: TileDownloadService.java    License: 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 #5
Source Project: android_maplibui   Author: nextgis   File: MapView.java    License: 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 #6
Source Project: android_maplibui   Author: nextgis   File: AttributesActivity.java    License: 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 #7
Source Project: android_maplibui   Author: nextgis   File: TMSLayerSettingsActivity.java    License: 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 #8
Source Project: android_maplib   Author: nextgis   File: AccurateLocationTaker.java    License: 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 #9
@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 #10
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 #11
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: 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 #12
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: 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 #13
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: 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 Project: android_maplib   Author: nextgis   File: GeoLinearRing.java    License: 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 #15
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: 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 #16
Source Project: android_maplib   Author: nextgis   File: GeoLineString.java    License: 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 #17
Source Project: android_maplib   Author: nextgis   File: NGWLookupTable.java    License: 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 #18
Source Project: android_maplib   Author: nextgis   File: NGWVectorLayer.java    License: 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 #19
Source Project: android_maplib   Author: nextgis   File: NGWVectorLayer.java    License: 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 #20
Source Project: android_maplib   Author: nextgis   File: Layer.java    License: 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 #21
Source Project: android_maplib   Author: nextgis   File: LocalTMSLayer.java    License: 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 Project: android_maplibui   Author: nextgis   File: RuleFeatureRendererUI.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void fillFieldValues() {
    String[] column = new String[]{Constants.FIELD_ID, mSelectedField};
    String[] from = new String[]{mSelectedField};
    int[] to = new int[]{android.R.id.text1};

    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);
    mData = db.query(true, mLayer.getPath().getName(), column, null, null, column[1], null, null, null);
    mValueAdapter = new SimpleCursorAdapter(getContext(), android.R.layout.simple_spinner_item, mData, from, to, 0);
    mValueAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mStyleRule.setKey(mSelectedField);
}
 
Example #23
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void notifyInsert(long rowId)
{

    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "notifyInsert id: " + rowId);
    }

    GeoGeometry geom = getGeometryForId(rowId);
    if (null != geom) {
        cacheGeometryEnvelope(rowId, geom);
        save();
        notifyLayerChanged();
    }
}
 
Example #24
Source Project: android_maplibui   Author: nextgis   File: NGWSettingsFragment.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addAutoSyncProperty(
        final IGISApplication application,
        final Account account,
        PreferenceGroup syncCategory)
{
    final String accountNameHash = "_" + account.name.hashCode();
    SharedPreferences sharedPreferences =
            mStyledContext.getSharedPreferences(Constants.PREFERENCES, Context.MODE_MULTI_PROCESS);

    CheckBoxPreference enablePeriodicSync = new CheckBoxPreference(mStyledContext);
    enablePeriodicSync.setKey(KEY_SYNC);
    enablePeriodicSync.setPersistent(false);
    enablePeriodicSync.setTitle(R.string.auto_sync);

    boolean isAccountSyncEnabled = isAccountSyncEnabled(account, application.getAuthority());
    enablePeriodicSync.setChecked(isAccountSyncEnabled);
    enablePeriodicSync.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            boolean isChecked = (boolean) newValue;
            setAccountSyncEnabled(account, application.getAuthority(), isChecked);
            return true;
        }
    });

    long timeStamp = sharedPreferences.getLong(
            com.nextgis.maplib.util.SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP
                    + accountNameHash, 0);
    if (isAccountSyncEnabled && timeStamp > 0) {
        enablePeriodicSync.setSummary(ControlHelper.getSyncTime(mStyledContext, timeStamp));
    } else {
        enablePeriodicSync.setSummary(R.string.auto_sync_summary);
    }
    syncCategory.addPreference(enablePeriodicSync);
}
 
Example #25
Source Project: android_maplibui   Author: nextgis   File: NGWLoginFragment.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onLoadFinished(
        @NonNull Loader<String> loader,
        String token)
{
    mSignInButton.setEnabled(true);
    if (null != mGuestButton) { // needed for overrides
        mGuestButton.setEnabled(true);
    }

    String accountName = "";
    try {
        String url = mUrlText;
        if (!url.startsWith("http")) {
            url = "http://" + url;
        }
        URI uri = new URI(url);
        if (uri.getHost() != null && uri.getHost().length() > 0) {
            accountName += uri.getHost();
        }
        if (uri.getPort() != 80 && uri.getPort() > 0) {
            accountName += ":" + uri.getPort();
        }
        if (uri.getPath() != null && uri.getPath().length() > 0) {
            accountName += uri.getPath();
        }
    } catch (URISyntaxException e) {
        accountName = mUrlText;
    }

    mUrlText = mUrlWithProtocol.get();
    if (loader.getId() == R.id.auth_token_loader) {
        if (token != null && token.length() > 0)
            onTokenReceived(accountName, token);
        else
            Toast.makeText(getActivity(), R.string.error_login, Toast.LENGTH_SHORT).show();
    } else if (loader.getId() == R.id.non_auth_token_loader)
        onTokenReceived(accountName, Constants.NGW_ACCOUNT_GUEST);
}
 
Example #26
Source Project: android_maplibui   Author: nextgis   File: NGWLoginFragment.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void onTokenReceived(
        String accountName,
        String token)
{
    IGISApplication app = (IGISApplication) getActivity().getApplication();
    String login = mLoginText;
    String password = mPasswordText;
    if (token.equals(Constants.NGW_ACCOUNT_GUEST)) {
        login = Constants.NGW_ACCOUNT_GUEST;
        password = null;
    }

    if (mForNewAccount) {
        boolean accountAdded = app.addAccount(accountName, mUrlText.toLowerCase(), login, password, token);

        if (null != mOnAddAccountListener) {
            Account account = null;
            if (accountAdded)
                account = app.getAccount(accountName);

            mOnAddAccountListener.onAddAccount(account, token, accountAdded);
        }
    } else {
        if (mChangeAccountUrl)
            app.setUserData(accountName, "url", mUrlText.toLowerCase());

        if (mChangeAccountLogin)
            app.setUserData(accountName, "login", login);

        app.setPassword(accountName, password);
        NGWSettingsFragment.updateAccountLayersCacheData(app, app.getAccount(accountName));

        getActivity().finish();
    }
}
 
Example #27
Source Project: android_maplibui   Author: nextgis   File: EditLayerOverlay.java    License: 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 #28
Source Project: android_gisapp   Author: nextgis   File: MainApplication.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void checkTracksLayerExist()
{
    List<ILayer> tracks = new ArrayList<>();
    LayerGroup.getLayersByType(mMap, Constants.LAYERTYPE_TRACKS, tracks);
    if (tracks.isEmpty()) {
        String trackLayerName = getString(R.string.tracks);
        TrackLayerUI trackLayer =
                new TrackLayerUI(getApplicationContext(), mMap.createLayerStorage(LAYER_TRACKS));
        trackLayer.setName(trackLayerName);
        trackLayer.setVisible(true);
        mMap.addLayer(trackLayer);
        mMap.save();
    }
}
 
Example #29
Source Project: android_maplibui   Author: nextgis   File: GISApplication.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Account getAccount(String accountName)
{
    if(!PermissionUtil.hasPermission(this, Manifest.permission.GET_ACCOUNTS)){
        return null;
    }

    if (!isAccountManagerValid()) {
        return null;
    }
    try {
        for (Account account : mAccountManager.getAccountsByType(getAccountsType())) {
            if (account == null) {
                continue;
            }
            if(Constants.DEBUG_MODE)
                Log.d(Constants.TAG, "getAccount check account: " + account.toString());
            if (account.name.equals(accountName)) {
                return account;
            }
        }
    }
    catch (SecurityException e){
        e.printStackTrace();
    }
    return null;
}
 
Example #30
Source Project: android_maplib   Author: nextgis   File: VectorLayer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void deleteAllTempAttaches()
{
    String layerPathName = mPath.getName();

    while (true) {
        Cursor cursor = queryFirstTempAttachFlags();
        Long featureId, attachId;

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

        Uri uri = Uri.parse(
                "content://" + mAuthority + "/" + layerPathName + "/" + featureId + "/"
                        + Constants.URI_ATTACH + "/" + attachId);
        uri = uri.buildUpon()
                .appendQueryParameter(URI_PARAMETER_TEMP, Boolean.FALSE.toString())
                .build();
        delete(uri, null, null);
    }
}