Move out dialog to activity
This commit is contained in:
parent
7ab05ae877
commit
a907d30b3b
6 changed files with 95 additions and 76 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<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() {
|
||||
if (SecondSplashScreenFragment.VISIBLE) {
|
||||
|
|
|
@ -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<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) {
|
||||
if(action.getDialogID() != 0) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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<String> 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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue