Search in sources :

Example 1 with ValueHolder

use of net.osmand.ValueHolder in project Osmand by osmandapp.

the class OsmandMonitoringPlugin method startGPXMonitoring.

public void startGPXMonitoring(final Activity map, final boolean showTrackSelection) {
    final ValueHolder<Integer> vs = new ValueHolder<Integer>();
    final ValueHolder<Boolean> choice = new ValueHolder<Boolean>();
    vs.value = settings.SAVE_GLOBAL_TRACK_INTERVAL.get();
    choice.value = settings.SAVE_GLOBAL_TRACK_REMEMBER.get();
    final Runnable runnable = new Runnable() {

        public void run() {
            app.getSavingTrackHelper().startNewSegment();
            settings.SAVE_GLOBAL_TRACK_INTERVAL.set(vs.value);
            settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
            settings.SAVE_GLOBAL_TRACK_REMEMBER.set(choice.value);
            int interval = settings.SAVE_GLOBAL_TRACK_INTERVAL.get();
            app.startNavigationService(NavigationService.USED_BY_GPX, interval < 30000 ? 0 : interval);
        }
    };
    if (choice.value || map == null) {
        runnable.run();
    } else {
        showIntervalChooseDialog(map, app.getString(R.string.save_track_interval_globally) + " : %s", app.getString(R.string.save_track_to_gpx_globally), SECONDS, MINUTES, choice, vs, showTrackSelection, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                runnable.run();
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) OsmAndTaskRunnable(net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable) OnClickListener(android.content.DialogInterface.OnClickListener) ValueHolder(net.osmand.ValueHolder)

Example 2 with ValueHolder

use of net.osmand.ValueHolder in project Osmand by osmandapp.

the class OsmandMonitoringPlugin method controlDialog.

public void controlDialog(final Activity map, final boolean showTrackSelection) {
    final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
    AlertDialog.Builder bld = new AlertDialog.Builder(map);
    final TIntArrayList items = new TIntArrayList();
    if (wasTrackMonitored) {
        items.add(R.string.gpx_monitoring_stop);
        items.add(R.string.gpx_start_new_segment);
        if (settings.LIVE_MONITORING.get()) {
            items.add(R.string.live_monitoring_stop);
        } else if (!settings.LIVE_MONITORING_URL.getProfileDefaultValue(settings.APPLICATION_MODE.get()).equals(settings.LIVE_MONITORING_URL.get())) {
            items.add(R.string.live_monitoring_start);
        }
    } else {
        items.add(R.string.gpx_monitoring_start);
    }
    if (app.getSavingTrackHelper().hasDataToSave()) {
        items.add(R.string.save_current_track);
    }
    String[] strings = new String[items.size()];
    for (int i = 0; i < strings.length; i++) {
        strings[i] = app.getString(items.get(i));
    }
    final int[] holder = new int[] { 0 };
    final Runnable run = new Runnable() {

        public void run() {
            int which = holder[0];
            int item = items.get(which);
            if (item == R.string.save_current_track) {
                saveCurrentTrack();
            } else if (item == R.string.gpx_monitoring_start) {
                if (app.getLocationProvider().checkGPSEnabled(map)) {
                    startGPXMonitoring(map, showTrackSelection);
                }
            } else if (item == R.string.gpx_monitoring_stop) {
                stopRecording();
            } else if (item == R.string.gpx_start_new_segment) {
                app.getSavingTrackHelper().startNewSegment();
            } else if (item == R.string.live_monitoring_stop) {
                settings.LIVE_MONITORING.set(false);
            } else if (item == R.string.live_monitoring_start) {
                final ValueHolder<Integer> vs = new ValueHolder<Integer>();
                vs.value = settings.LIVE_MONITORING_INTERVAL.get();
                showIntervalChooseDialog(map, app.getString(R.string.live_monitoring_interval) + " : %s", app.getString(R.string.save_track_to_gpx_globally), SECONDS, MINUTES, null, vs, showTrackSelection, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        settings.LIVE_MONITORING_INTERVAL.set(vs.value);
                        settings.LIVE_MONITORING.set(true);
                    }
                });
            }
            monitoringControl.updateInfo(null);
        }
    };
    if (strings.length == 1) {
        run.run();
    } else {
        bld.setItems(strings, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                holder[0] = which;
                run.run();
            }
        });
        bld.show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ValueHolder(net.osmand.ValueHolder) TIntArrayList(gnu.trove.list.array.TIntArrayList) OsmAndTaskRunnable(net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 3 with ValueHolder

use of net.osmand.ValueHolder in project Osmand by osmandapp.

the class FirstUsageWizardFragment method updateStorageView.

private void updateStorageView(View storageView) {
    if (storageView != null) {
        TextView title = (TextView) storageView.findViewById(R.id.storage_title);
        OsmandSettings settings = getMyApplication().getSettings();
        int type;
        if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
            type = settings.getExternalStorageDirectoryTypeV19();
        } else {
            ValueHolder<Integer> vh = new ValueHolder<>();
            settings.getExternalStorageDirectory(vh);
            if (vh.value != null && vh.value >= 0) {
                type = vh.value;
            } else {
                type = 0;
            }
        }
        title.setText(getString(R.string.storage_place_description, getStorageName(type)));
        TextView freeSpace = (TextView) storageView.findViewById(R.id.storage_free_space);
        TextView freeSpaceValue = (TextView) storageView.findViewById(R.id.storage_free_space_value);
        String freeSpaceStr = getString(R.string.storage_free_space) + ": ";
        freeSpace.setText(freeSpaceStr);
        freeSpaceValue.setText(getFreeSpace(settings.getExternalStorageDirectory()));
        AppCompatButton changeStorageButton = (AppCompatButton) storageView.findViewById(R.id.storage_change_button);
        if (wizardType == WizardType.MAP_DOWNLOAD) {
            changeStorageButton.setEnabled(false);
            changeStorageButton.setTextColor(getMyApplication().getResources().getColor(R.color.disabled_btn_text_color));
        } else {
            changeStorageButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (!DownloadActivity.hasPermissionToWriteExternalStorage(getContext())) {
                        ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, FIRST_USAGE_REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION);
                    } else {
                        DataStoragePlaceDialogFragment.showInstance(getActivity().getSupportFragmentManager(), false);
                    }
                }
            });
        }
    }
}
Also used : TextView(android.widget.TextView) ValueHolder(net.osmand.ValueHolder) View(android.view.View) TextView(android.widget.TextView) OsmandSettings(net.osmand.plus.OsmandSettings) AppCompatButton(android.support.v7.widget.AppCompatButton)

Example 4 with ValueHolder

use of net.osmand.ValueHolder in project Osmand by osmandapp.

the class OsmandSettings method freezeExternalStorageDirectory.

public void freezeExternalStorageDirectory() {
    if (Build.VERSION.SDK_INT >= 19) {
        int type = settingsAPI.getInt(globalPreferences, EXTERNAL_STORAGE_DIR_TYPE_V19, -1);
        if (type == -1) {
            ValueHolder<Integer> vh = new ValueHolder<>();
            File f = getExternalStorageDirectoryV19(vh);
            setExternalStorageDirectoryV19(vh.value, f.getAbsolutePath());
        }
    }
}
Also used : ValueHolder(net.osmand.ValueHolder) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 5 with ValueHolder

use of net.osmand.ValueHolder in project Osmand by osmandapp.

the class RoutingHelper method setNewRoute.

private void setNewRoute(RouteCalculationResult prevRoute, final RouteCalculationResult res, Location start) {
    final boolean newRoute = !prevRoute.isCalculated();
    if (isFollowingMode) {
        if (lastFixedLocation != null) {
            start = lastFixedLocation;
        }
        // try remove false route-recalculated prompts by checking direction to second route node
        boolean wrongMovementDirection = false;
        List<Location> routeNodes = res.getImmutableAllLocations();
        if (routeNodes != null && !routeNodes.isEmpty()) {
            int newCurrentRoute = lookAheadFindMinOrthogonalDistance(start, routeNodes, res.currentRoute, 15);
            if (newCurrentRoute + 1 < routeNodes.size()) {
                // This check is valid for Online/GPX services (offline routing is aware of route direction)
                wrongMovementDirection = checkWrongMovementDirection(start, routeNodes.get(newCurrentRoute + 1));
                // set/reset evalWaitInterval only if new route is in forward direction
                if (wrongMovementDirection) {
                    evalWaitInterval = 3000;
                } else {
                    evalWaitInterval = Math.max(3000, evalWaitInterval * 3 / 2);
                    evalWaitInterval = Math.min(evalWaitInterval, 120000);
                }
            }
        }
        // If route is in wrong direction after one more setLocation it will be recalculated
        if (!wrongMovementDirection || newRoute) {
            voiceRouter.newRouteIsCalculated(newRoute);
        }
    }
    app.getWaypointHelper().setNewRoute(res);
    app.runInUIThread(new Runnable() {

        @Override
        public void run() {
            ValueHolder<Boolean> showToast = new ValueHolder<Boolean>();
            showToast.value = true;
            Iterator<WeakReference<IRouteInformationListener>> it = listeners.iterator();
            while (it.hasNext()) {
                WeakReference<IRouteInformationListener> ref = it.next();
                IRouteInformationListener l = ref.get();
                if (l == null) {
                    it.remove();
                } else {
                    l.newRouteIsCalculated(newRoute, showToast);
                }
            }
            if (showToast.value && OsmandPlugin.isDevelopment()) {
                String msg = app.getString(R.string.new_route_calculated_dist) + ": " + OsmAndFormatter.getFormattedDistance(res.getWholeDistance(), app);
                if (res.getRoutingTime() != 0f) {
                    msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime(), app.accessibilityEnabled()) + ")";
                }
                app.showToastMessage(msg);
            }
        }
    });
}
Also used : ValueHolder(net.osmand.ValueHolder) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) WeakReference(java.lang.ref.WeakReference) Iterator(java.util.Iterator) Location(net.osmand.Location)

Aggregations

ValueHolder (net.osmand.ValueHolder)5 DialogInterface (android.content.DialogInterface)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 OsmAndTaskRunnable (net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatButton (android.support.v7.widget.AppCompatButton)1 View (android.view.View)1 TextView (android.widget.TextView)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 File (java.io.File)1 WeakReference (java.lang.ref.WeakReference)1 Iterator (java.util.Iterator)1 Location (net.osmand.Location)1 OsmandSettings (net.osmand.plus.OsmandSettings)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1