Move out dialog to activity

This commit is contained in:
Victor Shcherb 2020-02-11 17:17:49 +01:00
parent 7ab05ae877
commit a907d30b3b
6 changed files with 95 additions and 76 deletions

View file

@ -46,6 +46,7 @@ import net.osmand.plus.activities.DayNightHelper;
import net.osmand.plus.activities.ExitActivity; import net.osmand.plus.activities.ExitActivity;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.actions.OsmAndDialogs;
import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPI;
import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.api.SQLiteAPIImpl;
import net.osmand.plus.base.MapViewTrackingUtilities; 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 (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
if (warningNoneProvider && voiceProvider == null) { if (warningNoneProvider && voiceProvider == null) {
if (uiContext instanceof MapActivity) { if (uiContext instanceof MapActivity) {
((MapActivity) uiContext).showVoiceProviderDialog(applicationMode, applyAllModes); OsmAndDialogs.showVoiceProviderDialog((MapActivity) uiContext, applicationMode, applyAllModes);
} }
} }
} else { } else {

View file

@ -1090,75 +1090,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG); 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<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(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() { private void dismissSecondSplashScreen() {
if (SecondSplashScreenFragment.VISIBLE) { if (SecondSplashScreenFragment.VISIBLE) {

View file

@ -5,7 +5,23 @@ import java.util.Map;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; 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 { public class OsmAndDialogs {
@ -26,6 +42,75 @@ public class OsmAndDialogs {
} }
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();
}
public static void registerDialogAction(OsmAndAction action) { public static void registerDialogAction(OsmAndAction action) {
if(action.getDialogID() != 0) { if(action.getDialogID() != 0) {
dialogActions.put(action.getDialogID(), action); dialogActions.put(action.getDialogID(), action);

View file

@ -62,6 +62,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.actions.AppModeDialog; 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.base.ContextMenuFragment.MenuState;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
@ -1098,7 +1099,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (app != null) { if (app != null) {
String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(appMode); String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(appMode);
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
mapActivity.showVoiceProviderDialog(appMode, false); OsmAndDialogs.showVoiceProviderDialog(mapActivity, appMode, false);
} else { } else {
app.getRoutingOptionsHelper().switchSound(); app.getRoutingOptionsHelper().switchSound();
} }

View file

@ -24,6 +24,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.actions.OsmAndDialogs;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
@ -182,7 +183,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active);
String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode); String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode);
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
mapActivity.showVoiceProviderDialog(applicationMode, false); OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false);
} else { } else {
muteSoundItem[0].setChecked(!active); muteSoundItem[0].setChecked(!active);
muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()));

View file

@ -187,13 +187,13 @@ public class RoutingOptionsHelper {
public void applyVoiceProvider(MapActivity mapActivity, String provider, boolean applyAllModes) { public void applyVoiceProvider(MapActivity mapActivity, String provider, boolean applyAllModes) {
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode(); ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode();
OsmandSettings.OsmandPreference<String> VP = app.getSettings().VOICE_PROVIDER;
if (applyAllModes) { if (applyAllModes) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { 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); app.initVoiceCommandPlayer(mapActivity, selectedAppMode, false, null, true, false, applyAllModes);
} }