Java Code Examples for com.nextgis.maplib.map.MapContentProviderHelper#getDatabase()

The following examples show how to use com.nextgis.maplib.map.MapContentProviderHelper#getDatabase() . 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: 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 7
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 8
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 9
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 10
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 11
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;
    }
}