use of net.osmand.CallbackWithObject in project Osmand by osmandapp.
the class OsmandApplication method initVoiceCommandPlayer.
public void initVoiceCommandPlayer(final Activity uiContext, ApplicationMode applicationMode, boolean warningNoneProvider, Runnable run, boolean showDialog, boolean force) {
String voiceProvider = osmandSettings.VOICE_PROVIDER.get();
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
if (warningNoneProvider && voiceProvider == null) {
final AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
View view = uiContext.getLayoutInflater().inflate(R.layout.select_voice_first, null);
((ImageView) view.findViewById(R.id.icon)).setImageDrawable(getIconsCache().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) {
RoutePreferencesMenu.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(RoutePreferencesMenu.getVoiceProviderName(uiContext, result));
firstSelectedVoiceProvider = result;
}
return acceptableValue;
}
});
}
});
((ImageView) view.findViewById(R.id.dropDownIcon)).setImageDrawable(getIconsCache().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)) {
RoutePreferencesMenu.applyVoiceProvider((MapActivity) uiContext, firstSelectedVoiceProvider);
}
}
});
builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
osmandSettings.VOICE_PROVIDER.set(OsmandSettings.VOICE_PROVIDER_NOT_USE);
}
});
builder.setView(view);
builder.show();
}
} else {
if (player == null || !Algorithms.objectEquals(voiceProvider, player.getCurrentVoice()) || force) {
appInitializer.initVoiceDataInDifferentThread(uiContext, applicationMode, voiceProvider, run, showDialog);
}
}
}
Aggregations