Search in sources :

Example 1 with ApplicationMode

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

the class OsmAndDialogs method showVoiceProviderDialog.

public static void showVoiceProviderDialog(final MapActivity activity, final ApplicationMode applicationMode, final boolean applyAllModes) {
    OsmandApplication app = activity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    final RoutingOptionsHelper routingOptionsHelper = app.getRoutingOptionsHelper();
    final AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
    final String[] firstSelectedVoiceProvider = new String[1];
    View view = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.select_voice_first, null);
    ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, settings.isLightContent()));
    view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            routingOptionsHelper.selectVoiceGuidance(activity, new CallbackWithObject<String>() {

                @Override
                public boolean processResult(String result) {
                    boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider[0]);
                    if (acceptableValue) {
                        ((TextView) v.findViewById(R.id.selectText)).setText(routingOptionsHelper.getVoiceProviderName(v.getContext(), result));
                        firstSelectedVoiceProvider[0] = result;
                    }
                    return acceptableValue;
                }
            }, applicationMode);
        }
    });
    ((ImageView) view.findViewById(R.id.dropDownIcon)).setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, settings.isLightContent()));
    builder.setCancelable(true);
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (!Algorithms.isEmpty(firstSelectedVoiceProvider[0])) {
                routingOptionsHelper.applyVoiceProvider(activity, firstSelectedVoiceProvider[0], applyAllModes);
                if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(firstSelectedVoiceProvider[0])) {
                    settings.VOICE_MUTE.setModeValue(applicationMode, true);
                } else {
                    settings.VOICE_MUTE.setModeValue(applicationMode, false);
                }
            }
        }
    });
    builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            if (applyAllModes) {
                for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
                    // if (!settings.VOICE_PROVIDER.isSetForMode(mode)) {
                    settings.VOICE_PROVIDER.setModeValue(mode, OsmandSettings.VOICE_PROVIDER_NOT_USE);
                    settings.VOICE_MUTE.setModeValue(mode, true);
                // }
                }
            }
            settings.VOICE_PROVIDER.setModeValue(applicationMode, OsmandSettings.VOICE_PROVIDER_NOT_USE);
            settings.VOICE_MUTE.setModeValue(applicationMode, true);
        }
    });
    builder.setView(view);
    builder.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) RoutingOptionsHelper(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper) CallbackWithObject(net.osmand.CallbackWithObject) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 2 with ApplicationMode

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

the class MapActivityActions method createSwitchProfileOptionsMenu.

private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
    drawerMode = DRAWER_MODE_NORMAL;
    createProfilesController(app, optionsMenuHelper, nightMode, true);
    List<ApplicationMode> activeModes = ApplicationMode.values(app);
    ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
    String modeDescription;
    Map<String, ProfileDataObject> profilesObjects = routingDataUtils.getRoutingProfiles();
    for (final ApplicationMode appMode : activeModes) {
        if (appMode.isCustomProfile()) {
            modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_user_string));
        } else {
            modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_osmand_string));
        }
        int tag = currentMode.equals(appMode) ? PROFILES_CHOSEN_PROFILE_TAG : PROFILES_NORMAL_PROFILE_TAG;
        optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item).setIcon(appMode.getIconRes()).setColor(appMode.getProfileColor(nightMode)).setTag(tag).setTitle(appMode.toHumanString()).setDescription(modeDescription).setListener(new ItemClickListener() {

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
                app.getSettings().setApplicationMode(appMode);
                updateDrawerMenu();
                return false;
            }
        }).createItem());
    }
    optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item).setColor(ColorUtilities.getActiveColor(app, nightMode)).setTag(PROFILES_CONTROL_BUTTON_TAG).setTitle(getString(R.string.shared_string_manage)).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
            BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS);
            return true;
        }
    }).createItem());
    return optionsMenuHelper;
}
Also used : ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItemClickListener(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) FavouritePoint(net.osmand.data.FavouritePoint) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ProfileDataObject(net.osmand.plus.profiles.data.ProfileDataObject)

Example 3 with ApplicationMode

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

the class SearchScreen method onRouteSelected.

private void onRouteSelected(@NonNull SearchResult sr) {
    OsmandApplication app = getApp();
    if (sr.objectType == ObjectType.ROUTE) {
        ApplicationMode lastAppMode = app.getSettings().LAST_ROUTE_APPLICATION_MODE.get();
        ApplicationMode currentAppMode = app.getRoutingHelper().getAppMode();
        if (lastAppMode == ApplicationMode.DEFAULT) {
            lastAppMode = currentAppMode;
        }
        updateApplicationMode(currentAppMode, lastAppMode);
        app.getTargetPointsHelper().restoreTargetPoints(true);
    }
    app.getOsmandMap().getMapLayers().getMapControlsLayer().startNavigation();
    finish();
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode)

Example 4 with ApplicationMode

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

the class AppModeDialog method prepareAppModeView.

public static View prepareAppModeView(Activity a, final List<ApplicationMode> values, final Set<ApplicationMode> selected, ViewGroup parent, final boolean singleSelection, boolean useListBg, boolean useMapTheme, final View.OnClickListener onClickListener, boolean nightMode) {
    OsmandApplication app = (OsmandApplication) a.getApplication();
    final View ll = a.getLayoutInflater().inflate(R.layout.mode_toggles, parent);
    if (useListBg) {
        AndroidUtils.setListItemBackground(a, ll, nightMode);
    } else {
        ll.setBackgroundColor(ContextCompat.getColor(a, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
    }
    final View[] buttons = new View[values.size()];
    int k = 0;
    for (ApplicationMode ma : values) {
        buttons[k++] = createToggle(a.getLayoutInflater(), app, R.layout.mode_view, (LinearLayout) ll.findViewById(R.id.app_modes_content), ma, useMapTheme);
    }
    for (int i = 0; i < buttons.length; i++) {
        updateButtonState(app, values, selected, onClickListener, buttons, i, singleSelection, useMapTheme, nightMode);
    }
    ApplicationMode activeMode = app.getSettings().getApplicationMode();
    final int idx = values.indexOf(activeMode);
    OnGlobalLayoutListener globalListener = new OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            HorizontalScrollView scrollView = ll.findViewById(R.id.app_modes_scroll_container);
            LinearLayout container = ll.findViewById(R.id.app_modes_content);
            int s = container.getChildAt(idx) != null ? container.getChildAt(idx).getRight() : 0;
            scrollView.scrollTo(Math.max(s - scrollView.getWidth(), 0), 0);
            if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
                ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                ll.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    };
    ll.getViewTreeObserver().addOnGlobalLayoutListener(globalListener);
    return ll;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) HorizontalScrollView(android.widget.HorizontalScrollView) LinearLayout(android.widget.LinearLayout)

Example 5 with ApplicationMode

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

the class AppModeDialog method updateButtonStateForRoute.

public static void updateButtonStateForRoute(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, final boolean nightMode) {
    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);
        ImageView selection = tb.findViewById(R.id.selection);
        Drawable drawable = ctx.getUIUtilities().getPaintedIcon(mode.getIconRes(), mode.getProfileColor(nightMode));
        if (checked) {
            iv.setImageDrawable(drawable);
            iv.setContentDescription(String.format("%s %s", mode.toHumanString(), ctx.getString(R.string.item_checked)));
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                selection.setImageDrawable(ctx.getDrawable(R.drawable.btn_checked_border_light));
                AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.ripple_light, R.drawable.ripple_light);
            } else {
                AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_light);
            }
        } else {
            if (useMapTheme) {
                if (Build.VERSION.SDK_INT >= 21) {
                    Drawable active = ctx.getUIUtilities().getPaintedIcon(mode.getIconRes(), mode.getProfileColor(nightMode));
                    drawable = AndroidUtils.createPressedStateListDrawable(drawable, active);
                }
                iv.setImageDrawable(drawable);
                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                    selection.setImageDrawable(ctx.getDrawable(R.drawable.btn_border_pressed_light));
                    AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.ripple_light, R.drawable.ripple_light);
                } else {
                    AndroidUtils.setBackground(ctx, selection, nightMode, R.drawable.btn_border_pressed_trans_light, R.drawable.btn_border_pressed_trans_light);
                }
            } else {
                iv.setImageDrawable(ctx.getUIUtilities().getPaintedIcon(mode.getIconRes(), mode.getProfileColor(nightMode)));
            }
            iv.setContentDescription(String.format("%s %s", mode.toHumanString(), ctx.getString(R.string.item_unchecked)));
        }
        tb.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++) {
                    updateButtonStateForRoute(ctx, visible, selected, onClickListener, buttons, i, singleChoice, useMapTheme, nightMode);
                }
            }
        });
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View)

Aggregations

ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)163 View (android.view.View)35 OsmandApplication (net.osmand.plus.OsmandApplication)33 ArrayList (java.util.ArrayList)28 ImageView (android.widget.ImageView)27 TextView (android.widget.TextView)27 MapActivity (net.osmand.plus.activities.MapActivity)26 Context (android.content.Context)17 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)16 Drawable (android.graphics.drawable.Drawable)15 LatLon (net.osmand.data.LatLon)15 RoutingHelper (net.osmand.plus.routing.RoutingHelper)15 List (java.util.List)13 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)13 Nullable (androidx.annotation.Nullable)11 SuppressLint (android.annotation.SuppressLint)10 FragmentManager (androidx.fragment.app.FragmentManager)10 DialogInterface (android.content.DialogInterface)9 AlertDialog (androidx.appcompat.app.AlertDialog)9 WptPt (net.osmand.GPXUtilities.WptPt)9