Search in sources :

Example 1 with OsmandPreference

use of net.osmand.plus.OsmandSettings.OsmandPreference in project Osmand by osmandapp.

the class MapRouteInfoMenu method updateApplicationModes.

private void updateApplicationModes(final View parentView) {
    // final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
    // ApplicationMode am = settings.APPLICATION_MODE.get();
    final ApplicationMode am = routingHelper.getAppMode();
    final Set<ApplicationMode> selected = new HashSet<>();
    selected.add(am);
    ViewGroup vg = (ViewGroup) parentView.findViewById(R.id.app_modes);
    vg.removeAllViews();
    AppModeDialog.prepareAppModeView(mapActivity, selected, false, vg, true, false, true, new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (selected.size() > 0) {
                ApplicationMode next = selected.iterator().next();
                OsmandPreference<ApplicationMode> appMode = mapActivity.getMyApplication().getSettings().APPLICATION_MODE;
                if (routingHelper.isFollowingMode() && appMode.get() == am) {
                    appMode.set(next);
                // updateMenu();
                }
                routingHelper.setAppMode(next);
                mapActivity.getMyApplication().initVoiceCommandPlayer(mapActivity, next, true, null, false, false);
                routingHelper.recalculateRouteDueToSettingsChange();
            }
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) OsmandPreference(net.osmand.plus.OsmandSettings.OsmandPreference) ApplicationMode(net.osmand.plus.ApplicationMode) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) HashSet(java.util.HashSet)

Example 2 with OsmandPreference

use of net.osmand.plus.OsmandSettings.OsmandPreference in project Osmand by osmandapp.

the class SettingsNavigationActivity method onPreferenceClick.

@SuppressWarnings("unchecked")
@Override
public boolean onPreferenceClick(Preference preference) {
    if (preference == avoidRouting || preference == preferRouting) {
        List<RoutingParameter> prms = preference == avoidRouting ? avoidParameters : preferParameters;
        String[] vals = new String[prms.size()];
        OsmandPreference[] bls = new OsmandPreference[prms.size()];
        for (int i = 0; i < prms.size(); i++) {
            RoutingParameter p = prms.get(i);
            vals[i] = SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName());
            bls[i] = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
        }
        showBooleanSettings(vals, bls, preference.getTitle());
        return true;
    } else if (preference == autoZoom) {
        final ApplicationMode am = settings.getApplicationMode();
        final ContextMenuAdapter adapter = new ContextMenuAdapter();
        int i = 0;
        int selectedIndex = -1;
        adapter.addItem(ContextMenuItem.createBuilder(getString(R.string.auto_zoom_none)).setSelected(false).createItem());
        if (!settings.AUTO_ZOOM_MAP.get()) {
            selectedIndex = 0;
        }
        i++;
        for (AutoZoomMap autoZoomMap : AutoZoomMap.values()) {
            adapter.addItem(ContextMenuItem.createBuilder(getString(autoZoomMap.name)).setSelected(false).createItem());
            if (selectedIndex == -1 && settings.AUTO_ZOOM_MAP_SCALE.get() == autoZoomMap) {
                selectedIndex = i;
            }
            i++;
        }
        if (selectedIndex == -1) {
            selectedIndex = 0;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final int layout = R.layout.list_menu_item_native_singlechoice;
        final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {

            @NonNull
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                // User super class to create the View
                View v = convertView;
                if (v == null) {
                    v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
                }
                final ContextMenuItem item = adapter.getItem(position);
                TextView tv = (TextView) v.findViewById(R.id.text1);
                tv.setText(item.getTitle());
                tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
                return v;
            }
        };
        final int[] selectedPosition = { selectedIndex };
        builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int position) {
                selectedPosition[0] = position;
            }
        });
        builder.setTitle(R.string.auto_zoom_map).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                int position = selectedPosition[0];
                if (position == 0) {
                    settings.AUTO_ZOOM_MAP.set(false);
                } else {
                    settings.AUTO_ZOOM_MAP.set(true);
                    settings.AUTO_ZOOM_MAP_SCALE.set(AutoZoomMap.values()[position - 1]);
                }
            }
        }).setNegativeButton(R.string.shared_string_cancel, null);
        builder.create().show();
        return true;
    } else if (preference == reliefFactorRouting) {
        final ApplicationMode am = settings.getApplicationMode();
        final ContextMenuAdapter adapter = new ContextMenuAdapter();
        int i = 0;
        int selectedIndex = -1;
        for (RoutingParameter p : reliefFactorParameters) {
            adapter.addItem(ContextMenuItem.createBuilder(getRoutinParameterTitle(this, p)).setSelected(false).createItem());
            if (isRoutingParameterSelected(settings, am, p)) {
                selectedIndex = i;
            }
            i++;
        }
        if (selectedIndex == -1) {
            selectedIndex = 0;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        final int layout = R.layout.list_menu_item_native_singlechoice;
        final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, layout, R.id.text1, adapter.getItemNames()) {

            @NonNull
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {
                // User super class to create the View
                View v = convertView;
                if (v == null) {
                    v = SettingsNavigationActivity.this.getLayoutInflater().inflate(layout, null);
                }
                final ContextMenuItem item = adapter.getItem(position);
                TextView tv = (TextView) v.findViewById(R.id.text1);
                tv.setText(item.getTitle());
                tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16f);
                return v;
            }
        };
        final int[] selectedPosition = { selectedIndex };
        builder.setSingleChoiceItems(listAdapter, selectedIndex, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int position) {
                selectedPosition[0] = position;
            }
        });
        builder.setTitle(SettingsBaseActivity.getRoutingStringPropertyName(this, reliefFactorParameters.get(0).getGroup(), Algorithms.capitalizeFirstLetterAndLowercase(reliefFactorParameters.get(0).getGroup().replace('_', ' ')))).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                int position = selectedPosition[0];
                if (position >= 0 && position < reliefFactorParameters.size()) {
                    for (int i = 0; i < reliefFactorParameters.size(); i++) {
                        setRoutingParameterSelected(settings, am, reliefFactorParameters.get(i), i == position);
                    }
                // mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
                // updateParameters();
                }
            }
        }).setNegativeButton(R.string.shared_string_cancel, null);
        builder.create().show();
        return true;
    } else if (preference == showAlarms) {
        showBooleanSettings(new String[] { getString(R.string.show_traffic_warnings), getString(R.string.show_pedestrian_warnings), getString(R.string.show_cameras), getString(R.string.show_lanes), getString(R.string.show_tunnels) }, new OsmandPreference[] { settings.SHOW_TRAFFIC_WARNINGS, settings.SHOW_PEDESTRIAN, settings.SHOW_CAMERAS, settings.SHOW_LANES, settings.SHOW_TUNNELS }, preference.getTitle());
        return true;
    } else if (preference == speakAlarms) {
        AlertDialog dlg = showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_pedestrian), getString(R.string.speak_speed_limit), getString(R.string.speak_cameras), getString(R.string.announce_gpx_waypoints), getString(R.string.speak_favorites), getString(R.string.speak_poi) }, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS, settings.SPEAK_PEDESTRIAN, settings.SPEAK_SPEED_LIMIT, settings.SPEAK_SPEED_CAMERA, settings.ANNOUNCE_WPT, settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI }, preference.getTitle());
        final boolean initialSpeedCam = settings.SPEAK_SPEED_CAMERA.get();
        final boolean initialFavorites = settings.ANNOUNCE_NEARBY_FAVORITES.get();
        final boolean initialPOI = settings.ANNOUNCE_NEARBY_POI.get();
        // final boolean initialWpt = settings.ANNOUNCE_WPT.get();
        dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                if (settings.ANNOUNCE_NEARBY_POI.get() != initialPOI) {
                    settings.SHOW_NEARBY_POI.set(settings.ANNOUNCE_NEARBY_POI.get());
                }
                if (settings.ANNOUNCE_NEARBY_FAVORITES.get() != initialFavorites) {
                    settings.SHOW_NEARBY_FAVORITES.set(settings.ANNOUNCE_NEARBY_FAVORITES.get());
                }
                if (settings.ANNOUNCE_WPT.get()) {
                    settings.SHOW_WPT.set(settings.ANNOUNCE_WPT.get());
                }
                if (!initialSpeedCam) {
                    if (settings.SPEAK_SPEED_CAMERA.get()) {
                        settings.SPEAK_SPEED_CAMERA.set(false);
                        confirmSpeedCamerasDlg();
                    }
                }
            }
        });
        return true;
    }
    return false;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) AutoZoomMap(net.osmand.plus.OsmandSettings.AutoZoomMap) ApplicationMode(net.osmand.plus.ApplicationMode) RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) ContextMenuItem(net.osmand.plus.ContextMenuItem) ViewGroup(android.view.ViewGroup) OsmandPreference(net.osmand.plus.OsmandSettings.OsmandPreference) View(android.view.View) TextView(android.widget.TextView) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 TextView (android.widget.TextView)2 ApplicationMode (net.osmand.plus.ApplicationMode)2 OsmandPreference (net.osmand.plus.OsmandSettings.OsmandPreference)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 ImageView (android.widget.ImageView)1 HashSet (java.util.HashSet)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 AutoZoomMap (net.osmand.plus.OsmandSettings.AutoZoomMap)1 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)1 RoutingParameter (net.osmand.router.GeneralRouter.RoutingParameter)1