From a907d30b3b894f65d15b056be658bd53f4a3b053 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 11 Feb 2020 17:17:49 +0100 Subject: [PATCH] Move out dialog to activity --- .../net/osmand/plus/OsmandApplication.java | 3 +- .../osmand/plus/activities/MapActivity.java | 69 --------------- .../activities/actions/OsmAndDialogs.java | 87 ++++++++++++++++++- .../MapRouteInfoMenu.java | 3 +- .../RouteOptionsBottomSheet.java | 3 +- .../RoutingOptionsHelper.java | 6 +- 6 files changed, 95 insertions(+), 76 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 7f729ca523..1fa59571b7 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -46,6 +46,7 @@ import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.ExitActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; +import net.osmand.plus.activities.actions.OsmAndDialogs; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.base.MapViewTrackingUtilities; @@ -465,7 +466,7 @@ public class OsmandApplication extends MultiDexApplication { if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { if (warningNoneProvider && voiceProvider == null) { if (uiContext instanceof MapActivity) { - ((MapActivity) uiContext).showVoiceProviderDialog(applicationMode, applyAllModes); + OsmAndDialogs.showVoiceProviderDialog((MapActivity) uiContext, applicationMode, applyAllModes); } } } else { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 8de45d0011..e775297667 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1090,75 +1090,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG); } - public void showVoiceProviderDialog(final ApplicationMode applicationMode, final boolean applyAllModes) { - boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); - final RoutingOptionsHelper routingOptionsHelper = app.getRoutingOptionsHelper(); - final AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(this, nightMode)); - final String[] firstSelectedVoiceProvider = new String[1]; - - View view = UiUtilities.getInflater(this, 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(MapActivity.this, new CallbackWithObject() { - @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(MapActivity.this, 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) { - muteVoiceForAllProfiles(); - } else { - settings.VOICE_PROVIDER.setModeValue(applicationMode, OsmandSettings.VOICE_PROVIDER_NOT_USE); - settings.VOICE_MUTE.setModeValue(applicationMode, true); - } - } - }); - - builder.setView(view); - builder.show(); - } - - private void muteVoiceForAllProfiles() { - for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { - settings.VOICE_PROVIDER.setModeValue(mode, OsmandSettings.VOICE_PROVIDER_NOT_USE); - settings.VOICE_MUTE.setModeValue(mode, true); - } - } private void dismissSecondSplashScreen() { if (SecondSplashScreenFragment.VISIBLE) { diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java b/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java index 76c13a358d..8f299ced53 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java @@ -5,7 +5,23 @@ import java.util.Map; import android.app.Activity; import android.app.Dialog; +import android.content.DialogInterface; import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.CallbackWithObject; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu; +import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; +import net.osmand.util.Algorithms; public class OsmAndDialogs { @@ -24,7 +40,76 @@ public class OsmAndDialogs { action.prepareDialog(activity, args, dlg); } } - + + + 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() { + @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(); + } public static void registerDialogAction(OsmAndAction action) { if(action.getDialogID() != 0) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 3455b10b40..be4ce89b3a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -62,6 +62,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.actions.AppModeDialog; +import net.osmand.plus.activities.actions.OsmAndDialogs; import net.osmand.plus.base.ContextMenuFragment.MenuState; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; @@ -1098,7 +1099,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (app != null) { String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(appMode); if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { - mapActivity.showVoiceProviderDialog(appMode, false); + OsmAndDialogs.showVoiceProviderDialog(mapActivity, appMode, false); } else { app.getRoutingOptionsHelper().switchSound(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 1e2d17777f..b7771fcf14 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -24,6 +24,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.actions.OsmAndDialogs; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; @@ -182,7 +183,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode); if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { - mapActivity.showVoiceProviderDialog(applicationMode, false); + OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false); } else { muteSoundItem[0].setChecked(!active); muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 3ae9748fb1..eae018184e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -187,13 +187,13 @@ public class RoutingOptionsHelper { public void applyVoiceProvider(MapActivity mapActivity, String provider, boolean applyAllModes) { OsmandApplication app = mapActivity.getMyApplication(); ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode(); + OsmandSettings.OsmandPreference VP = app.getSettings().VOICE_PROVIDER; if (applyAllModes) { for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { - app.getSettings().VOICE_PROVIDER.setModeValue(mode, provider); + VP.setModeValue(mode, provider); } - } else { - app.getSettings().VOICE_PROVIDER.setModeValue(selectedAppMode, provider); } + VP.setModeValue(selectedAppMode, provider); app.initVoiceCommandPlayer(mapActivity, selectedAppMode, false, null, true, false, applyAllModes); }