com.nextgis.maplib.api.IGISApplication Java Examples

The following examples show how to use com.nextgis.maplib.api.IGISApplication. 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: 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 #2
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 #3
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 #4
Source File: NGWAccountAuthenticator.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Bundle addAccount(
        AccountAuthenticatorResponse accountAuthenticatorResponse,
        String accountType,
        String authTokenType,
        String[] requiredFeatures,
        Bundle options)
        throws NetworkErrorException
{
    IGISApplication app = (IGISApplication) mContext.getApplicationContext();
    final Intent intent = new Intent(mContext, NGWLoginActivity.class);
    intent.putExtra(app.getAccountsType(), accountType);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, accountAuthenticatorResponse);
    final Bundle bundle = new Bundle();
    if (options != null) {
        bundle.putAll(options);
    }
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}
 
Example #5
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 #6
Source File: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    int id = item.getItemId();

    if (id == android.R.id.home) {
        if (!checkEdits())
            finish();
        return true;
    } else if (id == R.id.menu_settings) {
        final IGISApplication app = (IGISApplication) getApplication();
        app.showSettings(SettingsConstantsUI.ACTION_PREFS_GENERAL);
        return true;
    } else if (id == R.id.menu_apply) {
        if (saveFeature())
            finish();
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #7
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public CurrentLocationOverlay(Context context, MapViewOverlays mapViewOverlays) {
    super(context, mapViewOverlays);
    Activity parent = (Activity) context;
    mGpsEventSource = ((IGISApplication) parent.getApplication()).getGpsEventSource();
    mMarkerColor = ControlHelper.getColor(mContext, R.attr.colorAccent);

    mTolerancePX = context.getResources().getDisplayMetrics().density * AUTOPAN_THRESHOLD;

    double longitude = 0, latitude = 0;
    mMarker = new OverlayItem(mapViewOverlays.getMap(), longitude, latitude, getDefaultMarker());
    mAccuracy = new OverlayItem(mapViewOverlays.getMap(), longitude, latitude, null);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    mShowMode = Integer.parseInt(preferences.getString(SettingsConstantsUI.KEY_PREF_SHOW_CURRENT_LOC, "3"));
    setShowAccuracy(0 != (mShowMode & WITH_ACCURACY));
}
 
Example #8
Source File: AccurateLocationTaker.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param context
 *         The context.
 * @param maxTakeCount
 *         The max count of the GPS taking. If null then count is ignored.
 * @param maxTakeTimeMillis
 *         The max time for GPS taking (milliseconds). If null then time is ignored.
 * @param publishProgressDelayMillis
 *         The delay (milliseconds) for publish progress.
 * @param circularErrorStr
 *         The circular error, may be "CE50", "CE90", "CE95" or "CE98". If null or something
 *         other then takes the default value, "CE50".
 */
public AccurateLocationTaker(
        Context context,
        Float maxTakenAccuracy,
        Integer maxTakeCount,
        Long maxTakeTimeMillis,
        long publishProgressDelayMillis,
        String circularErrorStr)
{
    mContext = context;
    IGISApplication app = (IGISApplication) context.getApplicationContext();
    mMaxTakenAccuracy = maxTakenAccuracy;
    mLocationManager = app.getGpsEventSource().mLocationManager;
    mMaxTakeCount = maxTakeCount;
    mMaxTakeTimeMillis = maxTakeTimeMillis;
    mPublishProgressDelayMillis = publishProgressDelayMillis;
    mCircularError = getCircularErrorFromString(circularErrorStr);
}
 
Example #9
Source File: AccountUtil.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static AccountData getAccountData(Context context, String accountName) throws IllegalStateException {
    IGISApplication app = (IGISApplication) context.getApplicationContext();
    Account account = app.getAccount(accountName);

    if (null == account) {
        throw new IllegalStateException("Account is null");
    }

    AccountData accountData = new AccountData();

    accountData.url = app.getAccountUrl(account);
    accountData.login = app.getAccountLogin(account);
    accountData.password = app.getAccountPassword(account);

    return accountData;
}
 
Example #10
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void deleteAccountLayers(
        final IGISApplication application,
        Account account)
{
    List<INGWLayer> layers = getLayersForAccount(application, account);

    for (INGWLayer layer : layers) {
        ((Layer) layer).delete();
    }

    application.getMap().save();

    if (null != mOnDeleteAccountListener) {
        mOnDeleteAccountListener.onDeleteAccount(account);
    }
}
 
Example #11
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void addEditAccountAction(
        final IGISApplication application,
        final Account account,
        PreferenceGroup actionCategory)
{
    Preference preferenceEdit = new Preference(mStyledContext);
    preferenceEdit.setTitle(R.string.edit_account);
    preferenceEdit.setSummary(R.string.edit_account_summary);

    String url = application.getAccountUrl(account);
    String login = application.getAccountLogin(account);

    Intent intent = new Intent(mStyledContext, NGWLoginActivity.class);
    intent.putExtra(NGWLoginActivity.FOR_NEW_ACCOUNT, false);
    intent.putExtra(NGWLoginActivity.ACCOUNT_URL_TEXT, url);
    intent.putExtra(NGWLoginActivity.ACCOUNT_LOGIN_TEXT, login);
    intent.putExtra(NGWLoginActivity.CHANGE_ACCOUNT_URL, false);
    intent.putExtra(NGWLoginActivity.CHANGE_ACCOUNT_LOGIN, true);
    preferenceEdit.setIntent(intent);

    actionCategory.addPreference(preferenceEdit);
}
 
Example #12
Source File: PhotoGallery.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void getAttaches(IGISApplication app, VectorLayer layer, long featureId, Map<String, Integer> map, boolean excludeSign, String comment) {
    Uri uri = Uri.parse("content://" + app.getAuthority() + "/" +
            layer.getPath().getName() + "/" + featureId + "/" + Constants.URI_ATTACH);
    MatrixCursor attachCursor = (MatrixCursor) layer.query(uri,
            new String[]{VectorLayer.ATTACH_DATA, VectorLayer.ATTACH_ID, VectorLayer.ATTACH_DESCRIPTION},
            FIELD_ID + " = " + featureId, null, null, null);

    if (attachCursor.moveToFirst()) {
        do {
            if (excludeSign && attachCursor.getInt(1) == Integer.MAX_VALUE)
                continue;

            if (comment != null && !attachCursor.getString(2).equals(comment))
                continue;
            map.put(attachCursor.getString(0), attachCursor.getInt(1));
        } while (attachCursor.moveToNext());
    }

    attachCursor.close();
}
 
Example #13
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 #14
Source File: NGWRasterLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setAccountCacheData() {
    IGISApplication app = (IGISApplication) mContext.getApplicationContext();
    Account account = app.getAccount(mAccountName);

    if (null != account) {
        mCacheLogin = app.getAccountLogin(account);
        mCachePassword = app.getAccountPassword(account);
        if (Constants.DEBUG_MODE)
            Log.d(Constants.TAG, "Get account. User: " + mCacheLogin);
    } else if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "Failed to get account for name: " + mAccountName);
    }
}
 
Example #15
Source File: NGWLookupTable.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setAccountCacheData()
{
    IGISApplication app = (IGISApplication) mContext.getApplicationContext();
    Account account = app.getAccount(mAccountName);

    if (null != account) {
        mCacheUrl = app.getAccountUrl(account);
        mCacheLogin = app.getAccountLogin(account);
        mCachePassword = app.getAccountPassword(account);
    }
}
 
Example #16
Source File: SyncAdapter.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressLint("MissingPermission")
public static void setSyncPeriod(
        IGISApplication application,
        Bundle extras,
        long pollFrequency)
{
    Context context = ((Context) application).getApplicationContext();
    final AccountManager accountManager = AccountManager.get(context);
    Log.d(TAG, "SyncAdapter: AccountManager.get(" + context + ")");

    for (Account account : accountManager.getAccountsByType(application.getAccountsType())) {
        ContentResolver.addPeriodicSync(account, application.getAuthority(), extras, pollFrequency);
    }
}
 
Example #17
Source File: LayersFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    IGISApplication application = (IGISApplication) getActivity().getApplication();
    switch (menuItem.getItemId()) {
        case R.id.menu_new:
            application.sendEvent(GA_LAYER, GA_CREATE, GA_LOCAL);
            Intent intentNewLayer = new Intent(getActivity(), CreateVectorLayerActivity.class);
            startActivity(intentNewLayer);
            return true;
        case R.id.menu_add_local:
            application.sendEvent(GA_LAYER, GA_CREATE, GA_IMPORT);
            ((MainActivity) getActivity()).addLocalLayer();
            return true;
        case R.id.menu_add_remote:
            application.sendEvent(GA_LAYER, GA_CREATE, GA_GEOSERVICE);
            ((MainActivity) getActivity()).addRemoteLayer();
            return true;
        case R.id.menu_add_ngw:
            if (!AccountUtil.isProUser(getActivity())) {
                ControlHelper.showProDialog(getActivity());
            } else {
                application.sendEvent(GA_LAYER, GA_CREATE, GA_NGW);
                ((MainActivity) getActivity()).addNGWLayer();
            }
            return true;
        default:
            return super.onContextItemSelected(menuItem);
    }
}
 
Example #18
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 #19
Source File: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onPause()
{
    if (null != findViewById(R.id.location_panel)) {
        IGISApplication app = (IGISApplication) getApplication();
        if (null != app) {
            GpsEventSource gpsEventSource = app.getGpsEventSource();
            gpsEventSource.removeListener(this);
        }
    }
    super.onPause();
}
 
Example #20
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
void testAttachUpdate()
{
    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 updateUri = Uri.parse("content://" + SettingsConstants.AUTHORITY + "/" +
                                  ngwVectorLayer.getPath().getName() + "/36/attach/1000");
    */
    Uri updateUri = Uri.parse(
            "content://" + AppSettingsConstants.AUTHORITY +
            "/layer_20150210140455993/36/attach/2");

    ContentValues values = new ContentValues();
    values.put(VectorLayer.ATTACH_DISPLAY_NAME, "no_image.jpg");
    values.put(VectorLayer.ATTACH_DESCRIPTION, "simple update description");
    //    values.put(VectorLayer.ATTACH_ID, 999);
    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 #21
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
void testAttachDelete()
{
    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 deleteUri = Uri.parse("content://" + SettingsConstants.AUTHORITY + "/" +
                            ngwVectorLayer.getPath().getName() + "/36/attach/1000");
    */
    Uri deleteUri = Uri.parse(
            "content://" + AppSettingsConstants.AUTHORITY +
                    "/layer_20150210140455993/36/attach/1");
    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 #22
Source File: TracksActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tracks);
    setToolbar(R.id.main_toolbar);

    mTracks = findViewById(R.id.lv_tracks);
    mTracks.setOnDataChangeListener(new TrackView.OnDataChangeListener() {
        @Override
        public void onDataChanged() {
            checkItemsCount();
        }
    });
    mTracks.setOnCheckedChangeListener(new TrackView.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged() {
            int count = mTracks.getSelectedItemsCount();
            if (count == 0 && mActionMode != null)
                mActionMode.finish();

            if (count > 0 && mActionMode == null)
                mActionMode = startSupportActionMode(TracksActivity.this);

            if (mActionMode != null)
                mActionMode.setTitle("" + count);
        }
    });

    IGISApplication application = (IGISApplication) getApplication();
    String authority = application.getAuthority();
    mContentUriTracks = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKS);
    mContentUriTrackPoints = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKPOINTS);
}
 
Example #23
Source File: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_standard_attributes);
    setToolbar(R.id.main_toolbar);

    final IGISApplication app = (IGISApplication) getApplication();
    createView(app, savedInstanceState);
    createLocationPanelView(app);
    createSoundPool();
}
 
Example #24
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 #25
Source File: SelectNGWResourceDialog.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Connections fillConnections(Context context, AccountManager accountManager)
{
    Connections connections = new Connections(context.getString(R.string.ngw_accounts));
    IGISApplication app = (IGISApplication) context.getApplicationContext();

    for (Account account : accountManager.getAccountsByType(app.getAccountsType())) {
        String url = app.getAccountUrl(account);
        String password = app.getAccountPassword(account);
        String login = app.getAccountLogin(account);
        connections.add(new Connection(account.name, login, password, url.toLowerCase()));
    }
    return connections;
}
 
Example #26
Source File: SelectNGWResourceDialog.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(
        int requestCode,
        int resultCode,
        Intent data)
{
    if (requestCode == ADD_ACCOUNT_CODE) {
        if (resultCode != Activity.RESULT_CANCELED) {
            //search new account and add it
            Connections connections = mListAdapter.getConnections();
            IGISApplication app = (IGISApplication) mContext.getApplicationContext();

            for (Account account : mAccountManager.getAccountsByType(app.getAccountsType())) {
                boolean find = false;
                for (int i = 0; i < connections.getChildrenCount(); i++) {
                    Connection connection = (Connection) connections.getChild(i);
                    if (null != connection && connection.getName().equals(account.name)) {
                        find = true;
                        break;
                    }
                }

                if (!find) {
                    String url = app.getAccountUrl(account);
                    String password = app.getAccountPassword(account);
                    String login = app.getAccountLogin(account);
                    connections.add(new Connection(account.name, login, password, url.toLowerCase()));
                    mListAdapter.notifyDataSetChanged();
                    break;
                }
            }
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
 
Example #27
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fillAccountPreferences(
            PreferenceGroup screen,
            final Account account)
    {
        final IGISApplication appContext = (IGISApplication) mStyledContext.getApplicationContext();

        // add sync settings group
        PreferenceCategory syncCategory = new PreferenceCategory(mStyledContext);
        syncCategory.setTitle(R.string.sync);
        screen.addPreference(syncCategory);

        // add auto sync property
        addAutoSyncProperty(appContext, account, syncCategory);

        // add time for periodic sync
        addPeriodicSyncTime(appContext, account, syncCategory);

        // add account layers
        addAccountLayers(screen, appContext, account);

        // add actions group
        PreferenceCategory actionCategory = new PreferenceCategory(mStyledContext);
        actionCategory.setTitle(R.string.actions);
        screen.addPreference(actionCategory);

        // add "Edit account" action
        addEditAccountAction(appContext, account, actionCategory);

        // add delete account action
        addDeleteAccountAction(appContext, account, actionCategory);

// TODO: for isMultiPane() change title of Settings fragment, not of Activity
//        if (mChangeTitle && !NGPreferenceActivity.isMultiPane(mActivity)) {
        if (mChangeTitle) {
            ActionBar ab = mActivity.getSupportActionBar();
            if (null != ab) {
                ab.setTitle(account.name);
            }
        }
    }
 
Example #28
Source File: NGWSettingsFragment.java    From android_maplibui with 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 #29
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void updateAccountLayersCacheData(
        final IGISApplication application,
        Account account)
{
    List<INGWLayer> layers = getLayersForAccount(application, account);

    for (INGWLayer layer : layers) {
        layer.setAccountCacheData();
    }
}
 
Example #30
Source File: Distance.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressLint("MissingPermission")
private void calculate(boolean toast) {
    if (getContext() != null) {
        IGISApplication app = (IGISApplication) getContext().getApplicationContext();
        GpsEventSource gpsEventSource = app.getGpsEventSource();
        Location current = gpsEventSource.getLastKnownLocation();
        if (current != null && mLocation != null)
            mValue = current.distanceTo(mLocation);
        else if (toast)
            Toast.makeText(getContext(), R.string.error_no_location, Toast.LENGTH_SHORT).show();
    } else if (toast)
        Toast.makeText(getContext(), R.string.error_no_location, Toast.LENGTH_SHORT).show();
}