com.nextgis.maplib.map.MapContentProviderHelper Java Examples

The following examples show how to use com.nextgis.maplib.map.MapContentProviderHelper. 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: SimpleFeatureRenderer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    android.os.Process.setThreadPriority(
            Constants.DEFAULT_DRAW_THREAD_PRIORITY);

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

    for(Long id : mFeatureIds) {
        if(mLayer.isFeatureHidden(id))
            continue;
        final GeoGeometry geometry = mLayer.getGeometryForId(id, mZoom, db);
        if (geometry != null) {
            final Style style = getStyle(id);
            style.onDraw(geometry, mDisplay);
        }
    }
}
 
Example #2
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void initialize(String tableName)
{
    Log.d(TAG, "init the change log for the layer " + tableName);

    String sqlCreateTable = "CREATE TABLE IF NOT EXISTS " + tableName + " ( ";
    sqlCreateTable += FIELD_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ";
    sqlCreateTable += FIELD_FEATURE_ID + " INTEGER, ";
    sqlCreateTable += FIELD_OPERATION + " INTEGER, ";
    sqlCreateTable += FIELD_ATTACH_ID + " INTEGER, ";
    sqlCreateTable += FIELD_ATTACH_OPERATION + " INTEGER";
    sqlCreateTable += " );";

    Log.d(TAG, "create the layer change table: " + sqlCreateTable);

    // create table
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);
    db.execSQL(sqlCreateTable);
}
 
Example #3
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Cursor query(
        String tableName,
        String[] projection,
        String selection,
        String[] selectionArgs,
        String sortOrder,
        String limit)

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

    try {
        return db.query(
                tableName, projection, selection, selectionArgs, null, null, sortOrder, limit);
    } catch (SQLiteException e) {
        Log.d(TAG, e.getLocalizedMessage());
        return null;
    }
}
 
Example #4
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static int delete(
        String tableName,
        String selection,
        String[] selectionArgs)
{
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);
    int retResult = 0;
    try {
        retResult = db.delete(tableName, selection, selectionArgs);
    } catch (SQLiteException e) {
        e.printStackTrace();
        Log.d(TAG, e.getLocalizedMessage());
    }
    return retResult;
}
 
Example #5
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static long getChangeCount(String tableName)
{
    String selection = getSelectionForSync();
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);

    try {
        // From sources of DatabaseUtils.queryNumEntries()
        String s = (!TextUtils.isEmpty(selection)) ? " where " + selection : "";
        return DatabaseUtils.longForQuery(db, "select count(*) from " + tableName + s, null);
    } catch (SQLiteException e) {
        e.printStackTrace();
        Log.d(TAG, e.getLocalizedMessage());
        return 0;
    }
}
 
Example #6
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
protected static void deleteLayers(Activity activity)
{
    MainApplication app = (MainApplication) activity.getApplication();
    for (int i = app.getMap().getLayerCount() - 1; i >= 0; i--) {
        ILayer layer = app.getMap().getLayer(i);
        if (!layer.getPath().getName().equals(MainApplication.LAYER_OSM) && !layer.getPath()
                .getName()
                .equals(MainApplication.LAYER_A) && !layer.getPath()
                .getName()
                .equals(MainApplication.LAYER_B) && !layer.getPath()
                .getName()
                .equals(MainApplication.LAYER_C) && !layer.getPath()
                .getName()
                .equals(MainApplication.LAYER_TRACKS)) {
            layer.delete();
        }
    }

    try {
        ((MapContentProviderHelper) MapBase.getInstance()).getDatabase(false).execSQL("VACUUM");
    } catch (SQLiteException e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: RuleFeatureRendererUI.java    From android_maplibui with 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 #8
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static List<INGWLayer> getLayersForAccount(
        final IGISApplication application,
        Account account)
{
    List<INGWLayer> out = new ArrayList<>();
    if (application == null || account == null) {
        return out;
    }

    MapContentProviderHelper.getLayersByAccount(application.getMap(), account.name, out);
    return out;
}
 
Example #9
Source File: DatabaseContext.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static SQLiteDatabase getDbForLayer(final VectorLayer layer){
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(false);
    // speedup writing
    db.rawQuery("PRAGMA synchronous=OFF", null);
    //db.rawQuery("PRAGMA locking_mode=EXCLUSIVE", null);
    db.rawQuery("PRAGMA journal_mode=OFF", null);
    db.rawQuery("PRAGMA count_changes=OFF", null);
    db.rawQuery("PRAGMA cache_size=15000", null);

    return db;
}
 
Example #10
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static long insert(
        String tableName,
        ContentValues values)
{
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(false);
    return db.insert(tableName, null, values);
}
 
Example #11
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static int update(
        String tableName,
        ContentValues values,
        String selection,
        String[] selectionArgs)
{
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);
    return db.update(tableName, values, selection, selectionArgs);
}
 
Example #12
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void delete(String tableName)
{
    try {
        MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
        SQLiteDatabase db = map.getDatabase(true);
        String tableDrop = "DROP TABLE IF EXISTS " + tableName;
        db.execSQL(tableDrop);
    } catch (SQLiteFullException | SQLiteReadOnlyDatabaseException e) {
        e.printStackTrace();
    }
}
 
Example #13
Source File: FeatureChanges.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static long getEntriesCount(String tableName)
{
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);

    try {
        return DatabaseUtils.queryNumEntries(db, tableName);
    } catch (SQLiteException e) {
        e.printStackTrace();
        Log.d(TAG, e.getLocalizedMessage());
        return 0;
    }
}
 
Example #14
Source File: LayersFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void setupSyncOptions()
{
    mAccounts.clear();
    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    Log.d(TAG, "LayersFragment: AccountManager.get(" + getActivity().getApplicationContext() + ")");
    final IGISApplication application = (IGISApplication) getActivity().getApplication();
    List<INGWLayer> layers = new ArrayList<>();

    for (Account account : accountManager.getAccountsByType(application.getAccountsType())) {
        layers.clear();
        MapContentProviderHelper.getLayersByAccount(application.getMap(), account.name, layers);

        if (layers.size() > 0)
            mAccounts.add(account);
    }

    if (mAccounts.isEmpty()) {
        if (null != mSyncButton) {
            mSyncButton.setEnabled(false);
            mSyncButton.setVisibility(View.GONE);
        }
        if (null != mInfoText) {
            mInfoText.setVisibility(View.INVISIBLE);
        }
    } else {
        if (null != mSyncButton) {
            mSyncButton.setVisibility(View.VISIBLE);
            mSyncButton.setEnabled(true);
            mSyncButton.setOnClickListener(this);
        }
        if (null != mInfoText) {
            mInfoText.setVisibility(View.VISIBLE);
        }
    }
}
 
Example #15
Source File: Combobox.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);
    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);
}
 
Example #16
Source File: SyncAdapter.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
     * Warning! When you stop the sync service by ContentResolver.cancelSync() then onPerformSync
     * stops after end of syncing of current NGWVectorLayer. The data structure of the current
     * NGWVectorLayer will be saved.
     * <p/>
     * <b>Description copied from class:</b> AbstractThreadedSyncAdapter Perform a sync for this
     * account. SyncAdapter-specific parameters may be specified in extras, which is guaranteed to
     * not be null. Invocations of this method are guaranteed to be serialized.
     */
    @Override
    public void onPerformSync(
            Account account,
            Bundle bundle,
            String authority,
            ContentProviderClient contentProviderClient,
            SyncResult syncResult)
    {
        Log.d(TAG, "onPerformSync");

        MapContentProviderHelper mapContentProviderHelper =(MapContentProviderHelper) MapBase.getInstance();
        getContext().sendBroadcast(new Intent(SYNC_START));

        mVersions = new HashMap<>();
        if (null != mapContentProviderHelper) {
            // FIXME Temporary fix till 3.0
//            mapContentProviderHelper.load(); // reload map for deleted/added layers
            sync(mapContentProviderHelper, authority, syncResult);
        }

        if (isCanceled()) {
            Log.d(Constants.TAG, "onPerformSync - SYNC_CANCELED is sent");
            getContext().sendBroadcast(new Intent(SYNC_CANCELED));
            return;
        }

        final String accountNameHash = "_" + account.name.hashCode();
        SharedPreferences settings = getContext().getSharedPreferences(Constants.PREFERENCES, MODE_MULTI_PROCESS);
        SharedPreferences.Editor editor = settings.edit();
        editor.putLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP + accountNameHash, System.currentTimeMillis());
        editor.putLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP, System.currentTimeMillis());
        editor.apply();

        mError = "";
        if (syncResult.stats.numIoExceptions > 0)
            mError += getContext().getString(R.string.sync_error_io);
        if (syncResult.stats.numParseExceptions > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_parse);
        }
        if (syncResult.stats.numAuthExceptions > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.error_auth);
        }
        if (syncResult.stats.numConflictDetectedExceptions > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_conflict);
        }
        if (syncResult.stats.numInserts > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_insert);
        }
        if (syncResult.stats.numUpdates > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_change);
        }
        if (syncResult.stats.numDeletes > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_delete);
        }
        if (syncResult.stats.numEntries > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_server);
        }
        if (syncResult.stats.numSkippedEntries > 0) {
            if (mError.length() > 0)
                mError += "\r\n";
            mError += getContext().getString(R.string.sync_error_oom);
        }

        Intent finish = new Intent(SYNC_FINISH);
        if (!TextUtils.isEmpty(mError))
            finish.putExtra(EXCEPTION, mError);
        getContext().sendBroadcast(finish);
    }