com.nextgis.maplib.map.MapBase Java Examples

The following examples show how to use com.nextgis.maplib.map.MapBase. 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: 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 #2
Source File: CreateVectorLayerActivity.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
private boolean createNewLayer() {
    MainApplication app = (MainApplication) getApplication();
    int geomType = getResources().getIntArray(R.array.geom_types)[mSpLayerType.getSelectedItemPosition()];
    List<Field> fields = mFieldAdapter.getFields();
    if (fields.size() == 0)
        fields.add(new Field(GeoConstants.FTString, "description", getString(R.string.default_field_name)));
    else
        for (int i = 0; i < fields.size(); i++)
            fields.get(i).setName("field_" + (i + 1));

    VectorLayer layer = app.createEmptyVectorLayer(mEtLayerName.getText().toString().trim(), null, geomType, fields);

    SimpleFeatureRenderer sfr = (SimpleFeatureRenderer) layer.getRenderer();
    if (null != sfr) {
        Style style = sfr.getStyle();
        if (null != style) {
            Random rnd = new Random(System.currentTimeMillis());
            style.setColor(Color.rgb(rnd.nextInt(255), rnd.nextInt(255), rnd.nextInt(255)));
        }
    }

    MapBase map = app.getMap();
    map.addLayer(layer);
    return map.save();
}
 
Example #3
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 #4
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 #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: 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 #7
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 #8
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 #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: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void createView(final IGISApplication app, Bundle savedState)
{
    //create and fill controls
    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        int layerId = extras.getInt(KEY_LAYER_ID);
        MapBase map = app.getMap();
        mLayer = (VectorLayer) map.getLayerById(layerId);

        if (null != mLayer) {
            mSharedPreferences = mLayer.getPreferences();

            mFields = new HashMap<>();
            mFeatureId = extras.getLong(KEY_FEATURE_ID);
            mIsViewOnly = extras.getBoolean(KEY_VIEW_ONLY, false);
            mIsGeometryChanged = extras.getBoolean(KEY_GEOMETRY_CHANGED, true);
            mGeometry = (GeoGeometry) extras.getSerializable(KEY_GEOMETRY);
            LinearLayout layout = findViewById(R.id.controls_list);
            fillControls(layout, savedState);
        } else {
            Toast.makeText(this, R.string.error_layer_not_inited, Toast.LENGTH_SHORT).show();
            finish();
        }
    }
}
 
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 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 #12
Source File: CreateVectorLayerActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
private boolean hasLayerWithSameName() {
    MainApplication app = (MainApplication) getApplication();
    MapBase map = app.getMap();

    for (int i = 0; i < map.getLayerCount(); i++)
        if (map.getLayer(i).getName().trim().equalsIgnoreCase(mEtLayerName.getText().toString().trim()))
            return true;

    return false;
}
 
Example #13
Source File: SelectZoomLevelsDialog.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
private long getTilesCount(AsyncTask task, MapBase map, int leftThumbIndex, int rightThumbIndex) {
    TMSLayer layer = (TMSLayer) map.getLayerById(getLayerId());
    GeoEnvelope envelope = getEnvelope();
    long total = 0;
    for (int zoom = leftThumbIndex; zoom <= rightThumbIndex; zoom++) {
        if (task != null && task.isCancelled())
            return total;

        total += MapUtil.getTileCount(task, envelope, zoom, layer.getTMSType());
    }

    return total;
}
 
Example #14
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
void testSync()
{
    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();
    NGWVectorLayer ngwVectorLayer;
    for (int i = 0; i < map.getLayerCount(); i++) {
        ILayer layer = map.getLayer(i);
        if (layer instanceof NGWVectorLayer) {
            ngwVectorLayer = (NGWVectorLayer) layer;
            Pair<Integer, Integer> ver = NGWUtil.getNgwVersion(this, ngwVectorLayer.getAccountName());
            ngwVectorLayer.sync(application.getAuthority(), ver, new SyncResult());
        }
    }
}
 
Example #15
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
BackgroundMoveTask(
        Activity activity,
        MapBase map,
        File path)
{
    mActivity = activity;
    mMap = map;
    mPath = path;
}
 
Example #16
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 #17
Source File: WalkEditService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addNotification() {
    if (!mShowNotification)
        return;

    MapBase map = MapBase.getInstance();
    ILayer layer = map.getLayerById(mLayerId);
    String name = "";
    if (null != layer)
        name = layer.getName();

    mTicker = String.format(getString(R.string.walkedit_title), name);
    Bitmap largeIcon = NotificationHelper.getLargeIcon(mSmallIcon, getResources());

    NotificationCompat.Builder builder = createBuilder(this, R.string.title_edit_by_walk);

    builder.setContentIntent(mOpenActivity)
           .setSmallIcon(mSmallIcon)
           .setLargeIcon(largeIcon)
           .setTicker(mTicker)
           .setWhen(System.currentTimeMillis())
           .setAutoCancel(false)
           .setContentTitle(mTicker)
           .setContentText(mTicker)
           .setOngoing(true);

    builder.addAction(R.drawable.ic_location, getString(R.string.tracks_open), mOpenActivity);

    mNotificationManager.notify(WALK_NOTIFICATION_ID, builder.build());
    startForeground(WALK_NOTIFICATION_ID, builder.build());
}
 
Example #18
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 #19
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 #20
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 #21
Source File: RebuildCacheService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void startNextTask() {
    if (mQueue.isEmpty()) {
        stopService();
        return;
    }

    mIsCanceled = false;
    final IProgressor progressor = this;
    new Thread(new Runnable() {
        @Override
        public void run() {
            mLayer = (VectorLayer) MapBase.getInstance().getLayerById(mQueue.remove(0));
            mIsRunning = true;
            mCurrentTasks++;
            String notifyTitle = getString(R.string.rebuild_cache);
            notifyTitle += ": " + mCurrentTasks + "/" + mQueue.size() + 1;

            mBuilder.setWhen(System.currentTimeMillis())
                    .setContentTitle(notifyTitle)
                    .setTicker(notifyTitle);
            mNotifyManager.notify(NOTIFICATION_ID, mBuilder.build());

            Process.setThreadPriority(Constants.DEFAULT_DOWNLOAD_THREAD_PRIORITY);
            if (mLayer != null)
                mLayer.rebuildCache(progressor);

            mIsRunning = mRemoveCurrent = false;
            startNextTask();
        }
    }).start();
}
 
Example #22
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 #23
Source File: DatabaseHelper.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * is called whenever the app is upgraded and launched and the database version is not the same
 * @param sqLiteDatabase Database
 * @param oldVersion The previous database version
 * @param newVersion The current database version
 */
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion)
{
    MapBase map = MapBase.getInstance();
    map.onUpgrade(sqLiteDatabase, oldVersion, newVersion);
}
 
Example #24
Source File: LayerFillService.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LayerFillService", "Received start id " + startId + ": " + intent);
    if (intent != null) {
        String action = intent.getAction();
        if (action != null && !TextUtils.isEmpty(action)) {
            switch (action) {
                case ACTION_ADD_TASK:
                    int layerGroupId = intent.getIntExtra(KEY_LAYER_GROUP_ID, Constants.NOT_FOUND);
                    mLayerGroup = (LayerGroup) MapBase.getInstance().getLayerById(layerGroupId);

                    int layerType = intent.getIntExtra(KEY_INPUT_TYPE, Constants.NOT_FOUND);
                    Bundle extra = intent.getExtras();

                    switch (layerType) {
                        case VECTOR_LAYER:
                            mQueue.add(new VectorLayerFillTask(extra));
                            break;
                        case VECTOR_LAYER_WITH_FORM:
                            mQueue.add(new UnzipForm(extra));
                            break;
                        case TMS_LAYER:
                            mQueue.add(new LocalTMSFillTask(extra));
                            break;
                        case NGW_LAYER:
                            mQueue.add(new NGWVectorLayerFillTask(extra));
                            break;
                    }

                    if(!mIsRunning){
                        startNextTask();
                    }

                    return START_STICKY;
                case ACTION_STOP:
                    mQueue.clear();
                    mIsCanceled = true;
                    startNextTask();
                    break;
                case ACTION_SHOW:
                    mProgressIntent.putExtra(KEY_STATUS, STATUS_SHOW).putExtra(KEY_TITLE, mNotifyTitle);
                    sendBroadcast(mProgressIntent);
                    break;
            }
        }
    }
    return START_STICKY;
}
 
Example #25
Source File: SelectZoomLevelsDialog.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
CountTilesTask(MapBase map, int from, int to) {
    mMap = map;
    mFrom = from;
    mTo = to;
}
 
Example #26
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
void testUpdate()
{
    //test sync
    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 updateUri = ContentUris.withAppendedId(uri, 29);
        ContentValues values = new ContentValues();
        values.put("width", 4);
        values.put("azimuth", 8.0);
        values.put("status", "test4");
        values.put("temperatur", -10);
        values.put("name", "xxx");

        Calendar calendar = new GregorianCalendar(2014, Calendar.JANUARY, 23);
        values.put("datetime", calendar.getTimeInMillis());
        try {
            GeoPoint pt = new GeoPoint(67, 65);
            pt.setCRS(CRS_WGS84);
            pt.project(CRS_WEB_MERCATOR);
            GeoMultiPoint mpt = new GeoMultiPoint();
            mpt.add(pt);
            values.put(Constants.FIELD_GEOM, mpt.toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }
        int result = getContentResolver().update(updateUri, values, null, null);
        if(Constants.DEBUG_MODE){
            if (result == 0) {
                Log.d(TAG, "update failed");
            } else {
                Log.d(TAG, "" + result);
            }
        }
    }
}
 
Example #27
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
void testInsert()
{
    //test sync
    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());
        ContentValues values = new ContentValues();
        //values.put(VectorLayer.FIELD_ID, 26);
        values.put("width", 1);
        values.put("azimuth", 2.0);
        values.put("status", "grot");
        values.put("temperatur", -13);
        values.put("name", "get");

        Calendar calendar = new GregorianCalendar(2015, Calendar.JANUARY, 23);
        values.put("datetime", calendar.getTimeInMillis());

        try {
            GeoPoint pt = new GeoPoint(37, 55);
            pt.setCRS(CRS_WGS84);
            pt.project(CRS_WEB_MERCATOR);
            GeoMultiPoint mpt = new GeoMultiPoint();
            mpt.add(pt);
            values.put(Constants.FIELD_GEOM, mpt.toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }
        Uri result = getContentResolver().insert(uri, values);
        if(Constants.DEBUG_MODE){
            if (result == null) {
                Log.d(TAG, "insert failed");
            } else {
                Log.d(TAG, result.toString());
            }
        }
    }
}
 
Example #28
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);
    }
 
Example #29
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 #30
Source File: IGISApplication.java    From android_maplib with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * @return A MapBase or any inherited classes or null if not created in application
 */
MapBase getMap();