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();
}
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;
}
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();
}
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;
}
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);
}
}
});
}
}
Aggregations