Fix sound button behavior remarks
This commit is contained in:
parent
f96681a68e
commit
5c49fd2aa5
6 changed files with 114 additions and 91 deletions
|
@ -148,8 +148,6 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
private File externalStorageDirectory;
|
||||
private boolean externalStorageDirectoryReadOnly;
|
||||
|
||||
private String firstSelectedVoiceProvider;
|
||||
|
||||
// Typeface
|
||||
|
||||
@Override
|
||||
|
@ -465,88 +463,16 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
boolean warningNoneProvider, Runnable run, boolean showDialog, boolean force, final boolean applyAllModes) {
|
||||
String voiceProvider = osmandSettings.VOICE_PROVIDER.getModeValue(applicationMode);
|
||||
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
|
||||
if (warningNoneProvider) {
|
||||
boolean nightMode = daynightHelper.isNightModeForMapControls();
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(uiContext, nightMode));
|
||||
|
||||
View view = UiUtilities.getInflater(uiContext, nightMode).inflate(R.layout.select_voice_first, null);
|
||||
|
||||
((ImageView) view.findViewById(R.id.icon))
|
||||
.setImageDrawable(getUIUtilities().getIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent()));
|
||||
|
||||
view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
routingOptionsHelper.selectVoiceGuidance((MapActivity) uiContext, new CallbackWithObject<String>() {
|
||||
@Override
|
||||
public boolean processResult(String result) {
|
||||
boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider);
|
||||
if (acceptableValue) {
|
||||
((TextView) v.findViewById(R.id.selectText))
|
||||
.setText(routingOptionsHelper.getVoiceProviderName(uiContext, result));
|
||||
firstSelectedVoiceProvider = result;
|
||||
}
|
||||
return acceptableValue;
|
||||
}
|
||||
}, applicationMode);
|
||||
}
|
||||
});
|
||||
|
||||
((ImageView) view.findViewById(R.id.dropDownIcon))
|
||||
.setImageDrawable(getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, getSettings().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)) {
|
||||
routingOptionsHelper.applyVoiceProvider((MapActivity) uiContext, firstSelectedVoiceProvider, applyAllModes);
|
||||
osmandSettings.VOICE_MUTE.setModeValue(applicationMode, false);
|
||||
}
|
||||
updateMuteButtons(uiContext);
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (applyAllModes) {
|
||||
muteVoiceForAllProfiles(uiContext);
|
||||
} else {
|
||||
osmandSettings.VOICE_PROVIDER.setModeValue(applicationMode, OsmandSettings.VOICE_PROVIDER_NOT_USE);
|
||||
osmandSettings.VOICE_MUTE.setModeValue(applicationMode, true);
|
||||
}
|
||||
updateMuteButtons(uiContext);
|
||||
}
|
||||
});
|
||||
|
||||
builder.setView(view);
|
||||
builder.show();
|
||||
if (warningNoneProvider && voiceProvider == null) {
|
||||
if (uiContext instanceof MapActivity) {
|
||||
((MapActivity) uiContext).showVoiceProviderDialog(applicationMode, applyAllModes);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice()) || force) {
|
||||
appInitializer.initVoiceDataInDifferentThread(uiContext, applicationMode, voiceProvider, run, showDialog);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateMuteButtons(Activity uiContext) {
|
||||
if (uiContext instanceof MapActivity) {
|
||||
((MapActivity) uiContext).getMapRouteInfoMenu().updateMenu();
|
||||
((MapActivity) uiContext).getMapRouteInfoMenu().updateOptions();
|
||||
}
|
||||
}
|
||||
|
||||
public void muteVoiceForAllProfiles(Activity uiContext) {
|
||||
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
|
||||
osmandSettings.VOICE_PROVIDER.setModeValue(mode, OsmandSettings.VOICE_PROVIDER_NOT_USE);
|
||||
osmandSettings.VOICE_MUTE.setModeValue(mode, true);
|
||||
if (uiContext instanceof MapActivity) {
|
||||
((MapActivity) uiContext).getMapRouteInfoMenu().updateMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NavigationService getNavigationService() {
|
||||
|
|
|
@ -39,11 +39,13 @@ import android.view.View;
|
|||
import android.view.ViewStub;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.SecondSplashScreenFragment;
|
||||
|
@ -81,6 +83,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
|
@ -110,6 +113,7 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
|||
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu;
|
||||
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.PlanRouteFragment;
|
||||
|
@ -122,6 +126,7 @@ import net.osmand.plus.resources.ResourceManager;
|
|||
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenuFragment;
|
||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
|
||||
import net.osmand.plus.routing.IRouteInformationListener;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
|
||||
|
@ -1083,6 +1088,77 @@ 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);
|
||||
}
|
||||
getMapRouteInfoMenu().updateMenu();
|
||||
}
|
||||
|
||||
private void dismissSecondSplashScreen() {
|
||||
if (SecondSplashScreenFragment.VISIBLE) {
|
||||
SecondSplashScreenFragment.VISIBLE = false;
|
||||
|
|
|
@ -494,13 +494,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
ApplicationMode mode = getRouteMode(from);
|
||||
//app.getSettings().APPLICATION_MODE.set(mode);
|
||||
app.getRoutingHelper().setAppMode(mode);
|
||||
String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(mode);
|
||||
if (voiceProvider == null) {
|
||||
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, showMenu);
|
||||
}
|
||||
if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
|
||||
app.muteVoiceForAllProfiles(mapActivity);
|
||||
}
|
||||
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, showMenu);
|
||||
// save application mode controls
|
||||
settings.FOLLOW_THE_ROUTE.set(false);
|
||||
app.getRoutingHelper().setFollowingMode(false);
|
||||
|
|
|
@ -160,6 +160,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
|
||||
private OnMarkerSelectListener onMarkerSelectListener;
|
||||
private StateChangedListener<Void> onStateChangedListener;
|
||||
private StateChangedListener<Boolean> voiceMuteChangeListener;
|
||||
@Nullable
|
||||
private View mainView;
|
||||
|
||||
|
@ -202,6 +203,12 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
updateMenu();
|
||||
}
|
||||
};
|
||||
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
|
||||
@Override
|
||||
public void stateChanged(Boolean change) {
|
||||
updateMenu();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void setMapActivity(@Nullable MapActivity mapActivity) {
|
||||
|
@ -305,6 +312,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
OsmandApplication app = getApp();
|
||||
if (app != null) {
|
||||
app.getTargetPointsHelper().addListener(onStateChangedListener);
|
||||
app.getSettings().VOICE_MUTE.addListener(voiceMuteChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,6 +320,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
OsmandApplication app = getApp();
|
||||
if (app != null) {
|
||||
app.getTargetPointsHelper().removeListener(onStateChangedListener);
|
||||
app.getSettings().VOICE_MUTE.removeListener(voiceMuteChangeListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -821,10 +830,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
|
|||
appMode.set(next);
|
||||
}
|
||||
routingHelper.setAppMode(next);
|
||||
String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(appMode.get());
|
||||
if (voiceProvider == null) {
|
||||
app.initVoiceCommandPlayer(mapActivity, next, true, null, false, false, true);
|
||||
}
|
||||
app.initVoiceCommandPlayer(mapActivity, next, true, null, false, false, true);
|
||||
routingHelper.recalculateRouteDueToSettingsChange();
|
||||
}
|
||||
}
|
||||
|
@ -1080,7 +1086,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)) {
|
||||
app.initVoiceCommandPlayer(mapActivity, appMode, true, null, true, false, false);
|
||||
mapActivity.showVoiceProviderDialog(appMode, false);
|
||||
} else {
|
||||
app.getRoutingOptionsHelper().switchSound();
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.widget.TextView;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndLocationSimulation;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -64,6 +65,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
@ColorRes
|
||||
private int selectedModeColorId;
|
||||
private MapActivity mapActivity;
|
||||
StateChangedListener<Boolean> voiceMuteChangeListener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -75,6 +77,12 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
mapActivity = getMapActivity();
|
||||
applicationMode = routingHelper.getAppMode();
|
||||
selectedModeColorId = applicationMode.getIconColorInfo().getColor(nightMode);
|
||||
voiceMuteChangeListener = new StateChangedListener<Boolean>() {
|
||||
@Override
|
||||
public void stateChanged(Boolean change) {
|
||||
updateParameters();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -117,6 +125,13 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
itemWithCompoundButton.setChecked(itemWithCompoundButton.isChecked());
|
||||
}
|
||||
}
|
||||
app.getSettings().VOICE_MUTE.addListener(voiceMuteChangeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
app.getSettings().VOICE_MUTE.removeListener(voiceMuteChangeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,7 +171,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)) {
|
||||
app.initVoiceCommandPlayer(mapActivity, applicationMode, true, null, true, false, true);
|
||||
mapActivity.showVoiceProviderDialog(applicationMode, false);
|
||||
} else {
|
||||
muteSoundItem[0].setChecked(!active);
|
||||
muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()));
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.osmand.plus.settings.preferences.ListPreferenceEx;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.plus.OsmandSettings.VOICE_PROVIDER_NOT_USE;
|
||||
import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
|
||||
import static net.osmand.plus.activities.SettingsNavigationActivity.MORE_VALUE;
|
||||
|
||||
|
@ -262,6 +263,11 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
|
|||
startActivity(intent);
|
||||
return false;
|
||||
} else if (newValue instanceof String) {
|
||||
if (VOICE_PROVIDER_NOT_USE.equals(newValue)) {
|
||||
settings.VOICE_MUTE.setModeValue(selectedMode, true);
|
||||
updateToolbar();
|
||||
setupPreferences();
|
||||
}
|
||||
settings.VOICE_PROVIDER.setModeValue(selectedMode, (String) newValue);
|
||||
app.initVoiceCommandPlayer(getActivity(), selectedMode, false, null, true, false, false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue