Search in sources :

Example 1 with IConfigurationProvider

use of org.osmdroid.config.IConfigurationProvider in project iGap-Android by KianIranian-STDG.

the class FileUtils method clearMapFile.

public void clearMapFile() {
    IConfigurationProvider configurationProvider = Configuration.getInstance();
    deleteRecursive((configurationProvider.getOsmdroidBasePath()));
}
Also used : IConfigurationProvider(org.osmdroid.config.IConfigurationProvider)

Example 2 with IConfigurationProvider

use of org.osmdroid.config.IConfigurationProvider in project iGap-Android by KianIranian-STDG.

the class FragmentiGapMap method deleteMapFileCash.

public static void deleteMapFileCash() {
    try {
        IConfigurationProvider configurationProvider = Configuration.getInstance();
        FileUtils.deleteRecursive((configurationProvider.getOsmdroidBasePath()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : IConfigurationProvider(org.osmdroid.config.IConfigurationProvider) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 3 with IConfigurationProvider

use of org.osmdroid.config.IConfigurationProvider in project Conversations by iNPUTmice.

the class LocationActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context ctx = getApplicationContext();
    setTheme(ThemeHelper.find(this));
    final PackageManager packageManager = ctx.getPackageManager();
    hasLocationFeature = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) || packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK);
    this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    this.marker_icon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.marker);
    // screen rotation or if there's no point because it's disabled anyways).
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && savedInstanceState == null) {
        requestPermissions(REQUEST_CODE_CREATE);
    }
    final IConfigurationProvider config = Configuration.getInstance();
    config.load(ctx, getPreferences());
    config.setUserAgentValue(BuildConfig.APPLICATION_ID + "/" + BuildConfig.VERSION_CODE);
    if (QuickConversationsService.isConversations() && getBooleanPreference("use_tor", R.bool.use_tor)) {
        config.setHttpProxy(HttpConnectionManager.getProxy());
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) IConfigurationProvider(org.osmdroid.config.IConfigurationProvider)

Example 4 with IConfigurationProvider

use of org.osmdroid.config.IConfigurationProvider in project Conversations by siacs.

the class LocationActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context ctx = getApplicationContext();
    setTheme(ThemeHelper.find(this));
    final PackageManager packageManager = ctx.getPackageManager();
    hasLocationFeature = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION) || packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS) || packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK);
    this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    this.marker_icon = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.marker);
    // screen rotation or if there's no point because it's disabled anyways).
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && savedInstanceState == null) {
        requestPermissions(REQUEST_CODE_CREATE);
    }
    final IConfigurationProvider config = Configuration.getInstance();
    config.load(ctx, getPreferences());
    config.setUserAgentValue(BuildConfig.APPLICATION_ID + "/" + BuildConfig.VERSION_CODE);
    if (QuickConversationsService.isConversations() && getBooleanPreference("use_tor", R.bool.use_tor)) {
        config.setHttpProxy(HttpConnectionManager.getProxy());
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) IConfigurationProvider(org.osmdroid.config.IConfigurationProvider)

Example 5 with IConfigurationProvider

use of org.osmdroid.config.IConfigurationProvider in project PhoneProfilesPlus by henrichg.

the class LocationGeofenceEditorActivityOSM method onCreate.

@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
    GlobalGUIRoutines.setTheme(this, false, false, /*, false*/
    false, false, true);
    // GlobalGUIRoutines.setLanguage(this);
    super.onCreate(savedInstanceState);
    IConfigurationProvider osmDroidCobfigurationProvider = org.osmdroid.config.Configuration.getInstance();
    osmDroidCobfigurationProvider.load(getApplicationContext(), PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
    osmDroidCobfigurationProvider.setUserAgentValue(BuildConfig.APPLICATION_ID);
    osmDroidCobfigurationProvider.setOsmdroidTileCache(getApplicationContext().getExternalFilesDir(null));
    osmDroidCobfigurationProvider.setOsmdroidBasePath(getApplicationContext().getExternalFilesDir(null));
    setContentView(R.layout.activity_location_geofence_editor_osm);
    setTaskDescription(new ActivityManager.TaskDescription(getString(R.string.ppp_app_name)));
    if (getSupportActionBar() != null) {
        // getSupportActionBar().setHomeButtonEnabled(true);
        // getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(R.string.location_editor_title);
        getSupportActionBar().setElevation(0);
    }
    // mResultReceiver = new AddressResultReceiver(new Handler(getMainLooper()));
    Intent intent = getIntent();
    geofenceId = intent.getLongExtra(LocationGeofencePreferenceX.EXTRA_GEOFENCE_ID, 0);
    if (geofenceId > 0) {
        geofence = DatabaseHandler.getInstance(getApplicationContext()).getGeofence(geofenceId);
        mLocation = new Location("LOC");
        mLocation.setLatitude(geofence._latitude);
        mLocation.setLongitude(geofence._longitude);
    }
    if (geofence == null) {
        geofenceId = 0;
        geofence = new Geofence();
        int _count = DatabaseHandler.getInstance(getApplicationContext()).getGeofenceCount() + 1;
        geofence._name = getString(R.string.event_preferences_location_new_location_name) + "_" + _count;
        geofence._radius = 100;
    }
    mapIsLoading = findViewById(R.id.location_editor_map_loading);
    mMap = findViewById(R.id.location_editor_map);
    mMap.setTileSource(TileSourceFactory.MAPNIK);
    // mMap.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
    mMap.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.ALWAYS);
    // mMap.setMaxZoomLevel(20d);
    mMap.setMultiTouchControls(true);
    // mMap.setTilesScaledToDpi(true);
    // mMap.getTileProvider().clearTileCache();
    boolean isNightMode;
    String applicationThene = ApplicationPreferences.applicationTheme(getApplicationContext(), false);
    switch(applicationThene) {
        case "white":
            // noinspection DuplicateBranchesInSwitch
            isNightMode = false;
            break;
        case "dark":
            isNightMode = true;
            break;
        case "night_mode":
            int nightModeFlags = getApplicationContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
            // if (notificationNightMode) {
            switch(nightModeFlags) {
                case Configuration.UI_MODE_NIGHT_YES:
                    isNightMode = true;
                    // notificationTextColor = "2";
                    break;
                case Configuration.UI_MODE_NIGHT_NO:
                    // noinspection DuplicateBranchesInSwitch
                    isNightMode = false;
                    // notificationTextColor = "1";
                    break;
                case Configuration.UI_MODE_NIGHT_UNDEFINED:
                    // noinspection DuplicateBranchesInSwitch
                    isNightMode = false;
                    break;
                default:
                    isNightMode = false;
            }
            break;
        default:
            isNightMode = false;
    }
    if (isNightMode)
        mMap.getOverlayManager().getTilesOverlay().setColorFilter(TilesOverlay.INVERT_COLORS);
    else
        mMap.getOverlayManager().getTilesOverlay().setColorFilter(null);
    // mMap.getOverlayManager().getTilesOverlay().setLoadingBackgroundColor(GlobalGUIRoutines.getThemeDialogBackgroundColor(this));
    // mMap.getOverlayManager().getTilesOverlay().setLoadingLineColor(GlobalGUIRoutines.getThemeNormalTextColor(this));
    IMapController mapController = mMap.getController();
    // mapController.setZoom(15f);
    /*
        mMap.getOverlayManager().getTilesOverlay().getTileStates().getRunAfters().add(() -> {
            if (mMap.getOverlayManager().getTilesOverlay().getTileStates().isDone()) {
                PPApplication.logE("LocationGeofenceEditorActivityOSM.getTileStatuses", "map loaded");
                if (mapIsLoading.getVisibility() != View.GONE)
                    mapIsLoading.setVisibility(View.GONE);
                if (mMap.getVisibility() != View.VISIBLE) {
                    mMap.setVisibility(View.VISIBLE);
                    addressText.setVisibility(View.VISIBLE);
                }
            }
        });
        */
    mMap.getOverlays().add(new MapEventsOverlay(new MapEventsReceiver() {

        @Override
        public boolean singleTapConfirmedHelper(GeoPoint point) {
            // PPApplication.logE("LocationGeofenceEditorActivityOSM.singleTapConfirmedHelper", "Map clicked");
            if (mLocation == null)
                mLocation = new Location("LOC");
            mLocation.setLatitude(point.getLatitude());
            mLocation.setLongitude(point.getLongitude());
            refreshActivity(true, false);
            return true;
        }

        @Override
        public boolean longPressHelper(GeoPoint p) {
            // Log.e("MapView", "long click");
            return false;
        }
    }));
    // radiusLabel = findViewById(R.id.location_pref_dlg_radius_seekbar_label);
    TextView radiusLabel = findViewById(R.id.location_pref_dlg_radius_label);
    radiusLabel.setText(getString(R.string.event_preferences_location_radius_label) + ":");
    radiusValue = findViewById(R.id.location_pref_dlg_radius_value);
    TooltipCompat.setTooltipText(radiusValue, getString(R.string.location_pref_dlg_edit_radius_tooltip));
    radiusValue.setText(String.valueOf(Math.round(geofence._radius)));
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle(R.string.event_preferences_location_radius_label);
    dialogBuilder.setCancelable(true);
    dialogBuilder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
        boolean persist = true;
        BigDecimal number = numberPicker.getEnteredNumber();
        if (isSmaller(number) || isBigger(number)) {
            /*String errorText = context.getString(R.string.number_picker_min_max_error, String.valueOf(preference.mMin), String.valueOf(preference.mMax));
            mNumberPicker.getErrorView().setText(errorText);
            mNumberPicker.getErrorView().show();*/
            persist = false;
        } else if (isSmaller(number)) {
            /*String errorText = context.getString(R.string.number_picker_min_error, String.valueOf(preference.mMin));
            mNumberPicker.getErrorView().setText(errorText);
            mNumberPicker.getErrorView().show();*/
            persist = false;
        } else if (isBigger(number)) {
            /*String errorText = context.getString(R.string.number_picker_max_error, String.valueOf(preference.mMax));
            mNumberPicker.getErrorView().setText(errorText);
            mNumberPicker.getErrorView().show();*/
            persist = false;
        }
        if (persist) {
            geofence._radius = numberPicker.getNumber().floatValue();
            radiusValue.setText(String.valueOf(Math.round(geofence._radius)));
            updateEditedMarker(true);
        }
    });
    dialogBuilder.setNegativeButton(android.R.string.cancel, null);
    LayoutInflater inflater = getLayoutInflater();
    @SuppressLint("InflateParams") View layout = inflater.inflate(R.layout.dialog_better_number_preference, null);
    dialogBuilder.setView(layout);
    numberPicker = layout.findViewById(R.id.better_number_picker);
    // Initialize state
    numberPicker.setMin(BigDecimal.valueOf(MIN_RADIUS));
    numberPicker.setMax(BigDecimal.valueOf(MAX_RADIUS));
    numberPicker.setPlusMinusVisibility(View.INVISIBLE);
    numberPicker.setDecimalVisibility(View.INVISIBLE);
    // mNumberPicker.setLabelText(getContext().getString(R.string.minutes_label_description));
    numberPicker.setNumber(Math.round(geofence._radius), null, null);
    if (ApplicationPreferences.applicationTheme(this, true).equals("dark"))
        numberPicker.setTheme(R.style.BetterPickersDialogFragment);
    else
        numberPicker.setTheme(R.style.BetterPickersDialogFragment_Light);
    valueDialog = dialogBuilder.create();
    // valueDialog.setOnShowListener(new DialogInterface.OnShowListener() {
    // @Override
    // public void onShow(DialogInterface dialog) {
    // Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
    // if (positive != null) positive.setAllCaps(false);
    // Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
    // if (negative != null) negative.setAllCaps(false);
    // }
    // });
    radiusValue.setOnClickListener(view -> {
        if (!(isFinishing()))
            valueDialog.show();
    });
    /*
        // seekBar is logarithmic
        SeekBar radiusSeekBar = findViewById(R.id.location_pref_dlg_radius_seekbar);
        final float minRadius = 20;
        final float maxRadius = 1020;
        int value = (int)(Math.sqrt(((geofence._radius - minRadius) / (maxRadius - minRadius)) * 1000.0f * 1000.0f));
        radiusSeekBar.setProgress(value);
        PPApplication.logE("LocationGeofenceEditorActivityOSM.onCreate", "geofence._radius="+geofence._radius);
        PPApplication.logE("LocationGeofenceEditorActivityOSM.onCreate", "seekBar value="+value);

        radiusSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                // Approximate an exponential curve with x^2.
                geofence._radius = ((progress * progress) / (1000.0f * 1000.0f)) * (maxRadius - minRadius) + minRadius;
                updateEditedMarker(false);
                //Log.d("LocationGeofenceEditorActivityOSM.onProgressChanged", "radius="+geofence._radius);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        */
    geofenceNameEditText = findViewById(R.id.location_editor_geofence_name);
    geofenceNameEditText.setBackgroundTintList(ContextCompat.getColorStateList(this, R.color.highlighted_spinner_all));
    geofenceNameEditText.setText(geofence._name);
    addressText = findViewById(R.id.location_editor_address_text);
    okButton = findViewById(R.id.location_editor_ok);
    okButton.setOnClickListener(v -> {
        String name = geofenceNameEditText.getText().toString();
        if ((!name.isEmpty()) && (mLocation != null)) {
            geofence._name = name;
            geofence._latitude = mLocation.getLatitude();
            geofence._longitude = mLocation.getLongitude();
            if (geofenceId > 0) {
                DatabaseHandler.getInstance(getApplicationContext()).updateGeofence(geofence);
            } else {
                DatabaseHandler.getInstance(getApplicationContext()).addGeofence(geofence);
            /*synchronized (PPApplication.locationScannerMutex) {
                        // start location updates
                        if ((PhoneProfilesService.getInstance() != null) && PhoneProfilesService.isLocationScannerStarted())
                            PhoneProfilesService.getGeofencesScanner().connectForResolve();
                    }*/
            }
            DatabaseHandler.getInstance(getApplicationContext()).checkGeofence(String.valueOf(geofence._id), 1);
            Intent returnIntent = new Intent();
            returnIntent.putExtra(LocationGeofencePreferenceX.EXTRA_GEOFENCE_ID, geofence._id);
            setResult(Activity.RESULT_OK, returnIntent);
            finish();
        }
    });
    Button cancelButton = findViewById(R.id.location_editor_cancel);
    cancelButton.setOnClickListener(v -> {
        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_CANCELED, returnIntent);
        finish();
    });
    AppCompatImageButton myLocationButton = findViewById(R.id.location_editor_my_location);
    TooltipCompat.setTooltipText(myLocationButton, getString(R.string.location_editor_change_location_dialog_title));
    myLocationButton.setOnClickListener(v -> {
        AlertDialog changeLocationDialog = new AlertDialog.Builder(this).setTitle(R.string.location_editor_change_location_dialog_title).setCancelable(true).setNegativeButton(android.R.string.cancel, null).setItems(R.array.locationEditorChangeLocationArray, (dialog, which) -> {
            IMapController _mapController = mMap.getController();
            switch(which) {
                case 0:
                    if (mLocation != null)
                        _mapController.setCenter(new GeoPoint(mLocation));
                    break;
                case 1:
                    if (mLastLocation != null)
                        _mapController.setCenter(new GeoPoint(mLastLocation));
                    break;
                case 2:
                    // getLastLocation();
                    if (mLastLocation != null)
                        mLocation = new Location(mLastLocation);
                    refreshActivity(true, true);
                    break;
                default:
            }
        }).create();
        // mSelectorDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        // @Override
        // public void onShow(DialogInterface dialog) {
        // Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
        // if (positive != null) positive.setAllCaps(false);
        // Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
        // if (negative != null) negative.setAllCaps(false);
        // }
        // });
        changeLocationDialog.show();
    });
    addressButton = findViewById(R.id.location_editor_address_btn);
    TooltipCompat.setTooltipText(addressButton, getString(R.string.location_editor_rename_with_address_button_tooltip));
    addressButton.setOnClickListener(v -> {
        AlertDialog renameGeofenceDialog = new AlertDialog.Builder(this).setTitle(R.string.location_editor_rename_with_address_button_tooltip).setCancelable(true).setNegativeButton(android.R.string.cancel, null).setItems(R.array.locationEditorRenameLocationArray, (dialog, which) -> {
            if (which == 0) {
                getGeofenceAddress();
            }
        }).create();
        // mSelectorDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        // @Override
        // public void onShow(DialogInterface dialog) {
        // Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
        // if (positive != null) positive.setAllCaps(false);
        // Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
        // if (negative != null) negative.setAllCaps(false);
        // }
        // });
        renameGeofenceDialog.show();
    });
    if (geofence != null)
        mapController.setCenter(new GeoPoint(geofence._latitude, geofence._longitude));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ActivityManager(android.app.ActivityManager) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) AppCompatResources(androidx.appcompat.content.res.AppCompatResources) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest) CustomZoomButtonsController(org.osmdroid.views.CustomZoomButtonsController) Criteria(android.location.Criteria) Intent(android.content.Intent) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) LocationListener(android.location.LocationListener) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) GeoPoint(org.osmdroid.util.GeoPoint) BigDecimal(java.math.BigDecimal) SuppressLint(android.annotation.SuppressLint) TooltipCompat(androidx.appcompat.widget.TooltipCompat) TileSourceFactory(org.osmdroid.tileprovider.tilesource.TileSourceFactory) Handler(android.os.Handler) View(android.view.View) Button(android.widget.Button) WorkManager(androidx.work.WorkManager) IMapController(org.osmdroid.api.IMapController) Settings(android.provider.Settings) TilesOverlay(org.osmdroid.views.overlay.TilesOverlay) Data(androidx.work.Data) ContextCompat(androidx.core.content.ContextCompat) MapEventsReceiver(org.osmdroid.events.MapEventsReceiver) IConfigurationProvider(org.osmdroid.config.IConfigurationProvider) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) LayoutInflater(android.view.LayoutInflater) MapEventsOverlay(org.osmdroid.views.overlay.MapEventsOverlay) IntentFilter(android.content.IntentFilter) Marker(org.osmdroid.views.overlay.Marker) BroadcastReceiver(android.content.BroadcastReceiver) Geocoder(android.location.Geocoder) DisplayMetrics(android.util.DisplayMetrics) MapView(org.osmdroid.views.MapView) WorkInfo(androidx.work.WorkInfo) TextView(android.widget.TextView) ExistingWorkPolicy(androidx.work.ExistingWorkPolicy) Configuration(android.content.res.Configuration) PreferenceManager(androidx.preference.PreferenceManager) Location(android.location.Location) Activity(android.app.Activity) LocationManager(android.location.LocationManager) EditText(android.widget.EditText) MapEventsOverlay(org.osmdroid.views.overlay.MapEventsOverlay) Intent(android.content.Intent) MapEventsReceiver(org.osmdroid.events.MapEventsReceiver) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) ActivityManager(android.app.ActivityManager) View(android.view.View) MapView(org.osmdroid.views.MapView) TextView(android.widget.TextView) GeoPoint(org.osmdroid.util.GeoPoint) SuppressLint(android.annotation.SuppressLint) BigDecimal(java.math.BigDecimal) GeoPoint(org.osmdroid.util.GeoPoint) Button(android.widget.Button) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) LayoutInflater(android.view.LayoutInflater) SuppressLint(android.annotation.SuppressLint) IConfigurationProvider(org.osmdroid.config.IConfigurationProvider) IMapController(org.osmdroid.api.IMapController) TextView(android.widget.TextView) Location(android.location.Location) SuppressLint(android.annotation.SuppressLint)

Aggregations

IConfigurationProvider (org.osmdroid.config.IConfigurationProvider)7 Context (android.content.Context)4 PackageManager (android.content.pm.PackageManager)3 SuppressLint (android.annotation.SuppressLint)2 Location (android.location.Location)2 View (android.view.View)2 IMapController (org.osmdroid.api.IMapController)2 GeoPoint (org.osmdroid.util.GeoPoint)2 MapView (org.osmdroid.views.MapView)2 Marker (org.osmdroid.views.overlay.Marker)2 Activity (android.app.Activity)1 ActivityManager (android.app.ActivityManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Configuration (android.content.res.Configuration)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Criteria (android.location.Criteria)1