Search in sources :

Example 31 with ApplicationMode

use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.

the class SettingsNavigationActivity method createUI.

private void createUI() {
    addPreferencesFromResource(R.xml.navigation_settings);
    PreferenceScreen screen = getPreferenceScreen();
    settings = getMyApplication().getSettings();
    routerServicePreference = (ListPreference) screen.findPreference(settings.ROUTER_SERVICE.getId());
    RouteService[] vls = RouteService.getAvailableRouters(getMyApplication());
    String[] entries = new String[vls.length];
    for (int i = 0; i < entries.length; i++) {
        entries[i] = vls[i].getName();
    }
    registerListPreference(settings.ROUTER_SERVICE, screen, entries, vls);
    registerBooleanPreference(settings.SNAP_TO_ROAD, screen);
    Integer[] intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90 };
    entries = new String[intValues.length];
    entries[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < intValues.length; i++) {
        entries[i] = (int) intValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(settings.AUTO_FOLLOW_ROUTE, screen, entries, intValues);
    autoZoom = screen.findPreference("auto_zoom_map_on_off");
    autoZoom.setOnPreferenceClickListener(this);
    // keep informing option:
    Integer[] keepInformingValues = new Integer[] { 0, 1, 2, 3, 5, 7, 10, 15, 20, 25, 30 };
    String[] keepInformingNames = new String[keepInformingValues.length];
    keepInformingNames[0] = getString(R.string.keep_informing_never);
    for (int i = 1; i < keepInformingValues.length; i++) {
        keepInformingNames[i] = keepInformingValues[i] + " " + getString(R.string.int_min);
    }
    registerListPreference(settings.KEEP_INFORMING, screen, keepInformingNames, keepInformingValues);
    SpeedConstants[] speedValues = SpeedConstants.values();
    String[] speedNamesVls = new String[speedValues.length];
    for (int i = 0; i < speedValues.length; i++) {
        speedNamesVls[i] = speedValues[i].toHumanString(this);
    }
    ;
    registerListPreference(settings.SPEED_SYSTEM, screen, speedNamesVls, speedValues);
    // screen power save option:
    Integer[] screenPowerSaveValues = new Integer[] { 0, 5, 10, 15, 20, 30, 45, 60 };
    String[] screenPowerSaveNames = new String[screenPowerSaveValues.length];
    screenPowerSaveNames[0] = getString(R.string.shared_string_never);
    for (int i = 1; i < screenPowerSaveValues.length; i++) {
        screenPowerSaveNames[i] = screenPowerSaveValues[i] + " " + getString(R.string.int_seconds);
    }
    registerListPreference(settings.WAKE_ON_VOICE_INT, screen, screenPowerSaveNames, screenPowerSaveValues);
    // registerBooleanPreference(settings.SHOW_ZOOM_BUTTONS_NAVIGATION, screen);
    showAlarms = (Preference) screen.findPreference("show_routing_alarms");
    showAlarms.setOnPreferenceClickListener(this);
    speakAlarms = (Preference) screen.findPreference("speak_routing_alarms");
    speakAlarms.setOnPreferenceClickListener(this);
    Float[] arrivalValues = new Float[] { 1.5f, 1f, 0.5f, 0.25f };
    String[] arrivalNames = new String[] { getString(R.string.arrival_distance_factor_early), getString(R.string.arrival_distance_factor_normally), getString(R.string.arrival_distance_factor_late), getString(R.string.arrival_distance_factor_at_last) };
    registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues);
    // array size should be equal!
    Float[] speedLimitsKm = new Float[] { -10f, -7f, -5f, 0f, 5f, 7f, 10f, 15f, 20f };
    Float[] speedLimitsMiles = new Float[] { -7f, -5f, -3f, 0f, 3f, 5f, 7f, 10f, 15f };
    if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS) {
        String[] speedNames = new String[speedLimitsKm.length];
        for (int i = 0; i < speedLimitsKm.length; i++) {
            speedNames[i] = speedLimitsKm[i] + " " + getString(R.string.km_h);
        }
        registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
        registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNames, speedLimitsKm);
    } else {
        String[] speedNames = new String[speedLimitsKm.length];
        for (int i = 0; i < speedNames.length; i++) {
            speedNames[i] = speedLimitsMiles[i] + " " + getString(R.string.mile_per_hour);
        }
        registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimitsKm);
        registerListPreference(settings.SWITCH_MAP_DIRECTION_TO_COMPASS, screen, speedNames, speedLimitsKm);
    }
    PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences");
    speedLimitExceed = (ListPreference) category.findPreference("speed_limit_exceed");
    ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
    if (!mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        category.removePreference(speedLimitExceed);
    }
    if (getIntent() != null && getIntent().hasExtra(INTENT_SKIP_DIALOG)) {
        setSelectedAppMode(settings.getApplicationMode());
    } else {
        profileDialog();
    }
    addVoicePrefs((PreferenceGroup) screen.findPreference("voice"));
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SpeedConstants(net.osmand.plus.OsmandSettings.SpeedConstants) ApplicationMode(net.osmand.plus.ApplicationMode) PreferenceCategory(android.preference.PreferenceCategory) RouteService(net.osmand.plus.routing.RouteProvider.RouteService)

Example 32 with ApplicationMode

use of net.osmand.plus.ApplicationMode 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)

Example 33 with ApplicationMode

use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.

the class AppModeDialog method prepareAppModeView.

public static View prepareAppModeView(Activity a, final Set<ApplicationMode> selected, boolean showDefault, ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener) {
    OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
    final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));
    if (!showDefault) {
        values.remove(ApplicationMode.DEFAULT);
    }
    if (showDefault || (settings.getApplicationMode() != ApplicationMode.DEFAULT && !singleSelection)) {
        selected.add(settings.getApplicationMode());
    }
    return prepareAppModeView(a, values, selected, parent, singleSelection, useListBg, useMapTheme, onClickListener);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) ApplicationMode(net.osmand.plus.ApplicationMode) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 34 with ApplicationMode

use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.

the class AppModeDialog method prepareAppModeDrawerView.

// special method for drawer menu
// needed because if there's more than 4 items  - the don't fit in drawer
public static View prepareAppModeDrawerView(Activity a, final Set<ApplicationMode> selected, boolean useMapTheme, final View.OnClickListener onClickListener) {
    OsmandSettings settings = ((OsmandApplication) a.getApplication()).getSettings();
    final List<ApplicationMode> values = new ArrayList<ApplicationMode>(ApplicationMode.values(settings));
    selected.add(settings.getApplicationMode());
    return prepareAppModeView(a, values, selected, null, true, true, useMapTheme, onClickListener);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) ApplicationMode(net.osmand.plus.ApplicationMode) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 35 with ApplicationMode

use of net.osmand.plus.ApplicationMode in project Osmand by osmandapp.

the class AppModeDialog method updateButtonState.

private static void updateButtonState(final OsmandApplication ctx, final List<ApplicationMode> visible, final Set<ApplicationMode> selected, final View.OnClickListener onClickListener, final View[] buttons, int i, final boolean singleChoice, final boolean useMapTheme) {
    if (buttons[i] != null) {
        View tb = buttons[i];
        final ApplicationMode mode = visible.get(i);
        final boolean checked = selected.contains(mode);
        ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon);
        boolean nightMode = isNightMode(ctx, useMapTheme);
        if (checked) {
            iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), nightMode ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light));
            iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_checked)));
            tb.findViewById(R.id.selection).setVisibility(View.VISIBLE);
        } else {
            if (useMapTheme) {
                iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), R.color.route_info_unchecked_mode_icon_color));
                iv.setBackgroundResource(AndroidUtils.resolveAttribute(ctx, android.R.attr.selectableItemBackground));
            } else {
                iv.setImageDrawable(ctx.getIconsCache().getThemedIcon(mode.getSmallIconDark()));
            }
            iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_unchecked)));
            tb.findViewById(R.id.selection).setVisibility(View.INVISIBLE);
        }
        iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean isChecked = !checked;
                if (singleChoice) {
                    if (isChecked) {
                        selected.clear();
                        selected.add(mode);
                    }
                } else {
                    if (isChecked) {
                        selected.add(mode);
                    } else {
                        selected.remove(mode);
                    }
                }
                if (onClickListener != null) {
                    onClickListener.onClick(null);
                }
                for (int i = 0; i < visible.size(); i++) {
                    updateButtonState(ctx, visible, selected, onClickListener, buttons, i, singleChoice, useMapTheme);
                }
            }
        });
    }
}
Also used : ApplicationMode(net.osmand.plus.ApplicationMode) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

ApplicationMode (net.osmand.plus.ApplicationMode)41 View (android.view.View)13 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)7 OsmandApplication (net.osmand.plus.OsmandApplication)7 OsmandSettings (net.osmand.plus.OsmandSettings)7 AlertDialog (android.support.v7.app.AlertDialog)6 ArrayList (java.util.ArrayList)6 DialogInterface (android.content.DialogInterface)5 AdapterView (android.widget.AdapterView)5 LatLon (net.osmand.data.LatLon)5 Intent (android.content.Intent)4 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 File (java.io.File)3 OsmandPreference (net.osmand.plus.OsmandSettings.OsmandPreference)3 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)3 Uri (android.net.Uri)2 PreferenceCategory (android.preference.PreferenceCategory)2