com.nextgis.maplib.util.SettingsConstants Java Examples

The following examples show how to use com.nextgis.maplib.util.SettingsConstants. 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: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume()
{
    if (null != findViewById(R.id.location_panel)) {
        IGISApplication app = (IGISApplication) getApplication();
        if (null != app) {
            GpsEventSource gpsEventSource = app.getGpsEventSource();
            gpsEventSource.addListener(this);
            if (mGPSDialog == null || !mGPSDialog.isShowing())
                mGPSDialog = NotificationHelper.showLocationInfo(this);
            setLocationText(gpsEventSource.getLastKnownLocation());
        }

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String def = "20";
        String preferred = prefs.getString(SettingsConstants.KEY_PREF_LOCATION_ACCURATE_COUNT, def);
        mMaxTakeCount = Integer.parseInt(preferred != null ? preferred : def);
    }
    super.onResume();
}
 
Example #2
Source File: GpsEventSource.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void updateActiveListeners() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    String value = sharedPreferences.getString(SettingsConstants.KEY_PREF_LOCATION_SOURCE, "3");
    mListenProviders = Integer.parseInt(value != null ? value : "3");

    String minTime = SettingsConstants.KEY_PREF_LOCATION_MIN_TIME;
    String minTimeStr = sharedPreferences.getString(minTime, "2");
    String minDistance = SettingsConstants.KEY_PREF_LOCATION_MIN_DISTANCE;
    String minDistanceStr = sharedPreferences.getString(minDistance, "10");
    mUpdateMinTime = Long.parseLong(minTimeStr != null ? minTimeStr : "2") * 1000;
    mUpdateMinDistance = Float.parseFloat(minDistanceStr != null ? minDistanceStr : "1000");

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

    mLocationManager.removeUpdates(mGpsLocationListener);
    if (mListeners.size() >= 1)
        requestUpdates();
}
 
Example #3
Source File: BootLoader.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void checkTrackerService(Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    boolean restoreTrack = preferences.getBoolean(SettingsConstants.KEY_PREF_TRACK_RESTORE, false);

    if (TrackerService.hasUnfinishedTracks(context)) {
        Intent trackerService = new Intent(context, TrackerService.class);
        if (!restoreTrack)
            trackerService.setAction(TrackerService.ACTION_STOP);

        ContextCompat.startForegroundService(context, trackerService);
    }
}
 
Example #4
Source File: WalkEditService.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void startWalkEdit() {
    SharedPreferences sharedPreferences = getSharedPreferences(getPackageName() + "_preferences", MODE_MULTI_PROCESS);

    String minTimeStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_LOCATION_MIN_TIME, "2");
    String minDistanceStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_LOCATION_MIN_DISTANCE, "10");
    long minTime = Long.parseLong(minTimeStr) * 1000;
    float minDistance = Float.parseFloat(minDistanceStr);

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

    mLocationManager.addGpsStatusListener(this);

    String provider = LocationManager.GPS_PROVIDER;
    if (mLocationManager.getAllProviders().contains(provider)) {
        mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this);
    }

    provider = LocationManager.NETWORK_PROVIDER;
    if (mLocationManager.getAllProviders().contains(provider)) {
        mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this);
    }

    NotificationHelper.showLocationInfo(this);
    initTargetIntent(mTargetActivity);
    addNotification();
}
 
Example #5
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected String getFeaturesUrl(AccountUtil.AccountData accountData)
{
    if (mTracked)
        return NGWUtil.getTrackedFeaturesUrl(accountData.url, mRemoteId, getPreferences().getLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP, 0));
    else
        return NGWUtil.getFeaturesUrl(accountData.url, mRemoteId, mServerWhere);
}
 
Example #6
Source File: LayersFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected void updateInfo() {
    if (null == mInfoText || getContext() == null) {
        return;
    }

    SharedPreferences sharedPreferences = getContext().getSharedPreferences(Constants.PREFERENCES, MODE_MULTI_PROCESS);
    long timeStamp = sharedPreferences.getLong(SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP, 0);
    if (timeStamp > 0) {
        mInfoText.setText(ControlHelper.getSyncTime(getContext(), timeStamp));
    }
}
 
Example #7
Source File: TrackerService.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) {
    String targetActivity = "";

    if (intent != null) {
        targetActivity = intent.getStringExtra(ConstantsUI.TARGET_CLASS);
        String action = intent.getAction();

        if (action != null && !TextUtils.isEmpty(action)) {
            switch (action) {
                case ACTION_SYNC:
                    if (mIsRunning || mLocationSenderThread != null)
                        return START_STICKY;

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                        int res = R.string.sync_started;
                        String title = getString(res);
                        NotificationCompat.Builder builder = createBuilder(this, res);
                        builder.setSmallIcon(mSmallIcon)
                                .setLargeIcon(mLargeIcon)
                                .setTicker(title)
                                .setWhen(System.currentTimeMillis())
                                .setAutoCancel(false)
                                .setContentTitle(title)
                                .setContentText(title)
                                .setOngoing(true);

                        startForeground(TRACK_NOTIFICATION_ID, builder.build());
                    }

                    mLocationSenderThread = createLocationSenderThread(500L);
                    mLocationSenderThread.start();
                    return START_NOT_STICKY;
                case ACTION_STOP:
                    removeNotification();
                    stopSelf();
                    return START_NOT_STICKY;
                case ACTION_SPLIT:
                    stopTrack();
                    startTrack();
                    addNotification();
                    return START_STICKY;
            }
        }
    }

    if (!mIsRunning) {
        if (!PermissionUtil.hasLocationPermissions(this)) {
            stopForeground(true);
            stopSelf();
            return START_NOT_STICKY;
        }

        mLocationManager.addGpsStatusListener(this);

        String time = SettingsConstants.KEY_PREF_TRACKS_MIN_TIME;
        String distance = SettingsConstants.KEY_PREF_TRACKS_MIN_DISTANCE;
        String minTimeStr = mSharedPreferences.getString(time, "2");
        String minDistanceStr = mSharedPreferences.getString(distance, "10");
        long minTime = Long.parseLong(minTimeStr) * 1000;
        float minDistance = Float.parseFloat(minDistanceStr);

        String provider = LocationManager.GPS_PROVIDER;
        if (mLocationManager.getAllProviders().contains(provider)) {
            mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this);

            if (Constants.DEBUG_MODE)
                Log.d(Constants.TAG, "Tracker service request location updates for " + provider);
        }

        provider = LocationManager.NETWORK_PROVIDER;
        if (mLocationManager.getAllProviders().contains(provider)) {
            mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this);

            if (Constants.DEBUG_MODE)
                Log.d(Constants.TAG, "Tracker service request location updates for " + provider);
        }

        NotificationHelper.showLocationInfo(this);

        // there are no tracks or last track correctly ended
        if (mSharedPreferencesTemp.getString(TRACK_URI, null) == null) {
            startTrack();
            mSharedPreferencesTemp.edit().putString(ConstantsUI.TARGET_CLASS, targetActivity).apply();
        } else {
            // looks like service was killed, restore data
            restoreData();
            targetActivity = mSharedPreferencesTemp.getString(ConstantsUI.TARGET_CLASS, "");
        }

        mLocationSenderThread = createLocationSenderThread(minTime);
        mLocationSenderThread.start();

        initTargetIntent(targetActivity);
        addNotification();
    }

    return START_STICKY;
}
 
Example #8
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 #9
Source File: SettingsFragment.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void createPreferences(PreferenceScreen screen)
{
    switch (mAction) {
        case SettingsConstantsUI.ACTION_PREFS_GENERAL:
            addPreferencesFromResource(R.xml.preferences_general);

            final ListPreference theme =
                    (ListPreference) findPreference(SettingsConstantsUI.KEY_PREF_THEME);
            initializeTheme(getActivity(), theme);
            final Preference reset =
                    findPreference(SettingsConstantsUI.KEY_PREF_RESET_SETTINGS);
            initializeReset(getActivity(), reset);
            break;
        case SettingsConstantsUI.ACTION_PREFS_MAP:
            addPreferencesFromResource(R.xml.preferences_map);

            final ListPreference showInfoPanel = (ListPreference) findPreference(
                    SettingsConstantsUI.KEY_PREF_SHOW_STATUS_PANEL);
            initializeShowStatusPanel(showInfoPanel);

            final ListPreference lpCoordinateFormat =
                    (ListPreference) findPreference(SettingsConstantsUI.KEY_PREF_COORD_FORMAT);
            final IntEditTextPreference etCoordinateFraction =
                    (IntEditTextPreference) findPreference(
                            SettingsConstantsUI.KEY_PREF_COORD_FRACTION);
            initializeCoordinates(lpCoordinateFormat, etCoordinateFraction);

            final ListPreference lpUnits = (ListPreference) findPreference(KEY_PREF_UNITS);
            initializeUnits(lpUnits);

            final SelectMapPathPreference mapPath = (SelectMapPathPreference) findPreference(
                    SettingsConstants.KEY_PREF_MAP_PATH);
            mapPath.setOnAttachedListener(this);
            initializeMapPath(getActivity(), mapPath);

            final ListPreference showCurrentLocation = (ListPreference) findPreference(
                    SettingsConstantsUI.KEY_PREF_SHOW_CURRENT_LOC);
            initializeShowCurrentLocation(showCurrentLocation);

            final ListPreference changeMapBG =
                    (ListPreference) findPreference(SettingsConstantsUI.KEY_PREF_MAP_BG);
            initializeMapBG(changeMapBG);
            break;
        case SettingsConstantsUI.ACTION_PREFS_LOCATION:
            addPreferencesFromResource(R.xml.preferences_location);

            final ListPreference lpLocationAccuracy =
                    (ListPreference) findPreference(SettingsConstants.KEY_PREF_LOCATION_SOURCE);
            initializeLocationAccuracy(lpLocationAccuracy, false);

            final ListPreference minTimeLoc = (ListPreference) findPreference(
                    SettingsConstants.KEY_PREF_LOCATION_MIN_TIME);
            final ListPreference minDistanceLoc = (ListPreference) findPreference(
                    SettingsConstants.KEY_PREF_LOCATION_MIN_DISTANCE);
            initializeLocationMins(minTimeLoc, minDistanceLoc, false);

            final EditTextPreference accurateMaxCount = (EditTextPreference) findPreference(
                    SettingsConstants.KEY_PREF_LOCATION_ACCURATE_COUNT);
            initializeAccurateTaking(accurateMaxCount);
            break;
        case SettingsConstantsUI.ACTION_PREFS_TRACKING:
            addPreferencesFromResource(R.xml.preferences_tracks);

            final ListPreference lpTracksAccuracy =
                    (ListPreference) findPreference(SettingsConstants.KEY_PREF_TRACKS_SOURCE);
            initializeLocationAccuracy(lpTracksAccuracy, true);

            final ListPreference minTime =
                    (ListPreference) findPreference(SettingsConstants.KEY_PREF_TRACKS_MIN_TIME);
            final ListPreference minDistance = (ListPreference) findPreference(
                    SettingsConstants.KEY_PREF_TRACKS_MIN_DISTANCE);
            initializeLocationMins(minTime, minDistance, true);

            final CheckBoxPreference uid = (CheckBoxPreference) findPreference(SettingsConstants.KEY_PREF_TRACK_SEND);
            initializeUid(uid);
            break;
    }
}